From ec182dffd75c5472c2f39666f36ae1b0dcbfa45e Mon Sep 17 00:00:00 2001 From: Julio Date: Wed, 20 Apr 2016 08:29:11 +0200 Subject: [PATCH] Add category edit option see BT#11081 --- main/inc/lib/plugin.class.php | 2 + main/inc/lib/sortable_table.class.php | 13 +++-- plugin/ticket/lang/english.php | 3 ++ plugin/ticket/src/categories.php | 63 +++++++++++++++++++++++ plugin/ticket/src/myticket.php | 18 +++++-- plugin/ticket/src/ticket_plugin.class.php | 20 +++++-- 6 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 plugin/ticket/src/categories.php diff --git a/main/inc/lib/plugin.class.php b/main/inc/lib/plugin.class.php index 1f6a6151b0..46f8175d43 100755 --- a/main/inc/lib/plugin.class.php +++ b/main/inc/lib/plugin.class.php @@ -325,6 +325,7 @@ class Plugin //1. Loading english if exists $english_path = $root.$plugin_name."/lang/english.php"; + if (is_readable($english_path)) { $strings = array(); include $english_path; @@ -332,6 +333,7 @@ class Plugin } $path = $root.$plugin_name."/lang/$language_interface.php"; + //2. Loading the system language if (is_readable($path)) { include $path; diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php index 39e5e36168..418397cd61 100755 --- a/main/inc/lib/sortable_table.class.php +++ b/main/inc/lib/sortable_table.class.php @@ -245,7 +245,6 @@ class SortableTable extends HTML_Table $empty_table = false; $content = $this->get_table_html(); - if ($this->get_total_number_of_items() == 0) { $cols = $this->getColCount(); $this->setCellAttributes(1, 0, 'style="font-style: italic;text-align:center;" colspan='.$cols); @@ -954,10 +953,18 @@ class SortableTable extends HTML_Table */ public function get_table_data($from = null, $per_page = null, $column = null, $direction = null, $sort = null) { + $data = []; if (!is_null($this->get_data_function)) { - return call_user_func($this->get_data_function, $from, $this->per_page, $this->column, $this->direction); + $data = call_user_func( + $this->get_data_function, + $from, + $this->per_page, + $this->column, + $this->direction + ); } - return array(); + + return $data; } diff --git a/plugin/ticket/lang/english.php b/plugin/ticket/lang/english.php index ab817e4d14..6fe6258dda 100755 --- a/plugin/ticket/lang/english.php +++ b/plugin/ticket/lang/english.php @@ -85,3 +85,6 @@ $strings['PleaseBeforeRegisterATicketSelectOneUser'] = "Please select a user bef $strings['RequestConfirmation'] = "Request confirmation"; $strings['TicketUpdated'] = "Ticket updated"; $strings['TicketClosed'] = "Ticket closed"; + +$strings['allow_category_edition'] = "Allow category edition"; + diff --git a/plugin/ticket/src/categories.php b/plugin/ticket/src/categories.php new file mode 100644 index 0000000000..a7178cef69 --- /dev/null +++ b/plugin/ticket/src/categories.php @@ -0,0 +1,63 @@ +get_lang('LastEdit'); + + +$libPath = api_get_path(LIBRARY_PATH); +$webLibPath = api_get_path(WEB_LIBRARY_PATH); + +$this_section = 'tickets'; +unset($_SESSION['this_section']); + +$table = new SortableTable( + 'TicketCategories', + array('TicketManager', 'getCategoriesCount'), + array('TicketManager', 'get_all_tickets_categories'), + 1 +); + +if ($table->per_page == 0) { + $table->per_page = 20; +} + +if (isset($_GET['action'])) { + global $table; + $action = $_GET['action']; + switch ($action) { + case 'assign': + if ($isAdmin && isset($_GET['ticket_id'])) + TicketManager::assign_ticket_user($_GET['ticket_id'], $user_id); + break; + default: + break; + } +} + +$user_id = api_get_user_id(); +$isAdmin = api_is_platform_admin(); + +Display::display_header($plugin->get_lang('MyTickets')); + +$table->set_header(0, $plugin->get_lang('Title'), true); +$table->set_header(1, get_lang('Description'), true, array("style" => "width:200px")); +$table->set_header(2, $plugin->get_lang('TotalTickets'), true); +$table->set_header(3, get_lang('Actions'), true); + +echo $table->return_table(); + +Display::display_footer(); diff --git a/plugin/ticket/src/myticket.php b/plugin/ticket/src/myticket.php index daef5b510a..1e8052af6e 100755 --- a/plugin/ticket/src/myticket.php +++ b/plugin/ticket/src/myticket.php @@ -12,8 +12,8 @@ $course_plugin = 'ticket'; require_once '../config.php'; $plugin = TicketPlugin::create(); -$tool_name = $plugin->get_lang('LastEdit'); +$tool_name = $plugin->get_lang('LastEdit'); api_block_anonymous_users(); $libPath = api_get_path(LIBRARY_PATH); @@ -289,12 +289,22 @@ if ($isAdmin) { echo '
'; if (api_is_platform_admin()) { - echo '' . + echo '' . '' . Display::return_icon('add.png', $plugin->get_lang('TckNew'), '', '32') . '' . '' . - Display::return_icon('export_excel.png', get_lang('Export'), '', '32') . '' . - ''; + Display::return_icon('export_excel.png', get_lang('Export'), '', '32') . ''; + + + if ($plugin->get('allow_category_edition')) { + echo Display::url( + Display::return_icon('document.png'), + api_get_path(WEB_PLUGIN_PATH) . 'ticket/src/categories.php' + ); + } + + echo ''; + } $form->display(); echo '
'; diff --git a/plugin/ticket/src/ticket_plugin.class.php b/plugin/ticket/src/ticket_plugin.class.php index baf83f6e5b..ae4b06e0e8 100755 --- a/plugin/ticket/src/ticket_plugin.class.php +++ b/plugin/ticket/src/ticket_plugin.class.php @@ -12,21 +12,30 @@ class TicketPlugin extends Plugin /** * Set the result * @staticvar null $result - * @return type + * @return TicketPlugin */ - static function create() + public static function create() { static $result = null; return $result ? $result : $result = new self(); } + /** + * TicketPlugin constructor. + */ protected function __construct() { $settings = array( 'tool_enable' => 'boolean', - 'allow_student_add' => 'boolean' + 'allow_student_add' => 'boolean', + 'allow_category_edition' => 'boolean' + ); + + parent::__construct( + '1.0', + 'Kenny Rodas Chavez, Genesis Lopez, Francis Gonzales, Yannick Warnier, Julio Montoya', + $settings ); - parent::__construct('1.0', 'Kenny Rodas Chavez, Genesis Lopez, Francis Gonzales, Yannick Warnier', $settings); } /** @@ -36,7 +45,6 @@ class TicketPlugin extends Plugin { // Create database tables and insert a Tab require_once api_get_path(SYS_PLUGIN_PATH) . PLUGIN_NAME . '/database.php'; - } /** @@ -87,4 +95,6 @@ class TicketPlugin extends Plugin echo ""; } } + + }