article_review.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Review extends oxAdminDetails
00010 {
00011 
00018     public function render()
00019     {
00020         $myConfig = $this->getConfig();
00021 
00022         parent::render();
00023 
00024         $this->_aViewData["edit"] = $oArticle = oxNew("oxarticle");
00025 
00026         $soxId = $this->getEditObjectId();
00027         $sRevoxId = oxRegistry::getConfig()->getRequestParameter('rev_oxid');
00028         if ($soxId != "-1" && isset($soxId)) {
00029 
00030             // load object
00031             $oArticle->load($soxId);
00032 
00033 
00034             $oRevs = $this->_getReviewList($oArticle);
00035 
00036             foreach ($oRevs as $oRev) {
00037                 if ($oRev->oxreviews__oxid->value == $sRevoxId) {
00038                     $oRev->selected = 1;
00039                     break;
00040                 }
00041             }
00042             $this->_aViewData["allreviews"] = $oRevs;
00043             $this->_aViewData["editlanguage"] = $this->_iEditLang;
00044 
00045             if (isset($sRevoxId)) {
00046                 $oReview = oxNew("oxreview");
00047                 $oReview->load($sRevoxId);
00048                 $this->_aViewData["editreview"] = $oReview;
00049 
00050                 $oUser = oxNew("oxuser");
00051                 $oUser->load($oReview->oxreviews__oxuserid->value);
00052                 $this->_aViewData["user"] = $oUser;
00053             }
00054             //show "active" checkbox if moderating is active
00055             $this->_aViewData["blShowActBox"] = $myConfig->getConfigParam('blGBModerate');
00056 
00057         }
00058 
00059         return "article_review.tpl";
00060     }
00061 
00069     protected function _getReviewList($oArticle)
00070     {
00071         $oDb = oxDb::getDb();
00072         $sSelect = "select oxreviews.* from oxreviews
00073                      where oxreviews.OXOBJECTID = " . $oDb->quote($oArticle->oxarticles__oxid->value) . "
00074                      and oxreviews.oxtype = 'oxarticle'";
00075 
00076         $aVariantList = $oArticle->getVariants();
00077 
00078         if ($this->getConfig()->getConfigParam('blShowVariantReviews') && count($aVariantList)) {
00079 
00080             // verifying rights
00081             foreach ($aVariantList as $oVariant) {
00082                 $sSelect .= "or oxreviews.oxobjectid = " . $oDb->quote($oVariant->oxarticles__oxid->value) . " ";
00083             }
00084 
00085         }
00086 
00087         //$sSelect .= "and oxreviews.oxtext".oxRegistry::getLang()->getLanguageTag($this->_iEditLang)." != ''";
00088         $sSelect .= "and oxreviews.oxlang = '" . $this->_iEditLang . "'";
00089         $sSelect .= "and oxreviews.oxtext != '' ";
00090 
00091         // all reviews
00092         $oRevs = oxNew("oxlist");
00093         $oRevs->init("oxreview");
00094         $oRevs->selectString($sSelect);
00095 
00096         return $oRevs;
00097     }
00098 
00102     public function save()
00103     {
00104         parent::save();
00105 
00106         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00107         // checkbox handling
00108         if ($this->getConfig()->getConfigParam('blGBModerate') && !isset($aParams['oxreviews__oxactive'])) {
00109             $aParams['oxreviews__oxactive'] = 0;
00110         }
00111 
00112         $oReview = oxNew("oxreview");
00113         $oReview->load(oxRegistry::getConfig()->getRequestParameter("rev_oxid"));
00114         $oReview->assign($aParams);
00115         $oReview->save();
00116     }
00117 
00121     public function delete()
00122     {
00123         $this->resetContentCache();
00124 
00125         $sRevoxId = oxRegistry::getConfig()->getRequestParameter("rev_oxid");
00126         $oReview = oxNew("oxreview");
00127         $oReview->load($sRevoxId);
00128         $oReview->delete();
00129 
00130         // recalculating article average rating
00131         $oRating = oxNew("oxRating");
00132         $sArticleId = $this->getEditObjectId();
00133 
00134         $oArticle = oxNew('oxArticle');
00135         $oArticle->load($sArticleId);
00136 
00137         $oArticle->setRatingAverage($oRating->getRatingAverage($sArticleId, 'oxarticle'));
00138         $oArticle->setRatingCount($oRating->getRatingCount($sArticleId, 'oxarticle'));
00139         $oArticle->save();
00140 
00141     }
00142 }