[ticket/289] Add method for generating forum select boxes

This commit is contained in:
Marc Alexander
2014-07-24 17:42:51 +02:00
parent 240168e925
commit 7f887b872c
6 changed files with 56 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ class portal_module
public $new_config = array();
protected $c_class;
protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container;
protected $root_path, $version_check, $request, $php_ext, $portal_helper;
protected $root_path, $version_check, $request, $php_ext, $portal_helper, $modules_helper;
public $module_column = array();
public function __construct()
@@ -41,6 +41,7 @@ class portal_module
$this->phpbb_container = $phpbb_container;
$this->version_check = $this->phpbb_container->get('board3.version.check');
$this->portal_helper = $this->phpbb_container->get('board3.portal.helper');
$this->modules_helper = $this->phpbb_container->get('board3.portal.modules_helper');
define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.modules.table'));
define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.config.table'));
@@ -330,9 +331,16 @@ class portal_module
$func = array($this->c_class, $vars['method']);
}
else
{
if ($vars['method'][0] == 'board3.portal.modules_helper')
{
$func = array($this->modules_helper, $vars['method'][1]);
}
else
{
$func = $vars['method'];
}
}
$content = call_user_func_array($func, $args);
}

View File

@@ -65,10 +65,42 @@ class modules_helper
$options = '<select id="' . $key . '" name="' . $key . '[]" multiple="multiple">';
foreach ($select_ary as $id => $option)
{
$options .= '<option value="' . $option['value'] . '"' . ((in_array($option['value'], $selected_options)) ? ' selected="selected"' : '') . '>' . $option['title'] . '</option>';
$options .= '<option value="' . $option['value'] . '"' . ((in_array($option['value'], $selected_options)) ? ' selected="selected"' : '') . (!empty($option['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $option['title'] . '</option>';
}
$options .= '</select>';
return $options;
}
/**
* Generate forum select box
*
* @param string $value Value of select box
* @param string $key Key of select box
*
* @return string HTML code of select box
* @access public
*/
public function generate_forum_select($value, $key)
{
$forum_list = make_forum_select(false, false, true, true, true, false, true);
$selected_options = $select_ary = array();
if(isset($this->config[$key]) && strlen($this->config[$key]) > 0)
{
$selected_options = explode(',', $this->config[$key]);
}
// Build forum options
foreach ($forum_list as $f_id => $f_row)
{
$select_ary[] = array(
'value' => $f_id,
'title' => $f_row['padding'] . $f_row['forum_name'],
'disabled' => $f_row['disabled'],
);
}
return $this->generate_select_box($key, $select_ary, $selected_options);
}
}

View File

@@ -121,7 +121,7 @@ class attachments extends module_base
'legend1' => 'ACP_PORTAL_ATTACHMENTS_NUMBER_SETTINGS',
'board3_attachments_number_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_NUMBER' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_attach_max_length_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_MAX_LENGTH' , 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true),
'board3_attachments_forum_ids_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_IDS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_forums', 'submit' => 'store_selected_forums'),
'board3_attachments_forum_ids_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_IDS', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => array('board3.portal.modules_helper', 'generate_forum_select'), 'submit' => 'store_selected_forums'),
'board3_attachments_forum_exclude_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FORUM_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'board3_attachments_filetype_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_FILETYPE', 'validate' => 'string', 'type' => 'custom', 'explain' => true, 'method' => 'select_filetype', 'submit' => 'store_filetypes'),
'board3_attachments_exclude_' . $module_id => array('lang' => 'PORTAL_ATTACHMENTS_EXCLUDE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),

View File

@@ -39,6 +39,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
new \board3\portal\modules\donation($config, $template, $user),
));
$phpbb_container->set('board3.portal.helper', new \board3\portal\includes\helper($phpbb_container->get('board3.module_collection')));
$phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper(new \phpbb\auth\auth()));
$phpbb_container->setParameter('board3.modules.table', $table_prefix . 'portal_modules');
$phpbb_container->setParameter('board3.config.table', $table_prefix . 'portal_config');
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put'));

View File

@@ -17,12 +17,14 @@
<table name="phpbb_forums">
<column>forum_id</column>
<column>parent_id</column>
<column>forum_name</column>
<column>forum_parents</column>
<column>forum_desc</column>
<column>forum_rules</column>
<row>
<value>1</value>
<value>0</value>
<value>forum_one</value>
<value></value>
<value></value>
<value></value>
@@ -30,6 +32,7 @@
<row>
<value>2</value>
<value>1</value>
<value>forum_two</value>
<value></value>
<value></value>
<value></value>

View File

@@ -83,4 +83,12 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
{
$this->assertEquals($expected, $this->modules_helper->generate_select_box($key, $select_ary, $selected_options));
}
public function test_generate_forum_select()
{
$this->assertEquals(
'<select id="bar" name="bar[]" multiple="multiple"><option value="1" disabled="disabled" class="disabled-option">forum_one</option><option value="2" disabled="disabled" class="disabled-option">forum_two</option></select>',
$this->modules_helper->generate_forum_select('foo', 'bar')
);
}
}