/** * Get the block nested items in the body of the page * * @param \Cms\Entity\Page $page * @return null */ private function getNestedBlockItems(\Cms\Entity\Page $page) { $serviceLocator = $this->getServiceLocator()->getServiceLocator(); $block = $serviceLocator->get('BlockService'); $translator = $serviceLocator->get('translator'); $value = $page->getContent(); if (!empty($value)) { $placeHolders = array(); if (preg_match_all('/\\{([^{}}]+)\\}/', $value, $matches)) { $placeHolders = $matches[1]; } foreach ($placeHolders as $placeHolder) { $theBlock = $block->findByPlaceholder($placeHolder); if (!empty($theBlock)) { $value = str_replace("{" . $placeHolder . "}", $theBlock->getContent(), $value); } else { $notfound = "<div class=\"alert alert-danger\">" . sprintf($translator->translate("Block %s%s%s doesn't found!"), "<strong>", $placeHolder, "</strong>") . "</div>"; $value = str_replace("{" . $placeHolder . "}", $notfound, $value); } } $page->setContent($value); return true; } return false; }
/** * Create new page * * * @access public * @uses Page * @uses PageForm * * @return ViewModel */ public function newAction() { $variables = array(); $pageModel = $this->getServiceLocator()->get('CMS\\Model\\Page'); $query = $this->getServiceLocator()->get('wrapperQuery')->setEntity('CMS\\Entity\\Page'); $pageObj = new Page(); $options = array(); $options['query'] = $query; $form = new PageForm(null, $options); $request = $this->getRequest(); if ($request->isPost()) { $data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray()); $form->setInputFilter($pageObj->getInputFilter($query)); $form->setData($data); $pageModel->setFormRequiredFields($form, $data, false); if ($form->isValid()) { $data = $form->getData(FormInterface::VALUES_AS_ARRAY); $pageModel->save($pageObj, $data, false); $url = $this->getEvent()->getRouter()->assemble(array('action' => 'index'), array('name' => 'cmsPage')); $this->redirect()->toUrl($url); } } $formViewHelper = new FormViewHelper(); $this->setFormViewHelper($formViewHelper); $variables['pageForm'] = $this->getFormView($form); $variables['pressReleaseType'] = PageTypes::PRESS_RELEASE_TYPE; return new ViewModel($variables); }
public function save(PageEntity $page) { $now = new \DateTime('now'); // Created if (!$page->getCreated()) { $page->setCreated($now); } // The updated datetime $page->setUpdated($now); $this->getEntityManager()->persist($page); $this->getEntityManager()->flush(); }
/** * Prepare logs * * @access public * @param array $logs * @return array logs prepared for display */ public function prepareHistory($logs) { $dummyPage = new PageEntity(); foreach ($logs as &$log) { foreach ($log['data'] as $dataKey => &$dataValue) { if ($dataKey == "body") { $dummyPage->body = $dataValue; $dataValue = $dummyPage->getBody(); } } } return $logs; }
/** * Save page * * @access public * @param CMS\Entity\Page $page * @param array $data ,default is empty array * @param bool $editFlag ,default is false */ public function save($page, $data = array(), $editFlag = false) { if (array_key_exists(FormButtons::SAVE_AND_PUBLISH_BUTTON, $data)) { $page->setStatus(Status::STATUS_ACTIVE); } elseif (array_key_exists(FormButtons::UNPUBLISH_BUTTON, $data)) { $page->setStatus(Status::STATUS_INACTIVE); } elseif (array_key_exists(FormButtons::SAVE_BUTTON, $data) && $editFlag === false) { $page->setStatus(Status::STATUS_INACTIVE); } if ($editFlag === true) { $data = array(); } $this->query->setEntity("CMS\\Entity\\Page")->save($page, $data); }
public function testSetters() { $page = new Page(); $page->setTitle('Imprint'); $this->assertEquals('Imprint', $page->getTitle()); $page->setRoute('imprint'); $this->assertEquals('imprint', $page->getRoute()); $page->setContent('lorem ipsum'); $this->assertEquals('lorem ipsum', $page->getContent()); $page->setStatus('published'); $this->assertEquals('published', $page->getStatus()); $now = new \DateTime('now'); $page->setCreated($now); $this->assertEquals($now, $page->getCreated()); $page->setUpdated($now); $this->assertEquals($now, $page->getUpdated()); }