ActionUserfeed

Package actions
Inheritance class ActionUserfeed » Action » LsObject
Since 1.0
Source Code /classes/actions/ActionUserfeed.class.php
Обрабатывает пользовательские ленты контента

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
aParams array Список параметров из URL Action
aParamsEventMatch array Список совпадений по регулярному выражению для евента Action
aRegisterEvent array Список зарегистрированных евентов Action
oEngine Engine|null Объект ядра Action
oUserCurrent ModuleUser_EntityUser|null Текущий пользователь ActionUserfeed
sActionTemplate string|null Шаблон экшена Action
sCurrentAction null|string Текущий экшен Action
sCurrentEvent string|null Текущий евент Action
sCurrentEventName string|null Имя текущий евента Action
sDefaultEvent string|null Дефолтный евент Action

Public Methods

Hide inherited methods

MethodDescriptionDefined By
EventShutdown() При завершении экшена загружаем в шаблон необходимые переменные ActionUserfeed
ExecEvent() Запускает евент на выполнение Action
GetActionClass() Получить каталог с шаблонами экшена(совпадает с именем класса) Action
GetCurrentEventName() Возвращает имя евента Action
GetDefaultEvent() Получает евент по умолчанию Action
GetParam() Получает параметр из URL по его номеру, если его нет то null Action
GetParams() Получает список параметров из УРЛ Action
GetTemplate() Получить шаблон Action
Init() Инициализация ActionUserfeed
SetDefaultEvent() Устанавливает евент по умолчанию Action
SetParam() Установить значение параметра(эмуляция параметра в URL). Action
__call() Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля Action
__construct() Конструктор Action

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
AddEvent() Добавляет евент в экшен Action
AddEventPreg() Добавляет евент в экшен, используя регулярное вырожение для евента и параметров Action
EventGetMore() Подгрузка ленты топиков (замена постраничности) ActionUserfeed
EventIndex() Выводит ленту контента(топики) для пользователя ActionUserfeed
EventNotFound() Вызывается в том случаи если не найден евент который запросили через URL Action
EventSubscribe() Подписка на контент блога или пользователя ActionUserfeed
EventSubscribeByLogin() Подписка на пользвователя по логину ActionUserfeed
EventUnsubscribe() Отписка от блога или пользователя ActionUserfeed
GetEventMatch() Возвращает элементы совпадения по регулярному выражению для евента Action
GetParamEventMatch() Возвращает элементы совпадения по регулярному выражению для параметров евента Action
RegisterEvent() Регистрация евентов ActionUserfeed
SetTemplate() Устанавливает какой шаблон выводить Action
SetTemplateAction() Устанавливает какой шаблон выводить Action

Property Details

oUserCurrent property
protected ModuleUser_EntityUser|null $oUserCurrent;

Текущий пользователь

Method Details

EventGetMore() method
protected void EventGetMore()
Source Code: /classes/actions/ActionUserfeed.class.php#87 (show)
protected function EventGetMore() {
    
/**
     * Устанавливаем формат Ajax ответа
     */
    
$this->Viewer_SetResponseAjax('json');
    
/**
     * Проверяем последний просмотренный ID топика
     */
    
$iFromId getRequest('last_id');
    if (!
$iFromId)  {
        
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
        return;
    }
    
/**
     * Получаем топики
     */
    
$aTopics $this->Userfeed_read($this->oUserCurrent->getId(), null$iFromId);
    
/**
     * Вызов хуков
     */
    
$this->Hook_Run('topics_list_show',array('aTopics'=>$aTopics));
    
/**
     * Загружаем данные в ajax ответ
     */
    
$oViewer=$this->Viewer_GetLocalViewer();
    
$oViewer->Assign('aTopics',  $aTopics);
    
$this->Viewer_AssignAjax('result'$oViewer->Fetch('topic_list.tpl'));
    
$this->Viewer_AssignAjax('topics_count'count($aTopics));

    if (
count($aTopics)) {
        
$this->Viewer_AssignAjax('iUserfeedLastId'end($aTopics)->getId());
    }
}

Подгрузка ленты топиков (замена постраничности)

EventIndex() method
protected void EventIndex()
Source Code: /classes/actions/ActionUserfeed.class.php#63 (show)
protected function EventIndex() {
    
/**
     * Получаем топики
     */
    
$aTopics $this->Userfeed_read($this->oUserCurrent->getId());
    
/**
     * Вызов хуков
     */
    
$this->Hook_Run('topics_list_show',array('aTopics'=>$aTopics));
    
$this->Viewer_Assign('aTopics'$aTopics);
    if (
count($aTopics)) {
        
$this->Viewer_Assign('iUserfeedLastId'end($aTopics)->getId());
    }
    if (
count($aTopics) < Config::Get('module.userfeed.count_default')) {
        
$this->Viewer_Assign('bDisableGetMoreButton'true);
    } else {
        
$this->Viewer_Assign('bDisableGetMoreButton'false);
    }
    
$this->SetTemplateAction('list');
}

Выводит ленту контента(топики) для пользователя

EventShutdown() method
public void EventShutdown()
Source Code: /classes/actions/ActionUserfeed.class.php#260 (show)
public function EventShutdown() {
    
/**
     * Подсчитываем новые топики
     */
    
$iCountTopicsCollectiveNew=$this->Topic_GetCountTopicsCollectiveNew();
    
$iCountTopicsPersonalNew=$this->Topic_GetCountTopicsPersonalNew();
    
$iCountTopicsNew=$iCountTopicsCollectiveNew+$iCountTopicsPersonalNew;
    
/**
     * Загружаем переменные в шаблон
     */
    
$this->Viewer_Assign('iCountTopicsCollectiveNew',$iCountTopicsCollectiveNew);
    
$this->Viewer_Assign('iCountTopicsPersonalNew',$iCountTopicsPersonalNew);
    
$this->Viewer_Assign('iCountTopicsNew',$iCountTopicsNew);
}

При завершении экшена загружаем в шаблон необходимые переменные

EventSubscribe() method
protected void EventSubscribe()
Source Code: /classes/actions/ActionUserfeed.class.php#124 (show)
protected function EventSubscribe() {
    
/**
     * Устанавливаем формат Ajax ответа
     */
    
$this->Viewer_SetResponseAjax('json');
    
/**
     * Проверяем наличие ID блога или пользователя
     */
    
if (!getRequest('id')) {
        
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
    }
    
$sType = (string)getRequest('type');
    
$iType null;
    
/**
     * Определяем тип подписки
     */
    
switch($sType) {
        case 
'blogs':
            
$iType ModuleUserfeed::SUBSCRIBE_TYPE_BLOG;
            
/**
             * Проверяем существование блога
             */
            
if (!$this->Blog_GetBlogById(getRequest('id'))) {
                
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
                return;
            }
            break;
        case 
'users':
            
$iType ModuleUserfeed::SUBSCRIBE_TYPE_USER;
            
/**
             * Проверяем существование пользователя
             */
            
if (!$this->User_GetUserById(getRequest('id'))) {
                
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
                return;
            }
            if (
$this->oUserCurrent->getId() == getRequest('id')) {
                
$this->Message_AddError($this->Lang_Get('userfeed_error_subscribe_to_yourself'),$this->Lang_Get('error'));
                return;
            }
            break;
        default:
            
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
            return;
    }
    
/**
     * Подписываем
     */
    
$this->Userfeed_subscribeUser($this->oUserCurrent->getId(), $iTypegetRequest('id'));
    
$this->Message_AddNotice($this->Lang_Get('userfeed_subscribes_updated'), $this->Lang_Get('attention'));
}

Подписка на контент блога или пользователя

EventSubscribeByLogin() method
protected void EventSubscribeByLogin()
Source Code: /classes/actions/ActionUserfeed.class.php#179 (show)
protected function EventSubscribeByLogin() {
    
/**
     * Устанавливаем формат Ajax ответа
     */
    
$this->Viewer_SetResponseAjax('json');
    
/**
     * Передан ли логин
     */
    
if (!getRequest('login') or !is_string(getRequest('login'))) {
        
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
        return;
    }
    
/**
     * Проверяем существование прользователя
     */
    
$oUser $this->User_getUserByLogin(getRequest('login'));
    if (!
$oUser) {
        
$this->Message_AddError($this->Lang_Get('user_not_found',array('login'=>htmlspecialchars(getRequest('login')))),$this->Lang_Get('error'));
        return;
    }
    
/**
     * Не даем подписаться на самого себя
     */
    
if ($this->oUserCurrent->getId() == $oUser->getId()) {
        
$this->Message_AddError($this->Lang_Get('userfeed_error_subscribe_to_yourself'),$this->Lang_Get('error'));
        return;
    }
    
/**
     * Подписываем
     */
    
$this->Userfeed_subscribeUser($this->oUserCurrent->getId(), ModuleUserfeed::SUBSCRIBE_TYPE_USER$oUser->getId());
    
/**
     * Загружаем данные ajax ответ
     */
    
$this->Viewer_AssignAjax('uid'$oUser->getId());
    
$this->Viewer_AssignAjax('user_login'$oUser->getLogin());
    
$this->Viewer_AssignAjax('user_web_path'$oUser->getUserWebPath());
    
$this->Viewer_AssignAjax('user_avatar_48'$oUser->getProfileAvatarPath(48));
    
$this->Viewer_AssignAjax('lang_error_msg'$this->Lang_Get('userfeed_subscribes_already_subscribed'));
    
$this->Viewer_AssignAjax('lang_error_title'$this->Lang_Get('error'));
    
$this->Message_AddNotice($this->Lang_Get('userfeed_subscribes_updated'), $this->Lang_Get('attention'));
}

Подписка на пользвователя по логину

EventUnsubscribe() method
protected void EventUnsubscribe()
Source Code: /classes/actions/ActionUserfeed.class.php#225 (show)
protected function EventUnsubscribe() {
    
/**
     * Устанавливаем формат Ajax ответа
     */
    
$this->Viewer_SetResponseAjax('json');
    if (!
getRequest('id')) {
        
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
        return;
    }
    
$sType = (string)getRequest('type');
    
$iType null;
    
/**
     * Определяем от чего отписываемся
     */
    
switch($sType) {
        case 
'blogs':
            
$iType ModuleUserfeed::SUBSCRIBE_TYPE_BLOG;
            break;
        case 
'users':
            
$iType ModuleUserfeed::SUBSCRIBE_TYPE_USER;
            break;
        default:
            
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
            return;
    }
    
/**
     * Отписываем пользователя
     */
    
$this->Userfeed_unsubscribeUser($this->oUserCurrent->getId(), $iTypegetRequest('id'));
    
$this->Message_AddNotice($this->Lang_Get('userfeed_subscribes_updated'), $this->Lang_Get('attention'));
}

Отписка от блога или пользователя

Init() method
public void Init()
Source Code: /classes/actions/ActionUserfeed.class.php#36 (show)
public function Init() {
    
/**
     * Доступ только у авторизованных пользователей
     */
    
$this->oUserCurrent $this->User_getUserCurrent();
    if (!
$this->oUserCurrent) {
        
parent::EventNotFound();
    }
    
$this->SetDefaultEvent('index');

    
$this->Viewer_Assign('sMenuItemSelect''feed');
}

Инициализация

RegisterEvent() method
protected void RegisterEvent()
Source Code: /classes/actions/ActionUserfeed.class.php#52 (show)
protected function RegisterEvent() {
    
$this->AddEvent('index''EventIndex');
    
$this->AddEvent('subscribe''EventSubscribe');
    
$this->AddEvent('subscribeByLogin''EventSubscribeByLogin');
    
$this->AddEvent('unsubscribe''EventUnSubscribe');
    
$this->AddEvent('get_more''EventGetMore');
}

Регистрация евентов