function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { return; if ($item->getType() == 'PluginCustomTab' && $item->canView()) { return Toolbox::ucfirst(_n("Profile", "Profiles", 1)); } return ''; }
static function pdfDevice(PluginPdfSimplePDF $pdf, Computer $computer) { global $DB; $devtypes = Item_Devices::getDeviceTypes(); $ID = $computer->getField('id'); if (!$computer->can($ID, 'r')) { return false; } $pdf->setColumnsSize(100); $pdf->displayTitle('<b>' . Toolbox::ucfirst(_n('Component', 'Components', 2)) . '</b>'); $pdf->setColumnsSize(3, 14, 42, 41); foreach ($devtypes as $itemtype) { $devicetypes = new $itemtype(); $specificities = $devicetypes->getSpecificities(); $specif_fields = array_keys($specificities); $specif_text = implode(',', $specif_fields); if (!empty($specif_text)) { $specif_text = " ," . $specif_text . " "; } $associated_type = str_replace('Item_', '', $itemtype); $linktable = getTableForItemType($itemtype); $fk = getForeignKeyFieldForTable(getTableForItemType($associated_type)); $query = "SELECT count(*) AS NB, `id`, `" . $fk . "`" . $specif_text . "\n FROM `" . $linktable . "`\n WHERE `items_id` = '" . $ID . "'\n AND `itemtype` = 'Computer'\n GROUP BY `" . $fk . "`" . $specif_text; $device = new $associated_type(); foreach ($DB->request($query) as $data) { if ($device->getFromDB($data[$fk])) { $spec = $device->getAdditionalFields(); $col4 = ''; if (count($spec)) { $colspan = 60 / count($spec); foreach ($spec as $i => $label) { if (isset($device->fields[$label["name"]]) && !empty($device->fields[$label["name"]])) { if ($label["type"] == "dropdownValue" && $device->fields[$label["name"]] != 0) { $table = getTableNameForForeignKeyField($label["name"]); $value = Dropdown::getDropdownName($table, $device->fields[$label["name"]]); $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', Html::clean($value) . " "); } else { $value = $device->fields[$label["name"]]; $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $value . " "); } } else { if (isset($device->fields[$label["name"] . "_default"]) && !empty($device->fields[$label["name"] . "_default"])) { $col4 .= '<b><i>' . sprintf(__('%1$s: %2$s'), $label["label"] . '</i></b>', $device->fields[$label["name"] . "_default"] . " "); } } } } $pdf->displayLine($data['NB'], $device->getTypeName(), $device->getName(), $col4); } } } $pdf->displaySpace(); }
/** * Return ItemType for a table * * @param $table string table name * * @return string itemtype corresponding to a table name parameter **/ function getItemTypeForTable($table) { global $CFG_GLPI; if (isset($CFG_GLPI['glpiitemtypetables'][$table])) { return $CFG_GLPI['glpiitemtypetables'][$table]; } else { $inittable = $table; $table = str_replace("glpi_", "", $table); $prefix = ""; if (preg_match('/^plugin_([a-z0-9]+)_/', $table, $matches)) { $table = preg_replace('/^plugin_[a-z0-9]+_/', '', $table); $prefix = "Plugin" . Toolbox::ucfirst($matches[1]); } if (strstr($table, '_')) { $split = explode('_', $table); foreach ($split as $key => $part) { $split[$key] = Toolbox::ucfirst(getSingular($part)); } $table = implode('_', $split); } else { $table = Toolbox::ucfirst(getSingular($table)); } $itemtype = $prefix . $table; // Get real existence of itemtype if ($item = getItemForItemtype($itemtype)) { $itemtype = get_class($item); $CFG_GLPI['glpiitemtypetables'][$inittable] = $itemtype; $CFG_GLPI['glpitablesitemtype'][$itemtype] = $inittable; return $itemtype; } return "UNKNOWN"; } }
/** * Get an itemtype by giving an injection class object * * @param $injectionClassName the injection class object * * @return an instance of the itemtype associated to the injection class */ static function getItemtypeByInjectionClass($injectionClass) { return Toolbox::ucfirst(getItemTypeForTable($injectionClass->getTable())); }