Ejemplo 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;
 }
Ejemplo n.º 2
0
 /**
  * Rewriting this method to output new urls.
  * Checks if a rewrite already exists, otherwise creates it.
  */
 public function getReviewUrl()
 {
     $product = $this->getProduct();
     $routePath = '';
     $routeParams = array();
     $storeId = Mage::app()->getStore()->getId();
     $this->setStoreId($storeId);
     if (!$product) {
         if ($this->getEntityId() != 1) {
             return parent::getReviewUrl();
         }
         $product = Mage::getModel('catalog/product')->load($this->getEntityPkValue());
     }
     $product->setStoreId($storeId);
     $idPath = sprintf('review/%d', $this->getId());
     $rewrite = $this->getUrlRewrite();
     $rewrite->setStoreId($storeId)->loadByIdPath($idPath);
     $storeUrl = Mage::getBaseUrl();
     if (substr($storeUrl, strlen($storeUrl) - 1, 1) != '/') {
         $storeUrl .= '/';
     }
     if ($rewrite->getId()) {
         // REWRITE RULE EXISTS
         $url = $storeUrl . $rewrite->getRequestPath();
     } else {
         // CREATE REWRITE RULE
         $model = Mage::getModel('reviewsearchfriendlyurls/url');
         $url = $storeUrl . $model->addSingleReviewUrlRewrite($this, $product);
     }
     return $url;
 }
Ejemplo n.º 3
0
 protected function _afterSave()
 {
     parent::_afterSave();
     foreach ($this->getProductCollection() as $product) {
         $product->cleanCache();
     }
 }
Ejemplo n.º 4
0
 function getRatingValues(Mage_Review_Model_Review $review)
 {
     $avg = 0;
     if (count($review->getRatingVotes())) {
         $ratings = array();
         $c = 0;
         foreach ($review->getRatingVotes() as $rating) {
             $type = $rating->getRatingCode();
             $pcnt = $rating->getPercent();
             if ($type) {
                 $val[$c][$type] = $pcnt;
             }
             $ratings[] = $rating->getPercent();
         }
         $c++;
         $avg = array_sum($ratings) / count($ratings);
     }
     return $val;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * @return float|number
  */
 protected function _getScore()
 {
     $ratings = array();
     foreach ($this->item->getRatingVotes() as $vote) {
         $ratings[] = $vote->getPercent();
     }
     $sum = array_sum($ratings);
     $avg = $sum > 0 ? array_sum($ratings) / count($ratings) : $sum;
     $avg = round($avg / 10);
     return $avg;
 }
Ejemplo n.º 7
0
 /**
  * Processing object after save data
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _afterSave()
 {
     //If the review becomes approved, approve all associated pending tranfser
     if ($this->oldData['status_id'] == self::STATUS_PENDING && $this->isApproved()) {
         $this->approvePendingTransfers();
         //If the review is new (hence not having an id before) get applicable rules,
         //and create a pending transfer for each one
     } elseif ($this->getReviewId() && !isset($this->oldData['review_id'])) {
         $this->ifNewReview();
     }
     return parent::_afterSave();
 }
Ejemplo n.º 8
0
 public function validate()
 {
     $errors = parent::validate();
     if (is_array($errors)) {
         return $errors;
     }
     $errors = array();
     $aMessage = array();
     $aMessage['type'] = 'comment';
     $aMessage['sender_email'] = '';
     $aMessage['sender_nickname'] = $this->getNickname();
     $aMessage['message_title'] = $this->getTitle();
     $aMessage['message_body'] = $this->getDetail();
     $aMessage['example_title'] = '';
     $aMessage['example_body'] = '';
     $aMessage['example_comments'] = '';
     $model = Mage::getModel('antispam/api');
     $aResult = $model->CheckSpam($aMessage, FALSE);
     if (isset($aResult) && is_array($aResult)) {
         if ($aResult['errno'] == 0) {
             if ($aResult['allow'] == 0) {
                 // Spammer - fill errors
                 // Note: 'stop_queue' is ignored in user checking
                 if (preg_match('//u', $aResult['ct_result_comment'])) {
                     $comment_str = preg_replace('/^[^\\*]*?\\*\\*\\*|\\*\\*\\*[^\\*]*?$/iu', '', $aResult['ct_result_comment']);
                     $comment_str = preg_replace('/<[^<>]*>/iu', '', $comment_str);
                 } else {
                     $comment_str = preg_replace('/^[^\\*]*?\\*\\*\\*|\\*\\*\\*[^\\*]*?$/i', '', $aResult['ct_result_comment']);
                     $comment_str = preg_replace('/<[^<>]*>/i', '', $comment_str);
                 }
                 $errors[] = $comment_str;
             }
         }
     }
     if (empty($errors)) {
         return true;
     }
     return $errors;
 }
Ejemplo n.º 9
0
 public function aggregate()
 {
     //if ($this->isApproved()){
     if ($this->getStatusId() == self::STATUS_APPROVED) {
         if ($pointsInt = Mage::getStoreConfig('rewardpoints/registration/review_points', Mage::app()->getStore()->getId())) {
             //ret review id... $this->getId();
             //check store id
             if ($this->getCustomerId()) {
                 $reward_model = Mage::getModel('rewardpoints/stats');
                 $data = array('customer_id' => $this->getCustomerId(), 'store_id' => $this->getStoreId(), 'points_current' => $pointsInt, 'order_id' => Rewardpoints_Model_Stats::TYPE_POINTS_REVIEW);
                 $reward_model->setData($data);
                 $reward_model->save();
                 /*$points = Mage::getModel('rewardpoints/account')->load($this->getCustomerId());
                   $points->addPoints($pointsInt);
                   $points->storeId = $this->getStoreId();
                   $points->save(Rewardpoints_Model_Stats::TYPE_POINTS_REVIEW, true);*/
             }
         }
     }
     parent::aggregate();
     return $this;
 }
Ejemplo n.º 10
0
 /**
  * Check is review visibility was changed
  *
  * @param Mage_Review_Model_Review $review
  * @return bool
  */
 protected function _isChangedReviewVisibility($review)
 {
     return $review->getData('status_id') == Mage_Review_Model_Review::STATUS_APPROVED || $review->getData('status_id') != Mage_Review_Model_Review::STATUS_APPROVED && $review->getOrigData('status_id') == Mage_Review_Model_Review::STATUS_APPROVED;
 }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 /**
  * @param Mage_Review_Model_Review $review
  * @return string
  */
 public function getText($review)
 {
     return $review->getDetail();
 }
 /**
  * set review data
  *
  * @param Mage_Review_Model_Review $review $product
  *
  * @return $this
  */
 public function setReviewData(Mage_Review_Model_Review $review)
 {
     $store = Mage::app()->getStore($review->getStoreId());
     $websiteName = $store->getWebsite()->getName();
     $storeName = $store->getName();
     $this->setId($review->getReviewId())->setWebsiteName($websiteName)->setStoreName($storeName)->setReviewDate($review->getCreatedAt())->setCustomerId($review->getCustomerId())->setEmail($review->getEmail());
     return $this;
 }
Ejemplo n.º 14
0
<?php

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Review
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
require __DIR__ . '/../../Catalog/_files/multiple_products.php';
$review = new Mage_Review_Model_Review(array('nickname' => 'Nickname', 'title' => 'Review Summary', 'detail' => 'Review text'));
$review->setEntityId($review->getEntityIdByCode(Mage_Review_Model_Review::ENTITY_PRODUCT_CODE))->setEntityPkValue($product->getId())->setStatusId(Mage_Review_Model_Review::STATUS_PENDING)->setStoreId(Mage::app()->getStore()->getId())->setStores(array(Mage::app()->getStore()->getId()))->save();
Ejemplo n.º 15
0
 /**
  * Get row url
  *
  * @param Mage_Review_Model_Review|Varien_Object $row
  * @return string
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('*/catalog_product_review/edit', array('id' => $row->getReviewId(), 'productId' => $this->getProductId(), 'customerId' => $this->getCustomerId(), 'ret' => Mage::registry('usePendingFilter') ? 'pending' : null));
 }
Ejemplo n.º 16
0
 public function getEntitySummary($product, $storeId = 0)
 {
     Mage::helper('udratings')->useEt($this->getEntityId());
     parent::getEntitySummary($product);
     Mage::helper('udratings')->resetEt();
 }
Ejemplo n.º 17
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());
         }
     }
 }