Beispiel #1
0
 public function favoriteAction()
 {
     $this->_initActions();
     $subject = $this->_getSubject();
     $this->_checkSubject();
     $viewer = Engine_Api::_()->user()->getViewer();
     if (Engine_Api::_()->book()->isFavorite($viewer, $subject) == NULL) {
         $actionTbl = Engine_Api::_()->getDbTable('actions', 'activity');
         $db = Engine_Db_Table::getDefaultAdapter();
         $db->beginTransaction();
         try {
             $favTable = new Book_Model_DbTable_Favorites();
             $fav = $favTable->createRow(array('parent_object_id' => $subject->getIdentity(), 'parent_object_type' => $subject->getType(), 'user_id' => $viewer->getIdentity()));
             $fav->save();
             $action = $actionTbl->addActivity($viewer, $subject, 'add_favorite');
             if ($action) {
                 $actionTbl->attachActivity($action, $subject);
             }
             $signature = $this->_getSignature();
             $signature->favorite_count = $signature->favorite_count + 1;
             $signature->save();
             $popularity = Engine_Api::_()->getItemTable('book_popularity')->getObject($subject->getType(), $subject->getIdentity());
             $popularity->favorite_count = $popularity->favorite_count + 1;
             $popularity->point = $popularity->point + Book_Plugin_Core::FAV_POINT;
             $popularity->save();
             $db->commit();
         } catch (Exception $e) {
             $db->rollBack();
             throw $e;
         }
         return $this->_forward('success', 'utility', 'core', array('layout' => 'default-simple', 'parentRefresh' => true, 'messages' => array(Zend_Registry::get('Zend_Translate')->_($this->_getAddFavoriteMsg()))));
     }
 }