. * ------------------------------------------------------------------------- * @copyright Copyright (C) 2009-2022 by GenericObject plugin team. * @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html * @link https://github.com/pluginsGLPI/genericobject * ------------------------------------------------------------------------- */ class PluginGenericobjectObject_Item extends CommonDBChild { public $dohistory = true; // From CommonDBRelation static public $itemtype_1 = "PluginGenericobjectObject"; static public $items_id_1 = 'plugin_genericobject_objects_id'; static public $itemtype_2 = 'itemtype'; static public $items_id_2 = 'items_id'; //Get itemtype name static function getTypeName($nb = 0) { global $LANG; $class = get_called_class(); //Datainjection : Don't understand why I need this trick : need to be investigated ! if (preg_match("/Injection$/i", $class)) { $class = str_replace("Injection", "", $class); } $item = new $class(); //Itemtype name can be contained in a specific locale field : try to load it PluginGenericobjectType::includeLocales($item->objecttype->fields['name']); if (isset($LANG['genericobject'][$class][0])) { return $LANG['genericobject'][$class][0]; } else { return $item->objecttype->fields['name']; } } static function canView() { return Session::haveRight(self::$itemtype_1, READ); } static function canCreate() { return Session::haveRight(self::$itemtype_1, CREATE); } /** * * Enter description here ... * @since 2.2.0 * @param CommonDBTM $item */ static function showItemsForSource(CommonDBTM $item) { } /** * * Enter description here ... * @since 2.2.0 * @param CommonDBTM $item */ static function showItemsForTarget(CommonDBTM $item) { } /** * * Enter description here ... * @since 2.2.0 */ static function registerType() { Plugin::registerClass(get_called_class(), ['addtabon' => self::getLinkedItemTypes()]); } static function getLinkedItemTypes() { $source_itemtype = self::getItemType1(); $source_item = new $source_itemtype; return $source_item->getLinkedItemTypesAsArray(); } static function getItemType1() { $classname = get_called_class(); return $classname::$itemtype_1; } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { $itemtypes = self::getLinkedItemTypes(); if (in_array(get_class($item), $itemtypes) || get_class($item) == self::getItemType1()) { return [1 => __("Objects management", "genericobject")]; } } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { $itemtypes = self::getLinkedItemTypes(); if (get_class($item) == self::getItemType1()) { self::showItemsForSource($item); } else if (in_array(get_class($item), $itemtypes)) { self::showItemsForTarget($item); } return true; } }