Add manageTab function to plugin main class - refs #7272

1.9.x
Imanol Losada 11 years ago
parent 7e0404a210
commit 1a6a4a927e
  1. 4
      main/admin/configure_plugin.php
  2. 37
      main/inc/lib/plugin.class.php
  3. 8
      plugin/buycourses/database.php
  4. 2
      plugin/buycourses/lang/english.php
  5. 2
      plugin/buycourses/lang/french.php
  6. 2
      plugin/buycourses/lang/spanish.php
  7. 5
      plugin/buycourses/src/buy_course_plugin.class.php

@ -69,6 +69,10 @@ if (isset($form)) {
1
);
}
if (isset($values['show_main_menu_tab'])) {
$objPlugin = $plugin_info['plugin_class']::create();
$objPlugin->manageTab($values['show_main_menu_tab']);
}
$message = Display::return_message(get_lang('Updated'), 'success');
}
}

@ -189,6 +189,12 @@ class Plugin
$help = null;
if ($this->get_lang_plugin_exists($name.'_help')) {
$help = $this->get_lang($name.'_help');
if ($name === "show_main_menu_tab") {
$pluginName = strtolower(str_replace('Plugin', '', get_class($this)));
$pluginUrl = api_get_path(WEB_PATH)."plugin/$pluginName/index.php";
$pluginUrl = "<a href=$pluginUrl>$pluginUrl</a>";
$help = sprintf($help, $pluginUrl);
}
}
switch ($type) {
@ -635,4 +641,35 @@ class Plugin
return $resp;
}
/**
* This method shows or hides plugin's tab
* @param boolean Shows or hides the main menu plugin tab
*/
public function manageTab($showTab)
{
$langString = str_replace('Plugin', '', get_class($this));
$pluginName = strtolower($langString);
$pluginUrl = 'plugin/'.$pluginName.'/index.php';
if ($showTab === 'true') {
$rsTab = $this->addTab($this->get_lang($langString), $pluginUrl);
if ($rsTab) {
echo "<script>location.href = '".Security::remove_XSS($_SERVER['REQUEST_URI'])."';</script>";
}
} else {
$settingsCurrentTable = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$conditions = array(
'where' => array(
"variable = 'show_tabs' AND title = ? AND comment = ? " => array(
$this->get_lang($langString),
$pluginUrl
)
)
);
$result = Database::select('subkey', $settingsCurrentTable, $conditions);
if (!empty($result)) {
$this->deleteTab($result[0]['subkey']);
}
}
}
}

@ -14,7 +14,6 @@ if (!function_exists('api_get_path')) {
/**
* Create the script context, then execute database queries to enable
*/
$objPlugin = BuyCoursesPlugin::create();
$table = Database::get_main_table(TABLE_BUY_SESSION);
$sql = "CREATE TABLE IF NOT EXISTS $table (
@ -407,10 +406,3 @@ $sql = "CREATE TABLE IF NOT EXISTS $table (
status VARCHAR(20) NOT NULL DEFAULT '',
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)";
Database::query($sql);
//Menu main tabs
$rsTab = $objPlugin->addTab($objPlugin->get_lang('BuyCourses'), 'plugin/buycourses/index.php');
if ($rsTab) {
echo "<script>location.href = '" . Security::remove_XSS($_SERVER['REQUEST_URI']) . "';</script>";
}

@ -1,6 +1,8 @@
<?php
$strings['plugin_title'] = "Sell courses";
$strings['plugin_comment'] = "Sell courses directly through your Chamilo portal, using a PayPal account to receive funds. This plugin is in beta version. Neither the Chamilo association nor the developers involved could be considered responsible of any issue you might suffer using this plugin.";
$strings['show_main_menu_tab'] = "Show tab in main menu";
$strings['show_main_menu_tab_help'] = "In case of not wanting to show the tab, you can create this link in your Chamilo homepage : %s";
$strings['Visible'] = "Show list";
$strings['Options'] = "Options";
$strings['Price'] = "Price";

@ -1,6 +1,8 @@
<?php
$strings['plugin_title'] = "Vente de cours";
$strings['plugin_comment'] = "Vendez vos cours directement depuis votre portail Chamilo, au travers d'un compte PayPal. Plugin en version beta, à utiliser avec précaution. Ni l'association Chamilo ni les développeurs impliqués dans le développement de ce plugin ne sauraient être tenus responsables d'un quelconque inconvénient causé par celui-ci.";
$strings['show_main_menu_tab'] = "Montrer l'onglet dans le menu principal";
$strings['show_main_menu_tab_help'] = "Dans le cas où l'onglet ne se montre pas, il est possible de rajouter le lien suivant à votre portail Chamilo: %s";
$strings['Visible'] = "Montrer dans la liste";
$strings['Options'] = "Options";
$strings['Price'] = "Prix";

@ -1,6 +1,8 @@
<?php
$strings['plugin_title'] = "Venta de cursos";
$strings['plugin_comment'] = "Vender cursos a través de PayPal directamente desde su portal Chamilo. Plugin en versión Beta, a usar con mucha precaución. La asociación Chamilo y los desarrolladores involucrados no pueden ser considerados responsables de cualquier inconveniente que se presente.";
$strings['show_main_menu_tab'] = "Mostrar pestaña en el menu principal";
$strings['show_main_menu_tab_help'] = "En caso de no querer mostrar la pestaña, puede agregar el siguiente enlace a su portal Chamilo: %s";
$strings['Visible'] = "Mostrar en el listado";
$strings['Options'] = "Opciones";
$strings['Price'] = "Precio";

@ -29,6 +29,7 @@ class BuyCoursesPlugin extends Plugin
Francis Gonzales and Yannick Warnier - BeezNest (integration),
Imanol Losada - BeezNest',
array(
'show_main_menu_tab' => 'boolean',
'include_sessions' => 'boolean',
'paypal_enable' => 'boolean',
'transfer_enable' => 'boolean',
@ -67,8 +68,6 @@ class BuyCoursesPlugin extends Plugin
$sql = "DROP TABLE IF EXISTS $tableToBeDeleted";
Database::query($sql);
}
$objPlugin = BuyCoursesPlugin::create();
$objPlugin->deleteTab('custom_tab_1');
$this->manageTab(false);
}
}

Loading…
Cancel
Save