當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CommonDropdown::import方法代碼示例

本文整理匯總了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;
 }
開發者ID:korial29,項目名稱:glpi,代碼行數:43,代碼來源:commontreedropdown.class.php

示例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;
 }
開發者ID:JULIO8,項目名稱:respaldo_glpi,代碼行數:49,代碼來源:entityinjection.class.php


注:本文中的CommonDropdown::import方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。