/** * @param $id * @param $action * @return string */ public function actionRating($id, $action) { $id = intval($id); $ratingValue = $this->_getRatingValue($action); if (!\Yii::$app->request->isAjax || !$id || !$ratingValue) { return \Yii::t("comment", "Bad request"); } $userId = \Yii::$app->user->id; $userHash = Utils::userHash(\Yii::$app->request->userIP); $isGuest = \Yii::$app->user->isGuest; $comment = Comment::find()->where(['id' => $id])->one(); if (!$comment) { return \Yii::t("comment", "Can't see any comments even through my spyglass"); } if ($isGuest && $comment->user_hash == $userHash || !$isGuest && $comment->user_id == $userId) { return \Yii::t("comment", "Avast! Ya can't vote for yer own comment"); } if ($this->_checkMark($comment->id, $isGuest, $userHash, $userId)) { return \Yii::t("comment", "C'mon, lad, ya've already voted on this comment"); } return $this->_saveRating($comment, $ratingValue); }
/** * @inheritdoc */ protected function getValue($event) { return Utils::userHash(\Yii::$app->request->userIP); }