* */ /** * Экшен обработки УРЛа вида /comments/ * * @package application.actions * @since 1.0 */ class ActionBlogs extends Action { /** * Инициализация */ public function Init() { /** * Загружаем в шаблон JS текстовки */ $this->Lang_AddLangJs(array( 'blog.join.join', 'blog.join.leave' )); /** * Устанавливаем title страницы */ $this->Viewer_AddHtmlTitle($this->Lang_Get('blog.menu.all_list')); } /** * Регистрируем евенты */ protected function RegisterEvent() { $this->AddEventPreg('/^(page([1-9]\d{0,5}))?$/i', 'EventShowBlogs'); $this->AddEventPreg('/^ajax-search$/i', 'EventAjaxSearch'); } /********************************************************************************** ************************ РЕАЛИЗАЦИЯ ЭКШЕНА *************************************** ********************************************************************************** */ /** * Поиск блогов по названию */ protected function EventAjaxSearch() { /** * Устанавливаем формат Ajax ответа */ $this->Viewer_SetResponseAjax('json'); /** * Фильтр */ $aFilter = array( 'exclude_type' => 'personal', ); $sOrderWay = in_array(getRequestStr('order'), array('desc', 'asc')) ? getRequestStr('order') : 'desc'; $sOrderField = in_array(getRequestStr('sort_by'), array( 'blog_id', 'blog_title', 'blog_count_user', 'blog_count_topic' )) ? getRequestStr('sort_by') : 'blog_count_user'; if (is_numeric(getRequestStr('pageNext')) and getRequestStr('pageNext') > 0) { $iPage = getRequestStr('pageNext'); } else { $iPage = 1; } /** * Получаем из реквеста первые буквы блога */ if ($sTitle = getRequestStr('sText')) { $sTitle = str_replace('%', '', $sTitle); } else { $sTitle = ''; } if ($sTitle) { $aFilter['title'] = "%{$sTitle}%"; } /** * Категории */ if (getRequestStr('category') and $oCategory = $this->Category_GetCategoryById(getRequestStr('category'))) { /** * Получаем ID всех блогов * По сути это костыль, но т.к. блогов обычно не много, то норм */ $aBlogIds = $this->Blog_GetTargetIdsByCategory($oCategory, 1, 1000, true); $aFilter['id'] = $aBlogIds ? $aBlogIds : array(0); } /** * Тип */ if (in_array(getRequestStr('type'), array('open', 'close'))) { $aFilter['type'] = getRequestStr('type'); } /** * Ищем блоги */ $aResult = $this->Blog_GetBlogsByFilter($aFilter, array($sOrderField => $sOrderWay), $iPage, Config::Get('module.blog.per_page')); $bHideMore = $iPage * Config::Get('module.blog.per_page') >= $aResult['count']; /** * Формируем и возвращает ответ */ $oViewer = $this->Viewer_GetLocalViewer(); $oViewer->Assign('blogs', $aResult['collection'], true); $oViewer->Assign('oUserCurrent', $this->User_GetUserCurrent()); $oViewer->Assign('textEmpty', $this->Lang_Get('search.alerts.empty'), true); $oViewer->Assign('useMore', true, true); $oViewer->Assign('hideMore', $bHideMore, true); $oViewer->Assign('searchCount', $aResult['count'], true); $this->Viewer_AssignAjax('sText', $oViewer->Fetch("components/blog/blog-list.tpl")); /** * Для подгрузки */ $this->Viewer_AssignAjax('count_loaded', count($aResult['collection'])); $this->Viewer_AssignAjax('pageNext', count($aResult['collection']) > 0 ? $iPage + 1 : $iPage); $this->Viewer_AssignAjax('bHideMore', $bHideMore); } /** * Отображение списка блогов */ protected function EventShowBlogs() { /** * Фильтр поиска блогов */ $aFilter = array( 'exclude_type' => 'personal' ); /** * Получаем список блогов */ $aResult = $this->Blog_GetBlogsByFilter($aFilter, array('blog_count_user' => 'desc'), 1, Config::Get('module.blog.per_page')); $aBlogs = $aResult['collection']; /** * Загружаем переменные в шаблон */ $this->Viewer_Assign("aBlogs", $aBlogs); $this->Viewer_Assign('iSearchCount', $aResult['count']); /** * Устанавливаем шаблон вывода */ $this->SetTemplateAction('index'); } }