Add filter for user to custom tabs - refs BT#12876

pull/2487/head
Angel Fernando Quiroz Campos 8 years ago
parent a83d681ac8
commit 833ef46693
  1. 12
      main/inc/lib/banner.lib.php
  2. 49
      main/inc/lib/plugin.class.php

@ -167,7 +167,17 @@ function getCustomTabs()
$result = Database::query($sql);
$customTabs = array();
while ($row = Database::fetch_assoc($result)) {
$customTabs[] = $row;
$shouldAdd = true;
if (strpos($row['subkey'], Plugin::TAB_FILTER_NO_STUDENT) !== false && api_is_student()) {
$shouldAdd = false;
} elseif (strpos($row['subkey'], Plugin::TAB_FILTER_ONLY_STUDENT) !== false && !api_is_student()) {
$shouldAdd = false;
}
if ($shouldAdd) {
$customTabs[] = $row;
}
}
return $customTabs;

@ -40,9 +40,9 @@ class Plugin
* main/img/icons/64/plugin_name_na.png
* @example
* $course_settings = array(
array('name' => 'big_blue_button_welcome_message', 'type' => 'text'),
array('name' => 'big_blue_button_record_and_store', 'type' => 'checkbox')
);
array('name' => 'big_blue_button_welcome_message', 'type' => 'text'),
array('name' => 'big_blue_button_record_and_store', 'type' => 'checkbox')
);
*/
public $course_settings = array();
/**
@ -51,6 +51,9 @@ class Plugin
*/
public $course_settings_callback = false;
const TAB_FILTER_NO_STUDENT = '::no-student';
const TAB_FILTER_ONLY_STUDENT = '::only-student';
/**
* Default constructor for the plugin class. By default, it only sets
* a few attributes of the object
@ -634,14 +637,14 @@ class Plugin
}
/**
* Add a tab to platform
* @param string $tabName
* @param string $url
*
* @return false|string
*/
public function addTab($tabName, $url)
/**
* Add a tab to platform
* @param string $tabName
* @param string $url
* @param string $userFilter Optional. Filter tab type
* @return false|string
*/
public function addTab($tabName, $url, $userFilter = null)
{
$sql = "SELECT * FROM settings_current
WHERE
@ -673,6 +676,17 @@ class Plugin
// End Check
$subkey = 'custom_tab_'.$tabNum;
if (!empty($userFilter)) {
switch ($userFilter) {
case self::TAB_FILTER_NO_STUDENT:
//no break
case self::TAB_FILTER_ONLY_STUDENT:
$subkey .= $userFilter;
break;
}
}
$attributes = array(
'variable' => 'show_tabs',
'subkey' => $subkey,
@ -730,9 +744,16 @@ class Plugin
$tabs = Database::store_result($result, 'ASSOC');
$i = 1;
foreach ($tabs as $row) {
$attributes = array(
'subkey' => 'custom_tab_'.$i
);
$newSubKey = "custom_tab_$i";
if (strpos($row['subkey'], self::TAB_FILTER_NO_STUDENT) !== false) {
$newSubKey .= self::TAB_FILTER_NO_STUDENT;
} elseif (strpos($row['subkey'], self::TAB_FILTER_ONLY_STUDENT) !== false) {
$newSubKey .= self::TAB_FILTER_ONLY_STUDENT;
}
$attributes = ['subkey' => $newSubKey];
$this->updateTab($row['subkey'], $attributes);
$i++;
}

Loading…
Cancel
Save