本文整理汇总了PHP中PluginDatainjectionCommonInjectionLib::getInjectionClassInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP PluginDatainjectionCommonInjectionLib::getInjectionClassInstance方法的具体用法?PHP PluginDatainjectionCommonInjectionLib::getInjectionClassInstance怎么用?PHP PluginDatainjectionCommonInjectionLib::getInjectionClassInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PluginDatainjectionCommonInjectionLib
的用法示例。
在下文中一共展示了PluginDatainjectionCommonInjectionLib::getInjectionClassInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: injectLine
/**
* 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: keepInfo
/**
* @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: getUsedMappingsOrInfos
/**
* @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;
}