Skip to content

Commit

Permalink
feat(issue): validation_percent
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 1, 2021
1 parent 429453d commit bd9b865
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -289,7 +290,7 @@ public static function getTicketStatusForIssue(Ticket $item) : array {
}
}

return ['status' => $status, 'user' => $user];
return ['status' => $status, 'user' => $user, 'validation_percent' => $validationPercent];
}

/**
Expand Down
14 changes: 8 additions & 6 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -410,7 +412,7 @@ public function rawSearchOptions() {

$tab[] = [
'id' => '1',
'table' => $this::getTable(),
'table' => self::getTable(),
'field' => 'name',
'name' => __('Name'),
'datatype' => 'itemlink',
Expand All @@ -423,7 +425,7 @@ public function rawSearchOptions() {

$tab[] = [
'id' => '2',
'table' => $this::getTable(),
'table' => self::getTable(),
'field' => 'display_id',
'name' => __('ID'),
'datatype' => 'string',
Expand All @@ -432,7 +434,7 @@ public function rawSearchOptions() {

$tab[] = [
'id' => '3',
'table' => $this::getTable(),
'table' => self::getTable(),
'field' => 'sub_itemtype',
'name' => __('Type'),
'searchtype' => [
Expand All @@ -445,7 +447,7 @@ public function rawSearchOptions() {

$tab[] = [
'id' => '4',
'table' => $this::getTable(),
'table' => self::getTable(),
'field' => 'status',
'name' => __('Status'),
'searchtype' => [
Expand All @@ -457,7 +459,7 @@ public function rawSearchOptions() {

$tab[] = [
'id' => '5',
'table' => $this::getTable(),
'table' => self::getTable(),
'field' => 'date_creation',
'name' => __('Opening date'),
'datatype' => 'datetime',
Expand All @@ -466,7 +468,7 @@ public function rawSearchOptions() {

$tab[] = [
'id' => '6',
'table' => $this::getTable(),
'table' => self::getTable(),
'field' => 'date_mod',
'name' => __('Last update'),
'datatype' => 'datetime',
Expand Down
1 change: 1 addition & 0 deletions install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand Down
7 changes: 7 additions & 0 deletions install/upgrade_to_2.12.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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`");
}
}

0 comments on commit bd9b865

Please sign in to comment.