/**
  * Поиск текста по топикам
  *
  * @param string $sRegExp
  * @param int    $iCount
  * @param int    $iCurrPage
  * @param int    $iPerPage
  * @param array  $aParams
  *
  * @return array
  */
 public function GetTopicsIdByRegexp($sRegExp, &$iCount, $iCurrPage, $iPerPage, $aParams)
 {
     $aData = $this->PrepareRegExp($sRegExp);
     $aWeight = array();
     // Обработка возможного фильтра. Пока параметр один - это разрешённые блоги для пользователя
     // но на будущее условия разделены
     if (isset($aParams['aFilter']) && is_array($aParams['aFilter']) && !empty($aParams['aFilter'])) {
         // Если определён список типов/ид. разрешённых блогов
         if (isset($aParams['aFilter']['blog_type']) && is_array($aParams['aFilter']['blog_type']) && !empty($aParams['aFilter']['blog_type'])) {
             $sWhere = '';
             $aBlogTypes = array();
             $aOrClauses = array();
             $aParams['aFilter']['blog_type'] = F::Array_FlipIntKeys($aParams['aFilter']['blog_type'], 0);
             foreach ($aParams['aFilter']['blog_type'] as $sType => $aBlogsId) {
                 if ($aBlogsId) {
                     if ($sType == '*') {
                         $aOrClauses[] = "(t.blog_id IN ('" . join("','", $aBlogsId) . "'))";
                     } else {
                         $aOrClauses[] = "b.blog_type='" . $sType . "' AND t.blog_id IN ('" . join("','", $aBlogsId) . "')";
                     }
                 } else {
                     $aBlogTypes[] = "'" . $sType . "'";
                 }
             }
             if ($aBlogTypes) {
                 $aOrClauses[] = '(b.blog_type IN (' . join(',', $aBlogTypes) . '))';
             }
             if ($aOrClauses) {
                 $sWhere .= ' AND (' . join(' OR ', $aOrClauses) . ')';
             }
         }
     }
     $aWeight[] = "(LOWER(t.topic_title) REGEXP " . $this->oDb->escape($aData['regexp']['phrase']) . ")*" . $aData['rates']['phrase'] * $aData['rates']['title'];
     $aWeight[] = "(LOWER(tc.topic_text_source) REGEXP " . $this->oDb->escape($aData['regexp']['phrase']) . ")*" . $aData['rates']['phrase'];
     foreach ($aData['words'] as $sWord) {
         $aWeight[] = "(LOWER(t.topic_title) REGEXP " . $this->oDb->escape($sWord) . ")*" . $aData['rates']['words'] * $aData['rates']['title'];
         $aWeight[] = "(LOWER(tc.topic_text_source) REGEXP " . $this->oDb->escape($sWord) . ")*" . $aData['rates']['words'];
     }
     $sWeight = implode('+', $aWeight);
     $aResult = array();
     $sql = "\n                SELECT t.topic_id,\n                    {$sWeight} AS weight\n                FROM ?_topic AS t\n                    INNER JOIN ?_topic_content AS tc ON tc.topic_id=t.topic_id\n                    " . (C::Get('module.search.accessible') ? 'INNER JOIN ?_blog AS b ON b.blog_id=t.blog_id' : '') . "\n                WHERE \n                    (topic_publish=1)\n                    " . $sWhere . "\n                     AND topic_index_ignore=0\n                     AND (\n                        (LOWER(t.topic_title) REGEXP ?)\n                        OR (LOWER(tc.topic_text_source) REGEXP ?)\n                     )\n                ORDER BY\n                    weight DESC,\n                    t.topic_id ASC\n                LIMIT ?d, ?d\n            ";
     $aRows = $this->oDb->selectPage($iCount, $sql, $aData['regexp']['words'], $aData['regexp']['words'], ($iCurrPage - 1) * $iPerPage, $iPerPage);
     if ($aRows) {
         foreach ($aRows as $aRow) {
             $aResult[] = $aRow['topic_id'];
         }
     }
     return $aResult;
 }
Exemple #2
0
 /**
  * Получает дополнительные данные(объекты) для топиков по их ID
  *
  * @param array|int  $aTopicId    Список ID топиков
  * @param array|null $aAllowData  Список типов дополнительных данных, которые нужно подключать к топикам
  *
  * @return ModuleTopic_EntityTopic[]
  */
 public function GetTopicsAdditionalData($aTopicId, $aAllowData = null)
 {
     if (!is_array($aTopicId)) {
         $aTopicId = array($aTopicId);
     }
     // * Получаем "голые" топики
     $aTopics = $this->GetTopicsByArrayId($aTopicId);
     if (!$aTopics) {
         return array();
     }
     if (is_null($aAllowData)) {
         $aAllowData = $this->aAdditionalData;
     }
     $aAllowData = F::Array_FlipIntKeys($aAllowData);
     // * Формируем ID дополнительных данных, которые нужно получить
     $aUserId = array();
     $aBlogId = array();
     $aTopicId = array();
     $aPhotoMainId = array();
     /** @var ModuleTopic_EntityTopic $oTopic */
     foreach ($aTopics as $oTopic) {
         if (isset($aAllowData['user'])) {
             $aUserId[] = $oTopic->getUserId();
         }
         if (isset($aAllowData['blog'])) {
             $aBlogId[] = $oTopic->getBlogId();
         }
         $aTopicId[] = $oTopic->getId();
         if ($oTopic->getPhotosetMainPhotoId()) {
             $aPhotoMainId[] = $oTopic->getPhotosetMainPhotoId();
         }
     }
     if ($aUserId) {
         $aUserId = array_unique($aUserId);
     }
     if ($aBlogId) {
         $aBlogId = array_unique($aBlogId);
     }
     /**
      * Получаем дополнительные данные
      */
     $aTopicsVote = array();
     $aFavouriteTopics = array();
     $aTopicsQuestionVote = array();
     $aTopicsRead = array();
     $aUsers = isset($aAllowData['user']) && is_array($aAllowData['user']) ? E::ModuleUser()->GetUsersAdditionalData($aUserId, $aAllowData['user']) : E::ModuleUser()->GetUsersAdditionalData($aUserId);
     $aBlogs = isset($aAllowData['blog']) && is_array($aAllowData['blog']) ? E::ModuleBlog()->GetBlogsAdditionalData($aBlogId, $aAllowData['blog']) : E::ModuleBlog()->GetBlogsAdditionalData($aBlogId);
     if (isset($aAllowData['vote']) && $this->oUserCurrent) {
         $aTopicsVote = E::ModuleVote()->GetVoteByArray($aTopicId, 'topic', $this->oUserCurrent->getId());
         $aTopicsQuestionVote = $this->GetTopicsQuestionVoteByArray($aTopicId, $this->oUserCurrent->getId());
     }
     if (isset($aAllowData['favourite']) && $this->oUserCurrent) {
         $aFavouriteTopics = $this->GetFavouriteTopicsByArray($aTopicId, $this->oUserCurrent->getId());
     }
     if (isset($aAllowData['fields'])) {
         $aTopicFieldValues = $this->GetTopicValuesByArrayId($aTopicId);
     }
     if (isset($aAllowData['comment_new']) && $this->oUserCurrent) {
         $aTopicsRead = $this->GetTopicsReadByArray($aTopicId, $this->oUserCurrent->getId());
     }
     $aPhotosetMainPhotos = $this->GetTopicPhotosByArrayId($aPhotoMainId);
     // * Добавляем данные к результату - списку топиков
     /** @var ModuleTopic_EntityTopic $oTopic */
     foreach ($aTopics as $oTopic) {
         if (isset($aUsers[$oTopic->getUserId()])) {
             $oTopic->setUser($aUsers[$oTopic->getUserId()]);
         } else {
             $oTopic->setUser(null);
             // или $oTopic->setUser(new ModuleUser_EntityUser());
         }
         if (isset($aBlogs[$oTopic->getBlogId()])) {
             $oTopic->setBlog($aBlogs[$oTopic->getBlogId()]);
         } else {
             $oTopic->setBlog(null);
             // или $oTopic->setBlog(new ModuleBlog_EntityBlog());
         }
         if (isset($aTopicsVote[$oTopic->getId()])) {
             $oTopic->setVote($aTopicsVote[$oTopic->getId()]);
         } else {
             $oTopic->setVote(null);
         }
         if (isset($aFavouriteTopics[$oTopic->getId()])) {
             $oTopic->setFavourite($aFavouriteTopics[$oTopic->getId()]);
         } else {
             $oTopic->setFavourite(null);
         }
         if (isset($aTopicsQuestionVote[$oTopic->getId()])) {
             $oTopic->setUserQuestionIsVote(true);
         } else {
             $oTopic->setUserQuestionIsVote(false);
         }
         if (isset($aTopicFieldValues[$oTopic->getId()])) {
             $oTopic->setTopicValues($aTopicFieldValues[$oTopic->getId()]);
         } else {
             $oTopic->setTopicValues(false);
         }
         if (isset($aTopicsRead[$oTopic->getId()])) {
             $oTopic->setCountCommentNew($oTopic->getCountComment() - $aTopicsRead[$oTopic->getId()]->getCommentCountLast());
             $oTopic->setDateRead($aTopicsRead[$oTopic->getId()]->getDateRead());
         } else {
             $oTopic->setCountCommentNew(0);
             $oTopic->setDateRead(F::Now());
         }
         if (isset($aPhotosetMainPhotos[$oTopic->getPhotosetMainPhotoId()])) {
             $oTopic->setPhotosetMainPhoto($aPhotosetMainPhotos[$oTopic->getPhotosetMainPhotoId()]);
         } else {
             $oTopic->setPhotosetMainPhoto(null);
         }
     }
     return $aTopics;
 }
Exemple #3
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;
 }
Exemple #4
0
 /**
  * Получает дополнительные данные(объекты) для разговоров по их ID
  *
  * @param array      $aTalkId       Список ID сообщений
  * @param array|null $aAllowData    Список дополнительных типов подгружаемых в объект
  *
  * @return array
  */
 public function GetTalksAdditionalData($aTalkId, $aAllowData = null)
 {
     if (!$aTalkId) {
         return array();
     }
     if (is_null($aAllowData)) {
         $aAllowData = $this->aAdditionalData;
     }
     $aAllowData = F::Array_FlipIntKeys($aAllowData);
     if (!is_array($aTalkId)) {
         $aTalkId = array($aTalkId);
     }
     // * Получаем "голые" разговоры
     $aTalks = $this->GetTalksByArrayId($aTalkId);
     // * Формируем ID дополнительных данных, которые нужно получить
     if (isset($aAllowData['favourite']) && $this->oUserCurrent) {
         $aFavouriteTalks = E::ModuleFavourite()->GetFavouritesByArray($aTalkId, 'talk', $this->oUserCurrent->getId());
     }
     $aUserId = array();
     $aCommentLastId = array();
     foreach ($aTalks as $oTalk) {
         if (isset($aAllowData['user'])) {
             $aUserId[] = $oTalk->getUserId();
         }
         if (isset($aAllowData['comment_last']) && $oTalk->getCommentIdLast()) {
             $aCommentLastId[] = $oTalk->getCommentIdLast();
         }
     }
     // * Получаем дополнительные данные
     $aTalkUsers = array();
     $aCommentLast = array();
     if (isset($aAllowData['user']) && is_array($aAllowData['user'])) {
         $aUsers = E::ModuleUser()->GetUsersAdditionalData($aUserId, $aAllowData['user']);
     } else {
         $aUsers = E::ModuleUser()->GetUsersAdditionalData($aUserId);
     }
     if (isset($aAllowData['talk_user']) && $this->oUserCurrent) {
         $aTalkUsers = $this->GetTalkUsersByArray($aTalkId, $this->oUserCurrent->getId());
     }
     if (isset($aAllowData['comment_last'])) {
         $aCommentLast = E::ModuleComment()->GetCommentsAdditionalData($aCommentLastId, array());
     }
     // Добавляем данные к результату - списку разговоров
     /** @var ModuleTalk_EntityTalk $oTalk */
     foreach ($aTalks as $oTalk) {
         if (isset($aUsers[$oTalk->getUserId()])) {
             $oTalk->setUser($aUsers[$oTalk->getUserId()]);
         } else {
             $oTalk->setUser(null);
             // или $oTalk->setUser(new ModuleUser_EntityUser());
         }
         if (isset($aTalkUsers[$oTalk->getId()])) {
             $oTalk->setTalkUser($aTalkUsers[$oTalk->getId()]);
         } else {
             $oTalk->setTalkUser(null);
         }
         if (isset($aFavouriteTalks[$oTalk->getId()])) {
             $oTalk->setIsFavourite(true);
         } else {
             $oTalk->setIsFavourite(false);
         }
         if ($oTalk->getCommentIdLast() && isset($aCommentLast[$oTalk->getCommentIdLast()])) {
             $oTalk->setCommentLast($aCommentLast[$oTalk->getCommentIdLast()]);
         } else {
             $oTalk->setCommentLast(null);
         }
     }
     return $aTalks;
 }
 public function EventDashboard()
 {
     $this->sMainMenuItem = 'info';
     $aDashboardWidgets = array('admin_dashboard_updates' => array('name' => 'admin_dashboard_updates', 'key' => 'admin.dashboard.updates', 'status' => Config::Val('admin.dashboard.updates', true), 'label' => E::ModuleLang()->Get('action.admin.dashboard_updates_title')), 'admin_dashboard_news' => array('name' => 'admin_dashboard_news', 'key' => 'admin.dashboard.news', 'status' => Config::Val('admin.dashboard.news', true), 'label' => E::ModuleLang()->Get('action.admin.dashboard_news_title')));
     if ($this->IsPost('widgets')) {
         $aWidgets = F::Array_FlipIntKeys($this->GetPost('widgets'));
         $aConfig = array();
         foreach ($aDashboardWidgets as $aDashboardWidget) {
             if (isset($aWidgets[$aDashboardWidget['name']])) {
                 $aConfig[$aDashboardWidget['key']] = 1;
             } else {
                 $aConfig[$aDashboardWidget['key']] = 0;
             }
         }
         Config::WriteCustomConfig($aConfig);
         R::Location('admin');
     }
     $this->_setTitle(E::ModuleLang()->Get('action.admin.menu_info_dashboard'));
     $this->SetTemplateAction('info/index');
     $this->sMenuItem = $this->_getMode(0, 'index');
     $aData = array('e-alto' => ALTO_VERSION, 'e-uniq' => E::ModuleSecurity()->GetUniqKey());
     $aPlugins = E::ModulePlugin()->GetPluginsList(true);
     foreach ($aPlugins as $oPlugin) {
         $aData['p-' . $oPlugin->GetId()] = $oPlugin->GetVersion();
     }
     $aSkins = E::ModuleSkin()->GetSkinsList();
     foreach ($aSkins as $oSkin) {
         $aData['s-' . $oSkin->GetId()] = $oSkin->GetVersion();
     }
     E::ModuleViewer()->Assign('sUpdatesRequest', base64_encode(http_build_query($aData)));
     E::ModuleViewer()->Assign('sUpdatesRefresh', true);
     E::ModuleViewer()->Assign('aDashboardWidgets', $aDashboardWidgets);
 }
Exemple #6
0
 /**
  * Получает дополнительные данные(объекты) для блогов по их ID
  *
  * @param array|int $aBlogsId   - Список ID блогов
  * @param array     $aAllowData - Список типов дополнительных данных, которые нужно получить для блогов
  * @param array     $aOrder     - Порядок сортировки
  *
  * @return array
  */
 public function GetBlogsAdditionalData($aBlogsId, $aAllowData = null, $aOrder = null)
 {
     if (!$aBlogsId) {
         return array();
     }
     if (is_null($aAllowData)) {
         $aAllowData = $this->aAdditionalData;
     }
     $aAllowData = F::Array_FlipIntKeys($aAllowData);
     if (!is_array($aBlogsId)) {
         $aBlogsId = array($aBlogsId);
     }
     // * Получаем блоги
     $aBlogs = $this->GetBlogsByArrayId($aBlogsId, $aOrder);
     if (!$aBlogs || is_array($aAllowData) && empty($aAllowData)) {
         // additional data not required
         return $aBlogs;
     }
     $sCacheKey = 'Blog_GetBlogsAdditionalData_' . md5(serialize(array($aBlogsId, $aAllowData, $aOrder)));
     if (false !== ($data = E::ModuleCache()->Get($sCacheKey, 'tmp'))) {
         return $data;
     }
     // * Формируем ID дополнительных данных, которые нужно получить
     $aUserId = array();
     foreach ($aBlogs as $oBlog) {
         if (isset($aAllowData['owner'])) {
             $aUserId[] = $oBlog->getOwnerId();
         }
     }
     // * Получаем дополнительные данные
     $aBlogUsers = array();
     $aBlogsVote = array();
     $aUsers = isset($aAllowData['owner']) && is_array($aAllowData['owner']) ? E::ModuleUser()->GetUsersAdditionalData($aUserId, $aAllowData['owner']) : E::ModuleUser()->GetUsersAdditionalData($aUserId);
     if (isset($aAllowData['relation_user']) && $this->oUserCurrent) {
         $aBlogUsers = $this->GetBlogUsersByArrayBlog($aBlogsId, $this->oUserCurrent->getId());
     }
     if (isset($aAllowData['vote']) && $this->oUserCurrent) {
         $aBlogsVote = E::ModuleVote()->GetVoteByArray($aBlogsId, 'blog', $this->oUserCurrent->getId());
     }
     $aBlogTypes = $this->GetBlogTypes();
     if (isset($aAllowData['media'])) {
         $aAvatars = E::ModuleUploader()->GetMediaObjects('blog_avatar', $aBlogsId, null, array('target_id'));
     }
     // * Добавляем данные к результату - списку блогов
     /** @var ModuleBlog_EntityBlog $oBlog */
     foreach ($aBlogs as $oBlog) {
         if (isset($aUsers[$oBlog->getOwnerId()])) {
             $oBlog->setOwner($aUsers[$oBlog->getOwnerId()]);
         } else {
             $oBlog->setOwner(null);
             // или $oBlog->setOwner(new ModuleUser_EntityUser());
         }
         if (isset($aBlogUsers[$oBlog->getId()])) {
             $oBlog->setCurrentUserRole($aBlogUsers[$oBlog->getId()]->getUserRole());
         }
         if (isset($aBlogsVote[$oBlog->getId()])) {
             $oBlog->setVote($aBlogsVote[$oBlog->getId()]);
         } else {
             $oBlog->setVote(null);
         }
         if (isset($aBlogTypes[$oBlog->getType()])) {
             $oBlog->setBlogType($aBlogTypes[$oBlog->getType()]);
         }
         if (isset($aAllowData['media'])) {
             // Sets blogs avatars
             if (isset($aAvatars[$oBlog->getId()])) {
                 $oBlog->setMediaResources('blog_avatar', $aAvatars[$oBlog->getId()]);
             } else {
                 $oBlog->setMediaResources('blog_avatar', array());
             }
         }
     }
     // Saves only for executing session, so any additional tags no required
     E::ModuleCache()->Set($aBlogs, $sCacheKey, array(), 'P1D', 'tmp');
     return $aBlogs;
 }
 /**
  * Строит строку условий для SQL запроса топиков
  *
  * @param array $aFilter    Фильтр
  *
  * @return string
  */
 protected function buildFilter($aFilter)
 {
     $sWhere = '';
     if (isset($aFilter['topic_date_more'])) {
         $sWhere .= " AND ((t.topic_date_show IS NOT NULL AND t.topic_date_show >  " . $this->oDb->escape($aFilter['topic_date_more']) . ")";
         $sWhere .= " OR (t.topic_date_show IS NULL AND t.topic_date_add >  " . $this->oDb->escape($aFilter['topic_date_more']) . "))";
     }
     if (isset($aFilter['topic_publish'])) {
         $sWhere .= " AND (t.topic_publish =  " . ($aFilter['topic_publish'] ? 1 : 0) . ")";
         $sWhere .= " AND (t.topic_date_show IS NULL OR t.topic_date_show <= '" . F::Now() . "')";
     }
     if (isset($aFilter['topic_index_ignore'])) {
         $sWhere .= " AND (";
         $sWhere .= "t.topic_index_ignore=" . ($aFilter['topic_index_ignore'] ? 1 : 0);
         if (!$aFilter['topic_index_ignore']) {
             $sWhere .= " OR t.topic_index_ignore IS NULL";
         }
         $sWhere .= ") ";
     }
     if (isset($aFilter['topic_rating']) && is_array($aFilter['topic_rating'])) {
         $sPublishIndex = '';
         if (isset($aFilter['topic_rating']['publish_index']) && $aFilter['topic_rating']['publish_index'] == 1) {
             $sPublishIndex = " OR topic_publish_index=1 ";
         }
         if ($aFilter['topic_rating']['type'] == 'top') {
             $sWhere .= " AND ( t.topic_rating >= " . (double) $aFilter['topic_rating']['value'] . " {$sPublishIndex} ) ";
         } else {
             $sWhere .= " AND ( t.topic_rating < " . (double) $aFilter['topic_rating']['value'] . "  ) ";
         }
     }
     if (isset($aFilter['topic_new'])) {
         $sWhere .= " AND (";
         $sWhere .= "(t.topic_date_show IS NOT NULL AND t.topic_date_show >=  '" . $aFilter['topic_new'] . "' AND t.topic_date_show <='" . F::Now() . "')";
         $sWhere .= " OR (t.topic_date_show IS NULL AND t.topic_date_add >=  '" . $aFilter['topic_new'] . "')";
         $sWhere .= ")";
     }
     if (isset($aFilter['user_id'])) {
         $sWhere .= is_array($aFilter['user_id']) ? " AND t.user_id IN(" . implode(', ', $aFilter['user_id']) . ")" : " AND t.user_id =  " . (int) $aFilter['user_id'];
     }
     if (isset($aFilter['blog_id'])) {
         if (!is_array($aFilter['blog_id'])) {
             $aFilter['blog_id'] = array($aFilter['blog_id']);
         }
         $sWhere .= " AND t.blog_id IN ('" . join("','", $aFilter['blog_id']) . "')";
     }
     if (isset($aFilter['topic_id']) && is_array($aFilter['topic_id'])) {
         $sWhere .= " AND t.topic_id IN ('" . join("','", $aFilter['topic_id']) . "')";
     }
     if (isset($aFilter['blog_type']) && is_array($aFilter['blog_type'])) {
         $aBlogTypes = array();
         $aOrClauses = array();
         $aFilter['blog_type'] = F::Array_FlipIntKeys($aFilter['blog_type'], 0);
         foreach ($aFilter['blog_type'] as $sType => $aBlogsId) {
             if ($aBlogsId) {
                 // 'type'=>array('id1', 'id2') - blog type & blogs id
                 if ($sType == '*') {
                     $aOrClauses[] = "(t.blog_id IN ('" . join("','", $aBlogsId) . "'))";
                 } else {
                     $aOrClauses[] = "b.blog_type='" . $sType . "' AND t.blog_id IN ('" . join("','", $aBlogsId) . "')";
                 }
             } else {
                 // blog type only
                 $aBlogTypes[] = "'" . $sType . "'";
             }
         }
         if ($aBlogTypes) {
             $aOrClauses[] = '(b.blog_type IN (' . join(',', $aBlogTypes) . '))';
         }
         if ($aOrClauses) {
             $sWhere .= ' AND (' . join(' OR ', $aOrClauses) . ')';
         }
     }
     if (isset($aFilter['blog_type_exclude']) && is_array($aFilter['blog_type_exclude'])) {
         $sWhere .= " AND (b.blog_type NOT IN ('" . join("','", $aFilter['blog_type_exclude']) . "'))";
     }
     if (isset($aFilter['topic_type'])) {
         if (!is_array($aFilter['topic_type'])) {
             $aFilter['topic_type'] = array($aFilter['topic_type']);
         }
         $sWhere .= " AND t.topic_type IN (" . join(",", array_map(array($this->oDb, 'escape'), $aFilter['topic_type'])) . ")";
     }
     return $sWhere;
 }
Exemple #8
0
 /**
  * Получение записей по ID с дополнительные связаными данными
  *
  * @param array $aWallId    - Список ID сообщений
  * @param array $aAllowData - Список типов дополнительных данных для подгрузки в сообщения стены
  *
  * @return array
  */
 public function GetWallAdditionalData($aWallId, $aAllowData = null)
 {
     if (!$aWallId) {
         return array();
     }
     if (is_null($aAllowData)) {
         $aAllowData = $this->aAdditionalData;
     }
     $aAllowData = F::Array_FlipIntKeys($aAllowData);
     if (!is_array($aWallId)) {
         $aWallId = array($aWallId);
     }
     $aWalls = $this->GetWallsByArrayId($aWallId);
     // * Формируем ID дополнительных данных, которые нужно получить
     $aUserId = array();
     $aWallUserId = array();
     $aWallReplyId = array();
     foreach ($aWalls as $oWall) {
         if (isset($aAllowData['user'])) {
             $aUserId[] = $oWall->getUserId();
         }
         if (isset($aAllowData['wall_user'])) {
             $aWallUserId[] = $oWall->getWallUserId();
         }
         // * Список последних записей хранится в строке через запятую
         if (isset($aAllowData['reply']) && !$oWall->getPid() && $oWall->getLastReply()) {
             $aReply = explode(',', trim($oWall->getLastReply()));
             $aWallReplyId = array_merge($aWallReplyId, $aReply);
         }
     }
     // * Получаем дополнительные данные
     $aUsers = isset($aAllowData['user']) && is_array($aAllowData['user']) ? E::ModuleUser()->GetUsersAdditionalData($aUserId, $aAllowData['user']) : E::ModuleUser()->GetUsersAdditionalData($aUserId);
     $aWallUsers = isset($aAllowData['wall_user']) && is_array($aAllowData['wall_user']) ? E::ModuleUser()->GetUsersAdditionalData($aWallUserId, $aAllowData['wall_user']) : E::ModuleUser()->GetUsersAdditionalData($aWallUserId);
     $aWallReply = array();
     if (isset($aAllowData['reply']) && count($aWallReplyId)) {
         $aWallReply = $this->GetWallAdditionalData($aWallReplyId, array('user' => array()));
     }
     // * Добавляем данные к результату
     foreach ($aWalls as $oWall) {
         if (isset($aUsers[$oWall->getUserId()])) {
             $oWall->setUser($aUsers[$oWall->getUserId()]);
         } else {
             $oWall->setUser(null);
             // или $oWall->setUser(new ModuleUser_EntityUser());
         }
         if (isset($aWallUsers[$oWall->getWallUserId()])) {
             $oWall->setWallUser($aWallUsers[$oWall->getWallUserId()]);
         } else {
             $oWall->setWallUser(null);
         }
         $aReply = array();
         if ($oWall->getLastReply()) {
             $aReplyId = explode(',', trim($oWall->getLastReply()));
             foreach ($aReplyId as $iReplyId) {
                 if (isset($aWallReply[$iReplyId])) {
                     $aReply[] = $aWallReply[$iReplyId];
                 }
             }
         }
         $oWall->setLastReplyWall($aReply);
     }
     return $aWalls;
 }
 /**
  * Site settings > Config parameters
  *
  * @param   string  $sSelectedSection
  */
 protected function _eventConfigParams($sSelectedSection)
 {
     $this->SetTemplateAction('settings/params');
     $aFields = F::IncludeFile(Config::Get('path.dir.config') . 'actions/admin.settings.php', false, true);
     foreach ($aFields as $nSec => $aSection) {
         foreach ($aSection as $nKey => $aItem) {
             $aItem['text'] = E::ModuleLang()->Text($aItem['label']);
             if (isset($aItem['help'])) {
                 $aItem['help'] = E::ModuleLang()->Text($aItem['help']);
             }
             if (isset($aItem['config'])) {
                 $aItem['value'] = Config::Get($aItem['config'], Config::LEVEL_CUSTOM);
                 $aItem['config'] = str_replace('.', '--', $aItem['config']);
                 if (!isset($aItem['valtype']) && isset($aItem['type']) && $aItem['type'] == 'checkbox') {
                     $aItem['valtype'] = 'boolean';
                 }
             }
             if (!empty($aItem['type'])) {
                 if ($aItem['type'] == 'password') {
                     $aItem['valtype'] = 'string';
                 } elseif ($aItem['type'] == 'select' && !empty($aItem['options'])) {
                     $aItem['options'] = F::Array_FlipIntKeys($aItem['options'], null);
                     foreach ($aItem['options'] as $sValue => $sText) {
                         if (is_null($sText)) {
                             $aItem['options'][$sValue] = $sValue;
                         } else {
                             $aItem['options'][$sValue] = E::ModuleLang()->Text($sText);
                         }
                     }
                 }
             }
             $aFields[$nSec][$nKey] = $aItem;
         }
     }
     if (($aData = $this->GetPost()) && isset($aFields[$sSelectedSection])) {
         $this->_eventConfigSave($aFields[$sSelectedSection], $aData);
     }
     if (!isset($aFields[$sSelectedSection])) {
         $sSelectedSection = F::Array_FirstKey($aFields);
         $this->_saveMode(0, $sSelectedSection);
     }
     E::ModuleViewer()->Assign('aFields', $aFields[$sSelectedSection]);
 }
Exemple #10
0
function func_array_simpleflip(&$arr, $sDefValue = 1)
{
    $arr = F::Array_FlipIntKeys($arr, $sDefValue);
}
Exemple #11
0
 /**
  * Возвращает список ID блогов по заданным критериям
  *
  * Общая структура массива критериев
  *  $aCriteria = array(
  *      'filter' => array(..),
  *      'order' => array(..),
  *      'limit' => array(..),
  * );
  *
  * Возвращаемое значение:
  *  array('data' => array(), 'total' => int)
  *
  * @param array $aCriteria
  *
  * @return array
  */
 public function GetBlogsIdByCriteria($aCriteria = array())
 {
     if (isset($aCriteria['filter'])) {
         $aFilter = $aCriteria['filter'];
     } else {
         $aFilter = array();
     }
     if (isset($aFilter['not_blog_id'])) {
         if (!is_array($aFilter['not_blog_id'])) {
             $aFilter['not_blog_id'] = array(intval($aFilter['not_blog_id']));
         }
     }
     if (isset($aFilter['blog_title_like'])) {
         if (substr($aFilter['blog_title_like'], -1) !== '%') {
             $aFilter['blog_title_like'] .= '%';
         }
     }
     if (isset($aFilter['exclude_type']) && !isset($aFilter['not_blog_type'])) {
         $aFilter['not_blog_type'] = $aFilter['exclude_type'];
     }
     if (isset($aFilter['include_type']) && !isset($aFilter['blog_type'])) {
         $aFilter['blog_type'] = $aFilter['include_type'];
     }
     // Сортировка
     $sSqlOrder = '';
     if (isset($aCriteria['order'])) {
         $aOrderAllow = array('blog_id', 'blog_title', 'blog_rating', 'blog_count_user', 'blog_count_topic');
         if (!is_array($aCriteria['order'])) {
             $aCriteria['order'] = array($aCriteria['order']);
         }
         $aOrders = F::Array_FlipIntKeys($aCriteria['order'], 'ASC');
         $aOrderList = array();
         foreach ($aOrders as $sField => $sWay) {
             $sField = strtolower(trim($sField));
             if (strpos($sField, ' ')) {
                 list($sField, $sWay) = explode(' ', $sField, 2);
             }
             if (in_array($sField, $aOrderAllow)) {
                 $aOrderList[] = $sField . ' ' . (strtoupper($sWay) == 'DESC' ? 'DESC' : 'ASC');
             }
         }
         if ($aOrderList) {
             $sSqlOrder = 'ORDER BY ' . implode(',', $aOrderList);
         }
     }
     // Установка лимита
     $sSqlLimit = '';
     list($nOffset, $nLimit) = $this->_prepareLimit($aCriteria);
     // Если задан ID блога, то всегда устанавливаем лимит
     if (isset($aFilter['blog_id']) && !is_array($aFilter['blog_id'])) {
         $nOffset = false;
         $nLimit = 1;
     }
     // Формируем строку лимита и автосчетчик общего числа записей
     if ($nOffset !== false && $nLimit !== false) {
         $sSqlLimit = 'LIMIT ' . $nOffset . ', ' . $nLimit;
         $nCalcTotal = static::CRITERIA_CALC_TOTAL_AUTO;
     } elseif ($nLimit != false && $nLimit != 1) {
         $sSqlLimit = 'LIMIT ' . $nLimit;
         $nCalcTotal = static::CRITERIA_CALC_TOTAL_AUTO;
     } else {
         $nCalcTotal = static::CRITERIA_CALC_TOTAL_SKIP;
     }
     // Обрабатываем опции
     if (isset($aCriteria['options']) && is_array($aCriteria['options'])) {
         if (array_key_exists('calc_total', $aCriteria['options'])) {
             if ($aCriteria['options']['calc_total'] != static::CRITERIA_CALC_TOTAL_AUTO) {
                 $nCalcTotal = $aCriteria['options']['calc_total'];
             }
             // Если требуется только подсчет записей, то строку лимита принудительно устанавливаем в 0
             // Запрос с LIMIT 0 отрабатывает моментально
             if ($aCriteria['options']['calc_total'] != static::CRITERIA_CALC_TOTAL_ONLY) {
                 $sSqlLimit = 'LIMIT 0';
             }
         }
     }
     // Необходимость JOIN'ов
     $aBlogTypeFields = array('allow_add', 'min_rate_add', 'allow_list', 'min_rate_list', 'acl_read', 'min_rate_read', 'acl_write', 'min_rate_write', 'acl_comment', 'min_rate_comment', 'index_ignore', 'membership');
     if ($aFilter && array_intersect(array_keys($aFilter), $aBlogTypeFields)) {
         $bBlogTypeJoin = true;
     } else {
         $bBlogTypeJoin = false;
     }
     $aBlogUserFields = array('user_role');
     if ($aFilter && array_intersect(array_keys($aFilter), $aBlogUserFields)) {
         $bBlogUserJoin = true;
     } else {
         $bBlogUserJoin = false;
     }
     $sql = "\n            SELECT b.blog_id\n            FROM ?_blog AS b\n                { INNER JOIN ?_blog_type AS bt ON bt.type_code=b.blog_type AND 1=?d }\n                { INNER JOIN ?_blog_user AS bu ON bu.blog_id=b.blog_id AND 1=?d }\n            WHERE\n                1 = 1\n                { AND (b.blog_id = ?d) }\n                { AND (b.blog_id IN (?a)) }\n                { AND (b.blog_id NOT IN (?a)) }\n                { AND (b.user_owner_id = ?d) }\n                { AND (b.user_owner_id IN (?a)) }\n                { AND (b.user_owner_id = ?d) }\n                { AND (b.user_owner_id IN (?a)) }\n                { AND (b.blog_type = ?) }\n                { AND (b.blog_type IN (?a)) }\n                { AND (b.blog_type != ?) }\n                { AND (b.blog_type NOT IN (?a)) }\n                { AND blog_url = ? }\n                { AND blog_url IN(?a) }\n                { AND blog_title = ? }\n                { AND blog_title LIKE ? }\n                { AND (bt.allow_add = ?d) }\n                { AND (bt.min_rate_add >= ?d) }\n                { AND (bt.allow_list = ?d) }\n                { AND (bt.min_rate_list >= ?d) }\n                { AND (bt.acl_read & ?d > 0) }\n                { AND (bt.min_rate_read >= ?d) }\n                { AND (bt.acl_write & ?d > 0) }\n                { AND (bt.min_rate_write >= ?d) }\n                { AND (bt.acl_comment & ?d > 0) }\n                { AND (bt.min_rate_comment >= ?d) }\n                { AND (bt.index_ignore = ?d) }\n                { AND (bt.membership = ?d) }\n                { AND (bu.user_role = ?d) }\n        " . $sSqlOrder . ' ' . $sSqlLimit;
     $aData = $this->oDb->selectCol($sql, $bBlogTypeJoin ? 1 : DBSIMPLE_SKIP, $bBlogUserJoin ? 1 : DBSIMPLE_SKIP, isset($aFilter['blog_id']) && !is_array($aFilter['blog_id']) ? $aFilter['blog_id'] : DBSIMPLE_SKIP, isset($aFilter['blog_id']) && is_array($aFilter['blog_id']) ? $aFilter['blog_id'] : DBSIMPLE_SKIP, isset($aFilter['not_blog_id']) ? $aFilter['not_blog_id'] : DBSIMPLE_SKIP, isset($aFilter['user_id']) && !is_array($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP, isset($aFilter['user_id']) && is_array($aFilter['user_id']) ? $aFilter['user_id'] : DBSIMPLE_SKIP, isset($aFilter['user_owner_id']) && !is_array($aFilter['user_owner_id']) ? $aFilter['user_owner_id'] : DBSIMPLE_SKIP, isset($aFilter['user_owner_id']) && is_array($aFilter['user_owner_id']) ? $aFilter['user_owner_id'] : DBSIMPLE_SKIP, isset($aFilter['blog_type']) && !is_array($aFilter['blog_type']) ? $aFilter['blog_type'] : DBSIMPLE_SKIP, isset($aFilter['blog_type']) && is_array($aFilter['blog_type']) ? $aFilter['blog_type'] : DBSIMPLE_SKIP, isset($aFilter['not_blog_type']) && !is_array($aFilter['not_blog_type']) ? $aFilter['not_blog_type'] : DBSIMPLE_SKIP, isset($aFilter['not_blog_type']) && is_array($aFilter['not_blog_type']) ? $aFilter['not_blog_type'] : DBSIMPLE_SKIP, isset($aFilter['blog_url']) && !is_array($aFilter['blog_url']) ? $aFilter['blog_url'] : DBSIMPLE_SKIP, isset($aFilter['blog_url']) && is_array($aFilter['blog_url']) ? $aFilter['blog_url'] : DBSIMPLE_SKIP, isset($aFilter['blog_title']) ? $aFilter['blog_title'] : DBSIMPLE_SKIP, isset($aFilter['blog_title_like']) ? $aFilter['blog_title_like'] : DBSIMPLE_SKIP, isset($aFilter['allow_add']) ? $aFilter['allow_add'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['min_rate_add']) ? $aFilter['min_rate_add'] : DBSIMPLE_SKIP, isset($aFilter['allow_list']) ? $aFilter['allow_list'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['min_rate_list']) ? $aFilter['min_rate_list'] : DBSIMPLE_SKIP, isset($aFilter['acl_read']) ? $aFilter['acl_read'] : DBSIMPLE_SKIP, isset($aFilter['min_rate_read']) ? $aFilter['min_rate_read'] : DBSIMPLE_SKIP, isset($aFilter['acl_write']) ? $aFilter['acl_write'] : DBSIMPLE_SKIP, isset($aFilter['min_rate_write']) ? $aFilter['min_rate_write'] : DBSIMPLE_SKIP, isset($aFilter['acl_comment']) ? $aFilter['acl_comment'] : DBSIMPLE_SKIP, isset($aFilter['min_rate_comment']) ? $aFilter['min_rate_comment'] : DBSIMPLE_SKIP, isset($aFilter['index_ignore']) ? $aFilter['index_ignore'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['membership']) ? $aFilter['membership'] ? 1 : 0 : DBSIMPLE_SKIP, isset($aFilter['user_role']) ? $aFilter['user_role'] : DBSIMPLE_SKIP);
     $aResult = array('data' => $aData ? $aData : array(), 'total' => -1);
     if ($nCalcTotal) {
         if ($nOffset == 0 && $nLimit > 0 && sizeof($aResult['data']) < $nLimit) {
             $aResult['total'] = sizeof($aResult['data']);
         } else {
             $sLastQuery = trim(E::ModuleDatabase()->GetLastQuery());
             $n = strpos($sLastQuery, ' LIMIT ');
             if ($n) {
                 $sql = str_replace('SELECT b.blog_id', 'SELECT COUNT(*) AS cnt', substr($sLastQuery, 0, $n));
                 $aData = $this->oDb->select($sql);
                 if ($aData) {
                     $aResult['total'] = $aData[0]['cnt'];
                 }
             }
         }
     }
     return $aResult;
 }
Exemple #12
0
 /**
  * Получает дополнительные данные(объекты) для комментов по их ID
  *
  * @param array|int  $aCommentId      Список ID комментов
  * @param array|null $aAllowData      Список типов дополнительных данных, которые нужно получить для комментариев
  * @param array      $aAdditionalData Predefined additional data
  *
  * @return array
  */
 public function GetCommentsAdditionalData($aCommentId, $aAllowData = null, $aAdditionalData = array())
 {
     if (!$aCommentId) {
         return array();
     }
     if (is_null($aAllowData)) {
         $aAllowData = $this->aAdditionalData;
     }
     $aAllowData = F::Array_FlipIntKeys($aAllowData);
     if (!is_array($aCommentId)) {
         $aCommentId = array($aCommentId);
     }
     // * Получаем комменты
     $aComments = $this->GetCommentsByArrayId($aCommentId);
     // * Формируем ID дополнительных данных, которые нужно получить
     $aUserId = array();
     $aTargetTypeId = array();
     foreach ($aComments as $oComment) {
         if (isset($aAllowData['user'])) {
             $aUserId[] = $oComment->getUserId();
         }
         if (isset($aAllowData['target'])) {
             $aTargetTypeId[$oComment->getTargetType()][] = $oComment->getTargetId();
         }
     }
     // * Получаем дополнительные данные
     if ($aUserId) {
         $aUsers = isset($aAllowData['user']) && is_array($aAllowData['user']) ? E::ModuleUser()->GetUsersAdditionalData($aUserId, $aAllowData['user']) : E::ModuleUser()->GetUsersAdditionalData($aUserId);
     }
     // * В зависимости от типа target_type достаем данные
     $aTargets = array();
     foreach ($aTargetTypeId as $sTargetType => $aTargetId) {
         if (isset($aAdditionalData['target'][$sTargetType])) {
             // predefined targets' data
             $aTargets[$sTargetType] = $aAdditionalData['target'][$sTargetType];
         } else {
             if (isset($aTargetTypeId['topic']) && $aTargetTypeId['topic']) {
                 // load targets' data
                 $aTargets['topic'] = E::ModuleTopic()->GetTopicsAdditionalData($aTargetTypeId['topic'], array('blog' => array('owner' => array(), 'relation_user'), 'user' => array()));
             } else {
                 // we don't know how to get targets' data
                 $aTargets['topic'] = array();
             }
         }
     }
     if (isset($aAllowData['vote']) && $this->oUserCurrent) {
         $aVote = E::ModuleVote()->GetVoteByArray($aCommentId, 'comment', $this->oUserCurrent->getId());
     } else {
         $aVote = array();
     }
     if (isset($aAllowData['favourite']) && $this->oUserCurrent) {
         $aFavouriteComments = E::ModuleFavourite()->GetFavouritesByArray($aCommentId, 'comment', $this->oUserCurrent->getId());
     } else {
         $aFavouriteComments = array();
     }
     // * Добавляем данные к результату
     foreach ($aComments as $oComment) {
         if (isset($aUsers[$oComment->getUserId()])) {
             $oComment->setUser($aUsers[$oComment->getUserId()]);
         } else {
             $oComment->setUser(null);
             // или $oComment->setUser(new ModuleUser_EntityUser());
         }
         if (isset($aTargets[$oComment->getTargetType()][$oComment->getTargetId()])) {
             $oComment->setTarget($aTargets[$oComment->getTargetType()][$oComment->getTargetId()]);
         } else {
             $oComment->setTarget(null);
         }
         if (isset($aVote[$oComment->getId()])) {
             $oComment->setVote($aVote[$oComment->getId()]);
         } else {
             $oComment->setVote(null);
         }
         if (isset($aFavouriteComments[$oComment->getId()])) {
             $oComment->setIsFavourite(true);
         } else {
             $oComment->setIsFavourite(false);
         }
     }
     return $aComments;
 }