Search::getOptionNumber PHP Method

getOptionNumber() static public method

Get an option number in the SEARCH_OPTION array
static public getOptionNumber ( $itemtype, $field ) : integer
$itemtype
$field name
return integer
    static function getOptionNumber($itemtype, $field)
    {
        $table = getTableForItemType($itemtype);
        $opts =& self::getOptions($itemtype);
        foreach ($opts as $num => $opt) {
            if (is_array($opt) && $opt['table'] == $table && $opt['field'] == $field) {
                return $num;
            }
        }
        return 0;
    }

Usage Example

Example #1
0
 /**
  * Display tickets for an item
  *
  * Will also display tickets of linked items
  *
  * @param $itemtype
  * @param $items_id
  *
  * @return nothing (display a table)
  **/
 static function showListForItem($itemtype, $items_id)
 {
     global $DB, $CFG_GLPI, $LANG;
     if (!haveRight("show_all_ticket", "1")) {
         return false;
     }
     if (!class_exists($itemtype)) {
         return false;
     }
     $item = new $itemtype();
     if (!$item->getFromDB($items_id)) {
         return false;
     }
     $restrict = '';
     $order = '';
     $options['reset'] = 'reset';
     if ($itemtype == 'Sla') {
         $restrict = "(`slas_id` = '{$items_id}')";
         $order = '`glpi_tickets`.`due_date` DESC';
         $options['field'][0] = 30;
         $options['searchtype'][0] = 'equals';
         $options['contains'][0] = $items_id;
         $options['link'][0] = 'AND';
     } else {
         $restrict = "(`items_id` = '{$items_id}' AND `itemtype` = '{$itemtype}')";
         $order = '`glpi_tickets`.`date_mod` DESC';
         $options['field'][0] = 12;
         $options['searchtype'][0] = 'equals';
         $options['contains'][0] = 'all';
         $options['link'][0] = 'AND';
         $options['itemtype2'][0] = $itemtype;
         $options['field2'][0] = Search::getOptionNumber($itemtype, 'id');
         $options['searchtype2'][0] = 'equals';
         $options['contains2'][0] = $items_id;
         $options['link2'][0] = 'AND';
     }
     $query = "SELECT " . self::getCommonSelect() . "\n                FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                WHERE {$restrict}" . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n                ORDER BY {$order}\n                LIMIT " . intval($_SESSION['glpilist_limit']);
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     // Ticket for the item
     echo "<div class='firstbloc'><table class='tab_cadre_fixe'>";
     if ($number > 0) {
         initNavigateListItems('Ticket', $item->getTypeName() . " = " . $item->getName());
         echo "<tr><th colspan='11'>";
         if ($number == 1) {
             echo $LANG['job'][10] . "&nbsp;:&nbsp;" . $number;
             echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&amp;') . "'>" . $LANG['buttons'][40] . "</a></span>";
         } else {
             echo $LANG['job'][8] . "&nbsp;:&nbsp;" . $number;
             echo "<span class='small_space'><a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($options, '&amp;') . "'>" . $LANG['buttons'][40] . "</a></span>";
         }
         echo "</th></tr>";
     } else {
         echo "<tr><th>" . $LANG['joblist'][8] . "</th></tr>";
     }
     // Link to open a new ticcket
     if ($items_id && in_array($itemtype, $_SESSION['glpiactiveprofile']['helpdesk_item_type'])) {
         echo "<tr><td class='tab_bg_2 center' colspan='11'>";
         echo "<a href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?items_id=" . "{$items_id}&amp;itemtype=" . "{$itemtype}\"><strong>" . $LANG['joblist'][7] . "</strong></a>";
         echo "</td></tr>";
     }
     // Ticket list
     if ($number > 0) {
         self::commonListHeader(HTML_OUTPUT);
         while ($data = $DB->fetch_assoc($result)) {
             addToNavigateListItems('Ticket', $data["id"]);
             self::showShort($data["id"], 0);
         }
     }
     echo "</table></div>";
     // Tickets for linked items
     if ($subquery = $item->getSelectLinkedItem()) {
         $query = "SELECT " . self::getCommonSelect() . "\n                   FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n                   WHERE (`itemtype`,`items_id`) IN (" . $subquery . ")" . getEntitiesRestrictRequest(' AND ', 'glpi_tickets') . "\n                   ORDER BY `glpi_tickets`.`date_mod` DESC\n                   LIMIT " . intval($_SESSION['glpilist_limit']);
         $result = $DB->query($query);
         $number = $DB->numrows($result);
         echo "<div class='spaced'><table class='tab_cadre_fixe'>";
         echo "<tr><th colspan='11'>";
         if ($number > 1) {
             echo $LANG['joblist'][28];
         } else {
             echo $LANG['joblist'][25];
         }
         echo "</th></tr>";
         if ($number > 0) {
             self::commonListHeader(HTML_OUTPUT);
             while ($data = $DB->fetch_assoc($result)) {
                 // addToNavigateListItems(TRACKING_TYPE,$data["id"]);
                 self::showShort($data["id"], 0);
             }
         } else {
             echo "<tr><th>" . $LANG['joblist'][8] . "</th></tr>";
         }
         echo "</table></div>";
     }
     // Subquery for linked item
 }
All Usage Examples Of Search::getOptionNumber