CRUD to tabs and add some default values - refs #6715

1.9.x
Francis Gonzales 12 years ago
parent 3ac9766bf0
commit 8bb5b94066
  1. 103
      main/inc/lib/plugin.class.php
  2. 55
      plugin/ticket/database.php
  3. 62
      plugin/ticket/lib/ticket_plugin.class.php

@ -462,4 +462,105 @@ class Plugin
{
}
}
/**
* This function add a tab to chamilo's platform
* @param type $tabName
*/
public function addTab($tabName, $url)
{
$sql = "SELECT *
FROM settings_current
WHERE variable = 'show_tabs'
AND subkey like 'custom_tab_%'";
$result = Database::query($sql);
$customTabsNum = Database::count_rows($result);
$tabNum = $customTabsNum + 1;
//Avoid Tab Name Spaces
$tabNameNoSpaces = preg_replace('/\s+/', '', $tabName);
$subkeytext = "Tabs" . $tabNameNoSpaces;
$subkey = 'custom_tab_' . $tabNum;
$attributes = array(
'variable' => 'show_tabs',
'subkey' => $subkey,
'type' => 'checkbox',
'category' => 'Platform',
'selected_value' => 'true',
'title' => $tabName,
'comment' => $url,
'subkeytext' => $subkeytext,
'access_url' => 1,
'access_url_changeable' => 0,
'access_url_locked' => 0
);
$resp = Database::insert('settings_current', $attributes);
//Save the id
$settings = $this->get_settings();
$setData = array (
'comment' => $subkey
);
$whereCond = array(
'id = ?' => key($settings)
);
Database::update('settings_current', $setData, $whereCond);
return $resp;
}
/**
* This function delete a tab to chamilo's platform
* @param type $tabKey
*/
public function deleteTab($key)
{
$sql = "SELECT *
FROM settings_current
WHERE variable = 'show_tabs'
AND subkey <> '$key'";
$resp = $result = Database::query($sql);
$customTabsNum = Database::count_rows($result);
if (!empty($key)) {
$whereCond = array(
'variable = ? AND subkey = ?' => array('show_tabs', $key)
);
Database::delete('settings_current', $whereCond);
//if there is more than one tab
//reenumerate them
if ($customTabsNum > 0) {
$i = 1;
while ($row = Database::fetch_assoc($result)) {
$attributes = array(
'subkey' => 'custom_tab_' . $i
);
$resp = $this->updateTab($row['subkey'], $attributes);
$i++;
}
}
}
return $resp;
}
/**
* This function updates the tabs attributes
* @param string $key
* @param array $attributes
* @return boolean
*/
public function updateTab($key, $attributes)
{
$whereCond = array(
'variable = ? AND subkey = ?' => array('show_tabs', $key)
);
Database::update('settings_current', $attributes, $whereCond);
return $resp;
}
}

@ -2,6 +2,10 @@
/**
* Contains the SQL for the tickets management plugin database structure
*/
$objPlugin = new TicketPlugin();
$table = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
iid int unsigned not null,
@ -13,6 +17,7 @@ $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
KEY FK_ticket_assigned_log (ticket_id))";
Database::query($sql);
//Category
$table = Database::get_main_table(TABLE_TICKET_CATEGORY);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
iid int unsigned not null,
@ -29,6 +34,41 @@ $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
PRIMARY KEY (iid))";
Database::query($sql);
//Default Categories
$categoRow = array(
$objPlugin->get_lang('Enrollment') => $objPlugin->get_lang('TicketsAboutEnrollment'),
$objPlugin->get_lang('GeneralInformation') => $objPlugin->get_lang('TicketsAboutGeneralInformation'),
$objPlugin->get_lang('RequestAndTramits') => $objPlugin->get_lang('TicketsAboutRequestAndTramits'),
$objPlugin->get_lang('AcademicIncidence') => $objPlugin->get_lang('TicketsAboutAcademicIncidence'),
$objPlugin->get_lang('VirtualCampus') => $objPlugin->get_lang('TicketsAboutVirtualCampus'),
$objPlugin->get_lang('OnlineEvaluation') => $objPlugin->get_lang('TicketsAboutOnlineEvaluation')
);
$i = 1;
foreach ($categoRow as $category => $description) {
//Online evaluation requires a course
if ($i == 6) {
$attributes = array(
'iid' => $i,
'category_id' => $i,
'name' => $category,
'description' => $description,
'project_id' => 1,
'course_required' => 1
);
} else {
$attributes = array(
'iid' => $i,
'category_id' => $i,
'project_id' => 1,
'description' => $description,
'name' => $category
);
}
Database::insert($table, $attributes);
$i++;
}
//END default categories
$table = Database::get_main_table(TABLE_TICKET_MESSAGE);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
message_id int UNSIGNED NOT NULL,
@ -91,6 +131,14 @@ $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
sys_lastedit_datetime datetime DEFAULT NULL,
PRIMARY KEY (iid))";
Database::query($sql);
//Default Project Table Ticket
$attributes = array(
'iid' => 1,
'project_id' => 1,
'name' => 'Ticket System'
);
Database::insert($table, $attributes);
//END
$table = Database::get_main_table(TABLE_TICKET_STATUS);
$sql = "CREATE TABLE IF NOT EXISTS ".$table." (
@ -129,9 +177,4 @@ $sql = "CREATE TABLE IF NOT EXISTS ".$table." (
Database::query($sql);
// Menu main tabs
//$table = Database::get_main_table('ticket_ticket');
//$sql = "INSERT INTO settings_current
//(variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable)
//VALUES
//('show_tabs', 'tickets', 'checkbox', 'Platform', 'true', 'ShowTabsTitle', 'ShowTabsComment', NULL, 'TabsTickets', 1)";
//Database::query($sql);
$objPlugin->addTab('Ticket', '/plugin/ticket/src/myticket.php');

@ -9,64 +9,33 @@
*/
class TicketPlugin extends Plugin
{
/**
* Set the result
* @staticvar null $result
* @return type
*/
static function create()
{
static $result = null;
return $result ? $result : $result = new self();
}
protected function __construct()
{
parent::__construct('1.0', 'Kenny Rodas Chavez, Genesis Lopez, Francis Gonzales, Yannick Warnier', array('tool_enable' => 'boolean'));
}
/**
* Install the ticket plugin
*/
public function install()
{
// Create database tables
// Create database tables and insert a Tab
require_once api_get_path(SYS_PLUGIN_PATH) . PLUGIN_NAME . '/database.php';
// Create link tab
// $homep = api_get_path(SYS_PATH).'home/'; //homep for Home Path
// $menutabs = 'home_tabs'; //menutabs for tabs Menu
// $menuf = $menutabs;
// $ext = '.html'; //ext for HTML Extension - when used frequently, variables are faster than hardcoded strings
// $lang = ''; //el for "Edit Language"
// if (!empty($_SESSION['user_language_choice'])) {
// $lang = $_SESSION['user_language_choice'];
// } elseif (!empty($_SESSION['_user']['language'])) {
// $lang = $_SESSION['_user']['language'];
// } else {
// $lang = api_get_setting('platformLanguage');
// }
// $link_url = api_get_path(WEB_PLUGIN_PATH).'ticket/s/myticket.php';
//
// $home_menu = '<li class="show_menu"><a href="'.$link_url.'" target="_self"><span>Ticket</span></a></li>';
//
// // Write
// if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
// if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
// $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
// fputs($fp, $home_menu);
// fclose($fp);
// if (file_exists($homep.$menuf.$ext)) {
// if (is_writable($homep.$menuf.$ext)) {
// $fpo = fopen($homep.$menuf.$ext, 'w');
// fputs($fpo, $home_menu);
// fclose($fpo);
// }
// }
// } else {
// $errorMsg = get_lang('HomePageFilesNotWritable');
// }
// } else {
// //File does not exist
// $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
// fputs($fp, $home_menu);
// fclose($fp);
// }
}
/**
* Uninstall the ticket plugin
*/
public function uninstall()
{
$tblSettings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
@ -80,12 +49,13 @@ class TicketPlugin extends Plugin
$tblTicketMessage = Database::get_main_table(TABLE_TICKET_MESSAGE);
$tblTicketCategory = Database::get_main_table(TABLE_TICKET_CATEGORY);
$tblTicketAssgLog = Database::get_main_table(TABLE_TICKET_ASSIGNED_LOG);
$settings = $this->get_settings();
$plugSetting = current($settings);
//Delete settings
$sql = "DELETE FROM $tblSettings WHERE variable = 'ticket_tool_enable'";
Database::query($sql);
$sql = "DROP TABLE IF EXISTS $tblTicketTicket";
Database::query($sql);
$sql = "DROP TABLE IF EXISTS $tblTicketStatus";
@ -104,5 +74,7 @@ class TicketPlugin extends Plugin
Database::query($sql);
$sql = "DROP TABLE IF EXISTS $tblTicketTicket";
Database::query($sql);
$this->deleteTab($plugSetting['comment']);
}
}
Loading…
Cancel
Save