. * --------------------------------------------------------------------- **/ class Pdu_Plug extends CommonDBRelation { static public $itemtype_1 = 'PDU'; static public $items_id_1 = 'pdus_id'; static public $itemtype_2 = 'Plug'; static public $items_id_2 = 'plugs_id'; static public $checkItem_1_Rights = self::DONT_CHECK_ITEM_RIGHTS; static public $mustBeAttached_1 = false; static public $mustBeAttached_2 = false; static function getTypeName($nb = 0) { return _n('PDU plug', 'PDU plugs', $nb); } function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { $nb = 0; switch ($item->getType()) { default: $field = $item->getType() == PDU::getType() ? 'pdus_id' : 'plugs_id'; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable( self::getTable(), [$field => $item->getID()] ); } return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), $nb); } return ''; } static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { self::showItems($item, $withtemplate); } /** * Print items * * @param PDU $pdu PDU instance * * @return void */ static function showItems(PDU $pdu) { global $DB; $ID = $pdu->getID(); $rand = mt_rand(); if (!$pdu->getFromDB($ID) || !$pdu->can($ID, READ)) { return false; } $canedit = $pdu->canEdit($ID); $items = $DB->request([ 'FROM' => self::getTable(), 'WHERE' => [ 'pdus_id' => $pdu->getID() ] ]); $link = new self(); Session::initNavigateListItems( self::getType(), //TRANS : %1$s is the itemtype name, // %2$s is the name of the item (used for headings of a list) sprintf( __('%1$s = %2$s'), $pdu->getTypeName(1), $pdu->getName() ) ); $items = iterator_to_array($items); if ($canedit) { $rand = mt_rand(); echo "\n