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())); }
public function removeFavoriteAction() { $this->_initActions(); $subject = $this->_getSubject(); $this->_checkSubject(); $viewer = Engine_Api::_()->user()->getViewer(); if (Engine_Api::_()->book()->isFavorite($viewer, $subject)) { $db = Engine_Db_Table::getDefaultAdapter(); $db->beginTransaction(); try { $favTable = new Book_Model_DbTable_Favorites(); $fav = $favTable->delete(array('parent_object_id = ?' => $subject->getIdentity(), 'parent_object_type = ?' => $subject->getType(), 'user_id = ?' => $viewer->getIdentity())); $signature = $this->_getSignature(); if ($signature->favorite_count > 0) { $signature->favorite_count = $signature->favorite_count - 1; $signature->save(); } if ($subject->getType() == 'book') { $popularity = Engine_Api::_()->getItem('book_popularity', $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->_getRemoveFavoriteMsg())))); } }