예제 #1
0
 /**
  * Метод строит html листочка на дереве дискуссии:
  * 
  * <li>
  * ....
  *    <ul>
  *       <li>
  *       ....
  *       </li>
  *    </ul>
  * </li>
  * 
  * @param DiscussionMsg $msg
  */
 public final function buildLeaf(DiscussionMsg $msg, $simple = false)
 {
     $msgId = $msg->getId();
     $author = $msg->getUser();
     $isDeleted = $msg->isDeleted();
     $isUserComment = $author->isAuthorised();
     $isCanConfirm = !$isUserComment && !$msg->isConfirmed() && !$isDeleted && AuthManager::isAuthorizedAsAdmin();
     $notKnown = !$msg->isKnown() && $msg->getUserTo() && $msg->getUserTo()->isIt(PsUser::instOrNull());
     $msgUnique = $msg->getUnique();
     $threadUnique = $this->SETTINGS->getThreadUnique($msg->getThreadId());
     //Мы открываем страницу для показа этого комментария
     $liId = RequestArrayAdapter::inst()->str(GET_PARAM_GOTO_MSG) === $msgUnique ? " id=\"{$msgUnique}\"" : '';
     //Классы li
     $liClasses = array('msg');
     if ($isDeleted) {
         $liClasses[] = 'deleted';
     }
     //Классы Comment
     $divClasses = array('comment', $msgUnique);
     if ($isUserComment) {
         $divClasses[] = 'user_comment';
     }
     if ($isCanConfirm) {
         $divClasses[] = 'not_confirmed';
     }
     //Данные для Comment
     $divData['unique'] = $msgUnique;
     //Имя пользователя
     $userName = $author->getName() . ($isUserComment ? ' (вы)' : '');
     //КНОПКИ УПРАВЛЕНИЯ СВЕРХУ
     $controlsTop = array();
     if (!$simple) {
         //Кнопки управления сверху
         $controlsTop[] = PsHtml::a(array('href' => '#'), '#');
         if (!$msg->isRoot()) {
             $controlsTop[] = PsHtml::a(array('href' => '#', 'class' => 'parent'), '↑');
         }
     }
     //Кнопки голосования
     if ($this->SETTINGS->isVotable()) {
         $userCanVote = AuthManager::isAuthorized() && !$isUserComment;
         $votes = VotesManager::inst()->getVotesCount($threadUnique, $msgId);
         $likeCtrl = array();
         if ($userCanVote) {
             $vote = VotesManager::inst()->getUserVotes($threadUnique, $msgId, AuthManager::getUserId());
             $likeCtrl[] = PsHtml::a(array('class' => 'like ' . ($vote > 0 ? 'active' : 'clickable')), '+1');
             $likeCtrl[] = PsHtml::a(array('class' => 'votes' . ($vote == 0 ? '' : ' clickable') . ($votes == 0 ? '' : ($votes > 0 ? ' green' : ' red'))), abs($votes));
             $likeCtrl[] = PsHtml::a(array('class' => 'dislike ' . ($vote < 0 ? 'active' : 'clickable')), '−1');
         } else {
             $likeCtrl[] = PsHtml::a(array('class' => 'votes' . ($votes == 0 ? '' : ($votes > 0 ? ' green' : ' red'))), abs($votes));
         }
         $controlsTop[] = PsHtml::span(array('class' => 'vote'), implode('', $likeCtrl));
     }
     $controlsTop = implode('', $controlsTop);
     //КНОПКИ УПРАВЛЕНИЯ СНИЗУ
     $controlsBottom = '';
     if (!$simple && !$isDeleted) {
         $controlsBottom = array();
         $controlsBottom['id'] = $msgId;
         if ($isCanConfirm) {
             $controlsBottom[SmartyFunctions::ACTION_CONFIRM] = 'Принять';
         }
         if (!$msg->isMaxDeepLevel()) {
             $controlsBottom[SmartyFunctions::ACTION_REPLY] = 'Ответить';
         }
         if ($isUserComment) {
             $controlsBottom[SmartyFunctions::ACTION_DELETE] = 'Удалить';
         } elseif (AuthManager::isAuthorizedAsAdmin()) {
             $controlsBottom[SmartyFunctions::ACTION_DELETE] = 'Удалить (админ)';
         }
         $controlsBottom = SmartyFunctions::psctrl($controlsBottom);
     }
     //Собираем параметры в кучу
     $params['msg'] = $msg;
     $params['new'] = $notKnown;
     $params['builder'] = $this;
     $params['liId'] = $liId;
     $params['liClasses'] = implode(' ', $liClasses);
     $params['divClasses'] = implode(' ', $divClasses);
     $params['divData'] = PsHtml::data2string($divData);
     $params['msgId'] = $msgId;
     $params['simple'] = $simple;
     $params['avatar'] = $author->getAvatarImg('42x', array('class' => 'small'));
     $params['userName'] = $userName;
     $params['controlsTop'] = $controlsTop;
     $params['controlsBottom'] = $controlsBottom;
     if ($msg->isTemplated()) {
         $params['msgCtt'] = TemplateMessages::inst()->decodeTemplateMsg($msg);
     } else {
         $params['msgCtt'] = $msg;
     }
     return PSSmarty::template('discussion/common/leaf.tpl', $params)->fetch();
 }
예제 #2
0
 /**
  * Основной метод удаления сообщения
  */
 public function deleteMsg(DiscussionMsg $msg)
 {
     check_condition(!$msg->isDeleted(), 'Massage is already deleted');
     //Выделим ряд переменных
     $msgId = $msg->getId();
     //Перенесём все данные в хранилище
     $this->backupMsg($msgId);
     //Вернём результат удаления
     $result['known'] = array();
     //Если есть потомки, то можем только обновить содержимое на null
     if ($this->hasChilds($msgId)) {
         $theme = $this->themeColumn ? ", {$this->themeColumn}=null" : '';
         $this->update("update {$this->table} set b_deleted=1, b_known=1, b_confirmed=1, content=null {$theme} where {$this->idColumn}=?", $msgId);
         $result['known'] = $this->markMsgChildsAsKnownDb($msgId, $msg->getUser()->getId());
         return $result;
         //---
     }
     //Удаляем комментарий физически
     $this->update("delete from {$this->table} where {$this->idColumn}=?", $msgId);
     //Проверим, нельзя ли физически удалить предка данного сообщения
     $this->tryCleanParentOf($msg);
     return $result;
 }