当前位置: 首页>>代码示例>>PHP>>正文


PHP Location::add方法代码示例

本文整理汇总了PHP中Location::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Location::add方法的具体用法?PHP Location::add怎么用?PHP Location::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Location的用法示例。


在下文中一共展示了Location::add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: RegexpRuleResultAssignTest

 /**
  * @test
  */
 public function RegexpRuleResultAssignTest()
 {
     global $DB, $PF_CONFIG;
     $DB->connect();
     $rule = new Rule();
     $location = new Location();
     $input = array('name' => 'Monsols04', 'entities_id' => 0);
     $location->add($input);
     $input = array('is_active' => 1, 'name' => 'Location regexp', 'match' => 'AND', 'sub_type' => 'PluginFusioninventoryInventoryRuleLocation', 'ranking' => 1);
     $rules_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $input = array('rules_id' => $rules_id, 'criteria' => "name", 'pattern' => "/computer (.*)/", 'condition' => PluginFusioninventoryInventoryRuleLocation::REGEX_MATCH);
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction();
     $input = array('rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'locations_id', 'value' => 1);
     $ruleaction->add($input);
     $input = array('name' => 'computer Monsols04');
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $ruleLocation = new PluginFusioninventoryInventoryRuleLocationCollection();
     $ruleLocation->getCollectionPart();
     $loc = $ruleLocation->processAllRules($input, array());
     $a_references = array('locations_id' => 1, '_ruleid' => 50);
     $this->assertEquals($a_references, $loc, 'Location result assign_result');
     $rule->delete(array('id' => $rules_id), True);
 }
开发者ID:korial29,项目名称:fusioninventory-for-glpi,代码行数:30,代码来源:RuleLocationTest.php

示例2: testTree

   /**
    * sons / ancestors for CommonTreeDropdown
    */
   public function testTree() {

      $entity = $this->sharedFixture['entity'][0];
      $loc = new Location();

      // A
      $id[0] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => 0,
                               'name'         => 'A'));
      $this->assertGreaterThan(0, $id[0]);

      // A > AA
      $id[1] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[0],
                               'name'         => 'AA'));
      $this->assertGreaterThan(0, $id[1]);
      $this->assertTrue($loc->getFromDB($id[1]));
      $this->assertEquals('A > AA', $loc->fields['completename']);

      // A > BB
      $id[2] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[0],
                               'name'         => 'BB'));
      $this->assertGreaterThan(0, $id[2]);
      $this->assertTrue($loc->getFromDB($id[2]));
      $this->assertEquals('A > BB', $loc->fields['completename']);

      // Sons of A (A, AA, BB)
      $sons = getSonsOf('glpi_locations',$id[0]);
      $this->assertEquals(3, count($sons));
      $this->assertArrayHasKey($id[0], $sons);
      $this->assertArrayHasKey($id[1], $sons);
      $this->assertArrayHasKey($id[2], $sons);

      // Ancestors of A (none)
      $parent = getAncestorsOf('glpi_locations', $id[0]);
      $this->assertEquals(0, count($parent));

      // Ancestors of AA (A)
      $parent = getAncestorsOf('glpi_locations', $id[1]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // Ancestors of BB (none)
      $parent = getAncestorsOf('glpi_locations', $id[2]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // B
      $id[3] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => 0,
                               'name'         => 'B'));
      $this->assertGreaterThan(0, $id[3]);

      // B > CC
      $id[4] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[3],
                               'name'         => 'CC'));
      $this->assertGreaterThan(0, $id[4]);
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('B > CC', $loc->fields['completename']);

      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(2, count($sons));
      $this->assertArrayHasKey($id[4], $sons);

      // B > CC > XXX
      $id[5] = $loc->add(array('entities_id'  => $entity,
                               'locations_id' => $id[4],
                               'name'         => 'XXX'));
      $this->assertGreaterThan(0, $id[5]);
      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('B > CC > XXX', $loc->fields['completename']);

      // B > CC => A > CC
      $res = $loc->update(array('id'           => $id[4],
                                'locations_id' => $id[0]));
      $this->assertTrue($res);
      $this->assertTrue($loc->getFromDB($id[4]));
      $this->assertEquals('A > CC', $loc->fields['completename']);

      // B > CC > XXX => A > CC > XXX
      $this->assertTrue($loc->getFromDB($id[5]));
      $this->assertEquals('A > CC > XXX', $loc->fields['completename']);

      // New parent of CC (A)
      $parent = getAncestorsOf('glpi_locations', $id[4]);
      $this->assertEquals(1, count($parent));
      $this->assertArrayHasKey($id[0], $parent);

      // New sons of B (only B)
      $sons = getSonsOf('glpi_locations',$id[3]);
      $this->assertEquals(1, count($sons));
      $this->assertArrayHasKey($id[3], $sons);

      // New sons of A (A, AA, BB, CC)
      $sons = getSonsOf('glpi_locations',$id[0]);
//.........这里部分代码省略.........
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:101,代码来源:TreeCache.php

示例3: generate_entity

/** Generate bigdump : generate items for an entity
 *
 * @param $ID_entity entity ID
**/
function generate_entity($ID_entity) {
   global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK,
         $DOCUMENTS, $NET_PORT, $NET_LOC;

   regenerateTreeCompleteName("glpi_entities");

   $current_year = date("Y");


   // DOMAIN
   $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine");
   $dp    = new Domain();
   $FIRST["domain"] = getMaxItem("glpi_domains")+1;

   for ($i=0 ; $i<$MAX['domain'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "domain $ID_entity '$i";
      }
      $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1,
                                              'comment'      => "comment $val")));
   }
   $LAST["domain"] = getMaxItem("glpi_domains");


   // STATUS
   $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'");
   $dp    = new State();
   $FIRST["state"] = getMaxItem("glpi_states")+1;
   for ($i=0 ; $i<$MAX['state'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "State $ID_entity '$i";
      }
      $state_id = $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                                          'entities_id'  => $ID_entity,
                                                          'is_recursive' => 1,
                                                          'comment'      => "comment $val")));

      // generate sub status
      for ($j=0 ; $j<$MAX['state'] ; $j++) {
         $val2 = "Sub $val $j";

         $dp->add(toolbox::addslashes_deep(array('name'         => $val2,
                                                 'entities_id'  => $ID_entity,
                                                 'is_recursive' => 1,
                                                 'states_id'    => $state_id,
                                                 'comment'      => "comment $val")));
      }

   }
   $LAST["state"]      = getMaxItem("glpi_states");


   // glpi_groups
   $FIRST["groups"] = getMaxItem("glpi_groups")+1;
   $group           = new Group();
   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
      $gID = $group->add(toolbox::addslashes_deep(
                         array('entities_id'  => $ID_entity,
                               'name'         => "group d'$i",
                               'comment'      => "comment group d'$i",
                               'is_assign'    => 0)));

      // Generate sub group
      for ($j=0 ; $j<$MAX['groups'] ; $j++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "subgroup d'$j",
                           'comment'      => "comment subgroup d'$j of group $i",
                           'groups_id'    => $gID,
                           'is_assign'    => 0)));
      }
   }

   $LAST["groups"]      = getMaxItem("glpi_groups");

   $FIRST["techgroups"] = $LAST["groups"]+1;

   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "tech group d'$i",
                           'comment'      => "comment tech group d'$i")));
   }

   $LAST["techgroups"] = getMaxItem("glpi_groups");
   regenerateTreeCompleteName("glpi_groups");


   // glpi_users
   $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1;
//.........这里部分代码省略.........
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:101,代码来源:generate_bigdump.function.php

示例4: plugin_moreldap_item_add_or_update_user

function plugin_moreldap_item_add_or_update_user($user)
{
    //Ignore users without auths_id
    if (!isset($user->input["auths_id"])) {
        return;
    }
    // We update LDAP field only if LDAP directory is defined
    if (isset($user->input["locations_id"])) {
        return;
    }
    // default : store locations outside of any entity
    $entityID = -1;
    $pluginAuthLDAP = new PluginMoreldapAuthLDAP();
    $authsId = isset($user->input["auths_id"]) ? $user->input["auths_id"] : $user->fields["auths_id"];
    if ($authsId > 0 && $pluginAuthLDAP->getFromDBByQuery("WHERE `id`='{$authsId}'")) {
        // The target entity for the locations to be created
        $entityID = $pluginAuthLDAP->fields['entities_id'];
        // find from config all attributes to read from LDAP
        $fields = array();
        $locationHierarchy = explode('>', $pluginAuthLDAP->fields['location']);
        foreach ($locationHierarchy as $locationSubAttribute) {
            $locationSubAttribute = trim($locationSubAttribute);
            if (strlen($locationSubAttribute) > 0) {
                $fields[] = $locationSubAttribute;
            }
        }
        // LDAP query to read the needed attributes for the user
        $ldap_connection = 0;
        if (!isset($user->input["_ldap_conn"]) || !isset($user->fields["_ldap_conn"])) {
            $ldap = new AuthLDAP();
            $ldap->getFromDB($authsId);
            $ldap_connection = $ldap->connect();
        } else {
            $ldap_connection = isset($user->input["_ldap_conn"]) ? $user->input["_ldap_conn"] : $user->fields["_ldap_conn"];
        }
        $userdn = isset($user->input["user_dn"]) ? $user->input["user_dn"] : $user->fields["user_dn"];
        $userdn = str_replace('\\\\', '\\', $userdn);
        $sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $fields);
        if (!is_resource($sr) || ldap_errno($ldap_connection) > 0) {
            return;
        }
        $v = AuthLDAP::get_entries_clean($ldap_connection, $sr);
        //Find all locations needed to create the deepest one
        $locationPath = array();
        $incompleteLocation = false;
        foreach ($fields as $locationSubAttribute) {
            $locationSubAttribute = strtolower($locationSubAttribute);
            if (isset($v[0][$locationSubAttribute][0])) {
                $locationPath[] = $v[0][$locationSubAttribute][0];
            } else {
                // A LDAP attribute is not defined for the user. Cannot build the completename
                // Therefore we must giveup importing this location
                $incompleteLocation = true;
            }
        }
        // TODO : test if location import is enabled earlier in this function
        if ($pluginAuthLDAP->fields['location_enabled'] == 'Y') {
            if ($incompleteLocation == false) {
                $location = new Location();
                $locationAncestor = 0;
                $locationCompleteName = array();
                $allLocationsExist = true;
                // Assume we created or found all locations
                // while ($locatinItem = array_shift($locationPath) && $allLocationsExist) {
                foreach ($locationPath as $locationItem) {
                    if ($allLocationsExist) {
                        $locationCompleteName[] = $locationItem;
                        $locationItem = Toolbox::addslashes_deep(array('entities_id' => $entityID, 'name' => $locationItem, 'locations_id' => $locationAncestor, 'completename' => implode(' > ', $locationCompleteName), 'is_recursive' => $pluginAuthLDAP->fields['is_recursive'], 'comment' => __("Created by MoreLDAP", "moreldap")));
                        $locationAncestor = $location->findID($locationItem);
                        if ($locationAncestor == -1) {
                            // The location does not exists yet
                            $locationAncestor = $location->add($locationItem);
                        }
                        if ($locationAncestor == false) {
                            // If a location could not be imported and does not exist
                            // then give up importing children items
                            $allLocationsExist = false;
                        }
                    }
                }
                if ($allLocationsExist) {
                    // All locations exist to match the path described un LDAP
                    $locations_id = $locationAncestor;
                    $myuser = new User();
                    // new var to prevent user->input erasing (object are always passed by "reference")
                    $myuser->update(array('id' => $user->getID(), 'locations_id' => $locations_id));
                }
            }
        } else {
            // If the location retrieval is disabled, enablig this line will erase the location for the user.
            // $fields['locations_id'] = 0;
        }
    }
}
开发者ID:pluginsGLPI,项目名称:moreldap,代码行数:94,代码来源:hook.php

示例5: showFormResCreateLocation

 /**
  * Résultat de la création du sous-lieu + ajout dans la base de données
  */
 static function showFormResCreateLocation($opt)
 {
     global $CFG_GLPI, $DB;
     $filename = $opt["document_id"] . $opt["name"] . "." . $opt["extension"];
     $filepath = "/_uploads/" . $filename;
     $id = 0;
     if ($opt["test"] == "existLocation") {
         $query = "SELECT `id`,`name`\n                  FROM `glpi_locations`\n                  WHERE `id` = '" . $opt["locations_id"] . "'";
         $result = $DB->query($query);
         while ($data = $DB->fetch_assoc($result)) {
             $name = $data['name'];
             $id = $data['id'];
         }
     } else {
         if ($opt["test"] == "newLocation") {
             $locations_id = $opt["locations_idParent"];
         }
     }
     $params = array("name" => $opt["name"], "document_id" => $opt["document_id"], "filepath" => $filepath, "filename" => $filename, "entities_id" => $opt["entities_id"], "locations_id" => $opt["locations_id"], "id" => $id, "itemtype" => "Location");
     //FONCTION QUI PERMET D'AJOUTER LE LIEU DANS LA BASE DE DONNEES
     $dropdown = new Location();
     //AJOUT DU LIEU
     if ($opt["test"] == 'newLocation') {
         if ($newID = $dropdown->add($params)) {
         } else {
             $locations_found = $dropdown->find("`name` = '" . $params['name'] . "' AND `entities_id` = '" . $params['entities_id'] . "' AND `locations_id` = '" . $params['locations_id'] . "'", '', '1');
             $newID = key($locations_found);
         }
         $opt["locations_id"] = $newID;
     }
     if ($opt["locations_id"] != $opt["locations_idParent"]) {
         //AJOUT DU DOC ASSOCIE AU LIEU
         $doc = new Document();
         $documentitem = new Document_Item();
         $self = new self();
         $input = array();
         $input["entities_id"] = $opt["entities_id"];
         $input["name"] = $opt["name"];
         $input["upload_file"] = $filename;
         //$input["documentcategories_id"]=$options["rubrique"];
         //$input["mime"]="text/html";
         $input["date_mod"] = date("Y-m-d H:i:s");
         $input["users_id"] = Session::getLoginUserID();
         $newdoc = $doc->add($input);
         // Add new location
         if ($opt["test"] == 'newLocation') {
             // We check if the element already exists
             $restrict = "`items_id` = '" . $newID . "' AND `itemtype` = 'Location'";
             if (countElementsInTable("glpi_plugin_positions_positions", $restrict) != 0) {
                 Session::addMessageAfterRedirect(__('This item is already bound to a location', 'positions'), false, ERROR);
                 Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_idParent"]);
                 // If not we can add its position and picture
             } else {
                 $documentitem->add(array('documents_id' => $newdoc, 'itemtype' => 'Location', 'items_id' => $newID, 'entities_id' => $opt["entities_id"]));
                 $param = array("items_id" => $newID, "entities_id" => $opt["entities_id"], "locations_id" => $opt["locations_idParent"], "itemtype" => "Location", "x_coordinates" => -800, "y_coordinates" => -150);
                 $self->add($param);
                 if ($opt["checked"] == 'on') {
                     self::showMapCreateLocation($opt);
                 } else {
                     if ($opt["checked"] == 'off') {
                         Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_id"]);
                     }
                 }
             }
             // Add existing location
         } else {
             if ($opt["test"] == 'existLocation') {
                 $documentitem->add(array('documents_id' => $newdoc, 'itemtype' => 'Location', 'items_id' => $id));
                 $param = array("items_id" => $id, "entities_id" => $opt["entities_id"], "locations_id" => $opt["locations_idParent"], "itemtype" => "Location", "x_coordinates" => -800, "y_coordinates" => -150);
                 $self->add($param);
                 if ($opt["checked"] == 'on') {
                     self::showMapCreateLocation($opt);
                 } else {
                     if ($opt["checked"] == 'off') {
                         Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_id"]);
                     }
                 }
             }
         }
     } else {
         Session::addMessageAfterRedirect(__('This item is already bound to a location', 'positions'), false, ERROR);
         Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_id"]);
     }
 }
开发者ID:nsautier,项目名称:positions,代码行数:87,代码来源:position.class.php

示例6: function

    }
    // $response = $request;
    echo json_encode($response);
});
$app->post('/location', function () use($app) {
    $request = (array) json_decode($app->request->getBody());
    switch ($request['action']) {
        case 'GET':
            break;
        case 'REMOVE':
            break;
        case 'EDIT':
            break;
        case 'ADD':
            $action = new Location();
            $action->add((array) $request['info']);
            $insert = new Request();
            $insert->insertNR($action->sql);
            if ($insert) {
                $response = (array) $request['info'];
            }
            break;
        default:
            # code...
            break;
    }
    // $response = array('hhold'=>$household,'locations'=>$locations);
    echo json_encode($response);
});
$app->post('/household', function () use($app) {
    $request = (array) json_decode($app->request->getBody());
开发者ID:bobbyfisher928,项目名称:OneYum,代码行数:31,代码来源:index.php

示例7: plugin_retrieve_more_data_from_ldap_moreldap

/**
 * Hook to add more data from ldap
 *
 * @param $datas   array
 *
 * @return un tableau
 **/
function plugin_retrieve_more_data_from_ldap_moreldap(array $fields)
{
    $pluginAuthLDAP = new PluginMoreldapAuthLDAP();
    $authLDAP = new AuthLDAP();
    $user = new User();
    $user->getFromDBbyDn($fields['user_dn']);
    // default : store locations outside of any entity
    $entityID = -1;
    if ($pluginAuthLDAP->getFromDBByQuery("WHERE `id`='" . $user->fields["auths_id"] . "'")) {
        $entityID = $pluginAuthLDAP->fields['entities_id'];
        if (isset($fields[$pluginAuthLDAP->fields['location']])) {
            // Explode multiple attributes for location hierarchy
            $locationHierarchy = explode('>', $pluginAuthLDAP->fields['location']);
            $locationPath = array();
            $incompleteLocation = false;
            foreach ($locationHierarchy as $locationSubAttribute) {
                $locationSubAttribute = trim($locationSubAttribute);
                if (isset($fields['_ldap_result'][0][strtolower($locationSubAttribute)][0])) {
                    $locationPath[] = $fields['_ldap_result'][0][strtolower($locationSubAttribute)][0];
                } else {
                    $incompleteLocation = true;
                }
            }
            if ($incompleteLocation == false) {
                if ($pluginAuthLDAP->fields['location_enabled'] == 'Y') {
                    $location = new Location();
                    $locationAncestor = 0;
                    $locationCompleteName = array();
                    foreach ($locationPath as $locationItem) {
                        $locationCompleteName[] = $locationItem;
                        $locationItem = Toolbox::addslashes_deep(array('entities_id' => $entityID, 'name' => $locationItem, 'locations_id' => $locationAncestor, 'completename' => implode(' > ', $locationCompleteName), 'is_recursive' => $pluginAuthLDAP->fields['is_recursive']));
                        $locationAncestor = $location->findID($locationItem);
                        if ($locationAncestor == -1) {
                            //The location does not exists yet
                            $locationAncestor = $location->add($locationItem);
                        }
                        if ($locationAncestor == false) {
                            // If a location could not be imported, then give up importing children items
                            break;
                        }
                    }
                    if ($locationAncestor != false) {
                        $fields['locations_id'] = $locationAncestor;
                    }
                } else {
                    //If the location retrieval is disabled, enablig this line will erase the location for the user.
                    //$fields['locations_id'] = 0;
                }
            }
        }
    }
    return $fields;
}
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:60,代码来源:hook.php


注:本文中的Location::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。