Exemplo n.º 1
0
 /**
  * @param $itemtype  itemtype
  * @param $criterion (default '')
  *
  * @return array of criteria
  **/
 static function getConditions($itemtype, $criterion = '')
 {
     $criteria = array(Rule::PATTERN_IS => __('is'), Rule::PATTERN_IS_NOT => __('is not'), Rule::PATTERN_CONTAIN => __('contains'), Rule::PATTERN_NOT_CONTAIN => __('does not contain'), Rule::PATTERN_BEGIN => __('starting with'), Rule::PATTERN_END => __('finished by'), Rule::REGEX_MATCH => __('regular expression matches'), Rule::REGEX_NOT_MATCH => __('regular expression does not match'), Rule::PATTERN_EXISTS => __('exists'), Rule::PATTERN_DOES_NOT_EXISTS => __('does not exist'));
     $extra_criteria = call_user_func(array($itemtype, 'addMoreCriteria'), $criterion);
     foreach ($extra_criteria as $key => $value) {
         $criteria[$key] = $value;
     }
     /// Add Under criteria if tree dropdown table used
     if ($item = getItemForItemtype($itemtype)) {
         $crit = $item->getCriteria($criterion);
         if (isset($crit['type']) && $crit['type'] == 'dropdown') {
             $crititemtype = getItemtypeForTable($crit['table']);
             if (($item = getItemForItemtype($crititemtype)) && $item instanceof CommonTreeDropdown) {
                 $criteria[Rule::PATTERN_UNDER] = __('under');
                 $criteria[Rule::PATTERN_NOT_UNDER] = __('not under');
             }
         }
     }
     return $criteria;
 }
 static function getItems($protocol, $params = array(), $original_params = array())
 {
     $flip = isset($params['options']['flip_itemtypes']) ? $params['options']['flip_itemtypes'] : false;
     if (!$flip) {
         //Source itemtype (used to find the right _items table)
         $source_itemtype = $params['options']['source_itemtype'];
         //Linked itemtype : items to look for in the _items table
         $linked_itemtype = $params['options']['linked_itemtype'];
         $item = new $linked_itemtype();
         $source_item = new $source_itemtype();
         $fk = getForeignKeyFieldForTable($source_item->getTable());
     } else {
         //Source itemtype (used to find the right _items table)
         $linked_itemtype = $params['options']['source_itemtype'];
         //Linked itemtype : items to look for in the _items table
         $source_itemtype = $params['options']['linked_itemtype'];
         $item = new $source_itemtype();
         $linked_item = new $linked_itemtype();
         $fk = "items_id";
     }
     $table = 'glpi_' . strtolower($source_itemtype) . 's_items';
     $sql = "`itemtype` = '" . $linked_itemtype . "'\n               AND `{$fk}` = '" . Toolbox::addslashes_deep($params['data']['id']) . "'";
     $computer_item = array('Monitor', 'Printer', 'Phone', 'Peripheral');
     $itemtype_class = getItemtypeForTable($table);
     $item_class = new $itemtype_class();
     if ($item_class instanceof CommonDBRelation && !in_array($linked_itemtype, $computer_item)) {
         $fk_items = $item_class->items_id_1;
     } else {
         if ($item_class instanceof CommonDBChild && !in_array($linked_itemtype, $computer_item)) {
             $fk_items = $item_class->items_id;
         } else {
             $fk_items = "items_id";
         }
     }
     $output = array();
     foreach (getAllDatasFromTable($table, $sql) as $data) {
         $item->getFromDB($data[$fk_items]);
         $resp = array();
         $toformat = array('data' => $item->fields, 'searchOptions' => Search::getOptions(get_class($item)), 'options' => $params['options']);
         parent::formatDataForOutput($toformat, $resp);
         $output[$item->fields['id']] = $resp;
     }
     return $output;
 }