Example #1
0
 /**
  * @return Supra\Package\Cms\Repository\PageAbstractRepository
  */
 protected function getRepository()
 {
     return $this->em->getRepository(Template::CN());
 }
 /**
  * @return SupraJsonResponse
  */
 public function saveSettingsAction()
 {
     $this->isPostRequest();
     $this->checkLock();
     $localization = $this->getPageLocalization();
     if (!$localization instanceof PageLocalization) {
         throw new \UnexpectedValueException(sprintf('Expecting PageLocalization instance, [%s] received.', get_class($localization)));
     }
     $this->saveLocalizationCommonSettingsAction();
     $input = $this->getRequestInput();
     //@TODO: validation
     $localization->setPathPart($input->get('path', ''));
     $templateId = $input->get('template');
     $template = $this->getEntityManager()->find(Template::CN(), $templateId);
     if ($template === null) {
         throw new CmsException(null, sprintf('Specified template [%s] not found.'));
     }
     if (!$template->equals($localization->getTemplate())) {
         $localization->setTemplate($template);
     }
     $localization->setActive($input->filter('active', null, false, FILTER_VALIDATE_BOOLEAN));
     $localization->setMetaDescription($input->get('description'));
     $localization->setMetaKeywords($input->get('keywords'));
     $global = $input->filter('global', false, false, FILTER_VALIDATE_BOOLEAN);
     // @TODO: possible 'global' property renaming is needed, it's confusing.
     if ($global === false && $localization->getMaster()->isRoot()) {
         throw new \LogicException('It is not allowed to disable translation of root page.');
     }
     $localization->getMaster()->setGlobal($global);
     // @TODO: would be nice if date/time would be sent as single value.
     $publicationScheduleDate = $input->get('scheduled_date');
     $scheduleDateTime = null;
     if (!empty($publicationScheduleDate)) {
         $publicationScheduleTime = $input->get('scheduled_time', '00:00:00');
         $scheduleDateTime = \DateTime::createFromFormat('Y-m-d/H:i:s', "{$publicationScheduleDate}/{$publicationScheduleTime}");
         if ($scheduleDateTime === false) {
             throw new \RuntimeException(sprintf('Failed to create page publication schedule datetime object from date [%s] and time [%s] values.', $publicationScheduleDate, $publicationScheduleTime));
         }
     }
     // @TODO: would be nice if date/time would be sent as single value.
     $creationDate = $input->get('created_date');
     $creationTime = $input->get('created_time', '00:00:00');
     $creationDateTime = \DateTime::createFromFormat('Y-m-d/H:i:s', "{$creationDate}/{$creationTime}");
     if ($creationDateTime === false) {
         throw new \RuntimeException(sprintf('Failed to create page creation datetime object from date [%s] and time [%s] values.', $creationDate, $creationTime));
     }
     $localization->setCreationTime($creationDateTime);
     // @TODO: JS might not inform about redirect data if it was not changed.
     if ($localization->hasRedirectTarget()) {
         $this->getEntityManager()->remove($localization->getRedirectTarget());
     }
     $redirectTargetData = $input->get('redirect', array());
     if (!empty($redirectTargetData)) {
         $redirectTarget = $this->createRedirectTargetFromData($redirectTargetData);
         $this->getEntityManager()->persist($redirectTarget);
         $localization->setRedirectTarget($redirectTarget);
     }
     try {
         $this->getEntityManager()->flush();
     } catch (DuplicatePagePathException $e) {
         throw new CmsException(null, $e->getMessage());
     }
     return new SupraJsonResponse();
 }
 /**
  * @param EntityManager $em
  * @param ClassMetadata $class
  */
 public function __construct(EntityManager $em, ClassMetadata $class)
 {
     parent::__construct($em, $class);
     // Bind additional conditions to the nested set repository
     $this->nestedSetRepository->setAdditionalCondition(sprintf('e INSTANCE OF %s', Template::CN()), 'discr IN ("template")');
 }
 /**
  * Responds with Templates sitemap tree data
  *
  * @return SupraJsonResponse
  */
 public function templatesListAction()
 {
     return new SupraJsonResponse($this->loadSitemapTree(Template::CN()));
 }