behaviors.patch

tsmr, 04/27/2020 11:38 AM

Download (9.32 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();
......
378 388
      Dropdown::showYesNo("is_tickettasktodo", $config->fields['is_tickettasktodo']);
379 389
      echo "</td></tr>";
380 390

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

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

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

  
383 406
      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'],