/**
  * Blogs from a certain category
  *
  * @param void
  * @return ViewModel
  **/
 public function blogsAction()
 {
     $query = $this->getRequest()->getQuery();
     $category = $this->_categoryService->getFromName($query->name);
     $posts = $this->_postService->getPagedFromCategory($category, $query->page);
     return new ViewModel(array('category' => $category, 'posts' => $posts));
 }
示例#2
0
 public function generateCache(PostService $postService)
 {
     $posts = $postService->getLastPost();
     $categories = $this->categoryService->getAllOrdered();
     $renderer = $this->getServiceLocator()->get('ViewRenderer');
     $view = $renderer->render('layout/sidebar', array('posts' => $posts, 'categories' => $categories));
     file_put_contents($this->getCacheDirectory() . '/sidebar.cache', $view);
 }
 /**
  * Returns CategoryList instance.
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return CategoryList
  * @override
  **/
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $serviceLocator Zend\View\HelperPluginManager */
     $sm = $serviceLocator->getServiceLocator();
     $em = $sm->get('em');
     $service = new CategoryService($em);
     $categories = $service->getPublishedWithCount();
     $helper = new CategoryList();
     $helper->setCategories($categories);
     return $helper;
 }
示例#4
0
 /**
  * To update/edit a blog post
  *
  * @parmam void
  * @return ViewModel
  * @throws AccessProhibitedException
  **/
 public function editAction()
 {
     $this->_checkAcl('edit');
     $request = $this->getRequest();
     $post = $this->_postService->getFromId($request->getQuery('id'));
     $categoryService = new CategoryService($this->_em);
     $form = new PostForm();
     $form->bind($post);
     $form->setCategoryList($categoryService->getAll());
     $this->_postService->setForm($form);
     if ($request->isPost()) {
         $this->_postService->save($request->getPost());
     }
     return new ViewModel(array('form' => $form, 'post' => $post, 'messages' => $this->_postService->getMessages(PostService::MSG_NOTICE), 'errors' => $this->_postService->getMessages(PostService::MSG_ERROR)));
 }
 /**
  * Returns SearchController instance.
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return BlogController
  * @override
  **/
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $serviceLocator Zend\Mvc\Controller\ControllerManager */
     $sm = $serviceLocator->getServiceLocator();
     $em = $sm->get('em');
     $categoryService = new CategoryService($em);
     $categories = $categoryService->getPublishedWithCount();
     $postService = new PostService($em);
     $years = $postService->getValidYears();
     $form = new SearchForm();
     $form->setCategoryList($categories);
     $form->setYearList($years);
     $service = new SearchService($em);
     $service->setForm($form);
     $controller = new SearchController();
     $controller->setService($service);
     return $controller;
 }
示例#6
0
 /**
  * Saves a post
  *
  * @param array $data
  * @return boolean
  **/
 public function save($data = array())
 {
     $data['content'] = str_replace(array('Â', ' '), '', $data['content']);
     $form = $this->getForm();
     $form->setData($data);
     if ($form->isValid()) {
         $post = $form->getData();
         $post->setDateModified(new DateTime());
         // Silly Doctrine.
         $categoryService = new CategoryService($this->em);
         $category = $categoryService->findById($post->getCategory()->getId());
         $post->setCategory($category);
         $this->em->persist($post);
         $this->em->flush();
         $this->addMessage('Successfully saved post.', self::MSG_NOTICE);
         return true;
     }
     $this->addMessage('Kindly fix the form errors.', self::MSG_ERROR);
     return false;
 }