<?php
namespace Cms\ContainerBundle\Controller;
use App\Component\Blobs\BlobManagers\DepartmentBlobManager;
use Cms\ContainerBundle\Doctrine\ContainerRepository;
use Cms\ContainerBundle\Doctrine\NestedContainerRepository;
use Cms\ContainerBundle\Entity\Container;
use Cms\ContainerBundle\Entity\Containers\GenericContainer;
use Cms\ContainerBundle\Entity\Containers\IntranetContainer;
use Cms\ContainerBundle\Entity\Containers\PersonalContainer;
use Cms\ContainerBundle\Form\Type\Container\GenericContainerType;
use Cms\ContainerBundle\Form\Type\Container\IntranetContainerType;
use Cms\ContainerBundle\Form\Type\Container\PersonalContainerType;
use Cms\ContainerBundle\Form\Type\ContainerFaviconType;
use Cms\ContainerBundle\Form\Type\ContainerRobotsType;
use Cms\ContainerBundle\Form\Type\ContainerSitemapType;
use Cms\ContainerBundle\Form\Type\ContainerThemeType;
use Cms\ContainerBundle\Service\ContainerService;
use Cms\CoreBundle\Model\Scenes\DashboardScenes\DocumentScene;
use Cms\ContainerBundle\Form\Type\ContainerAssignType;
use Cms\ContainerBundle\Form\Type\ContainerMoveType;
use Cms\CoreBundle\Util\Controller;
use Cms\CoreBundle\Util\DateTimeUtils;
use Cms\CoreBundle\Util\Doctrine\EntityManager;
use Cms\FileBundle\Controller\DashboardController as CmsDashboardController;
use Cms\FileBundle\Entity\Nodes\Folder;
use Cms\FrontendBundle\Controller\CatchallController;
use Cms\ModuleBundle\Controller\ContentController;
use Cms\Modules\PageBundle\Entity\Page\PageHistory;
use Cms\Modules\PageBundle\Entity\Page\PageProxy;
use Cms\NavigationBundle\Controller\DefaultController;
use Cms\SitebuilderBundle\Model\DeployOptions;
use Cms\SitebuilderBundle\Service\WorksheetBuilder;
use Cms\SitebuilderBundle\Util\Deployer;
use Doctrine\Common\Util\ClassUtils;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
/**
* Class ContainerController
* @package Cms\ContainerBundle\Controller
*/
final class ContainerController extends Controller
{
const ROUTES__INDEX = 'cms.container.dashboard.container.index';
const ROUTES__INDEX_GENERIC = 'cms.container.dashboard.container.index_generic';
const ROUTES__INDEX_PERSONAL = 'cms.container.dashboard.container.index_personal';
const ROUTES__INDEX_INTRANET = 'cms.container.dashboard.container.index_intranet';
const ROUTES__VIEW = 'cms.container.dashboard.container.view';
const ROUTES__CREATE_TYPED = 'cms.container.dashboard.container.create_typed';
const ROUTES__CREATE_CHILD = 'cms.container.dashboard.container.create_child';
const ROUTES__EDIT = 'cms.container.dashboard.container.edit';
const ROUTES__TOGGLE_HIDDEN = 'cms.container.dashboard.container.toggle_hidden';
const ROUTES__MOVE = 'cms.container.dashboard.container.move';
const ROUTES__DELETE = 'cms.container.dashboard.container.delete';
const ROUTES__MODULES = 'cms.container.dashboard.container.modules';
const ROUTES__ASSIGN = 'cms.container.dashboard.container.assign';
const ROUTES__FAVICON = 'cms.container.dashboard.domain.favicon';
const ROUTES__ROBOTS = 'cms.container.dashboard.domain.robots';
const ROUTES__SITEMAP = 'cms.container.dashboard.domain.sitemap';
const ROUTES__NAVIGATION = DefaultController::ROUTES__EDIT;
const ROUTES__FAVORITE_CREATE = 'cms.container.dashboard.container.favorite_create';
const ROUTES__FAVORITE_DELETE = 'cms.container.dashboard.container.favorite_delete';
const ROUTES__THEME = 'cms.container.dashboard.container.theme';
const ROUTES__WORKSHEET = 'cms.container.dashboard.container.worksheet';
/**
* @return ContainerRepository
*/
private function getContainerRepository()
{
return $this->getEntityManager()->getRepository(Container::class);
}
/**
* @param Container $container
*/
private function reorder(Container $container)
{
// get the gedmo tree repo for containers
/** @var NestedContainerRepository $repo */
$repo = $this->getEntityManager()->getCustomRepository(
NestedContainerRepository::class,
Container::class
);
// NOTE: it is important that we do not verify, otherwise it would take a long time to complete
$repo->reorder($container, 'name', 'ASC', false);
}
/**
* @param string $containerId
* @return Response
*
* @Route(
* "/{containerId}/worksheet",
* name = ContainerController::ROUTES__WORKSHEET,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function worksheetAction($containerId)
{
// get us
$container = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $container::DISCR . '.manage',
array($container, $container)
);
// build
$data = $this->getWorksheetBuilder()->build($container);
// done
return new Response(
$data,
200,
array(
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'Content-Disposition' => sprintf(
'%s; filename="%s__worksheet__%s.xlsx"',
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$container->getTenant()->getSlug(),
$container->getSlug()
),
)
);
}
/**
* @param Request $request
* @param string $containerId
* @return DocumentScene|RedirectResponse
*
* @Route(
* "/{containerId}/theme",
* name = ContainerController::ROUTES__THEME,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function themeAction(Request $request, $containerId)
{
// get us
$container = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $container::DISCR . '.manage',
array($container, $container)
);
// get the starting theme
$theme = $container->getDefaultTheme();
// create a form
$form = $this->createForm(ContainerThemeType::class, $container);
// check for submission
if ($this->handleForm($form, $request)) {
// if the theme changed, we need to clear the inner and outers set on the container
if ($container->getDefaultTheme() !== $theme || $container->getDefaultTheme() === null) {
$container->setDefaultOuterLayout(null);
if ($container->getDefaultInnerLayout() && $container->getDefaultInnerLayout()->getTheme() !== null) {
$container->setDefaultInnerLayout(null);
}
}
// save to db
$this->getEntityManager()->save($container);
// must log this action
$this->getActivityLogger()->createLog($container);
// redirect to the index
return $this->redirectToRoute(self::ROUTES__VIEW, array(
'containerId' => $container->getId()
));
}
// html view stuff
return $this->view(
array(
'current' => $container,
'parent' => $container->getParent(),
'form' => $form->createView(),
)
);
}
/**
* @param Request $request
* @param string $containerId
* @return RedirectResponse
* @throws \Exception
*
* @Route(
* "/{containerId}/like",
* name = ContainerController::ROUTES__FAVORITE_CREATE,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function favoriteCreateAction(Request $request, $containerId)
{
// get the container
$container = $this->getContainerRepository()->findExact($containerId);
// get the current account and try to find a favorite already for this
$account = $this->getGlobalContext()->getEffectiveAccount();
if ( ! $account->getFavorites()->contains($container)) {
$account->addFavorite($container);
$this->getEntityManager()->save($account);
}
// attempt to redirect to where we came from, or a default location otherwise
$redirect = $request->headers->get('Referer');
if (empty($redirect)) {
$redirect = $this->generateUrl(
self::ROUTES__VIEW,
array(
'containerId' => $containerId,
)
);
}
// perform the redirect
return new RedirectResponse($redirect);
}
/**
* @param Request $request
* @param string $containerId
* @return RedirectResponse
* @throws \Exception
*
* @Route(
* "/{containerId}/unlike",
* name = ContainerController::ROUTES__FAVORITE_DELETE,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function favoriteDeleteAction(Request $request, $containerId)
{
// get the current container
$container = $this->getContainerRepository()->findExact($containerId);
// try to find existing favorite
$account = $this->getGlobalContext()->getEffectiveAccount();
$account->removeFavorite($container);
$this->getEntityManager()->save($account);
$redirect = $request->headers->get('Referer');
if (empty($redirect)) {
$redirect = $this->generateUrl(
self::ROUTES__VIEW,
array(
'containerId' => $containerId,
)
);
}
// perform the redirect
return new RedirectResponse($redirect);
}
/**
* @param string $type
* @return array|Container[]
* @throws \Exception
*/
private function findRoots($type)
{
switch (true) {
case $type === GenericContainer::DISCR:
return $this->getEntityManager()->getRepository(GenericContainer::class)->findAllRoots();
case $type === PersonalContainer::DISCR:
return $this->getEntityManager()->getRepository(PersonalContainer::class)->findAllRootsForAccount(
$this->getGlobalContext()->getEffectiveAccount()
);
case $type === IntranetContainer::DISCR:
return $this->getEntityManager()->getRepository(IntranetContainer::class)->findAllRoots();
}
throw new \Exception();
}
/**
* @param string $type
* @return DocumentScene
* @throws \Exception
*
*
* @Route(
* "/",
* name = ContainerController::ROUTES__INDEX,
* defaults = {
* "type" = "generic"
* }
* )
* @Route(
* "/generic",
* name = ContainerController::ROUTES__INDEX_GENERIC,
* defaults = {
* "type" = "generic"
* }
* )
* @Route(
* "/personal",
* name = ContainerController::ROUTES__INDEX_PERSONAL,
* defaults = {
* "type" = "personal"
* }
* )
* @Route(
* "/intranet",
* name = ContainerController::ROUTES__INDEX_INTRANET,
* defaults = {
* "type" = "intranet"
* }
* )
*/
public function indexAction($type)
{
// get roots for type
$roots = $this->findRoots($type);
// html work
return $this->view(
array(
'type' => $type,
'roots' => $roots,
// TODO: do we need this for any view anymore?
'routes' => array(
'files' => CmsDashboardController::ROUTES__LIST_CHILDREN,
),
)
);
}
/**
* @param string $type
* @return string
* @throws \Exception
*/
private function determineClass($type)
{
switch ($type) {
case GenericContainer::DISCR:
return GenericContainer::class;
case PersonalContainer::DISCR:
return PersonalContainer::class;
case IntranetContainer::DISCR:
return IntranetContainer::class;
}
throw new \Exception();
}
/**
* @param string $type
* @return string
* @throws \Exception
*/
private function determineForm($type)
{
switch ($type) {
case GenericContainer::DISCR:
return GenericContainerType::class;
case PersonalContainer::DISCR:
return PersonalContainerType::class;
case IntranetContainer::DISCR:
return IntranetContainerType::class;
}
throw new \Exception();
}
private function onCreate(Container $container, FormInterface $form)
{
switch (true) {
// generic containers
case $container instanceof GenericContainer:
case $container instanceof IntranetContainer:
// just generate the default things for a "blank" container
$this->getEntityManager()->persistAll($this->generateDefaultContainerEntities($container));
break;
// personal container stuff
case $container instanceof PersonalContainer:
// set the account, if there is a parent, use that, otherwise, use current user
if ( ! empty ($container->getParent())) {
$container->setAccount($container->getParent()->getAccount());
} else {
$container->setAccount($this->getGlobalContext()->getEffectiveAccount());
}
// handle deployment of siteplan for model selection
if (empty($container->getParent()) && $form->has('model') && ! empty($form->get('model')->getData())) {
$this->getEntityManager()->persistAll(
$this->getDeployer()->deploy(
$form->get('model')->getData(),
(new DeployOptions(PersonalContainer::DISCR))
->setExisting($container)
)
);
} else {
$this->getEntityManager()->persistAll($this->generateDefaultContainerEntities($container));
}
break;
}
}
/**
* @param Request $request
* @param string $type
* @param string $containerId
* @return DocumentScene|RedirectResponse
* @throws \Exception
*
* @Route(
* "/create/{type}",
* name = ContainerController::ROUTES__CREATE_TYPED,
* requirements = {
* "type" = "generic|personal|intranet"
* }
* )
* @Route(
* "/{containerId}/create",
* name = ContainerController::ROUTES__CREATE_CHILD,
* requirements = {
* "containerId" = "[0-9]+"
* }
* )
*/
public function createAction(Request $request, $type = null, $containerId = null)
{
// enforce parent if doing a child
$parent = null;
if ( ! empty($containerId)) {
$parent = $this->getContainerRepository()->findExact($containerId);
}
// enforce type of container getting created
$cls = null;
switch (true) {
// no type and no parent, this is a problem
case (empty($type) && empty($parent)):
throw new \Exception();
// we have a type and no parent, so creating a root of a certain type
case ( ! empty($type) && empty($parent)):
$cls = $this->determineClass($type);
break;
// we have a parent given, child must be the parent type no matter what; but type should be empty
case (empty($type) && ! empty($parent)):
$cls = ClassUtils::getClass($parent);
break;
// we have a parent given and a type, this is a bad combo of parameters
case ( ! empty($type) && ! empty($parent)):
throw new \Exception();
}
// just double check typing is correct
switch (true) {
case empty($cls):
case ! class_exists($cls):
case ! is_subclass_of($cls, Container::class):
case ( ! empty($parent) && ClassUtils::getClass($parent) !== $cls):
throw new \Exception();
}
// create new of that type
/** @var Container $new */
$new = new $cls();
// AUDIT
$this->denyAccessUnlessGranted(
array_filter([
($new instanceof PersonalContainer) ? 'campussuite.cms.me.sites' : null,
'campussuite.cms.container.' . $new::DISCR . '.manage',
]),
$parent
);
// create a form
$form = $this->createForm(
$this->determineForm($new::DISCR),
$new,
array('isRoot' => empty($parent))
);
// check for post
if ($this->handleForm($form, $request)) {
// attach parent if any
if ( ! empty($parent)) {
$new->setParent($parent);
}
// save to db in transaction as we may do other things as well
$this->getEntityManager()->transactional(
function (EntityManager $em) use ($new, $form, $parent) {
// persist the new thing being created
$em->persist($new);
// call any special handling logic for container creation
$this->onCreate($new, $form);
// things should be persisted, flush them now to save them all to db
$em->flush();
// reorder containers so they show up in lists correctly
$this->reorder(( ! empty($parent)) ? $parent : $new);
}
);
// must log this action
$this->getActivityLogger()->createLog($new);
// redirect based on whether we made a root or a child
if ( ! empty($parent)) {
$redirect = $this->redirectToRoute(
self::ROUTES__VIEW,
array(
'containerId' => $parent->getId(),
)
);
} else {
switch ($type) {
case GenericContainer::DISCR:
$route = self::ROUTES__INDEX;
break;
case PersonalContainer::DISCR:
$route = self::ROUTES__INDEX_PERSONAL;
break;
case IntranetContainer::DISCR:
$route = self::ROUTES__INDEX_INTRANET;
break;
default:
$route = self::ROUTES__INDEX;
}
$redirect = $this->redirectToRoute($route);
}
return $redirect;
}
// html view stuff
return $this->view(
array(
'form' => $form->createView(),
'type' => $type,
'parent' => $parent,
)
);
}
/**
* @param string $containerId
* @return RedirectResponse
*
* @Route(
* "/{containerId}/hidden",
* name = ContainerController::ROUTES__TOGGLE_HIDDEN,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function toggleHiddenAction($containerId)
{
// enforce container
$current = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
array(
'campussuite.cms.container.' . $current::DISCR . '.manage',
),
array($current, $current)
);
// toggle and save to db
$this->getEntityManager()->save(
$current->setHidden( ! $current->isHidden())
);
// redirect back to view page
return $this->redirectToRoute(
self::ROUTES__VIEW,
array(
'containerId' => $current->getParent()->getId(),
)
);
}
/**
* @param Request $request
* @param string $containerId
* @return DocumentScene|RedirectResponse
* @throws \Exception
*
* @Route(
* "/{containerId}/edit",
* name = ContainerController::ROUTES__EDIT,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function editAction(Request $request, $containerId)
{
// enforce container
$current = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
array(
'campussuite.cms.container.' . $current::DISCR . '.manage',
),
array($current, $current)
);
// grab the parent
$parent = $current->getParent();
// create a form
$form = $this->createForm(
$this->determineForm($current::DISCR),
$current,
array('isRoot' => empty($parent))
);
// check for post
if ($this->handleForm($form, $request)) {
// wrap in a transaction
$this->getEntityManager()->transactional(
function (EntityManager $em) use ($current, $parent) {
// save to db
$em->save($current);
// handle reordering
$this->reorder(( ! empty($parent)) ? $parent : $current);
}
);
// must log action
$this->getActivityLogger()->createLog($current);
// redirect back to view page
return $this->redirectToRoute(
self::ROUTES__VIEW,
array(
'containerId' => $current->getId(),
)
);
}
// html view stuff
return $this->view(
array(
'current' => $current,
'parent' => $parent,
'form' => $form->createView(),
)
);
}
/**
* @param string $containerId
* @return DocumentScene|RedirectResponse
*
* @Route(
* "/{containerId}",
* name = ContainerController::ROUTES__VIEW,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function viewAction($containerId)
{
// enforce container
$current = $this->getContainerRepository()->findExact($containerId);
// get the parent
$parent = $current->getParent();
// get all immediate child containers
$things = $current->getChildren();
// if there are no roots, redirect to the pages listing
if (count($things) === 0) {
return $this->redirectToRoute(
ContentController::ROUTES__PROXY_LIST,
array(
'container' => $containerId,
'module' => 'page',
)
);
}
$favorite = ($this->getGlobalContext()->getEffectiveAccount()
->getFavorites()
->contains($current)) ? $current : null;
// get the ancestors
$ancestors = $this->getContainerRepository()->findAncestors($current);
// html view stuff
return $this->view(
array(
'all' => $this->getContainerRepository()->findAllHierarchy($current),
'current' => $current,
'favorites' => $this->getGlobalContext()->getEffectiveAccount()->getFavorites(),
'favorite' => $favorite,
'ancestors' => $ancestors,
'parent' => $parent,
'things' => $things,
'routes' => array(
'list_children' => CmsDashboardController::ROUTES__LIST_CHILDREN,
'list_roots' => CmsDashboardController::ROUTES__LIST_ROOTS,
'proxy_list' => ContentController::ROUTES__PROXY_LIST,
'proxy_create' => ContentController::ROUTES__PROXY_CREATE,
'public_personal' => CatchallController::ROUTES__PERSONAL,
),
)
);
}
/**
* @param Request $request
* @param string $containerId
* @return DocumentScene|RedirectResponse
* @throws \Exception
*
* @Route(
* "/{containerId}/move",
* name = ContainerController::ROUTES__MOVE,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function moveAction(Request $request, $containerId)
{
// find the container
$container = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
array(
'campussuite.cms.container.' . $container::DISCR . '.manage',
),
array($container, $container)
);
// track the old parent
$old = $container->getParent();
if ($old === null) {
throw new \Exception('This domain cannot be moved');
}
// build form
$form = $this->createForm(ContainerMoveType::class, $container, []);
// check for post
if ($request->isMethod(Request::METHOD_POST)) {
// process form
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// get the new parent
$new = $container->getParent();
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $new::DISCR . '.manage',
array($new, $new)
);
// wrap in a db transaction
$this->getEntityManager()->transactional(
function (EntityManager $em) use ($container, $old, $new) {
// save
$em->save($container);
// handle reordering
if ( ! empty($old)) {
$this->reorder($old);
}
$em->flush();
if ( ! empty($new)) {
$this->reorder($new);
}
}
);
$this->addFlash('success', 'Department "' . $container->getName() . '" was moved.');
// record log
$this->getActivityLogger()->createLog($container);
// redirect to parent index
return $this->redirectToRoute(
self::ROUTES__VIEW,
array(
'containerId' => $container->getParent()->getId()
)
);
}
}
// html view stuff
return $this->view(
array(
'current' => $container,
'form' => $form->createView(),
)
);
}
/**
* @param Request $request
* @param string $containerId
* @return DocumentScene|RedirectResponse
*
* @Route(
* "/{containerId}/delete",
* name = ContainerController::ROUTES__DELETE,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function deleteAction(Request $request, $containerId)
{
// find the container
$current = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
array(
'campussuite.cms.container.' . $current::DISCR . '.manage',
),
array($current, $current)
);
// get parent and type
$type = $current::DISCR;
$parent = $current->getParent();
// get the direct children of this department
$children = $this->getEntityManager()->getRepository(ClassUtils::getClass($current))->findBy(
array(
'parent' => $current,
),
array(
'name' => 'ASC',
)
);
// check for submission
if ($this->handleSecureDelete($request)) {
// if we are a root, and we have children, prevent the deletion
if (empty($current->getParent()) && ! empty($children)) {
throw new \Exception();
}
// wrap in a transaction
$this->getEntityManager()->transactional(
function (EntityManager $em) use ($current, $parent) {
// run the deletion
$em->delete($current);
// reorder things to that they list correctly when pulling all items
if ( ! empty($parent)) {
$this->reorder($parent);
}
}
);
// record log
$this->getActivityLogger()->createLog($current, $containerId);
// redirect back to index
if ( ! empty($parent)) {
$redirect = $this->redirectToRoute(
self::ROUTES__VIEW,
array(
'containerId' => $parent->getId(),
)
);
} else {
switch ($type) {
case GenericContainer::DISCR:
$route = self::ROUTES__INDEX;
break;
case PersonalContainer::DISCR:
$route = self::ROUTES__INDEX_PERSONAL;
break;
case IntranetContainer::DISCR:
$route = self::ROUTES__INDEX_INTRANET;
break;
default:
$route = self::ROUTES__INDEX;
}
$redirect = $this->redirectToRoute($route);
}
return $redirect;
}
// html view stuff
return $this->view(
array(
'current' => $current,
'parent' => $parent,
'children' => $children,
)
);
}
/**
* @param Request $request
* @param string $containerId
* @return DocumentScene|RedirectResponse
* @throws \Exception
*
* @Route(
* "/{containerId}/assign",
* name = ContainerController::ROUTES__ASSIGN,
* requirements = {
* "containerId" = "[1-9]\d*"
* }
* )
*/
public function assignAction(Request $request, $containerId)
{
// find the root container
$root = $this->getContainerRepository()->findExact($containerId);
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $root::DISCR . '.manage',
array($root, $root)
);
// only for generic type
if ( ! $root instanceof GenericContainer) {
throw new \Exception();
}
// make sure it is a root
if ( ! empty($root->getParent())) {
throw new \Exception();
}
// build form
$form = $this->createForm(ContainerAssignType::class, $root, []);
// check for post
if ($this->handleForm($form, $request)) {
// save changes
$this->getEntityManager()->save($root);
// record log
$this->getActivityLogger()->createLog($root);
// redirect to index
return $this->redirectToRoute(self::ROUTES__INDEX);
}
// html work
return $this->view(
array(
'root' => $root,
'form' => $form->createView(),
)
);
}
/**
* Operations with favicon for container.
*
* @param GenericContainer $container
* @return DocumentScene|RedirectResponse
*
* @Route(
* "/{container}/favicon",
* name = ContainerController::ROUTES__FAVICON,
* requirements = {
* "container" = "[1-9]\d*",
* },
* )
* @ParamConverter(
* "container",
* class = GenericContainer::class,
* )
*/
public function faviconAction(GenericContainer $container)
{
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $container::DISCR . '.manage',
[$container, $container]
);
// generate the form
$form = $this->createForm(
ContainerFaviconType::class,
[],
[
'favicon_sizes' => DepartmentBlobManager::FAVICON_SIZES,
]
);
// attempt to handle form
if ($this->handleForm($form)) {
// get favicon data
$data = [];
foreach (DepartmentBlobManager::FAVICON_SIZES as $key) {
$data[$key] = $form->get($key)->getData() ?: null;
}
// save them
$this->getContainerService()->saveFavicons(
$container,
$data
);
// record log
$this->getActivityLogger()->createLog($container);
// back to sites index
return $this->redirectToRoute(
self::ROUTES__FAVICON,
[
'container' => $container->getId(),
]
);
}
return $this->view(
[
'root' => $container,
'parent' => $container->getParent(),
'form' => $form->createView(),
'favicons' => DepartmentBlobManager::FAVICON_SIZES,
]
);
}
/**
* Operations with robots.txt for domain.
*
* @param GenericContainer $container
* @return DocumentScene|RedirectResponse
*
* @Route(
* "/{container}/robots",
* name = ContainerController::ROUTES__ROBOTS,
* requirements = {
* "container" = "[1-9]\d*",
* },
* )
* @ParamConverter(
* "container",
* class = GenericContainer::class,
* )
*/
public function robotsAction(GenericContainer $container)
{
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $container::DISCR . '.manage',
[$container, $container]
);
// get the departments blob manager
$blobs = $this->getDepartmentBlobManager();
// create form to handle robots text
$form = $this->createForm(
ContainerRobotsType::class,
[
'content' => $blobs->getRobots($container) ?: '',
]
);
// process the form
if ($this->handleForm($form)) {
// write the contents to s3
$blobs->uploadRobots(
$container,
trim($form->get('content')->getData())
);
// record log
$this->getActivityLogger()->createLog($container);
// back to index
return $this->redirectToRoute(ContainerController::ROUTES__INDEX);
}
return $this->view(
[
'root' => $container,
'parent' => $container->getParent(),
'form' => $form->createView(),
]
);
}
/**
* Operations with sitemap.xml for current domain.
*
* @param GenericContainer $container
* @return DocumentScene|RedirectResponse
*
* @Route(
* "/{container}/sitemap",
* name = ContainerController::ROUTES__SITEMAP,
* requirements = {
* "container" = "[1-9]\d*",
* },
* )
* @ParamConverter(
* "container",
* class = GenericContainer::class,
* )
*/
public function sitemapAction(GenericContainer $container)
{
// AUDIT
$this->denyAccessUnlessGranted(
'campussuite.cms.container.' . $container::DISCR . '.manage',
[$container, $container]
);
// get the departments blob manager
$blobs = $this->getDepartmentBlobManager();
// create form for sitemap management
$form = $this->createForm(
ContainerSitemapType::class,
[
'content' => $blobs->getSitemap($container) ?: '',
]
);
// handle form submission
if ($this->handleForm($form)) {
// write the contents to s3
$blobs->uploadSitemap(
$container,
trim($form->get('content')->getData())
);
// record log
$this->getActivityLogger()->createLog($container);
// back to index
return $this->redirectToRoute(ContainerController::ROUTES__INDEX);
}
return $this->view(
[
'root' => $container,
'parent' => $container->getParent(),
'form' => $form->createView(),
]
);
}
/**
* Generates default data entities for new created container
*
* @param Container $container
* @return array
*/
private function generateDefaultContainerEntities(Container $container)
{
// create index page
/** @var PageProxy $proxy */
$proxy = (new PageProxy())
->setContainer($container)
->getData()
->setTitle('Index')
->setSlug('index')
->entity();
// create first history entry for index page
// TODO: this needs handled by the content management service when it is ready
$history = (new PageHistory())
->setProxy($proxy)
->setTimestamp(DateTimeUtils::now())
->setData($proxy->getData());
// attach history
$proxy->setHistory($history);
// send back objects
return array(
// empty folder for images
(new Folder())
->setName('images')
->setContainer($container),
// empty folder for documents
(new Folder())
->setName('documents')
->setContainer($container),
// the index page proxy and history
$proxy,
$history,
);
}
/**
* @return ContainerService|object
*/
private function getContainerService(): ContainerService
{
return $this->get(__METHOD__);
}
/**
* @return WorksheetBuilder|object
*/
private function getWorksheetBuilder(): WorksheetBuilder
{
return $this->get(__METHOD__);
}
/**
* @return Deployer|object
*/
private function getDeployer(): Deployer
{
return $this->get(__METHOD__);
}
/**
* @return DepartmentBlobManager|object
*/
private function getDepartmentBlobManager(): DepartmentBlobManager
{
return $this->get(__METHOD__);
}
}