Файл: forsoc.ru/ext/vse/similartopics/event/ucp_listener.php
Строк: 81
<?php
/**
*
* Precise Similar Topics
*
* @copyright (c) 2014 Matt Friedman
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace vsesimilartopicsevent;
use SymfonyComponentEventDispatcherEventSubscriberInterface;
/**
* Event listener
*/
class ucp_listener implements EventSubscriberInterface
{
/** @var phpbbauthauth */
protected $auth;
/** @var phpbbconfigconfig */
protected $config;
/** @var phpbbrequestrequest */
protected $request;
/** @var phpbbtemplatetemplate */
protected $template;
/** @var phpbbuser */
protected $user;
/**
* Constructor
*
* @param phpbbauthauth $auth
* @param phpbbconfigconfig $config
* @param phpbbrequestrequest $request
* @param phpbbtemplatetemplate $template
* @param phpbbuser $user
* @access public
*/
public function __construct(phpbbauthauth $auth, phpbbconfigconfig $config, phpbbrequestrequest $request, phpbbtemplatetemplate $template, phpbbuser $user)
{
$this->auth = $auth;
$this->config = $config;
$this->request = $request;
$this->template = $template;
$this->user = $user;
}
/**
* Assign functions defined in this class to event listeners in the core
*
* @return array
* @static
* @access public
*/
static public function getSubscribedEvents()
{
return array(
'core.ucp_prefs_view_data' => 'ucp_prefs_get_data',
'core.ucp_prefs_view_update_data' => 'ucp_prefs_set_data',
);
}
/**
* Get user's Similar Topics option and display it in UCP Prefs View page
*
* @param object $event The event object
* @return null
* @access public
*/
public function ucp_prefs_get_data($event)
{
// Request the user option vars and add them to the data array
$event['data'] = array_merge($event['data'], array(
'similar_topics' => $this->request->variable('similar_topics', (int) $this->user->data['user_similar_topics']),
));
// Output the data vars to the template (except on form submit)
if (!$event['submit'])
{
$this->user->add_lang_ext('vse/similartopics', 'similar_topics');
$this->template->assign_vars(array(
'S_SIMILAR_TOPICS' => $this->config['similar_topics'] && $this->auth->acl_get('u_similar_topics'),
'S_DISPLAY_SIMILAR_TOPICS' => $event['data']['similar_topics'],
));
}
}
/**
* Add user's Similar Topics option state into the sql_array
*
* @param object $event The event object
* @return null
* @access public
*/
public function ucp_prefs_set_data($event)
{
$event['sql_ary'] = array_merge($event['sql_ary'], array(
'user_similar_topics' => $event['data']['similar_topics'],
));
}
}