behaviors.patch

tsmr, 04/27/2020 03:40 PM

Download (11.8 KB)

View differences:

inc/config.class.php (working copy)
93 93
                     `is_ticketlocation_mandatory` tinyint(1) NOT NULL default '0',
94 94
                     `is_requester_mandatory` tinyint(1) NOT NULL default '0',
95 95
                     `is_ticketdate_locked` tinyint(1) NOT NULL default '0',
96
                     `is_addnewgroupassigntech_on_update` tinyint(1) NOT NULL default '0',
97
                     `is_newticketsolution_updatetechnician` tinyint(1) NOT NULL default '0',
96 98
                     `use_assign_user_group` tinyint(1) NOT NULL default '0',
97 99
                     `tickets_id_format` VARCHAR(15) NULL,
98 100
                     `changes_id_format` VARCHAR(15) NULL,
......
197 199
         // version 2.2.2
198 200
         $mig->addField($table, 'changes_id_format', 'VARCHAR(15) NULL',
199 201
                        ['after' => 'tickets_id_format']);
202

  
203
         // version 2.2.3
204
         $mig->addField($table, 'is_addnewgroupassigntech_on_update', 'bool');
205
         $mig->addField($table, 'is_newticketsolution_updatetechnician', 'bool');
200 206
      }
201 207

  
202 208
   }
......
213 219
                   1 => __('First'),
214 220
                   2 => __('All')];
215 221

  
222
      $defaultnofirst = [0 => __('No'),
223
                         1 => __('Default'),
224
                         2 => __('First')];
225

  
216 226
      $config = self::getInstance();
217 227

  
218 228
      $config->showFormHeader();
......
332 342
      echo "</td><td>";
333 343
      Dropdown::showYesNo("is_tickettechgroup_mandatory",
334 344
                          $config->fields['is_tickettechgroup_mandatory']);
335
      echo "</td><td rowspan='7' colspan='2' class='center'>";
345
      echo "</td><td rowspan='6' colspan='2' class='center'>";
336 346
      echo "<textarea cols='60' rows='12' name='comment' >".$config->fields['comment']."</textarea>";
347
      echo "<br>".sprintf(__('%1$s: %2$s'), __('Last update'),
348
                          Html::convDateTime($config->fields["date_mod"]));
337 349
      echo "</td></tr>";
338 350

  
339 351
      echo "<tr class='tab_bg_1'>";
340
      echo "<br>".sprintf(__('%1$s; %2$s'), __('Last update'),
341
            Html::convDateTime($config->fields["date_mod"]));
342
      echo "</td></tr>";
343

  
344

  
345
      echo "<tr class='tab_bg_1'>";
346 352
      echo "<td>".__('Location is mandatory before ticket is solved/closed', 'behaviors');
347 353
      echo "</td><td>";
348 354
      Dropdown::showYesNo("is_ticketlocation_mandatory",
349 355
      $config->fields['is_ticketlocation_mandatory']);
350 356
      echo "</td></tr>";
351 357

  
358
      echo "<tr class='tab_bg_1'>";
352 359
      echo "</td><td>".__('Task category is mandatory in a task', 'behaviors')."</td><td>";
353 360
      Dropdown::showYesNo("is_tickettaskcategory_mandatory",
354 361
      $config->fields['is_tickettaskcategory_mandatory']);
362
      echo "</td></tr>";
355 363

  
356 364
      echo "<tr class='tab_bg_1'>";
357 365
      echo "<td>".__("Deny change of ticket's creation date", "behaviors")."</td><td>";
358 366
      Dropdown::showYesNo("is_ticketdate_locked", $config->fields['is_ticketdate_locked']);
359
      echo "</td><td colspan='2'></td></tr>";
367
      echo "</td></tr>";
360 368

  
361 369
      echo "<tr class='tab_bg_1'>";
362 370
      echo "<td>".__('Protect from simultaneous update', 'behaviors')."</td><td>";
363 371
      Dropdown::showYesNo("use_lock", $config->fields['use_lock']);
364
      echo "</td><td colspan='2'></td></tr>";
372
      echo "</td></tr>";
365 373

  
366 374
      echo "<tr class='tab_bg_1'>";
367 375
      echo "<td>".__('Single technician and group', 'behaviors')."</td><td>";
......
370 378
              2 => __('Single user or group', 'behaviors')];
371 379
      Dropdown::showFromArray('single_tech_mode', $tab,
372 380
                              ['value' => $config->fields['single_tech_mode']]);
373
      echo "</td><td colspan='2'></td></tr>";
381
      echo "</td></tr>";
374 382

  
375 383
      echo "<tr class='tab_bg_1'>";
376 384
      echo "<td>".__('Block the solving/closing of a the ticket if task do to', 'behaviors');
377 385
      echo "</td><td>";
378 386
      Dropdown::showYesNo("is_tickettasktodo", $config->fields['is_tickettasktodo']);
379
      echo "</td></tr>";
387
      echo "</td><td colspan='4'></td></tr>";
380 388

  
389
      echo "<tr class='tab_bg_1'>";
390
      echo "<td>". __('Update of the assigned technician on a new ticket solution', 'behaviors');
391
      echo "</td><td>";
392
      Dropdown::showYesNo("is_newticketsolution_updatetechnician", $config->fields['is_newticketsolution_updatetechnician']);
393
      echo "</td><td colspan='4'></td></tr>";
394

  
395
      echo "<tr class='tab_bg_1'>";
396
      echo "<td>". __("Add technician user's assign group on update", 'behaviors');
397
      echo "</td><td>";
398
      Dropdown::showFromArray('is_addnewgroupassigntech_on_update', $defaultnofirst,
399
         ['value' => $config->fields['is_addnewgroupassigntech_on_update']]);
400
      echo "</td><td colspan='4'></td></tr>";
401

  
381 402
      $config->showFormButtons(['candel'=>false]);
382 403

  
383 404
      return false;
inc/itilsolution.class.php (working copy)
171 171
         }
172 172
      }
173 173
   }
174

  
175
   static function afterUpdate(ITILSolution $soluce) {
176
      $ticket = new Ticket();
177
      $config = new Config();
178
      if ($ticket->getFromDB($soluce->input['items_id'])
179
         && $soluce->input['itemtype'] == 'Ticket') {
180
         if ($config->getField('is_newticketsolution_updatetechnician')) {
181
            $logged_user_id = Session::getLoginUserID();
182
            $ticket_user = new Ticket_User();
183
            $data_ticket_user = $ticket_user->find(['tickets_id' => $ticket->getID(), 'type' => CommonITILActor::ASSIGN]);
184
            $is_user_logged_assign = false;
185
            foreach ($data_ticket_user  as $user) {
186
               if ($user['users_id'] != $logged_user_id) {
187
                  $ticket_user = new Ticket_User();
188
                  $ticket_user->deleteByCriteria(['tickets_id' => $ticket->getID(), 'users_id' => $user['users_id']]);
189
               } else {
190
                  $is_user_logged_assign = true;
191
               }
192
            }
193
            if (!$is_user_logged_assign) {
194
               $ticket_user->add(['tickets_id' => $ticket->getID(), 'users_id' =>
195
                  $logged_user_id, 'type' => CommonITILActor::ASSIGN]);
196
            }
197
         }
198
      }
199
   }
174 200
}
inc/ticket.class.php (working copy)
533 533
            }
534 534
         }
535 535
      }
536
   }
537 536

  
537
      if ($config->getField('is_addnewgroupassigntech_on_update') && isset($ticket->input['_itil_assign']) &&
538
         $ticket->input['_itil_assign']['_type'] == 'user'
539
         && $ticket->input['_itil_assign']['users_id'] > 0) {
540
         if ($config->getField('is_addnewgroupassigntech_on_update') > 0) {
541
            //default group
542
            if ($config->getField('is_addnewgroupassigntech_on_update') == 1) {
543
               if ($ticket->countGroups(CommonITILActor::ASSIGN) > 0) {
544
                  $groups_user = PluginBehaviorsUser::getDefaultTechnicianGroupOrFirst($ticket->fields['entities_id'],
545
                     $ticket->input['_itil_assign']['users_id'],true, false);
546
                  foreach ($ticket->getGroups(CommonITILActor::ASSIGN) as $ticket_group) {
547
                     if ($ticket_group['groups_id'] != $groups_user) {
548
                        $ticket->input['_additional_groups_assigns'][] = $groups_user;
549
                     }
550
                  }
551
               } else {
552
                  $ticket->input['_groups_id_assign']
553
                     = PluginBehaviorsUser::getDefaultTechnicianGroupOrFirst($ticket->fields['entities_id'],
554
                     $ticket->input['_itil_assign']['users_id'],true,false);
555
               }
556
               // First group
557
            } else {
558
               if ($ticket->countGroups(CommonITILActor::ASSIGN) > 0) {
559
                  $groups_user = PluginBehaviorsUser::getDefaultTechnicianGroupOrFirst($ticket->fields['entities_id'],
560
                     $ticket->input['_itil_assign']['users_id'],false, true);
561
                  foreach ($ticket->getGroups(CommonITILActor::ASSIGN) as $ticket_group) {
562
                     if ($ticket_group['groups_id'] != $groups_user) {
563
                        $ticket->input['_additional_groups_assigns'][] = $groups_user;
564
                     }
565
                  }
566
               } else {
567
                  $ticket->input['_groups_id_assign']
568
                     = PluginBehaviorsUser::getDefaultTechnicianGroupOrFirst($ticket->fields['entities_id'],
569
                     $ticket->input['_itil_assign']['users_id'],false,true);
570
                  }
571
               }
572
            }
573
         }
574
      }
538 575

  
539 576
   static function onNewTicket() {
540 577

  
......
607 644
            }
608 645
         }
609 646
      }
647

  
648
      if ($ticket->getField('status') == Ticket::SOLVED) {
649
         if ($config->getField('is_newticketsolution_updatetechnician')) {
650
            $logged_user_id        = Session::getLoginUserID();
651
            $ticket_user           = new Ticket_User();
652
            $data_ticket_user      = $ticket_user->find(['tickets_id' => $ticket->getID(), 'type' => CommonITILActor::ASSIGN]);
653
            $is_user_logged_assign = false;
654
            foreach ($data_ticket_user as $user) {
655
               if ($user['users_id'] != $logged_user_id) {
656
                  $ticket_user   = new Ticket_User();
657
                  $ticket_user->deleteByCriteria(['tickets_id' => $ticket->getID(), 'users_id' => $user['users_id']]);
658
               } else {
659
                  $is_user_logged_assign = true;
660
               }
661
            }
662
            if (!$is_user_logged_assign) {
663
               $ticket_user->add(['tickets_id' => $ticket->getID(), 'users_id' => $logged_user_id, 'type' => CommonITILActor::ASSIGN]);
664
            }
665
         }
666
      }
610 667
   }
611 668

  
612

  
613 669
   static function preClone(Ticket $srce, Array $input) {
614 670
      global $DB;
615 671

  
inc/user.class.php (working copy)
73 73
      return self::getUserGroup($entity, $userid, '`is_assign`', $first);
74 74
   }
75 75

  
76
   static function getDefaultTechnicianGroupOrFirst($entity, $userid, $default=true, $first=true) {
77
      global $DB;
78
      $dbu    = new DbUtils();
79

  
80
      if ($default) {
81
         $query = ['FIELDS'     => ['glpi_users' => ['groups_id']],
82
            'FROM'       => 'glpi_users',
83
            'WHERE'      => ['id' => $userid]];
84

  
85
      } else {
86
         $query = ['FIELDS'     => ['glpi_groups' => ['id']],
87
            'FROM'       => 'glpi_groups_users',
88
            'INNER JOIN' => ['glpi_groups' => ['FKEY' => ['glpi_groups' => 'id',
89
               'glpi_groups_users' => 'groups_id']]],
90
            'WHERE'      => ['users_id' => $userid,
91
               $dbu->getEntitiesRestrictCriteria('glpi_groups','', $entity, true),
92
               '`is_assign`']];
93
      }
94

  
95
      foreach ($DB->request($query) as $data) {
96
         if ($default) {
97
            return $data['groups_id'];
98
         } else if ($first) {
99
            return $data['id'];
100
         }
101
      }
102
   }
103

  
76 104
}
setup.php (working copy)
46 46
       'Document_Item'      => ['PluginBehaviorsDocument_Item',     'afterAdd']];
47 47

  
48 48
   $PLUGIN_HOOKS['item_update']['behaviors'] =
49
      ['Ticket'             => ['PluginBehaviorsTicket',             'afterUpdate']];
49
      ['Ticket'             => ['PluginBehaviorsTicket',             'afterUpdate'],
50
       'ITILSolution'       => ['PluginBehaviorsITILSolution',       'afterUpdate']];
50 51

  
51 52
   $PLUGIN_HOOKS['pre_item_add']['behaviors'] =
52 53
      ['Ticket'             => ['PluginBehaviorsTicket',       'beforeAdd'],