Ejemplo n.º 1
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return \Zend\Navigation\Navigation
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $this->rcmUserService = $serviceLocator->get('RcmUser\\Service\\RcmUserService');
     $this->cmsPermissionChecks = $serviceLocator->get('Rcm\\Acl\\CmsPermissionsChecks');
     $this->currentSite = $serviceLocator->get('Rcm\\Service\\CurrentSite');
     $config = $serviceLocator->get('config');
     /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     /** @var \Rcm\Repository\Page $pageRepo */
     $this->pageRepo = $entityManager->getRepository('\\Rcm\\Entity\\Page');
     $application = $serviceLocator->get('Application');
     /** @var RouteMatch $routeMatch */
     $routeMatch = $application->getMvcEvent()->getRouteMatch();
     if (!in_array($routeMatch->getMatchedRouteName(), $config['Rcm']['RcmCmsPageRouteNames'])) {
         return parent::createService($serviceLocator);
     }
     $pageMatch = $routeMatch->getParam('page', 'index');
     if ($pageMatch instanceof Page) {
         $pageMatch = $pageMatch->getName();
     }
     $this->pageRevision = $routeMatch->getParam('revision', null);
     $pageTypeMatch = $routeMatch->getParam('pageType', 'n');
     if (!empty($pageMatch)) {
         $this->page = $this->pageRepo->findOneBy(['name' => $pageMatch, 'pageType' => $pageTypeMatch]);
     }
     return parent::createService($serviceLocator);
 }
Ejemplo n.º 2
0
 /**
  * Is the page valid?
  *
  * @param string $value Page to validate
  *
  * @return bool
  */
 public function isValid($value)
 {
     $this->setValue($value);
     $check = $this->pageRepo->findOneBy(['pageId' => $value, 'pageType' => $this->pageType, 'site' => $this->site]);
     if (empty($check)) {
         $this->error(self::PAGE_TEMPLATE);
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Creates a new CMS page
  *
  * @return ViewModel
  */
 public function newAction()
 {
     if (!$this->rcmIsAllowed('sites.' . $this->currentSite->getSiteId() . '.pages', 'create')) {
         $response = new Response();
         $response->setStatusCode('401');
         return $response;
     }
     /** @var \RcmAdmin\Form\NewPageForm $form */
     $form = $this->getServiceLocator()->get('FormElementManager')->get('RcmAdmin\\Form\\NewPageForm');
     /** @var \Zend\Http\Request $request */
     $request = $this->request;
     if ($request->isGet()) {
         $form->get('url')->setValue($request->getQuery('url'));
     }
     $data = $request->getPost();
     $form->setValidationGroup('url');
     $form->setData($data);
     if ($request->isPost() && $form->isValid()) {
         $validatedData = $form->getData();
         // Create a new page
         if (empty($validatedData['page-template']) && !empty($validatedData['main-layout'])) {
             $pageData = ['name' => $validatedData['url'], 'pageTitle' => $validatedData['title'], 'siteLayoutOverride' => $validatedData['main-layout'], 'author' => $this->rcmUserGetCurrentUser()->getName()];
             $this->pageRepo->createPage($this->currentSite, $pageData);
         } elseif (!empty($validatedData['page-template'])) {
             /** @var \Rcm\Entity\Page $page */
             $page = $this->pageRepo->findOneBy(['pageId' => $validatedData['page-template'], 'pageType' => 't']);
             if (empty($page)) {
                 throw new PageNotFoundException('No template found for page id: ' . $validatedData['page-template']);
             }
             $pageData = ['author' => $this->rcmUserGetCurrentUser()->getName(), 'name' => $validatedData['url'], 'pageTitle' => $validatedData['title'], 'pageType' => 'n'];
             $this->pageRepo->copyPage($this->currentSite, $page, $pageData);
         }
         $this->view->setVariable('newPageUrl', $this->urlToPage($validatedData['url'], 'n'));
         $this->view->setTemplate('rcm-admin/page/success');
         return $this->view;
     } elseif ($request->isPost() && !$form->isValid()) {
         $this->view->setVariable('errors', $form->getMessages());
     }
     $this->view->setVariable('form', $form);
     return $this->view;
 }
Ejemplo n.º 4
0
Archivo: Page.php Proyecto: reliv/rcm
 /**
  * Is the page valid?
  *
  * @param string $value Page to validate
  *
  * @return bool
  */
 public function isValid($value)
 {
     $nameOk = parent::isValid($value);
     if (!$nameOk) {
         return false;
     }
     $check = $this->pageRepo->findOneBy(['name' => $value, 'pageType' => $this->pageType, 'site' => $this->siteId]);
     if (!empty($check)) {
         $this->error(self::PAGE_EXISTS);
         return false;
     }
     return true;
 }