Ejemplo n.º 1
0
 /**
  * Метод вызывается из Ajax для выполнения действия над комментарием
  */
 public final function executeCommentAction($msgId, $action)
 {
     $msg = $this->getMsgById($msgId);
     check_condition(!$msg->isDeleted(), 'Сообщение удалено');
     $this->validateThreadId($msg->getThreadId());
     $USER = PsUser::inst();
     $msgId = $msg->getId();
     $userId = $USER->getId();
     $authorId = $msg->getUser()->getId();
     $RESPONSE = '';
     switch ($action) {
         //УДАЛЕНИЕ
         case self::COMMENT_ACTION_DELETE:
             check_condition($USER->isAuthorisedAsAdmin() || $USER->isIt($authorId), 'Недостаточно прав');
             $RESPONSE = $this->BEAN->deleteMsg($msg);
             $RESPONSE['known'] = $this->convertMsgIdsToUniques($RESPONSE['known']);
             break;
             //ПОДТВЕРЖДЕНИЕ
         //ПОДТВЕРЖДЕНИЕ
         case self::COMMENT_ACTION_CONFIRM:
             check_condition($USER->isAuthorisedAsAdmin(), 'Недостаточно прав');
             $this->BEAN->confirmMsg($msg);
             if ($msg->isToUser($USER)) {
                 $this->BEAN->markMsgAsKnownDb($msg);
             }
             break;
             //ОТМЕТКА О ПРОЧИТАННОСТИ
         //ОТМЕТКА О ПРОЧИТАННОСТИ
         case self::COMMENT_ACTION_KNOWN:
             check_condition($msg->isToUser($USER), 'Это сообщение отправлено не вам');
             $this->BEAN->markMsgAsKnownDb($msg);
             if ($USER->isAuthorisedAsAdmin()) {
                 $this->BEAN->confirmMsg($msg);
             }
             break;
         case self::COMMENT_ACTION_LIKE:
         case self::COMMENT_ACTION_DISLIKE:
         case self::COMMENT_ACTION_UNVOTE:
             check_condition($this->SETTINGS->isVotable(), 'Голосование запрещено');
             check_condition(!$USER->isIt($authorId), 'Запрещено голосовать за своё сообщение');
             $threadUnique = $this->SETTINGS->getThreadUnique($msg->getThreadId());
             switch ($action) {
                 case self::COMMENT_ACTION_LIKE:
                     VotesManager::inst()->addVote($threadUnique, $msgId, $userId, $authorId, 1);
                     break;
                 case self::COMMENT_ACTION_DISLIKE:
                     VotesManager::inst()->addVote($threadUnique, $msgId, $userId, $authorId, -1);
                     break;
                 case self::COMMENT_ACTION_UNVOTE:
                     VotesManager::inst()->removeVote($threadUnique, $msgId, $userId);
                     break;
             }
             $RESPONSE = VotesManager::inst()->getVotesCount($threadUnique, $msgId);
             break;
         default:
             raise_error("Неизвестное действие [{$action}].");
     }
     return $RESPONSE;
 }
Ejemplo n.º 2
0
 /**
  * Генерация лайков к сообщениям дискуссий
  */
 public final function generateCommentLikes()
 {
     TESTBean::inst()->cleanVotes();
     $userIds = TESTBean::inst()->getUserIds();
     $controllers = Handlers::getInstance()->getDiscussionControllers();
     /** @var $ctrl DiscussionController */
     foreach ($controllers as $ctrt) {
         $settings = $ctrt->getDiscussionSettings();
         if (!$settings->isVotable()) {
             continue;
             //---
         }
         $messages = TESTBean::inst()->getAllMessages($settings);
         foreach ($messages as $msg) {
             $msgId = $msg[$settings->getIdColumn()];
             $threadUnique = $settings->getThreadUnique($msg[$settings->getThreadIdColumn()]);
             $authorId = $msg['id_user'];
             foreach ($userIds as $userId) {
                 if ($authorId == $userId) {
                     continue;
                     //За свои сообщения не голосуем
                 }
                 $votes = rand(-1, 1);
                 if (!$votes) {
                     continue;
                 }
                 VotesManager::inst()->addVote($threadUnique, $msgId, $userId, $authorId, $votes);
             }
         }
     }
 }