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