CommonITILObject::getAllTypesForHelpdesk PHP Метод

getAllTypesForHelpdesk() статический публичный Метод

Get all available types to which an ITIL object can be assigned
static public getAllTypesForHelpdesk ( )
    static function getAllTypesForHelpdesk()
    {
        global $PLUGIN_HOOKS, $CFG_GLPI;
        /// TODO ticket_types -> itil_types
        $types = array();
        $ptypes = array();
        //Types of the plugins (keep the plugin hook for right check)
        if (isset($PLUGIN_HOOKS['assign_to_ticket'])) {
            foreach ($PLUGIN_HOOKS['assign_to_ticket'] as $plugin => $value) {
                $ptypes = Plugin::doOneHook($plugin, 'AssignToTicket', $ptypes);
            }
        }
        asort($ptypes);
        //Types of the core (after the plugin for robustness)
        foreach ($CFG_GLPI["ticket_types"] as $itemtype) {
            if ($item = getItemForItemtype($itemtype)) {
                if (!isPluginItemType($itemtype) && in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
                    $types[$itemtype] = $item->getTypeName(1);
                }
            }
        }
        asort($types);
        // core type first... asort could be better ?
        // Drop not available plugins
        foreach ($ptypes as $itemtype => $itemtype_name) {
            if (!in_array($itemtype, $_SESSION["glpiactiveprofile"]["helpdesk_item_type"])) {
                unset($ptypes[$itemtype]);
            }
        }
        $types = array_merge($types, $ptypes);
        return $types;
    }

Usage Example

Пример #1
0
 /**
  * Make a select box for Tracking All Devices
  *
  * @param $myname             select name
  * @param $itemtype           preselected value.for item type
  * @param $items_id           preselected value for item ID (default 0)
  * @param $admin              is an admin access ? (default 0)
  * @param $users_id           user ID used to display my devices (default 0
  * @param $entity_restrict    Restrict to a defined entity (default -1)
  *
  * @return nothing (print out an HTML select box)
  **/
 static function dropdownAllDevices($myname, $itemtype, $items_id = 0, $admin = 0, $users_id = 0, $entity_restrict = -1)
 {
     global $CFG_GLPI, $DB;
     $rand = mt_rand();
     if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] == 0) {
         echo "<input type='hidden' name='{$myname}' value='0'>";
         echo "<input type='hidden' name='items_id' value='0'>";
     } else {
         echo "<div id='tracking_all_devices'>";
         if ($_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_ALL_HARDWARE)) {
             // Display a message if view my hardware
             if ($users_id && $_SESSION["glpiactiveprofile"]["helpdesk_hardware"] & pow(2, self::HELPDESK_MY_HARDWARE)) {
                 echo __('Or complete search') . "&nbsp;";
             }
             $types = parent::getAllTypesForHelpdesk();
             echo "<select id='search_{$myname}{$rand}' name='{$myname}'>\n";
             echo "<option value='-1' >" . Dropdown::EMPTY_VALUE . "</option>\n";
             echo "<option value='' " . (empty($itemtype) || $itemtype === 0 ? " selected" : "") . ">" . __('General') . "</option>";
             $found_type = false;
             foreach ($types as $type => $label) {
                 if (strcmp($type, $itemtype) == 0) {
                     $found_type = true;
                 }
                 echo "<option value='" . $type . "' " . (strcmp($type, $itemtype) == 0 ? " selected" : "") . ">" . $label . "</option>\n";
             }
             echo "</select>";
             $params = array('itemtype' => '__VALUE__', 'entity_restrict' => $entity_restrict, 'admin' => $admin, 'myname' => "items_id");
             Ajax::updateItemOnSelectEvent("search_{$myname}{$rand}", "results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php", $params);
             echo "<span id='results_{$myname}{$rand}'>\n";
             // Display default value if itemtype is displayed
             if ($found_type && $itemtype) {
                 if (($item = getItemForItemtype($itemtype)) && $items_id) {
                     if ($item->getFromDB($items_id)) {
                         echo "<select name='items_id'>\n";
                         echo "<option value='{$items_id}'>" . $item->getName() . "</option>";
                         echo "</select>";
                     }
                 } else {
                     $params['itemtype'] = $itemtype;
                     echo "<script type='text/javascript' >\n";
                     Ajax::updateItemJsCode("results_{$myname}{$rand}", $CFG_GLPI["root_doc"] . "/ajax/dropdownTrackingDeviceType.php", $params);
                     echo '</script>';
                 }
             }
             echo "</span>\n";
         }
         echo "</div>";
     }
     return $rand;
 }
CommonITILObject