From bd9b865c1d8996d133506efce73aa1c7a78e08f1 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 11 Mar 2021 17:04:57 +0100 Subject: [PATCH] feat(issue): validation_percent Signed-off-by: Thierry Bugier --- inc/common.class.php | 3 ++- inc/issue.class.php | 14 ++++++++------ install/mysql/plugin_formcreator_empty.sql | 1 + install/upgrade_to_2.12.php | 7 +++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 6b0ad3d60..02cd63389 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -267,6 +267,7 @@ public static function getTicketStatusForIssue(Ticket $item) : array { 'timeline_position ASC' ], 1); $user = 0; + $validationPercent = $item->fields['validation_percent']; $ticketValidationCount = count($ticketValidations); if ($ticketValidationCount) { $row = array_shift($ticketValidations); @@ -289,7 +290,7 @@ public static function getTicketStatusForIssue(Ticket $item) : array { } } - return ['status' => $status, 'user' => $user]; + return ['status' => $status, 'user' => $user, 'validation_percent' => $validationPercent]; } /** diff --git a/inc/issue.class.php b/inc/issue.class.php index 1c3cbfa77..40417e388 100644 --- a/inc/issue.class.php +++ b/inc/issue.class.php @@ -104,6 +104,7 @@ public static function getSyncIssuesRequest() : AbstractQuery { 'groups_id_validator as groups_id_validator', 'comment as comment' ], + new QueryExpression("IF(`$formAnswerTable`.`status` = '" . PluginFormcreatorFormAnswer::STATUS_ACCEPTED . "', '100', '0') as `validation_percent`"), ], 'DISTINCT' => true, 'FROM' => $formAnswerTable, @@ -160,6 +161,7 @@ public static function getSyncIssuesRequest() : AbstractQuery { "$ticketUserTable.users_id as requester_id", new QueryExpression("IF(`$ticketValidationTable`.`users_id_validate` IS NULL, 0, `$ticketValidationTable`.`users_id_validate`) as users_id_validator"), new QueryExpression('0 as groups_id_validator'), + 'validation_percent as validation_percent', "$ticketTable.content as comment", ], 'DISTINCT' => true, @@ -410,7 +412,7 @@ public function rawSearchOptions() { $tab[] = [ 'id' => '1', - 'table' => $this::getTable(), + 'table' => self::getTable(), 'field' => 'name', 'name' => __('Name'), 'datatype' => 'itemlink', @@ -423,7 +425,7 @@ public function rawSearchOptions() { $tab[] = [ 'id' => '2', - 'table' => $this::getTable(), + 'table' => self::getTable(), 'field' => 'display_id', 'name' => __('ID'), 'datatype' => 'string', @@ -432,7 +434,7 @@ public function rawSearchOptions() { $tab[] = [ 'id' => '3', - 'table' => $this::getTable(), + 'table' => self::getTable(), 'field' => 'sub_itemtype', 'name' => __('Type'), 'searchtype' => [ @@ -445,7 +447,7 @@ public function rawSearchOptions() { $tab[] = [ 'id' => '4', - 'table' => $this::getTable(), + 'table' => self::getTable(), 'field' => 'status', 'name' => __('Status'), 'searchtype' => [ @@ -457,7 +459,7 @@ public function rawSearchOptions() { $tab[] = [ 'id' => '5', - 'table' => $this::getTable(), + 'table' => self::getTable(), 'field' => 'date_creation', 'name' => __('Opening date'), 'datatype' => 'datetime', @@ -466,7 +468,7 @@ public function rawSearchOptions() { $tab[] = [ 'id' => '6', - 'table' => $this::getTable(), + 'table' => self::getTable(), 'field' => 'date_mod', 'name' => __('Last update'), 'datatype' => 'datetime', diff --git a/install/mysql/plugin_formcreator_empty.sql b/install/mysql/plugin_formcreator_empty.sql index 1e61c00e5..437c4f6ee 100644 --- a/install/mysql/plugin_formcreator_empty.sql +++ b/install/mysql/plugin_formcreator_empty.sql @@ -253,6 +253,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_issues` ( `requester_id` int(11) NOT NULL DEFAULT '0', `users_id_validator` int(11) NOT NULL DEFAULT '0', `groups_id_validator` int(11) NOT NULL DEFAULT '0', + `validation_percent` int(11) NOT NULL DEFAULT '0', `comment` longtext, PRIMARY KEY (`id`), INDEX `original_id_sub_itemtype` (`original_id`, `sub_itemtype`), diff --git a/install/upgrade_to_2.12.php b/install/upgrade_to_2.12.php index 2c2372749..3dd77afb7 100644 --- a/install/upgrade_to_2.12.php +++ b/install/upgrade_to_2.12.php @@ -47,6 +47,7 @@ public function upgrade(Migration $migration) { $table = 'glpi_plugin_formcreator_issues'; $migration->changeField($table, 'date_creation', 'date_creation', 'timestamp'. ' NOT NULL DEFAULT CURRENT_TIMESTAMP'); $migration->changeField($table, 'date_mod', 'date_mod', 'timestamp'. ' NOT NULL DEFAULT CURRENT_TIMESTAMP'); + $this->addValidationPercent(); $this->changeDropdownTreeSettings(); @@ -89,4 +90,10 @@ public function changeDropdownTreeSettings() { $DB->update($table, ['values' => $newValues], ['id' => $row['id']]); } } + + public function addValidationPercent() { + $table = 'glpi_plugin_formcreator_issues'; + $this->migration->addField($table, 'validation_percent', 'integer', ['after' => 'groups_id_validator']); + $this->migration->addPostQuery("UPDATE `$table` as `i` INNER JOIN `glpi_tickets` as `t` ON (`i`.`original_id` = `t`.`id` AND `i`.`sub_itemtype` = 'Ticket') SET `i`.`validation_percent`=`t`.`validation_percent`"); + } } \ No newline at end of file