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. 10
      main/inc/lib/banner.lib.php
  2. 31
      main/inc/lib/plugin.class.php

@ -167,8 +167,18 @@ function getCustomTabs()
$result = Database::query($sql); $result = Database::query($sql);
$customTabs = array(); $customTabs = array();
while ($row = Database::fetch_assoc($result)) { while ($row = Database::fetch_assoc($result)) {
$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; $customTabs[] = $row;
} }
}
return $customTabs; return $customTabs;
} }

@ -51,6 +51,9 @@ class Plugin
*/ */
public $course_settings_callback = false; 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 * Default constructor for the plugin class. By default, it only sets
* a few attributes of the object * a few attributes of the object
@ -638,10 +641,10 @@ class Plugin
* Add a tab to platform * Add a tab to platform
* @param string $tabName * @param string $tabName
* @param string $url * @param string $url
* * @param string $userFilter Optional. Filter tab type
* @return false|string * @return false|string
*/ */
public function addTab($tabName, $url) public function addTab($tabName, $url, $userFilter = null)
{ {
$sql = "SELECT * FROM settings_current $sql = "SELECT * FROM settings_current
WHERE WHERE
@ -673,6 +676,17 @@ class Plugin
// End Check // End Check
$subkey = 'custom_tab_'.$tabNum; $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( $attributes = array(
'variable' => 'show_tabs', 'variable' => 'show_tabs',
'subkey' => $subkey, 'subkey' => $subkey,
@ -730,9 +744,16 @@ class Plugin
$tabs = Database::store_result($result, 'ASSOC'); $tabs = Database::store_result($result, 'ASSOC');
$i = 1; $i = 1;
foreach ($tabs as $row) { foreach ($tabs as $row) {
$attributes = array( $newSubKey = "custom_tab_$i";
'subkey' => '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); $this->updateTab($row['subkey'], $attributes);
$i++; $i++;
} }

Loading…
Cancel
Save