function addItem($plugin_racks_racks_id, $rack_size, $face, $ID, $itemtype, $spec, $position) { $space_left = $this->checkPosition($plugin_racks_racks_id, $rack_size, $face, $ID, $itemtype, $spec, $position); if ($space_left >= 0) { $values["plugin_racks_racks_id"] = $plugin_racks_racks_id; $values["faces_id"] = $face; $values["items_id"] = $ID; $values["plugin_racks_itemspecifications_id"] = $spec; $values["itemtype"] = $itemtype; $values["position"] = $position; $PluginRacksItemSpecification = new PluginRacksItemSpecification(); $PluginRacksItemSpecification->GetfromDB($spec); $values["amps"] = $PluginRacksItemSpecification->fields["amps"]; $values["flow_rate"] = $PluginRacksItemSpecification->fields["flow_rate"]; $values["dissipation"] = $PluginRacksItemSpecification->fields["dissipation"]; $values["weight"] = $PluginRacksItemSpecification->fields["weight"]; $this->add($values); //If rack's location must be copied in the associated item $config = PluginRacksConfig::getConfig(); if ($config->canAddLocationOnNewItem()) { $rack = new PluginRacksRack(); $rack->getFromDB($plugin_racks_racks_id); if ($rack->fields['locations_id'] > 0) { if (preg_match("/(.*)Model/", $itemtype, $results)) { $item = new $results[1](); $item->update(array('id' => $ID, 'locations_id' => $rack->fields['locations_id'])); } } } } return $space_left; }
function post_updateItem($history = 1) { $config = PluginRacksConfig::getConfig(); if ($config->canForwardLocation() && isset($this->updates) && in_array('locations_id', $this->updates)) { $locations_id = $this->fields['locations_id']; $items = getAllDatasFromTable('glpi_plugin_racks_racks_items', "`plugin_racks_racks_id`='" . $this->getID() . "'"); foreach ($items as $item) { if (preg_match("/(.*)Model/", $item['itemtype'], $results)) { if (class_exists($results[1])) { $myitem = new $results[1](); $myitem->update(array('id' => $item['items_id'], 'locations_id' => $locations_id)); } } } } }