Exemplo n.º 1
0
 /**
  * Retrieve review data as xml object
  *
  * @param Mage_Review_Model_Review $review
  * @param string $itemNodeName
  * @return Mage_XmlConnect_Model_Simplexml_Element
  */
 public function reviewToXmlObject(Mage_Review_Model_Review $review, $itemNodeName = 'item')
 {
     $rating = 0;
     /** @var $item Mage_XmlConnect_Model_Simplexml_Element */
     $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>');
     if ($review->getId()) {
         $item->addChild('review_id', $review->getId());
         $item->addChild('created_at', $this->formatDate($review->getCreatedAt()));
         $item->addChild('title', $item->escapeXml($review->getTitle()));
         $item->addChild('nickname', $item->escapeXml($review->getNickname()));
         $detail = $item->escapeXml($review->getDetail());
         if ($itemNodeName == 'item') {
             $remainder = '';
             $deviceType = Mage::helper('xmlconnect')->getDeviceType();
             if ($deviceType != Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD) {
                 $detail = Mage::helper('core/string')->truncate($detail, self::REVIEW_DETAIL_TRUNCATE_LEN, '', $remainder, false);
             }
         }
         $item->addChild('detail', $detail);
         $summary = Mage::getModel('rating/rating')->getReviewSummary($review->getId());
         if ($summary->getCount() > 0) {
             $rating = round($summary->getSum() / $summary->getCount() / 10);
         }
         if ($rating) {
             $item->addChild('rating_votes', $rating);
         }
     }
     return $item;
 }
Exemplo n.º 2
0
 /**
  * Do the points transfer for the review
  *
  * @param  Mage_Review_Model_Review $review
  * @param  int $rule       : Special Rule
  * @return boolean            : whether or not the point-transfer succeeded
  */
 public function transferReviewPoints($review, $rule)
 {
     $num_points = $rule->getPointsAmount();
     $currency_id = $rule->getPointsCurrencyId();
     $review_id = $review->getId();
     $rule_id = $rule->getId();
     $transfer = $this->initTransfer($num_points, $currency_id, $rule_id);
     $customer_id = $review->getCustomerId();
     if (!$transfer) {
         return false;
     }
     // get the default starting status - usually Pending
     if (!$transfer->setStatus(null, Mage::helper('rewards/config')->getInitialTransferStatusAfterReview())) {
         // we tried to use an invalid status... is getInitialTransferStatusAfterReview() improper ??
         return false;
     }
     $transfer->setReviewId($review_id)->setComments(Mage::getStoreConfig('rewards/transferComments/reviewOrRatingEarned'))->setCustomerId($customer_id)->save();
     return true;
 }
Exemplo n.º 3
0
 /**
  * Gets the average rating for the review
  *
  * @param Mage_Review_Model_Review $review
  *
  * @return bool|float
  */
 public function getAverageRatingByReview(Mage_Review_Model_Review $review)
 {
     $collection = Mage::getModel('rating/rating_option_vote')->getResourceCollection()->setReviewFilter($review->getId())->setStoreFilter(Mage::app()->getStore()->getId());
     $rating = $this->getAverageRatingByCollection($collection);
     if (!$rating) {
         return false;
     }
     return $this->formaRatingtNumber($rating);
 }
Exemplo n.º 4
0
 /**
  * set id
  */
 public function setUid()
 {
     parent::setUid($this->item->getId());
 }
Exemplo n.º 5
0
 /**
  * @param Mage_Review_Model_Review $review
  * @return int
  */
 public function getUpdateReviewId($review)
 {
     return $review->getId();
 }
Exemplo n.º 6
0
 public function delete(Mage_Review_Model_Review $review)
 {
     if ($review->getId()) {
         try {
             $this->_write->beginTransaction();
             $condition = $this->_write->quoteInto('review_id = ?', $review->getId());
             $review->load($review->getId());
             $this->_write->delete($this->_reviewTable, $condition);
             $this->_write->commit();
             $this->aggregate($review);
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
 }