OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
article_review.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
18  public function render()
19  {
20  $myConfig = $this->getConfig();
21 
23 
24  $this->_aViewData["edit"] = $oArticle = oxNew("oxarticle");
25 
26  $soxId = $this->getEditObjectId();
27  $sRevoxId = oxRegistry::getConfig()->getRequestParameter('rev_oxid');
28  if ($soxId != "-1" && isset($soxId)) {
29 
30  // load object
31  $oArticle->load($soxId);
32 
33 
34  $oRevs = $this->_getReviewList($oArticle);
35 
36  foreach ($oRevs as $oRev) {
37  if ($oRev->oxreviews__oxid->value == $sRevoxId) {
38  $oRev->selected = 1;
39  break;
40  }
41  }
42  $this->_aViewData["allreviews"] = $oRevs;
43  $this->_aViewData["editlanguage"] = $this->_iEditLang;
44 
45  if (isset($sRevoxId)) {
46  $oReview = oxNew("oxreview");
47  $oReview->load($sRevoxId);
48  $this->_aViewData["editreview"] = $oReview;
49 
50  $oUser = oxNew("oxuser");
51  $oUser->load($oReview->oxreviews__oxuserid->value);
52  $this->_aViewData["user"] = $oUser;
53  }
54  //show "active" checkbox if moderating is active
55  $this->_aViewData["blShowActBox"] = $myConfig->getConfigParam('blGBModerate');
56 
57  }
58 
59  return "article_review.tpl";
60  }
61 
69  protected function _getReviewList($oArticle)
70  {
71  $oDb = oxDb::getDb();
72  $sSelect = "select oxreviews.* from oxreviews
73  where oxreviews.OXOBJECTID = " . $oDb->quote($oArticle->oxarticles__oxid->value) . "
74  and oxreviews.oxtype = 'oxarticle'";
75 
76  $aVariantList = $oArticle->getVariants();
77 
78  if ($this->getConfig()->getConfigParam('blShowVariantReviews') && count($aVariantList)) {
79 
80  // verifying rights
81  foreach ($aVariantList as $oVariant) {
82  $sSelect .= "or oxreviews.oxobjectid = " . $oDb->quote($oVariant->oxarticles__oxid->value) . " ";
83  }
84 
85  }
86 
87  //$sSelect .= "and oxreviews.oxtext".oxRegistry::getLang()->getLanguageTag($this->_iEditLang)." != ''";
88  $sSelect .= "and oxreviews.oxlang = '" . $this->_iEditLang . "'";
89  $sSelect .= "and oxreviews.oxtext != '' ";
90 
91  // all reviews
92  $oRevs = oxNew("oxlist");
93  $oRevs->init("oxreview");
94  $oRevs->selectString($sSelect);
95 
96  return $oRevs;
97  }
98 
102  public function save()
103  {
104  parent::save();
105 
106  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
107  // checkbox handling
108  if ($this->getConfig()->getConfigParam('blGBModerate') && !isset($aParams['oxreviews__oxactive'])) {
109  $aParams['oxreviews__oxactive'] = 0;
110  }
111 
112  $oReview = oxNew("oxreview");
113  $oReview->load(oxRegistry::getConfig()->getRequestParameter("rev_oxid"));
114  $oReview->assign($aParams);
115  $oReview->save();
116  }
117 
121  public function delete()
122  {
123  $this->resetContentCache();
124 
125  $sRevoxId = oxRegistry::getConfig()->getRequestParameter("rev_oxid");
126  $oReview = oxNew("oxreview");
127  $oReview->load($sRevoxId);
128  $oReview->delete();
129 
130  // recalculating article average rating
131  $oRating = oxNew("oxRating");
132  $sArticleId = $this->getEditObjectId();
133 
134  $oArticle = oxNew('oxArticle');
135  $oArticle->load($sArticleId);
136 
137  $oArticle->setRatingAverage($oRating->getRatingAverage($sArticleId, 'oxarticle'));
138  $oArticle->setRatingCount($oRating->getRatingCount($sArticleId, 'oxarticle'));
139  $oArticle->save();
140 
141  }
142 }