Merge pull request #292 from marc1706/ticket/291
[ticket/291] Add controller helper for portal functions
This commit is contained in:
@@ -8,6 +8,7 @@ services:
|
||||
- @template
|
||||
- @dbal.conn
|
||||
- @pagination
|
||||
- @board3.portal.modules_helper
|
||||
- @request
|
||||
- %core.php_ext%
|
||||
- %core.root_path%
|
||||
@@ -179,6 +180,7 @@ services:
|
||||
- @config
|
||||
- @dbal.conn
|
||||
- @pagination
|
||||
- @board3.portal.modules_helper
|
||||
- @request
|
||||
- @template
|
||||
- %core.root_path%
|
||||
|
||||
@@ -23,9 +23,9 @@ services:
|
||||
- @template
|
||||
- @user
|
||||
- @path_helper
|
||||
- @board3.portal.helper
|
||||
- %core.root_path%
|
||||
- .%core.php_ext%
|
||||
- @board3.module_collection
|
||||
- %board3.config.table%
|
||||
- %board3.modules.table%
|
||||
|
||||
@@ -45,3 +45,13 @@ services:
|
||||
- @service_container
|
||||
tags:
|
||||
- { name: service_collection, tag: board3.module }
|
||||
|
||||
board3.portal.helper:
|
||||
class: board3\portal\includes\helper
|
||||
arguments:
|
||||
- @board3.module_collection
|
||||
|
||||
board3.portal.modules_helper:
|
||||
class: board3\portal\includes\modules_helper
|
||||
arguments:
|
||||
- @auth
|
||||
|
||||
@@ -13,51 +13,51 @@ class main
|
||||
{
|
||||
/**
|
||||
* Auth object
|
||||
* @var phpbb_auth
|
||||
* @var \phpbb\auth\auth
|
||||
*/
|
||||
private $auth;
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* phpBB Config object
|
||||
* @var phpbb_config_db
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
private $config;
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Template object
|
||||
* @var phpbb_template
|
||||
* @var \phpbb\template
|
||||
*/
|
||||
private $template;
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var phpbb_user
|
||||
* @var \phpbb\user
|
||||
*/
|
||||
private $user;
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* phpBB root path
|
||||
* @var string
|
||||
*/
|
||||
private $phpbb_root_path;
|
||||
protected $phpbb_root_path;
|
||||
|
||||
/**
|
||||
* PHP file extension
|
||||
* @var string
|
||||
*/
|
||||
private $php_ext;
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* Portal root path
|
||||
* @var string
|
||||
*/
|
||||
private $root_path;
|
||||
protected $root_path;
|
||||
|
||||
/**
|
||||
* Portal includes path
|
||||
* @var string
|
||||
*/
|
||||
private $includes_path;
|
||||
protected $includes_path;
|
||||
|
||||
/**
|
||||
* phpBB path helper
|
||||
@@ -66,28 +66,27 @@ class main
|
||||
protected $path_helper;
|
||||
|
||||
/**
|
||||
* Board3 Modules service collection
|
||||
* @var phpbb\di\service_collection
|
||||
* Portal Helper object
|
||||
* @var \board3\portal\includes\helper
|
||||
*/
|
||||
protected $modules;
|
||||
protected $portal_helper;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
* the dependencies defined in the services.yml file for this service.
|
||||
* @param phpbb_auth $auth Auth object
|
||||
* @param phpbb_config_db $config phpBB Config object
|
||||
* @param phpbb_template $template Template object
|
||||
* @param phpbb_user $user User object
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @param \phpbb\config\config $config phpBB Config object
|
||||
* @param \phpbb\template $template Template object
|
||||
* @param \phpbb\user $user User object
|
||||
* @param \phpbb\path_helper $path_helper phpBB path helper
|
||||
* @param \board3\portal\includes\portal_helper $portal_helper Portal helper class
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param string $php_ext PHP file extension
|
||||
* @param \phpbb\di\service_collection $modules Board3 Modules service
|
||||
* collection
|
||||
* @param string $config_table Board3 config table
|
||||
* @param string $modules_table Board3 modules table
|
||||
*/
|
||||
public function __construct($auth, $config, $template, $user, $path_helper, $phpbb_root_path, $php_ext, $modules, $config_table, $modules_table)
|
||||
public function __construct($auth, $config, $template, $user, $path_helper, $portal_helper, $phpbb_root_path, $php_ext, $config_table, $modules_table)
|
||||
{
|
||||
global $portal_root_path;
|
||||
|
||||
@@ -98,7 +97,7 @@ class main
|
||||
$this->path_helper = $path_helper;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->register_modules($modules);
|
||||
$this->portal_helper = $portal_helper;
|
||||
|
||||
$this->includes_path = $phpbb_root_path . 'ext/board3/portal/includes/';
|
||||
$this->root_path = $phpbb_root_path . 'ext/board3/portal/';
|
||||
@@ -114,25 +113,6 @@ class main
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register list of Board3 Portal modules
|
||||
*
|
||||
* @param \phpbb\di\service_collection $modules Board3 Modules service
|
||||
* collection
|
||||
* @return null
|
||||
*/
|
||||
protected function register_modules($modules)
|
||||
{
|
||||
foreach ($modules as $current_module)
|
||||
{
|
||||
$class_name = '\\' . get_class($current_module);
|
||||
if (!isset($this->modules[$class_name]))
|
||||
{
|
||||
$this->modules[$class_name] = $current_module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension front handler method. This is called automatically when your extension is accessed
|
||||
* through index.php?ext=example/foobar
|
||||
@@ -180,26 +160,9 @@ class main
|
||||
}
|
||||
|
||||
// Do not try to load non-existent modules
|
||||
if (!isset($this->modules[$row['module_classname']]))
|
||||
if (!($module = $this->portal_helper->get_module($row['module_classname'])))
|
||||
{
|
||||
if (file_exists("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}"))
|
||||
{
|
||||
include("{$this->includes_path}modules/portal_{$row['module_classname']}{$this->php_ext}");
|
||||
}
|
||||
|
||||
$class_name = 'portal_' . $row['module_classname'] . '_module';
|
||||
if (class_exists($class_name))
|
||||
{
|
||||
$module = new $class_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$module = $this->modules[$row['module_classname']];
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +280,7 @@ class main
|
||||
}
|
||||
|
||||
// check if user should be able to access this page
|
||||
private function check_permission()
|
||||
protected function check_permission()
|
||||
{
|
||||
if (!isset($this->config['board3_enable']) || !$this->config['board3_enable'] || !$this->auth->acl_get('u_view_portal'))
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@ function obtain_portal_modules()
|
||||
// fetch post for news & announce
|
||||
function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false)
|
||||
{
|
||||
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache;
|
||||
global $db, $phpbb_root_path, $auth, $user, $bbcode_bitfield, $bbcode, $portal_config, $config, $cache, $phpbb_container;
|
||||
|
||||
$posts = $update_count = array();
|
||||
$post_time = ($time == 0) ? '' : 'AND t.topic_time > ' . (time() - $time * 86400);
|
||||
@@ -101,15 +101,10 @@ function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_pos
|
||||
$str_where = '';
|
||||
$topic_icons = array(0);
|
||||
$have_icons = 0;
|
||||
$modules_helper = $phpbb_container->get('board3.portal.modules_helper');
|
||||
|
||||
if ($permissions == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
// Get disallowed forums
|
||||
$disallow_access = $modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if ($invert == true)
|
||||
{
|
||||
|
||||
67
includes/helper.php
Normal file
67
includes/helper.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal v2.1
|
||||
* @copyright (c) 2014 Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\includes;
|
||||
|
||||
class helper
|
||||
{
|
||||
/**
|
||||
* Board3 Modules service collection
|
||||
* @var \phpbb\di\service_collection
|
||||
*/
|
||||
protected $modules;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
* the dependencies defined in the services.yml file for this service.
|
||||
* @param \phpbb\di\service_collection $modules Board3 Modules service
|
||||
* collection
|
||||
*/
|
||||
public function __construct($modules)
|
||||
{
|
||||
$this->register_modules($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register list of Board3 Portal modules
|
||||
*
|
||||
* @param \phpbb\di\service_collection $modules Board3 Modules service
|
||||
* collection
|
||||
* @return null
|
||||
*/
|
||||
protected function register_modules($modules)
|
||||
{
|
||||
foreach ($modules as $current_module)
|
||||
{
|
||||
$class_name = '\\' . get_class($current_module);
|
||||
if (!isset($this->modules[$class_name]))
|
||||
{
|
||||
$this->modules[$class_name] = $current_module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module specified by module class name
|
||||
*
|
||||
* @param string $module_name Module class name
|
||||
*/
|
||||
public function get_module($module_name)
|
||||
{
|
||||
if (isset($this->modules[$module_name]))
|
||||
{
|
||||
return $this->modules[$module_name];
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
includes/modules_helper.php
Normal file
50
includes/modules_helper.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package Board3 Portal v2.1
|
||||
* @copyright (c) 2014 Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\includes;
|
||||
|
||||
class modules_helper
|
||||
{
|
||||
/**
|
||||
* Auth object
|
||||
* @var \phpbb\auth\auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
* the dependencies defined in the services.yml file for this service.
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
*/
|
||||
public function __construct($auth)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of disallowed forums
|
||||
*
|
||||
* @param bool $disallow_access Whether the array for disallowing access
|
||||
* should be filled
|
||||
*/
|
||||
public function get_disallowed_forums($disallow_access)
|
||||
{
|
||||
if ($disallow_access == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
|
||||
return $disallow_access;
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,9 @@ class announcements extends module_base
|
||||
/** @var \phpbb\pagination */
|
||||
protected $pagination;
|
||||
|
||||
/** @var \board3\portal\includes\modules_helper */
|
||||
protected $modules_helper;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
@@ -80,12 +83,13 @@ class announcements extends module_base
|
||||
* @param \phpbb\template $template phpBB template
|
||||
* @param \phpbb\db\driver $db Database driver
|
||||
* @param \phpbb\pagination $pagination phpBB pagination
|
||||
* @param \board3\portal\includes\modules_helper $modules_helper Portal modules helper
|
||||
* @param \phpbb\request\request $request phpBB request
|
||||
* @param string $phpEx php file extension
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $template, $db, $pagination, $request, $phpEx, $phpbb_root_path, $user)
|
||||
public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
@@ -93,6 +97,7 @@ class announcements extends module_base
|
||||
$this->template = $template;
|
||||
$this->db = $db;
|
||||
$this->pagination = $pagination;
|
||||
$this->modules_helper = $modules_helper;
|
||||
$this->request = $request;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
@@ -137,14 +142,8 @@ class announcements extends module_base
|
||||
|
||||
$str_where = '';
|
||||
|
||||
if($permissions == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
// Get disallowed forums
|
||||
$disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if($this->config['board3_announcements_forum_exclude_' . $module_id] == true)
|
||||
{
|
||||
|
||||
@@ -56,6 +56,9 @@ class news extends module_base
|
||||
/** @var \phpbb\pagination */
|
||||
protected $pagination;
|
||||
|
||||
/** @var \board3\portal\includes\modules_helper */
|
||||
protected $modules_helper;
|
||||
|
||||
/** @var \phpbb\request\request */
|
||||
protected $request;
|
||||
|
||||
@@ -79,19 +82,21 @@ class news extends module_base
|
||||
* @param \phpbb\config\config $config phpBB config
|
||||
* @param \phpbb\db\driver $db phpBB db driver
|
||||
* @param \phpbb\pagination $pagination phpBB pagination
|
||||
* @param \board3\portal\includes\modules_helper $modules_helper Portal modules helper
|
||||
* @param \phpbb\request\request $request phpBB request
|
||||
* @param \phpbb\template $template phpBB template
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param string $phpEx php file extension
|
||||
* @param \phpbb\user $user phpBB user object
|
||||
*/
|
||||
public function __construct($auth, $cache, $config, $db, $pagination, $request, $template, $phpbb_root_path, $phpEx, $user)
|
||||
public function __construct($auth, $cache, $config, $db, $pagination, $modules_helper, $request, $template, $phpbb_root_path, $phpEx, $user)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->pagination = $pagination;
|
||||
$this->modules_helper = $modules_helper;
|
||||
$this->request = $request;
|
||||
$this->template = $template;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
@@ -134,14 +139,8 @@ class news extends module_base
|
||||
|
||||
$str_where = '';
|
||||
|
||||
if($permissions == true)
|
||||
{
|
||||
$disallow_access = array_unique(array_keys($this->auth->acl_getf('!f_read', true)));
|
||||
}
|
||||
else
|
||||
{
|
||||
$disallow_access = array();
|
||||
}
|
||||
// Get disallowed forums
|
||||
$disallow_access = $this->modules_helper->get_disallowed_forums($permissions);
|
||||
|
||||
if($this->config['board3_news_exclude_' . $module_id] == true)
|
||||
{
|
||||
|
||||
38
tests/unit/includes/fixtures/auth.xml
Normal file
38
tests/unit/includes/fixtures/auth.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_acl_users">
|
||||
<column>user_id</column>
|
||||
<column>forum_id</column>
|
||||
<column>auth_option_id</column>
|
||||
<column>auth_role_id</column>
|
||||
<column>auth_setting</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value>16</value>
|
||||
<value>0</value>
|
||||
</row>
|
||||
</table>
|
||||
<table name="phpbb_forums">
|
||||
<column>forum_id</column>
|
||||
<column>parent_id</column>
|
||||
<column>forum_parents</column>
|
||||
<column>forum_desc</column>
|
||||
<column>forum_rules</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>0</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>1</value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
<value></value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
||||
53
tests/unit/includes/helper_test.php
Normal file
53
tests/unit/includes/helper_test.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class board3_includes_helper_test extends \board3\portal\tests\testframework\test_case
|
||||
{
|
||||
protected $portal_helper;
|
||||
|
||||
protected $modules;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$config = new \phpbb\config\config(array());
|
||||
$this->modules = array(
|
||||
'\board3\portal\modules\link_us' => new \board3\portal\modules\link_us($config, new \board3\portal\tests\mock\template($this), new \board3\portal\tests\mock\user),
|
||||
);
|
||||
|
||||
$this->portal_helper = $this->get_portal_helper($this->modules);
|
||||
}
|
||||
|
||||
protected function get_portal_helper($modules)
|
||||
{
|
||||
$this->portal_helper = new \board3\portal\includes\helper($modules);
|
||||
|
||||
return $this->portal_helper;
|
||||
}
|
||||
|
||||
public function data_get_module()
|
||||
{
|
||||
return array(
|
||||
array(false, '\board3\portal\modules\user_menu'),
|
||||
array('\board3\portal\modules\link_us', '\board3\portal\modules\link_us'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_get_module
|
||||
*/
|
||||
public function test_get_module($expected, $module_name)
|
||||
{
|
||||
if (!empty($expected))
|
||||
{
|
||||
$expected = $this->modules[$expected];
|
||||
}
|
||||
$this->assertEquals($expected, $this->portal_helper->get_module($module_name));
|
||||
}
|
||||
}
|
||||
46
tests/unit/includes/modules_helper_test.php
Normal file
46
tests/unit/includes/modules_helper_test.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class board3_includes_modules_helper_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $modules_helper;
|
||||
|
||||
protected $modules;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/auth.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$auth = new \phpbb\auth\auth();
|
||||
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth);
|
||||
}
|
||||
|
||||
public function data_get_disallowed_forums()
|
||||
{
|
||||
return array(
|
||||
array(array(), false),
|
||||
array(array(0 => 1, 1 => 2), true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_get_disallowed_forums
|
||||
*/
|
||||
public function test_get_disallowed_forums($expected, $input)
|
||||
{
|
||||
$this->assertEquals($expected, $this->modules_helper->get_disallowed_forums($input));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user