Ejemplo n.º 1
0
 /**
  *
  * Create or overwrite files for an itemtype
  * @since 2.2.0
  * @param $itemtype the itemtype to check
  * @param $name type's short name
  * @param $overwrite force to overwrite existing files
  * @return nothing
  */
 static function checkClassAndFilesForOneItemType($itemtype, $name, $overwrite = false)
 {
     global $DB;
     $table = getTableForItemType($itemtype);
     //If class doesn't exist but table exists, create class
     if (TableExists($table) && ($overwrite || !class_exists($itemtype))) {
         self::addNewObject($name, $itemtype, array('add_table' => false, 'create_default_profile' => false, 'add_injection_file' => false, 'add_language_file' => false));
     }
     foreach ($DB->list_fields($table) as $field => $options) {
         if (preg_match("/s_id\$/", $field)) {
             $dropdowntable = getTableNameForForeignKeyField($field);
             $dropdownclass = getItemTypeForTable($dropdowntable);
             if (TableExists($dropdowntable) && !class_exists($dropdownclass)) {
                 $name = str_replace("glpi_plugin_genericobject_", "", $dropdowntable);
                 $name = getSingular($name);
                 $params = PluginGenericobjectField::getOptionsWithGlobal($field, $dropdownclass);
                 $params['linked_itemtype'] = $itemtype;
                 self::addNewDropdown($name, 'PluginGenericobject' . ucfirst($name), $params);
             }
         }
     }
 }
Ejemplo n.º 2
0
 function getObjectSearchOptions($with_linkfield = false)
 {
     global $DB, $GO_FIELDS, $GO_BLACKLIST_FIELDS;
     $datainjection_blacklisted = array('id', 'date_mod', 'entities_id');
     $index_exceptions = array('entities_id' => 80, 'is_recursive' => 86, 'date_mod' => 19, 'comment' => 16, 'notepad' => 90, 'name' => 1, 'id' => 2);
     $index = 3;
     $options = array();
     $table = getTableForItemType(get_called_class());
     foreach (PluginGenericobjectSingletonObjectField::getInstance(get_called_class()) as $field => $values) {
         $searchoption = PluginGenericobjectField::getOptionsWithGlobal($field, $this->objecttype->fields['itemtype']);
         //Some fields have fixed index values...
         $currentindex = $index;
         if (isset($index_exceptions[$field])) {
             $currentindex = $index_exceptions[$field];
         } elseif (in_array($currentindex, $index_exceptions)) {
             //If this index is reserved, jump to next
             $currentindex++;
         }
         if (in_array($field, array('is_deleted'))) {
             continue;
         }
         $item = new $this->objecttype->fields['itemtype']();
         //Table definition
         $tmp = getTableNameForForeignKeyField($field);
         if ($with_linkfield) {
             $options[$currentindex]['linkfield'] = $field;
         }
         if ($tmp != '') {
             $itemtype = getItemTypeForTable($tmp);
             $tmpobj = new $itemtype();
             //Set table
             $options[$currentindex]['table'] = $tmp;
             //Set field
             if ($tmpobj instanceof CommonTreeDropdown) {
                 $options[$currentindex]['field'] = 'completename';
             } else {
                 $options[$currentindex]['field'] = 'name';
             }
         } else {
             $options[$currentindex]['table'] = $table;
             $options[$currentindex]['field'] = $field;
         }
         $options[$currentindex]['name'] = $searchoption['name'];
         //Massive action or not
         if (isset($searchoption['massiveaction'])) {
             $options[$currentindex]['massiveaction'] = $searchoption['massiveaction'];
         }
         //Datainjection option
         if (!in_array($field, $datainjection_blacklisted)) {
             $options[$currentindex]['injectable'] = 1;
         } else {
             $options[$currentindex]['injectable'] = 0;
         }
         //Field type
         switch ($values['Type']) {
             default:
             case "varchar(255)":
                 if ($field == 'name') {
                     $options[$currentindex]['datatype'] = 'itemlink';
                     $options[$currentindex]['itemlink_type'] = get_called_class();
                     $options[$currentindex]['massiveaction'] = false;
                 } else {
                     if (isset($searchoption['datatype']) && $searchoption['datatype'] == 'weblink') {
                         $options[$currentindex]['datatype'] = 'weblink';
                     } else {
                         $options[$currentindex]['datatype'] = 'string';
                     }
                 }
                 if ($item->canUsePluginDataInjection()) {
                     //Datainjection specific
                     $options[$currentindex]['checktype'] = 'text';
                     $options[$currentindex]['displaytype'] = 'text';
                 }
                 break;
             case "tinyint(1)":
                 $options[$currentindex]['datatype'] = 'bool';
                 if ($item->canUsePluginDataInjection()) {
                     //Datainjection specific
                     $options[$currentindex]['displaytype'] = 'bool';
                 }
                 break;
             case "text":
             case "longtext":
                 $options[$currentindex]['datatype'] = 'text';
                 if ($item->canUsePluginDataInjection()) {
                     //Datainjection specific
                     $options[$currentindex]['displaytype'] = 'multiline_text';
                 }
                 break;
             case "int(11)":
                 $options[$currentindex]['datatype'] = 'integer';
                 if ($item->canUsePluginDataInjection()) {
                     if ($tmp != '') {
                         $options[$currentindex]['displaytype'] = 'dropdown';
                         $options[$currentindex]['checktype'] = 'text';
                     } else {
                         //Datainjection specific
                         $options[$currentindex]['displaytype'] = 'dropdown_integer';
                         $options[$currentindex]['checktype'] = 'integer';
                     }
                 }
                 break;
             case "float":
             case "decimal":
                 $options[$currentindex]['datatype'] = $values['Type'];
                 if ($item->canUsePluginDataInjection()) {
                     //Datainjection specific
                     $options[$currentindex]['display'] = 'text';
                     $options[$currentindex]['checktype'] = $values['Type'];
                 }
                 break;
             case "date":
                 $options[$currentindex]['datatype'] = 'date';
                 if ($item->canUsePluginDataInjection()) {
                     //Datainjection specific
                     $options[$currentindex]['displaytype'] = 'date';
                     $options[$currentindex]['checktype'] = 'date';
                 }
                 break;
             case "datetime":
                 $options[$currentindex]['datatype'] = 'datetime';
                 if ($item->canUsePluginDataInjection()) {
                     //Datainjection specific
                     $options[$currentindex]['displaytype'] = 'date';
                     $options[$currentindex]['checktype'] = 'date';
                 }
                 break;
         }
         $index++;
     }
     return $options;
 }