diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index 5004c8e882..8349ac8f44 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.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; diff --git a/main/inc/lib/plugin.class.php b/main/inc/lib/plugin.class.php index 9acd3cc378..91d645c9e3 100755 --- a/main/inc/lib/plugin.class.php +++ b/main/inc/lib/plugin.class.php @@ -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++; }