Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['rating_id', 'object_id', 'object_model_id', 'rating_item_id', 'date'], 'required'], [['object_id', 'object_model_id', 'rating_item_id', 'value', 'user_id'], 'integer'], [['user_id'], 'default', 'value' => 0], [['date'], 'safe'], [['rating_id'], 'string', 'max' => 255], [['value'], function ($attribute, $params) {
         $rating = RatingItem::getOneItemByAttributes(['id' => isset($this->rating_item_id) ? $this->rating_item_id : null], true);
         $value = intval($this->value);
         if (!empty($rating)) {
             if ($value > $rating['max_value']) {
                 $value = $rating['max_value'];
             } elseif ($value < $rating['min_value']) {
                 $value = $rating['min_value'];
             }
         }
         $this->value = $value;
     }]];
 }
 /**
  * @param null $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function actionItemDelete($id = null)
 {
     $item = RatingItem::getOneItemByAttributes(['id' => $id]);
     if (empty($item)) {
         throw new NotFoundHttpException();
     }
     $group = $item->rating_group;
     $item->delete();
     return $this->redirect(Url::to(['group-edit', 'group' => urlencode($group)]));
 }