Esempio n. 1
0
 /**
  * Удаляет свзяанные с топиком данные
  *
  * @param   int|array $aTopicId   ID топика или массив ID
  *
  * @return  bool
  */
 public function DeleteTopicAdditionalData($aTopicId)
 {
     if (!is_array($aTopicId)) {
         $aTopicId = array(intval($aTopicId));
     }
     // * Удаляем контент топика
     $this->DeleteTopicContentByTopicId($aTopicId);
     /**
      * Удаляем комментарии к топику.
      * При удалении комментариев они удаляются из избранного,прямого эфира и голоса за них
      */
     E::ModuleComment()->DeleteCommentByTargetId($aTopicId, 'topic');
     /**
      * Удаляем топик из избранного
      */
     $this->DeleteFavouriteTopicByArrayId($aTopicId);
     /**
      * Удаляем топик из прочитанного
      */
     $this->DeleteTopicReadByArrayId($aTopicId);
     /**
      * Удаляем голосование к топику
      */
     E::ModuleVote()->DeleteVoteByTarget($aTopicId, 'topic');
     /**
      * Удаляем теги
      */
     $this->DeleteTopicTagsByTopicId($aTopicId);
     /**
      * Удаляем фото у топика фотосета
      */
     if ($aPhotos = $this->getPhotosByTopicId($aTopicId)) {
         foreach ($aPhotos as $oPhoto) {
             $this->deleteTopicPhoto($oPhoto);
         }
     }
     /**
      * Чистим зависимые кеши
      */
     E::ModuleCache()->CleanByTags(array('topic_update'));
     foreach ($aTopicId as $nTopicId) {
         E::ModuleCache()->Delete("topic_{$nTopicId}");
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Получает дополнительные данные(объекты) для юзеров по их ID
  *
  * @param array|int $aUsersId   - Список ID пользователей
  * @param array     $aAllowData - Список типоd дополнительных данных для подгрузки у пользователей
  *
  * @return ModuleUser_EntityUser[]
  */
 public function GetUsersAdditionalData($aUsersId, $aAllowData = null)
 {
     if (!$aUsersId) {
         return array();
     }
     if (!is_array($aUsersId)) {
         $aUsersId = array($aUsersId);
     } else {
         $aUsersId = array_unique($aUsersId);
     }
     if (sizeof($aUsersId) == 1) {
         $iUserId = reset($aUsersId);
         if ($this->oUserCurrent && $this->oUserCurrent->getId() == $iUserId) {
             return array($iUserId => $this->oUserCurrent);
         }
     }
     if (is_null($aAllowData)) {
         $aAllowData = $this->aAdditionalData;
     }
     $aAllowData = F::Array_FlipIntKeys($aAllowData);
     // * Получаем юзеров
     $aUsers = $this->GetUsersByArrayId($aUsersId);
     // * Получаем дополнительные данные
     $aSessions = array();
     $aFriends = array();
     $aVote = array();
     $aGeoTargets = array();
     $aNotes = array();
     if (isset($aAllowData['session'])) {
         $aSessions = $this->GetSessionsByArrayId($aUsersId);
     }
     if (isset($aAllowData['friend']) && $this->oUserCurrent) {
         $aFriends = $this->GetFriendsByArray($aUsersId, $this->oUserCurrent->getId());
     }
     if (isset($aAllowData['vote']) && $this->oUserCurrent) {
         $aVote = E::ModuleVote()->GetVoteByArray($aUsersId, 'user', $this->oUserCurrent->getId());
     }
     if (isset($aAllowData['geo_target'])) {
         $aGeoTargets = E::ModuleGeo()->GetTargetsByTargetArray('user', $aUsersId);
     }
     if (isset($aAllowData['note']) && $this->oUserCurrent) {
         $aNotes = $this->GetUserNotesByArray($aUsersId, $this->oUserCurrent->getId());
     }
     $aAvatars = E::ModuleUploader()->GetMediaObjects('profile_avatar', $aUsersId, null, array('target_id'));
     // * Добавляем данные к результату
     /** @var ModuleUser_EntityUser $oUser */
     foreach ($aUsers as $oUser) {
         if (isset($aSessions[$oUser->getId()])) {
             $oUser->setSession($aSessions[$oUser->getId()]);
         } else {
             $oUser->setSession(null);
             // или $oUser->setSession(new ModuleUser_EntitySession());
         }
         if ($aFriends && isset($aFriends[$oUser->getId()])) {
             $oUser->setUserFriend($aFriends[$oUser->getId()]);
         } else {
             $oUser->setUserFriend(null);
         }
         if (isset($aVote[$oUser->getId()])) {
             $oUser->setVote($aVote[$oUser->getId()]);
         } else {
             $oUser->setVote(null);
         }
         if (isset($aGeoTargets[$oUser->getId()])) {
             $aTargets = $aGeoTargets[$oUser->getId()];
             $oUser->setGeoTarget(isset($aTargets[0]) ? $aTargets[0] : null);
         } else {
             $oUser->setGeoTarget(null);
         }
         if (isset($aAllowData['note'])) {
             if (isset($aNotes[$oUser->getId()])) {
                 $oUser->setUserNote($aNotes[$oUser->getId()]);
             } else {
                 $oUser->setUserNote(false);
             }
         }
         if (isset($aAvatars[$oUser->getId()])) {
             $oUser->setMediaResources('profile_avatar', $aAvatars[$oUser->getId()]);
         } else {
             $oUser->setMediaResources('profile_avatar', array());
         }
     }
     return $aUsers;
 }
Esempio n. 3
0
 /**
  * Голосование админа
  */
 public function EventAjaxVote()
 {
     // * Устанавливаем формат ответа
     E::ModuleViewer()->SetResponseAjax('json');
     if (!E::IsAdmin()) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error'));
         return;
     }
     $nUserId = $this->GetPost('idUser');
     if (!$nUserId || !($oUser = E::ModuleUser()->GetUserById($nUserId))) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_not_found'), E::ModuleLang()->Get('error'));
         return;
     }
     $nValue = $this->GetPost('value');
     $oUserVote = E::GetEntity('Vote');
     $oUserVote->setTargetId($oUser->getId());
     $oUserVote->setTargetType('user');
     $oUserVote->setVoterId($this->oUserCurrent->getId());
     $oUserVote->setDirection($nValue);
     $oUserVote->setDate(F::Now());
     $iVal = (double) E::ModuleRating()->VoteUser($this->oUserCurrent, $oUser, $nValue);
     $oUserVote->setValue($iVal);
     $oUser->setCountVote($oUser->getCountVote() + 1);
     if (E::ModuleVote()->AddVote($oUserVote) && E::ModuleUser()->Update($oUser)) {
         E::ModuleViewer()->AssignAjax('iRating', $oUser->getRating());
         E::ModuleViewer()->AssignAjax('iSkill', $oUser->getSkill());
         E::ModuleViewer()->AssignAjax('iCountVote', $oUser->getCountVote());
         E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('user_vote_ok'), E::ModuleLang()->Get('attention'));
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('action.admin.vote_error'), E::ModuleLang()->Get('error'));
     }
 }
Esempio n. 4
0
 /**
  * Голосование за пользователя
  *
  */
 protected function EventVoteUser()
 {
     // * Пользователь авторизован?
     if (!$this->oUserCurrent) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error'));
         return;
     }
     // * Пользователь существует?
     if (!($oUser = E::ModuleUser()->GetUserById(F::GetRequestStr('idUser', null, 'post')))) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error'));
         return;
     }
     // * Голосует за себя?
     if ($oUser->getId() == $this->oUserCurrent->getId()) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_vote_error_self'), E::ModuleLang()->Get('attention'));
         return;
     }
     // * Уже голосовал?
     if ($oUserVote = E::ModuleVote()->GetVote($oUser->getId(), 'user', $this->oUserCurrent->getId())) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_vote_error_already'), E::ModuleLang()->Get('attention'));
         return;
     }
     // * Имеет право на голосование?
     if (!E::ModuleACL()->CanVoteUser($this->oUserCurrent, $oUser)) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('user_vote_error_acl'), E::ModuleLang()->Get('attention'));
         return;
     }
     // * Как проголосовал
     $iValue = F::GetRequestStr('value', null, 'post');
     if (!in_array($iValue, array('1', '-1'))) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('attention'));
         return;
     }
     // * Голосуем
     /** @var ModuleVote_EntityVote $oUserVote */
     $oUserVote = E::GetEntity('Vote');
     $oUserVote->setTarget($oUser);
     $oUserVote->setTargetId($oUser->getId());
     $oUserVote->setTargetType('user');
     $oUserVote->setVoter($this->oUserCurrent);
     $oUserVote->setVoterId($this->oUserCurrent->getId());
     $oUserVote->setDirection($iValue);
     $oUserVote->setDate(F::Now());
     if ($iValue != 0) {
         $nDeltaRating = (double) E::ModuleRating()->VoteUser($this->oUserCurrent, $oUser, $iValue);
     } else {
         $nDeltaRating = 0.0;
     }
     $oUserVote->setValue($nDeltaRating);
     $oUser->setCountVote($oUser->getCountVote() + 1);
     if (E::ModuleVote()->AddVote($oUserVote) && E::ModuleUser()->Update($oUser)) {
         E::ModuleMessage()->AddNoticeSingle(E::ModuleLang()->Get('user_vote_ok'), E::ModuleLang()->Get('attention'));
         E::ModuleViewer()->AssignAjax('iRating', number_format($oUser->getRating(), Config::Get('view.skill_length')));
         E::ModuleViewer()->AssignAjax('iSkill', number_format($oUser->getSkill(), Config::Get('view.rating_length')));
         E::ModuleViewer()->AssignAjax('iCountVote', $oUser->getCountVote());
         // * Добавляем событие в ленту
         E::ModuleStream()->Write($oUserVote->getVoterId(), 'vote_user', $oUser->getId());
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error'));
         return;
     }
 }
Esempio n. 5
0
 /**
  * Удаляет блог
  *
  * @param   int|array $aBlogsId   ID блога|массив ID блогов
  *
  * @return  bool
  */
 public function DeleteBlog($aBlogsId)
 {
     // Получаем массив ID, если передан объект или массив объектов
     $aBlogsId = $this->_entitiesId($aBlogsId);
     if ($aBlogsId) {
         // * Получаем идентификаторы топиков блога. Удаляем топики блога.
         // * При удалении топиков удаляются комментарии к ним и голоса.
         $aTopicsId = E::ModuleTopic()->GetTopicsByBlogId($aBlogsId);
         // * Если блог не удален, возвращаем false
         if (!$this->oMapper->DeleteBlog($aBlogsId)) {
             return false;
         }
         if ($aTopicsId) {
             // * Удаляем топики
             E::ModuleTopic()->DeleteTopics($aTopicsId);
         }
         // * Удаляем связи пользователей блога.
         $this->oMapper->DeleteBlogUsersByBlogId($aBlogsId);
         // * Удаляем голосование за блог
         E::ModuleVote()->DeleteVoteByTarget($aBlogsId, 'blog');
         // * Чистим кеш
         E::ModuleCache()->CleanByTags(array('blog_update', 'topic_update', 'comment_online_update_topic', 'comment_update'));
         foreach ($aBlogsId as $nBlogId) {
             E::ModuleCache()->CleanByTags(array("blog_relation_change_blog_{$nBlogId}"));
             E::ModuleCache()->Delete("blog_{$nBlogId}");
         }
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Удаляет комментарии из базы данных
  *
  * @param   array|int   $aTargetsId      Список ID владельцев
  * @param   string      $sTargetType     Тип владельцев
  *
  * @return  bool
  */
 public function DeleteCommentByTargetId($aTargetsId, $sTargetType)
 {
     if (!is_array($aTargetsId)) {
         $aTargetsId = array($aTargetsId);
     }
     // * Получаем список идентификаторов удаляемых комментариев
     $aCommentsId = $this->GetCommentsIdByTargetsId($aTargetsId, $sTargetType);
     // * Если ни одного комментария не найдено, выходим
     if (!count($aCommentsId)) {
         return true;
     }
     $bResult = $this->oMapper->DeleteCommentByTargetId($aTargetsId, $sTargetType);
     if ($bResult) {
         // * Удаляем комментарии из избранного
         $this->DeleteFavouriteCommentsByArrayId($aCommentsId);
         // * Удаляем комментарии к топику из прямого эфира
         $this->DeleteCommentOnlineByArrayId($aCommentsId, $sTargetType);
         // * Удаляем голосование за комментарии
         E::ModuleVote()->DeleteVoteByTarget($aCommentsId, 'comment');
     }
     // * Чистим зависимые кеши, даже если что-то не так пошло
     if (Config::Get('sys.cache.solid')) {
         foreach ($aTargetsId as $nTargetId) {
             E::ModuleCache()->CleanByTags(array("comment_update", "comment_target_{$nTargetId}_{$sTargetType}"));
         }
     } else {
         foreach ($aTargetsId as $nTargetId) {
             E::ModuleCache()->CleanByTags(array("comment_target_{$nTargetId}_{$sTargetType}"));
         }
         if ($aCommentsId) {
             // * Удаляем кеш для каждого комментария
             foreach ($aCommentsId as $iCommentId) {
                 E::ModuleCache()->Delete("comment_{$iCommentId}");
             }
         }
     }
     return $bResult;
 }