Esempio n. 1
0
 /**
  * Inject one line of datas
  *
  * @param $line   one line of data to import
  * @param $index  the line number is the file
  **/
 function injectLine($line, $index)
 {
     //Store all fields to injection, sorted by itemtype
     $fields_toinject = array();
     $mandatory_fields = array();
     //Get the injectionclass associated to the itemtype
     $itemtype = $this->getModel()->getItemtype();
     $injectionClass = PluginDatainjectionCommonInjectionLib::getInjectionClassInstance($itemtype);
     $several = PluginDatainjectionMapping::getSeveralMappedField($this->getModel()->fields['id']);
     //First of all : transform $line which is an array of values to inject into another array
     //which looks like this :
     //array(itemtype=>array(field=>value,field2=>value2))
     //Note : ignore values which are not mapped with a glpi's field
     $searchOptions = $injectionClass->getOptions($itemtype);
     for ($i = 0; $i < count($line); $i++) {
         $mapping = $this->getModel()->getMappingByRank($i);
         //If field is mapped with a value in glpi
         if ($mapping != null && $mapping->getItemtype() != PluginDatainjectionInjectionType::NO_VALUE) {
             $this->addValueToInject($fields_toinject, $searchOptions, $mapping, $line[$i], $several);
         }
     }
     //Create an array with the mandatory mappings
     foreach ($this->getModel()->getMappings() as $mapping) {
         if ($mapping->isMandatory()) {
             $mandatory_fields[$mapping->getItemtype()][$mapping->getValue()] = $mapping->isMandatory();
         }
     }
     //Add fields needed for injection
     $this->addRequiredFields($itemtype, $fields_toinject);
     //Optional data to be added to the fields to inject (won't be checked !)
     $optional_data = $this->addAdditionalInformations($this->infos);
     //--------------- Set all needed options ------------------//
     //Check options
     $checks = array('ip' => true, 'mac' => true, 'integer' => true, 'yes' => true, 'bool' => true, 'date' => $this->getModel()->getDateFormat(), 'float' => $this->getModel()->getFloatFormat(), 'string' => true, 'right_r' => true, 'right_rw' => true, 'interface' => true, 'auth_method' => true, 'port_unicity' => $this->getModel()->getPortUnicity());
     //Rights options
     $rights = array('add_dropdown' => $this->getModel()->getCanAddDropdown(), 'overwrite_notempty_fields' => $this->getModel()->getCanOverwriteIfNotEmpty(), 'can_add' => $this->model->getBehaviorAdd(), 'can_update' => $this->model->getBehaviorUpdate(), 'can_delete' => false);
     //Field format options
     $formats = array('date_format' => $this->getModel()->getDateFormat(), 'float_format' => $this->getModel()->getFloatFormat());
     //Check options : by default check all types
     $options = array('checks' => $checks, 'entities_id' => $this->getEntity(), 'rights' => $rights, 'formats' => $formats, 'mandatory_fields' => $mandatory_fields, 'optional_data' => $optional_data);
     //Will manage add or update
     $results = $injectionClass->addOrUpdateObject($fields_toinject, $options);
     //Add injected line number to the result array
     $results['line'] = $index;
     if ($results['status'] != PluginDatainjectionCommonInjectionLib::SUCCESS) {
         $this->error_lines[] = $line;
     }
     return $results;
 }
Esempio n. 2
0
 function populateSeveraltimesMappedFields()
 {
     $this->severaltimes_mapped = PluginDatainjectionMapping::getSeveralMappedField($this->fields['id']);
 }