Beispiel #1
0
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         $ratingStat = RatingStat::findOne(['record_id' => $this->record_id, 'rating' => $this->rating]);
         if (!$ratingStat) {
             $ratingStat = new RatingStat();
             $ratingStat->record_id = $this->record_id;
             $ratingStat->rating = $this->rating;
             $ratingStat->count = 0;
         }
         $ratingStat->count = intval($ratingStat->count) + 1;
         $ratingStat->save();
     }
 }
Beispiel #2
0
 /**
  * @return string
  */
 public function run()
 {
     if (!$this->_initError) {
         return $this->render('index', ['min' => $this->_ratingModule->min, 'max' => $this->_ratingModule->max, 'step' => $this->_ratingModule->step, 'recordId' => $this->recordId, 'ratingStats' => RatingStat::findAll(['record_id' => $this->recordId])]);
     }
     return \Yii::t("rating", "Unknown recordId");
 }