Example #1
0
 /**
  * Category Combobox
  *
  * @return Zend_Form_Element_Select
  */
 protected function _category()
 {
     $element = new Zend_Form_Element_Select('categoryId');
     $element->setLabel('Category')->setRequired(true)->addDecorators($this->_inputDecorators)->setAttribs(array('class' => 'span4'));
     $categories = new Blog_Model_Category_Manager();
     $select = $categories->getDbTable()->select()->order('path');
     $select->order('path');
     $select->where('path LIKE (?)', Blog_Model_Category_Manager::CATEGORY_ALIAS . '/%');
     foreach ($categories->getDbTable()->fetchAll($select) as $row) {
         $element->addMultiOption($row->id, str_repeat("…", $row->level - 1) . " " . $row->title);
     }
     return $element;
 }
Example #2
0
 /**
  * View blog category
  */
 public function categoryAction()
 {
     if (!($alias = $this->_getParam('alias'))) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     $category = new Blog_Model_Category_Manager();
     if (!($row = $category->getByAlias($alias))) {
         throw new Zend_Controller_Action_Exception('Blog not found');
     }
     $post = new Blog_Model_Post_Table();
     $source = $post->getSelect($row);
     $paginator = Zend_Paginator::factory($source);
     $paginator->getView()->route = 'blogcategory';
     $paginator->setItemCountPerPage($this->_itemsPerPage);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $this->view->paginator = $paginator;
     $this->view->category = $row;
     $this->render('index');
 }
Example #3
0
 /**
  * Get Zend_Db_Table_Select
  *
  * @param object|integer $category
  * @param integer $author
  * @param string  $date
  * @return Zend_Db_Table_Select
  */
 public function getSelect($category = null, $author = null, $date = 'NOW')
 {
     $users = new Users_Model_User_Table();
     $categories = new Categories_Model_Category_Table();
     $select = $this->select()->setIntegrityCheck(false);
     $select->from(array('p' => $this->_name), array('*'))->joinLeft(array('u' => $users->info('name')), 'p.userId = u.id', array('login'))->joinLeft(array('c' => $categories->info('name')), 'c.id = p.categoryId', array('categoryTitle' => 'title', 'categoryAlias' => 'alias'))->group('p.id')->where('p.status=?', Blog_Model_Post::STATUS_PUBLISHED)->order('published DESC');
     if ($date) {
         if ('NOW' == $date) {
             $date = date('Y-m-d H:i:s');
         }
         $select->where('published <=?', $date);
     }
     if ($category) {
         if (!$category instanceof Zend_Db_Table_Row_Abstract) {
             $manager = new Blog_Model_Category_Manager();
             $category = $manager->getById($category);
         }
         //$separator = Categories_Model_Category::PATH_SEPARATOR;
         $select->where('c.path LIKE ?', '%' . $category->alias . '%');
     }
     return $select;
 }
Example #4
0
 /**
  * Category blog rss
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function categoryAction()
 {
     $limit = 10;
     if (!($alias = $this->_getParam('alias'))) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     $category = new Blog_Model_Category_Manager();
     if (!($row = $category->getByAlias($alias))) {
         throw new Zend_Controller_Action_Exception('Blog not found');
     }
     $url = $this->_helper->url;
     $serverUrl = $this->_request->getScheme() . '://' . $this->_request->getHttpHost();
     $title = $row->title . " Blog Rss Feed";
     $link = $url->url(array('alias' => $row->alias), 'blogcategory');
     $feed = new Zend_Feed_Writer_Feed();
     $feed->setTitle($title);
     $feed->setLink($serverUrl . $link);
     $feed->setFeedLink('http://www.example.com/atom', 'atom');
     $feed->addAuthor(array('name' => 'Blog Owner Name', 'email' => null, 'uri' => $serverUrl));
     $posts = new Blog_Model_Post_Table();
     $select = $posts->getSelect($row);
     $feed->setDateModified(time());
     foreach ($posts->fetchAll($select->limit($limit)) as $i => $row) {
         if (0 == $i) {
             $feed->setDateModified(strtotime($row->updated));
         }
         $postUrl = $url->url(array('alias' => $row->alias), 'blogpost');
         $entry = $feed->createEntry();
         $entry->setTitle($row->title);
         $entry->setLink($serverUrl . $postUrl);
         $entry->addAuthor($row->login, null, null);
         $entry->setDateModified(strtotime($row->updated));
         $entry->setDateCreated(strtotime($row->published));
         $entry->setDescription($row->teaser);
         $feed->addEntry($entry);
     }
     echo $feed->export('atom');
 }
Example #5
0
 public function testEditWithDataAction()
 {
     $table = new Blog_Model_Post_Table();
     $manager = new Blog_Model_Category_Manager();
     $rootCat = $manager->getRoot();
     $cat = $manager->getDbTable()->createRow($this->_fixture['category']);
     $rootCat->addChild($cat);
     $post = $table->createRow($this->_fixture['post']);
     $post->save();
     $this->_doLogin();
     $this->request->setMethod('POST')->setPost(array('title' => 'tttttttt', 'body' => 'tttttttt', 'categoryId' => 93, 'status' => 'draft'));
     $this->dispatch('/blog/post/edit/alias/' . $this->_fixture['post']['alias']);
     $this->assertModule('blog');
     $this->assertController('post');
     $this->assertAction('edit');
     $post->delete();
     $cat->delete();
 }