<?php
class actionUsersKarmaVote extends cmsAction {
public function run($profile_id) {
if (!$this->cms_user->is_logged) {
return cmsCore::error404();
}
if (!$this->request->isAjax()) {
return cmsCore::error404();
}
$direction = $this->request->get('direction', '');
$comment = $this->request->get('comment', '');
//
// Проверяем валидность
//
$is_valid = cmsUser::isAllowed('users', 'vote_karma') &&
$this->cms_user->id != $profile_id &&
(!$this->options['is_karma_comments'] || $comment);
if (!$is_valid) {
return $this->cms_template->renderJSON([
'error' => true,
'message' => LANG_ERROR
]);
}
$profile = $this->model->getUser($profile_id);
if (!$profile || $profile['is_locked'] ||
!$this->model->isUserCanVoteKarma($this->cms_user->id, $profile_id, $this->options['karma_time'])) {
return $this->cms_template->renderJSON([
'error' => true,
'message' => LANG_ERROR
]);
}
//
// Сохраняем оценку
//
$vote = [
'user_id' => $this->cms_user->id,
'profile_id' => $profile_id,
'points' => $direction == 'up' ? 1 : -1,
'comment' => $comment
];
$user_ids = $this->cms_user->id;
$user_voted = $this->cms_user->nickname;
$user_voteds = "<a title=\"$user_voted\" href=\"/users/$user_ids\">$user_voted</a>";
$vote_id = $this->model->addKarmaVote($vote);
$value = $profile['karma'] + $vote['points'];
cmsEventsManager::hook('users_karma_vote', [
'profile' => $profile,
'vote' => $vote
]);
$points = $vote['points'];
if ($points > 0){
$mess = $user_voteds . ' ' . 'оставил Вам <div class="positive_otz">ПОЛОЖИТЕЛЬНЫЙ</div> отзыв' . ' ' . 'с комментарием:' . '<blockquote class="otziv"> ' .$comment . '</blockquote> ' . 'НЕ ЗАБУДЬТЕ ЕГО ОТБЛАГОДАРИТЬ';}
else
{$mess = $user_voteds . ' ' . 'оставил Вам <div class="negative_otz">НЕГАТИВНЫЙ</div> отзыв' . ' ' . 'с комментарием' . '<blockquote class="otziv"> ' .$comment . '</blockquote> ';}
if ($points != 0){
'user_id' => $this->cms_user->id,
'points' => $points,
'comment' => $mess
);
cmsCore::getModel('users')->addKarmaVote($item);
$messenger = cmsCore::getController('messages');
$messenger->addRecipient($profile);
$messenger->sendNoticePM(array( 'content' => $mess,
'title' => 'Посмотреть отзыв',
'href' => href_to('users', $profile_id, 'karma')
)
)
));
}
return $this->cms_template->renderJSON([
'error' => $vote_id ? false : true,
'value' => html_signed_num($value),
'css_class' => html_signed_class($value)
]);
}
}
?>