コード例 #1
0
ファイル: engine.class.php プロジェクト: JULIO8/respaldo_glpi
 /**
  * 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;
 }
コード例 #2
0
ファイル: info.class.php プロジェクト: JULIO8/respaldo_glpi
 /**
  * @param $info      PluginDatainjectionInfo object
  * @param $value
  **/
 static function keepInfo(PluginDatainjectionInfo $info, $value)
 {
     $itemtype = $info->getInfosType();
     $injectionClass = PluginDatainjectionCommonInjectionLib::getInjectionClassInstance($itemtype);
     $options = $injectionClass->getOptions($itemtype);
     $option = PluginDatainjectionCommonInjectionLib::findSearchOption($options, $info->getValue());
     if ($option) {
         switch ($option['displaytype']) {
             default:
             case 'text':
             case 'multiline_text':
                 if ($value != PluginDatainjectionCommonInjectionLib::EMPTY_VALUE) {
                     return true;
                 }
                 return false;
             case 'dropdown':
             case 'user':
             case 'contact':
                 if ($value != PluginDatainjectionCommonInjectionLib::DROPDOWN_EMPTY_VALUE) {
                     return true;
                 }
                 return false;
         }
     }
 }
コード例 #3
0
 /**
  * @param $options   array
  **/
 static function getUsedMappingsOrInfos($options = array())
 {
     global $DB;
     $p['itemtype'] = self::NO_VALUE;
     $p['primary_type'] = '';
     $p['mapping_or_info'] = array();
     $p['called_by'] = '';
     $p['need_decode'] = true;
     foreach ($options as $key => $value) {
         $p[$key] = $value;
     }
     if ($p['need_decode']) {
         $mapping_or_info = json_decode(Toolbox::stripslashes_deep($options['mapping_or_info']), true);
     } else {
         $mapping_or_info = $options['mapping_or_info'];
     }
     $used = array();
     $table = $p['called_by'] == 'PluginDatainjectionMapping' ? "glpi_plugin_datainjection_mappings" : "glpi_plugin_datainjection_infos";
     $datas = getAllDatasFromTable($table, "`models_id` = '" . $mapping_or_info['models_id'] . "'");
     $injectionClass = PluginDatainjectionCommonInjectionLib::getInjectionClassInstance($p['itemtype']);
     $options = $injectionClass->getOptions();
     foreach ($datas as $data) {
         if ($data['value'] != self::NO_VALUE) {
             foreach ($options as $option) {
                 if (isset($option['table']) && $option['table'] == getItemTypeForTable($data['itemtype']) && $option['linkfield'] == $data['value'] && $option['displaytype'] != 'multiline_text' && $mapping_or_info['value'] != $data['value']) {
                     $used[$option['linkfield']] = $option['linkfield'];
                     break;
                 }
             }
         }
     }
     return $used;
 }