示例#1
0
 public function indexAction()
 {
     $request = Zend_Controller_Front::getInstance()->getRequest();
     if ($request->isPost()) {
         $this->getElement()->clearDecorators();
     }
     $bookTable = new Book_Model_DbTable_Books();
     $bookTableName = $bookTable->info(Zend_Db_Table_Abstract::NAME);
     $bookSelect = $bookTable->getSelect();
     $popularityTbl = new Book_Model_DbTable_Popularities();
     $popularityTblName = $popularityTbl->info(Zend_Db_Table_Abstract::NAME);
     $bookSelect->joinLeft($popularityTblName, "{$popularityTblName}.resource_id = {$bookTableName}.book_id", array("{$popularityTblName}.point"));
     $bookSelect->where("{$popularityTblName}.resource_type = ?", 'book');
     $bookSelect->order("{$popularityTblName}.point DESC");
     $bookSelect->order("{$popularityTblName}.posted_date DESC");
     $this->view->paginator = $paginator = Zend_Paginator::factory($bookSelect);
     if ($paginator->getTotalItemCount() == 0) {
         return $this->setNoRender();
     }
     $itemCountPerPage = $this->_getParam('itemCountPerPage', 12);
     if (empty($itemCountPerPage)) {
         $itemCountPerPage = 12;
     }
     $paginator->setItemCountPerPage($itemCountPerPage);
     $paginator->setCurrentPageNumber($this->_getParam('page', 1));
     $this->view->viewInfo = $this->_getParam('viewInfo');
 }
示例#2
0
 public function onCoreLikeDeleteBefore($event)
 {
     $like = $event->getPayload();
     if (isset($like) && !empty($like)) {
         if (in_array($like->resource_type, $this->_getModuleItems())) {
             $popularityTbl = new Book_Model_DbTable_Popularities();
             $popularitySelect = $popularityTbl->select();
             $popularitySelect->where('resource_id = ?', $like->resource_id);
             $popularitySelect->where('resource_type = ?', $like->resource_type);
             $item = $popularityTbl->fetchRow($popularitySelect);
             if (empty($item)) {
                 $item = $popularityTbl->getObject($like->resource_type, $like->resource_id);
             }
             $item->like_count = $item->like_count - 1;
             $item->point = $item->point - self::LIKE_POINT;
             $item->save();
         }
     }
 }
示例#3
0
 protected function _postDelete()
 {
     parent::_postDelete();
     $bookPhotoTbl = new Book_Model_DbTable_Photos();
     $bookPhotoTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $bookAuthorTbl = new Book_Model_DbTable_BookAuthor();
     $bookAuthorTbl->delete(array('book_id = ?' => $this->getIdentity()));
     $bookFavTbl = new Book_Model_DbTable_Favorites();
     $bookFavTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $bookPostTbl = new Book_Model_DbTable_Posts();
     $bookPostTbl->update(array('parent_id' => NULL, 'parent_type' => NULL), array('parent_id = ?' => $this->getIdentity(), 'parent_type = ?' => $this->getType()));
     $bookRatingTbl = new Book_Model_DbTable_Ratings();
     $bookRatingTbl->delete(array('parent_object_type = ?' => $this->getType(), 'parent_object_id = ?' => $this->getIdentity()));
     $popularityTbl = new Book_Model_DbTable_Popularities();
     $popularity = $popularityTbl->delete(array('resource_id = ?' => $this->getIdentity(), 'resource_type = ?' => $this->getType()));
 }
示例#4
0
 protected function _postInsert()
 {
     parent::_postInsert();
     $signatureTbl = new Book_Model_DbTable_Signatures();
     $signature = $signatureTbl->createRow(array('parent_object_id' => $this->getIdentity(), 'parent_object_type' => $this->getType(), 'favorite_count' => 0, 'view_count' => 0));
     $signature->save();
     $popularityTbl = new Book_Model_DbTable_Popularities();
     $popularity = $popularityTbl->createRow(array('resource_id' => $this->getIdentity(), 'resource_type' => $this->getType(), 'posted_date' => date('Y-m-d H:i:s')));
     $popularity->save();
 }