Example #1
0
function dropdown_getTypeName($class, $nb = 0)
{
    global $GO_FIELDS;
    $fk = getForeignKeyFieldForTable(getTableForItemType($class));
    $instance = new $class();
    $options = PluginGenericobjectField::getFieldOptions($fk, $instance->linked_itemtype);
    $dropdown_type = isset($options['dropdown_type']) ? $options['dropdown_type'] : null;
    $label = $options['name'];
    if (!is_null($dropdown_type) and $dropdown_type === 'isolated') {
        $linked_itemtype_object = new $instance->linked_itemtype();
        $label .= " (" . __($linked_itemtype_object::getTypeName(), 'genericobject') . ")";
    }
    if ($label != '') {
        return $label;
    } else {
        return $class;
    }
}
Example #2
0
 /**
  * Get all dropdown fields associated with an itemtype
  * @param itemtype the itemtype
  * @return an array or fields that represents the dropdown tables
  */
 static function getDropdownForItemtype($itemtype)
 {
     global $DB;
     $associated_tables = array();
     if (class_exists($itemtype)) {
         $source_table = getTableForItemType($itemtype);
         foreach (PluginGenericobjectSingletonObjectField::getInstance($itemtype) as $field => $value) {
             $table = getTableNameForForeignKeyField($field);
             $options = PluginGenericobjectField::getFieldOptions($field, $itemtype);
             if (isset($options['input_type']) and $options['input_type'] === 'dropdown' and preg_match('/^glpi_plugin_genericobject/', $table)) {
                 $associated_tables[] = $table;
             }
         }
     }
     return $associated_tables;
 }
Example #3
0
   function getObjectSearchOptions($with_linkfield = false) {
      global $DB, $GO_FIELDS, $GO_BLACKLIST_FIELDS;

      $datainjection_blacklisted = array('id', 'date_mod', 'entities_id');
      $index_exceptions = array('name' => 1, 'id' => 2, 'comment' => 16, 'date_mod' => 19,
                                 'entities_id' => 80, 'is_recursive' => 86, 'notepad' => 90);
      $index   = 3;
      $options = array();
      $table   = getTableForItemType(get_called_class());

      foreach (
         PluginGenericobjectSingletonObjectField::getInstance(get_called_class())
         as $field => $values
      ) {
         $searchoption = PluginGenericobjectField::getFieldOptions(
            $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)":
               if ($tmp != '') {
                  $options[$currentindex]['datatype'] = 'dropdown';
               } else {
                  $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 = $currentindex + 1;
      }
      asort($options);
      return $options;
   }