Bonjour,

Voici un patch qui permet d'ajouter des hooks aux plugins afin
d'afficher ce qu'on veut pour les items de tickets.

Là par exemple, je suis en train de porter le plugin appliance en 0.85,
et dans ce plugin on crée un applicatif et dans cet applicatif, on peut
avoir plusieurs items (exemple un 'cluster xx' peut avoir plusieurs
ordinateurs, un switch...)

Ainsi donc ce patch permet d'ajouter notre classe de relation entre
le cluster et l'ordinateur en item de ticket

Ainsi il faut rajouter dans le plugin :

Dans le setup.php :
   $PLUGIN_HOOKS['assign_to_ticket_dropdown']['appliances'] = true;
   $PLUGIN_HOOKS['assign_to_ticket_itemtype']['appliances'] =
   array('PluginAppliancesAppliance_Item');


assign_to_ticket_dropdown => pour dire qu'on veut afficher une dropdown
personalisée dans l'ajout d'un item au ticket et va appeler la fonction
'plugin_appliances_AssignToTicketDropdown'

assign_to_ticket_itemtype => ce sont la liste des itemtypes qui seront
définis dans la table glpi_items_tickets et pour lequel on appelle la
fonction 'plugin_appliances_AssignToTicketDisplay' qui va gérer
l'affichage du tableau dans l'onglets items du ticket


Est-ce assez clair?

Si c'est OK, je peux pousser directement sur le dépot ;)


Cordialement,
--
David DURIEUX
Tel : +33 (0)4.82.53.30.53
Mail : d.duri...@siprossii.com
Site Web : http://www.siprossii.com/

SIPROSSII
Rue des jardins
69860 Monsols
FRANCE
Index: ajax/dropdownTrackingDeviceType.php
===================================================================
--- ajax/dropdownTrackingDeviceType.php	(revision 23363)
+++ ajax/dropdownTrackingDeviceType.php	(working copy)
@@ -42,7 +42,23 @@
     && CommonITILObject::isPossibleToAssignType($_POST["itemtype"])) {
    $table = getTableForItemType($_POST["itemtype"]);
    $rand  = mt_rand();
+   // Custom dropdown
+      $ptypes = array();
+   if (isset($PLUGIN_HOOKS['assign_to_ticket_dropdown'])) {
+      foreach ($PLUGIN_HOOKS['assign_to_ticket_dropdown'] as $plugin => $value) {
+         $ptypes = Plugin::doOneHook($plugin, 'AssignToTicket', array());
+         foreach ($ptypes as $pitemtype => $pvalue) {
+            if ($pitemtype == $_POST["itemtype"]) {
+               Plugin::doOneHook($plugin, 'AssignToTicketDropdown', $_POST);
+               exit;
+            }
+         }
+      }
+   }
 
+
+
+
    // Message for post-only
    if (!isset($_POST["admin"]) || ($_POST["admin"] == 0)) {
       echo "<br>".__('Enter the first letters (user, item name, serial or asset number)');
Index: inc/item_ticket.class.php
===================================================================
--- inc/item_ticket.class.php	(revision 23363)
+++ inc/item_ticket.class.php	(working copy)
@@ -165,7 +165,7 @@
     * @return Nothing (display)
    **/
    static function showForTicket(Ticket $ticket) {
-      global $DB, $CFG_GLPI;
+      global $DB, $CFG_GLPI, $PLUGIN_HOOKS;
 
       $instID = $ticket->fields['id'];
 
@@ -325,6 +325,17 @@
                echo "</tr>";
             }
             $totalnb += $nb;
+         } else {
+            if (isset($PLUGIN_HOOKS['assign_to_ticket_itemtype'])) {
+               foreach ($PLUGIN_HOOKS['assign_to_ticket_itemtype'] as $plugin => $value) {
+                  if (in_array($itemtype, $value)) {
+                     Plugin::doOneHook($plugin, 'AssignToTicketDisplay',
+                             array('itemtype'   => $itemtype,
+                                   'tickets_id' => $instID,
+                                   'canedit'    => $canedit));
+                  }
+               }
+            }
          }
       }
 
Index: inc/search.class.php
===================================================================
--- inc/search.class.php	(revision 23363)
+++ inc/search.class.php	(working copy)
@@ -3751,7 +3751,7 @@
    **/
    static function giveItem($itemtype, $ID, array $data, $num, $meta=0,
                             array $addobjectparams=array()) {
-      global $CFG_GLPI;
+      global $CFG_GLPI, $PLUGIN_HOOKS;
 
       $searchopt = &self::getOptions($itemtype);
       if (isset($CFG_GLPI["union_search_type"][$itemtype])
@@ -4208,7 +4208,17 @@
                      if (is_numeric($key)) {
                         if (!empty($val['itemtype'])
                                 && ($item = getItemForItemtype($val['itemtype']))) {
-                           if ($item->getFromDB($val['name'])) {
+                           $custom = false;
+                           if (isset($PLUGIN_HOOKS['assign_to_ticket_itemtype'])) {
+                              foreach ($PLUGIN_HOOKS['assign_to_ticket_itemtype'] as $plugin => $value) {
+                                 if (in_array($val['itemtype'], $value)) {
+                                    $items[] = Plugin::doOneHook($plugin, 'AssignToTicketGiveItem', $val);
+                                    $custom = true;
+                                 }
+                              }
+                           }
+                           if (!$custom
+                                   && $item->getFromDB($val['name'])) {
                               $items[] = $item->getLink(array('comments' => true));
                            }
                         }
_______________________________________________
Glpi-dev mailing list
Glpi-dev@gna.org
https://mail.gna.org/listinfo/glpi-dev

Reply via email to