public function checkRated($object_id, $object_type, $user_id) { if (!empty($user_id)) { $ratingTable = new Book_Model_DbTable_Ratings(); $select = $ratingTable->select()->where('parent_object_type = ?', $object_type)->where('parent_object_id = ?', $object_id)->where('user_id = ?', $user_id); return $ratingTable->fetchRow($select) != NULL; } return NULL; }
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 getRatingSum() { $table = new Book_Model_DbTable_Ratings(); $ratingSum = $table->select()->from($table->info('name'), new Zend_Db_Expr('SUM(rating)'))->where('parent_object_id = ?', $this->getIdentity())->where('parent_object_type = ?', $this->getType())->query()->fetchColumn(0); return $ratingSum; }