Patch corrigé, il y avait du code au mauvais endroit

David
++


Le Thu, 12 Feb 2015 10:49:37 +0100
David DURIEUX <d.duri...@siprossii.com> a écrit:

>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'];
 
@@ -290,39 +290,52 @@
             $nb            = $DB->numrows($result_linked);
 
             for ($prem=true ; $data=$DB->fetch_assoc($result_linked) ; $prem=false) {
-               $name = $data["name"];
-               if ($_SESSION["glpiis_ids_visible"]
-                   || empty($data["name"])) {
-                  $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
+               $continue = true;
+               if (isset($PLUGIN_HOOKS['assign_to_ticket_itemtype'])) {
+                  foreach ($PLUGIN_HOOKS['assign_to_ticket_itemtype'] as $plugin => $value) {
+                     if (in_array($itemtype, $value)) {
+                        $continue = Plugin::doOneHook($plugin, 'AssignToTicketDisplay',
+                                array('itemtype'   => $itemtype,
+                                      'canedit'    => $canedit,
+                                      'data'       => $data));
+                     }
+                  }
                }
-               if($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk') {
-                  $link     = Toolbox::getItemTypeFormURL($itemtype);
-                  $namelink = "<a href=\"".$link."?id=".$data["id"]."\">".$name."</a>";
-               } else {
-                  $namelink = $name;
-               }
+               if ($continue) {
+                  $name = $data["name"];
+                  if ($_SESSION["glpiis_ids_visible"]
+                      || empty($data["name"])) {
+                     $name = sprintf(__('%1$s (%2$s)'), $name, $data["id"]);
+                  }
+                  if($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk') {
+                     $link     = Toolbox::getItemTypeFormURL($itemtype);
+                     $namelink = "<a href=\"".$link."?id=".$data["id"]."\">".$name."</a>";
+                  } else {
+                     $namelink = $name;
+                  }
 
-               echo "<tr class='tab_bg_1'>";
-               if ($canedit) {
-                  echo "<td width='10'>";
-                  Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]);
-                  echo "</td>";
+                  echo "<tr class='tab_bg_1'>";
+                  if ($canedit) {
+                     echo "<td width='10'>";
+                     Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]);
+                     echo "</td>";
+                  }
+                  if ($prem) {
+                     $typename = $item->getTypeName($nb);
+                     echo "<td class='center top' rowspan='$nb'>".
+                            (($nb > 1) ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename)."</td>";
+                  }
+                  echo "<td class='center'>";
+                  echo Dropdown::getDropdownName("glpi_entities", $data['entity'])."</td>";
+                  echo "<td class='center".
+                           (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'");
+                  echo ">".$namelink."</td>";
+                  echo "<td class='center'>".(isset($data["serial"])? "".$data["serial"]."" :"-").
+                       "</td>";
+                  echo "<td class='center'>".
+                         (isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."</td>";
+                  echo "</tr>";
                }
-               if ($prem) {
-                  $typename = $item->getTypeName($nb);
-                  echo "<td class='center top' rowspan='$nb'>".
-                         (($nb > 1) ? sprintf(__('%1$s: %2$s'), $typename, $nb) : $typename)."</td>";
-               }
-               echo "<td class='center'>";
-               echo Dropdown::getDropdownName("glpi_entities", $data['entity'])."</td>";
-               echo "<td class='center".
-                        (isset($data['is_deleted']) && $data['is_deleted'] ? " tab_bg_2_2'" : "'");
-               echo ">".$namelink."</td>";
-               echo "<td class='center'>".(isset($data["serial"])? "".$data["serial"]."" :"-").
-                    "</td>";
-               echo "<td class='center'>".
-                      (isset($data["otherserial"])? "".$data["otherserial"]."" :"-")."</td>";
-               echo "</tr>";
             }
             $totalnb += $nb;
          }
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