public static function fromArray(array $values) { $self = new self(); $self->addValues($values); return $self; }
static function printerInventoryTransformation($array) { $a_inventory = array(); $thisc = new self(); // * INFO $array_tmp = $thisc->addValues($array['INFO'], array('NAME' => 'name', 'SERIAL' => 'serial', 'ID' => 'id', 'MANUFACTURER' => 'manufacturers_id', 'LOCATION' => 'locations_id', 'MODEL' => 'printermodels_id', 'MEMORY' => 'memory_size')); $array_tmp['is_dynamic'] = 1; $array_tmp['have_ethernet'] = 1; $a_inventory['Printer'] = $array_tmp; $a_inventory['itemtype'] = 'Printer'; $array_tmp = $thisc->addValues($array['INFO'], array('COMMENTS' => 'sysdescr')); $array_tmp['last_fusioninventory_update'] = date('Y-m-d H:i:s'); $a_inventory['PluginFusioninventoryPrinter'] = $array_tmp; // * PORTS $a_inventory['networkport'] = array(); if (isset($array['PORTS'])) { foreach ($array['PORTS']['PORT'] as $a_port) { if (!isset($a_port['IFNUMBER'])) { $array_tmp = $thisc->addValues($a_port, array('IFNAME' => 'name', 'IFNUMBER' => 'logical_number', 'MAC' => 'mac', 'IP' => 'ip', 'IFTYPE' => 'iftype')); $a_inventory['networkport'][$a_port['IFNUMBER']] = $array_tmp; } } } // CARTRIDGES $a_inventory['cartridge'] = array(); if (isset($array['CARTRIDGES'])) { $pfMapping = new PluginFusioninventoryMapping(); foreach ($array['CARTRIDGES'] as $name => $value) { $plugin_fusioninventory_mappings = $pfMapping->get("Printer", strtolower($name)); if ($plugin_fusioninventory_mappings) { if (strstr($value, 'pages')) { // 30pages $value = str_replace('pages', '', $value); $value = 0 - $value; } else { if ($value == '') { // no info // nothing to do } else { if (is_numeric($value)) { // percentage // nothing to do } else { if ($value == 'OK') { // state type 'OK' $value = 100000; } else { // special cases $value = ''; } } } } if ($value != '') { $a_inventory['cartridge'][$plugin_fusioninventory_mappings['id']] = $value; } } } } // * PAGESCOUNTER $a_inventory['pagecounters'] = array(); if (isset($array['PAGECOUNTERS'])) { $array_tmp = $thisc->addValues($array['PAGECOUNTERS'], array('TOTAL' => 'pages_total', 'BLACK' => 'pages_n_b', 'COLOR' => 'pages_color', 'RECTOVERSO' => 'pages_recto_verso', 'SCANNED' => 'scanned', 'PRINTTOTAL' => 'pages_total_print', 'PRINTBLACK' => 'pages_n_b_print', 'PRINTCOLOR' => 'pages_color_print', 'COPYTOTAL' => 'pages_total_copy', 'COPYBLACK' => 'pages_n_b_copy', 'COPYCOLOR' => 'pages_color_copy', 'FAXTOTAL' => 'pages_total_fax')); $a_inventory['pagecounters'] = $array_tmp; } return $a_inventory; }