You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2018-03-05 14:57:24

amma35
Moderator
Registered: 2017-02-08
Posts: 58

[Behaviors] Adding a feature - Mandatory task category

Hi,

Following a request, we want to add in the configuration the possibility of having the obligatory task category and verification when adding ticket tasks.

Would you be interested in this feature if I provided a patch?

Thank you in advance

Offline

#2 2018-03-12 12:06:46

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,273

Re: [Behaviors] Adding a feature - Mandatory task category

Ticket added in the plugin: https://forge.glpi-project.org/issues/5552


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#3 2018-03-12 16:36:57

amma35
Moderator
Registered: 2017-02-08
Posts: 58

Re: [Behaviors] Adding a feature - Mandatory task category

All right, thank you.
I transmit the patch file as soon as it is done.

Offline

#4 2018-04-04 11:07:36

amma35
Moderator
Registered: 2017-02-08
Posts: 58

Re: [Behaviors] Adding a feature - Mandatory task category

Please find the patch file with the addition of the feature.

Let me know if you need to make any changes.

Index: inc/config.class.php
===================================================================
--- inc/config.class.php	(revision 258)
+++ inc/config.class.php	(working copy)
@@ -102,6 +102,7 @@
                      `groupasset` tinyint(1) NOT NULL default '0',
                      `clone` tinyint(1) NOT NULL default '0',
                      `is_tickettasktodo` tinyint(1) NOT NULL default '0',
+                     `is_tickettaskcategory_mandatory` tinyint(1) NOT NULL default '0',
                      `date_mod` datetime default NULL,
                      `comment` text,
                      PRIMARY KEY  (`id`)
@@ -187,6 +188,9 @@
 
          $mig->addField($table, 'is_tickettasktodo', 'bool', ['after' => 'clone']);
 
+         //Version 2.0.3
+         $mig->addField($table, 'is_tickettaskcategory_mandatory', 'bool', ['after' => 'is_tickettasktodo']);
+
       }
 
       return true;
@@ -282,7 +286,7 @@
       echo "<td>".__('Duration is mandatory before ticket is solved/closed', 'behaviors')."</td><td>";
       Dropdown::showYesNo("is_ticketrealtime_mandatory",
                           $config->fields['is_ticketrealtime_mandatory']);
-      echo "</td><td colspan='2' class='tab_bg_2 b center'>".__('Comments');
+      echo "</td><td colspan='2' class='tab_bg_2 b center'>"._n('Ticket task', 'Ticket tasks', 1);
       echo "</td></tr>";
 
 
@@ -290,10 +294,8 @@
       echo "<td>".__('Category is mandatory before ticket is solved/closed', 'behaviors')."</td><td>";
       Dropdown::showYesNo("is_ticketcategory_mandatory",
                           $config->fields['is_ticketcategory_mandatory']);
-      echo "</td><td rowspan='7' colspan='2' class='center'>";
-      echo "<textarea cols='60' rows='12' name='comment' >".$config->fields['comment']."</textarea>";
-      echo "<br>".sprintf(__('%1$s; %2$s'), __('Last update'),
-            Html::convDateTime($config->fields["date_mod"]));
+      echo "<td>".__('Mandatory task category', 'behaviors')."</td><td>";
+      Dropdown::showYesNo('is_tickettaskcategory_mandatory', $config->fields['is_tickettaskcategory_mandatory']);
       echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>";
@@ -301,6 +303,7 @@
       echo "</td><td>";
       Dropdown::showYesNo("is_ticketsolutiontype_mandatory",
                           $config->fields['is_ticketsolutiontype_mandatory']);
+      echo "</td><td colspan='2' class='tab_bg_2 b center'>".__('Comments');
       echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>";
@@ -308,6 +311,10 @@
       echo "</td><td>";
       Dropdown::showYesNo("is_ticketsolution_mandatory",
                           $config->fields['is_ticketsolution_mandatory']);
+      echo "</td><td rowspan='7' colspan='2' class='center'>";
+      echo "<textarea cols='60' rows='12' name='comment' >".$config->fields['comment']."</textarea>";
+      echo "<br>".sprintf(__('%1$s; %2$s'), __('Last update'),
+                          Html::convDateTime($config->fields["date_mod"]));
       echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>";
@@ -327,12 +334,12 @@
       echo "<tr class='tab_bg_1'>";
       echo "<td>".__("Deny change of ticket's creation date", "behaviors")."</td><td>";
       Dropdown::showYesNo("is_ticketdate_locked", $config->fields['is_ticketdate_locked']);
-      echo "</td><td colspan='2'></td></tr>";
+      echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>";
       echo "<td>".__('Protect from simultaneous update', 'behaviors')."</td><td>";
       Dropdown::showYesNo("use_lock", $config->fields['use_lock']);
-      echo "</td><td colspan='2'></td></tr>";
+      echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>";
       echo "<td>".__('Single technician and group', 'behaviors')."</td><td>";
@@ -341,7 +348,7 @@
               2 => __('Single user or group', 'behaviors')];
       Dropdown::showFromArray('single_tech_mode', $tab,
                               ['value' => $config->fields['single_tech_mode']]);
-      echo "</td><td colspan='2'></td></tr>";
+      echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>";
       echo "<td>".__('Block the solving/closing of a the ticket if task do to', 'behaviors');
@@ -350,7 +357,8 @@
       echo "</td></tr>";
 
       echo "<tr class='tab_bg_1'>"; // Problem - Update
-      echo "<td colspan=2' class='tab_bg_2 b center'>".__('Update of a problem')."</td></tr>";
+      echo "<td colspan=2' class='tab_bg_2 b center'>".__('Update of a problem')."</td>";
+      echo "</td><td colspan='2'></td></tr>";
 
       echo "<tr class='tab_bg_1'>";
       echo "<td>".__('Type of solution is mandatory before problem is solved/closed', 'behaviors');
Index: inc/tickettask.class.php
===================================================================
--- inc/tickettask.class.php	(nonexistent)
+++ inc/tickettask.class.php	(working copy)
@@ -0,0 +1,76 @@
+<?php
+/**
+ * -------------------------------------------------------------------------
+ *
+ * LICENSE
+ *
+ * This file is part of Behaviors plugin for GLPI.
+ *
+ * Behaviors is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Behaviors is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Behaviors. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package   behaviors
+ * @author    Remi Collet, Nelly Mahu-Lasson
+ * @copyright Copyright (c) 2010-2018 Behaviors plugin team
+ * @license   AGPL License 3.0 or (at your option) any later version
+ * http://www.gnu.org/licenses/agpl-3.0-standalone.html
+ * @link      https://forge.glpi-project.org/projects/behaviors
+ * @link      http://www.glpi-project.org/
+ * @since     2010
+ *
+ * --------------------------------------------------------------------------
+ */
+
+class PluginBehaviorsTicketTask {
+
+   static function beforeAdd(TicketTask $tickettask) {
+
+      if (!is_array($tickettask->input) || !count($tickettask->input)) {
+         // Already cancel by another plugin
+         return false;
+      }
+
+      //      Toolbox::logDebug("PluginBehaviorsTicketTask::beforeAdd(), TicketTask=", $tickettask);
+      $config = PluginBehaviorsConfig::getInstance();
+
+      if ($config->getField('is_tickettaskcategory_mandatory')
+          && (!isset($tickettask->input['taskcategories_id'])
+              || ($tickettask->input['taskcategories_id'] <= 0))) {
+
+         Session::addMessageAfterRedirect(__("Category is mandatory", 'behaviors'), true, ERROR);
+         return $tickettask->input = false;
+      }
+
+   }
+
+   static function beforeUpdate(TicketTask $tickettask) {
+
+      if (!is_array($tickettask->input) || !count($tickettask->input)) {
+         // Already cancel by another plugin
+         return false;
+      }
+
+      //      Toolbox::logDebug("PluginBehaviorsTicketTask::beforeUpdate(), TicketTask=", $tickettask);
+      $config = PluginBehaviorsConfig::getInstance();
+
+      if ($config->getField('is_tickettaskcategory_mandatory')
+          && (!isset($tickettask->input['taskcategories_id'])
+              || ($tickettask->input['taskcategories_id'] <= 0))) {
+
+         Session::addMessageAfterRedirect(__("Category is mandatory", 'behaviors'), true, ERROR);
+         return $tickettask->input = false;
+      }
+
+   }
+
+}
\ No newline at end of file
Index: setup.php
===================================================================
--- setup.php	(revision 258)
+++ setup.php	(working copy)
@@ -62,7 +62,8 @@
        'TicketSatisfaction' => ['PluginBehaviorsTicketSatisfaction', 'afterUpdate']];
 
    $PLUGIN_HOOKS['pre_item_add']['behaviors'] =
-      ['Ticket'             => ['PluginBehaviorsTicket', 'beforeAdd']];
+      ['Ticket'             => ['PluginBehaviorsTicket', 'beforeAdd'],
+       'TicketTask'         => ['PluginBehaviorsTicketTask', 'beforeAdd']];
 
    $PLUGIN_HOOKS['post_prepareadd']['behaviors'] =
       ['Ticket'             => ['PluginBehaviorsTicket', 'afterPrepareAdd']];
@@ -69,7 +70,8 @@
 
    $PLUGIN_HOOKS['pre_item_update']['behaviors'] =
       ['Problem'            => ['PluginBehaviorsProblem', 'beforeUpdate'],
-       'Ticket'             => ['PluginBehaviorsTicket',  'beforeUpdate']];
+       'Ticket'             => ['PluginBehaviorsTicket',  'beforeUpdate'],
+       'TicketTask'         => ['PluginBehaviorsTicketTask',  'beforeUpdate']];
 
    $PLUGIN_HOOKS['pre_item_purge']['behaviors'] =
       ['Computer'           => ['PluginBehaviorsComputer',  'beforePurge']];
@@ -104,7 +106,7 @@
 function plugin_version_behaviors() {
 
    return ['name'           => __('Behaviours', 'behaviors'),
-           'version'        => '2.0.3',
+           'version'        => '2.0.4',
            'license'        => 'AGPLv3+',
            'author'         => 'Remi Collet, Nelly Mahu-Lasson',
            'homepage'       => 'https://forge.glpi-project.org/projects/behaviors',

Offline

#5 2018-09-06 15:00:46

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,273

Re: [Behaviors] Adding a feature - Mandatory task category

Done in latest version: https://forge.glpi-project.org/news/375


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

Board footer

Powered by FluxBB