Example #1
0
 /**
  * Return data of rating summary
  *
  * @param Mage_Rating_Model_Rating $object
  * @return array
  */
 protected function _getEntitySummaryData($object)
 {
     $read = $this->_getReadAdapter();
     $sql = "SELECT\n                    {$this->getTable('rating_vote')}.entity_pk_value as entity_pk_value,\n                    SUM({$this->getTable('rating_vote')}.percent) as sum,\n                    COUNT(*) as count,\n                    {$this->getTable('review/review_store')}.store_id\n                FROM\n                    {$this->getTable('rating_vote')}\n                INNER JOIN\n                    {$this->getTable('review/review')}\n                    ON {$this->getTable('rating_vote')}.review_id={$this->getTable('review/review')}.review_id\n                LEFT JOIN\n                    {$this->getTable('review/review_store')}\n                    ON {$this->getTable('rating_vote')}.review_id={$this->getTable('review/review_store')}.review_id\n                INNER JOIN\n                    {$this->getTable('rating/rating_store')} AS rst\n                    ON rst.rating_id = {$this->getTable('rating_vote')}.rating_id AND rst.store_id = {$this->getTable('review/review_store')}.store_id\n                INNER JOIN\n                    {$this->getTable('review/review_status')} AS review_status\n                    ON {$this->getTable('review/review')}.status_id = review_status.status_id\n                WHERE ";
     if ($object->getEntityPkValue()) {
         $sql .= "{$read->quoteInto($this->getTable('rating_vote') . '.entity_pk_value=?', $object->getEntityPkValue())} AND ";
     }
     $sql .= "review_status.status_code = 'approved'\n                GROUP BY\n                    {$this->getTable('rating_vote')}.entity_pk_value, {$this->getTable('review/review_store')}.store_id";
     return $read->fetchAll($sql);
 }
 /**
  * Review summary
  *
  * @param Mage_Rating_Model_Rating $object
  * @param boolean $onlyForCurrentStore
  * @return array
  */
 public function getReviewSummary($object, $onlyForCurrentStore = true)
 {
     $adapter = $this->_getReadAdapter();
     $sumColumn = new Zend_Db_Expr("SUM(rating_vote.{$adapter->quoteIdentifier('percent')})");
     $countColumn = new Zend_Db_Expr('COUNT(*)');
     $select = $adapter->select()->from(array('rating_vote' => $this->getTable('rating/rating_option_vote')), array('sum' => $sumColumn, 'count' => $countColumn))->joinLeft(array('review_store' => $this->getTable('review/review_store')), 'rating_vote.review_id = review_store.review_id', array('review_store.store_id'))->join(array('rating_store' => $this->getTable('rating/rating_store')), 'rating_store.rating_id = rating_vote.rating_id AND rating_store.store_id = review_store.store_id', array())->where('rating_vote.review_id = :review_id')->group('rating_vote.review_id')->group('review_store.store_id');
     $data = $adapter->fetchAll($select, array(':review_id' => $object->getReviewId()));
     if ($onlyForCurrentStore) {
         foreach ($data as $row) {
             if ($row['store_id'] == Mage::app()->getStore()->getId()) {
                 $object->addData($row);
             }
         }
         return $object;
     }
     $result = array();
     $stores = Mage::app()->getStore()->getResourceCollection()->load();
     foreach ($data as $row) {
         $clone = clone $object;
         $clone->addData($row);
         $result[$clone->getStoreId()] = $clone;
     }
     $usedStoresId = array_keys($result);
     foreach ($stores as $store) {
         if (!in_array($store->getId(), $usedStoresId)) {
             $clone = clone $object;
             $clone->setCount(0);
             $clone->setSum(0);
             $clone->setStoreId($store->getId());
             $result[$store->getId()] = $clone;
         }
     }
     return array_values($result);
 }
Example #3
0
 /**
  * Save correct store list in rating (while Managing Ratings)
  *
  * @param Mage_Rating_Model_Rating $model
  * @return Enterprise_AdminGws_Model_Models
  */
 public function ratingSaveBefore($model)
 {
     if (!$model->isObjectNew()) {
         $roleStoreIds = $this->_role->getStoreIds();
         // Store list that was assigned to current rating previously
         $origStoreIds = (array) $model->getResource()->getStores($model->getId());
         // Store list that admin is currently trying to assign to current rating
         $postStoreIds = array_intersect((array) $model->getStores(), $roleStoreIds);
         $storeIds = array_merge(array_diff($origStoreIds, $roleStoreIds), $postStoreIds);
         $model->setStores($storeIds);
     }
 }