本文整理匯總了PHP中CommonDropdown::import方法的典型用法代碼示例。如果您正苦於以下問題:PHP CommonDropdown::import方法的具體用法?PHP CommonDropdown::import怎麽用?PHP CommonDropdown::import使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CommonDropdown
的用法示例。
在下文中一共展示了CommonDropdown::import方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: import
/**
* Import a dropdown - check if already exists
*
* @param $input array of value to import (name or completename, ...)
*
* @return the ID of the new or existing dropdown
**/
function import(array $input)
{
if (isset($input['name'])) {
return parent::import($input);
}
if (!isset($input['completename']) || empty($input['completename'])) {
return -1;
}
// Import a full tree from completename
$names = explode('>', $input['completename']);
$fk = $this->getForeignKeyField();
$i = count($names);
$parent = 0;
foreach ($names as $name) {
$i--;
if (empty($name)) {
// Skip empty name (completename starting/endind with >, double >, ...)
continue;
}
$tmp['name'] = $name;
$tmp[$fk] = $parent;
if (isset($input['entities_id'])) {
$tmp['entities_id'] = $input['entities_id'];
}
if (!$i) {
// Other fields (comment, ...) only for last node of the tree
foreach ($input as $key => $val) {
if ($key != 'completename') {
$tmp[$key] = $val;
}
}
}
$parent = parent::import($tmp);
}
return $parent;
}
示例2: customimport
/**
* @param $input array
* @param $add (true by default)
* @param $rights array
**/
function customimport($input = array(), $add = true, $rights = array())
{
if (!isset($input['completename']) || empty($input['completename'])) {
return -1;
}
// Import a full tree from completename
$names = explode('>', $input['completename']);
$fk = $this->getForeignKeyField();
$i = count($names);
$parent = 0;
$entity = new Entity();
$level = 0;
foreach ($names as $name) {
$name = trim($name);
$i--;
$level++;
if (empty($name)) {
// Skip empty name (completename starting/endind with >, double >, ...)
continue;
}
$tmp['name'] = $name;
if (!$i) {
// Other fields (comment, ...) only for last node of the tree
foreach ($input as $key => $val) {
if ($key != 'completename') {
$tmp[$key] = $val;
}
}
}
$tmp['level'] = $level;
$tmp['entities_id'] = $parent;
//Does the entity alread exists ?
$results = getAllDatasFromTable('glpi_entities', "`name`='{$name}' AND `entities_id`='{$parent}'");
//Entity doesn't exists => create it
if (empty($results)) {
$parent = CommonDropdown::import($tmp);
} else {
//Entity already exists, use the ID as parent
$ent = array_pop($results);
$parent = $ent['id'];
}
}
return $parent;
}