Exemplo n.º 1
0
 static function getAddSearchOptions($itemtype, $containers_id = false)
 {
     global $DB;
     $opt = array();
     $i = 76665;
     $query = "SELECT fields.name, fields.label, fields.type, fields.is_readonly,\n            containers.name as container_name, containers.label as container_label,\n            containers.itemtypes, containers.id as container_id, fields.id as field_id\n         FROM glpi_plugin_fields_containers containers\n         INNER JOIN glpi_plugin_fields_fields fields\n            ON containers.id = fields.plugin_fields_containers_id\n            AND containers.is_active = 1\n         WHERE containers.itemtypes LIKE '%{$itemtype}%'\n            AND fields.type != 'header'\n            ORDER BY fields.id ASC";
     $res = $DB->query($query);
     while ($data = $DB->fetch_assoc($res)) {
         if ($containers_id !== false) {
             // Filter by container (don't filter by SQL for have $i value with few containers for a itemtype)
             if ($data['container_id'] != $containers_id) {
                 $i++;
                 continue;
             }
         }
         $tablename = "glpi_plugin_fields_" . strtolower($itemtype . getPlural(preg_replace('/s$/', '', $data['container_name'])));
         //get translations
         $container = ['itemtype' => PluginFieldsContainer::getType(), 'id' => $data['container_id'], 'label' => $data['container_label']];
         $data['container_label'] = PluginFieldsLabelTranslation::getLabelFor($container);
         $field = ['itemtype' => PluginFieldsField::getType(), 'id' => $data['field_id'], 'label' => $data['label']];
         $data['label'] = PluginFieldsLabelTranslation::getLabelFor($field);
         $opt[$i]['table'] = $tablename;
         $opt[$i]['field'] = $data['name'];
         $opt[$i]['name'] = $data['container_label'] . " - " . $data['label'];
         $opt[$i]['linkfield'] = $data['name'];
         $opt[$i]['joinparams']['jointype'] = "itemtype_item";
         $opt[$i]['pfields_type'] = $data['type'];
         if ($data['is_readonly']) {
             $opt[$i]['massiveaction'] = false;
         }
         if ($data['type'] === "dropdown") {
             $opt[$i]['table'] = 'glpi_plugin_fields_' . $data['name'] . 'dropdowns';
             $opt[$i]['field'] = 'completename';
             $opt[$i]['linkfield'] = "plugin_fields_" . $data['name'] . "dropdowns_id";
             $opt[$i]['forcegroupby'] = true;
             $opt[$i]['joinparams']['jointype'] = "";
             $opt[$i]['joinparams']['beforejoin']['table'] = $tablename;
             $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item";
         }
         if ($data['type'] === "dropdownuser") {
             $opt[$i]['table'] = 'glpi_users';
             $opt[$i]['field'] = 'name';
             $opt[$i]['linkfield'] = $data['name'];
             $opt[$i]['right'] = 'all';
             $opt[$i]['forcegroupby'] = true;
             $opt[$i]['joinparams']['jointype'] = "";
             $opt[$i]['joinparams']['beforejoin']['table'] = $tablename;
             $opt[$i]['joinparams']['beforejoin']['joinparams']['jointype'] = "itemtype_item";
         }
         switch ($data['type']) {
             case 'dropdown':
             case 'dropdownuser':
                 $opt[$i]['datatype'] = "dropdown";
                 break;
             case 'yesno':
                 $opt[$i]['datatype'] = "bool";
                 break;
             case 'textarea':
                 $opt[$i]['datatype'] = "text";
                 break;
             case 'number':
                 $opt[$i]['datatype'] = "number";
                 break;
             case 'date':
             case 'datetime':
                 $opt[$i]['datatype'] = $data['type'];
                 break;
             default:
                 $opt[$i]['datatype'] = "string";
         }
         $i++;
     }
     return $opt;
 }