function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) { if (!$withtemplate) { switch ($item->getType()) { case 'Problem': $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countElementsInTable('glpi_items_problems', "`problems_id` = '" . $item->getID() . "'"); } return self::createTabEntry(_n('Item', 'Items', Session::getPluralNumber()), $nb); case 'User': $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countDistinctElementsInTable('glpi_problems_users', 'problems_id', "`users_id` = '" . $item->getID() . "'"); } return self::createTabEntry(Problem::getTypeName(Session::getPluralNumber()), $nb); case 'Group': $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countDistinctElementsInTable('glpi_groups_problems', 'problems_id', "`groups_id` = '" . $item->getID() . "'"); } return self::createTabEntry(Problem::getTypeName(Session::getPluralNumber()), $nb); case 'Supplier': $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { $nb = countDistinctElementsInTable('glpi_problems_suppliers', 'problems_id', "`suppliers_id` = '" . $item->getID() . "'"); } return self::createTabEntry(Problem::getTypeName(Session::getPluralNumber()), $nb); default: if (Session::haveRight("problem", Problem::READALL)) { $nb = 0; if ($_SESSION['glpishow_count_on_tabs']) { // Direct one $nb = countElementsInTable('glpi_items_problems', " `itemtype` = '" . $item->getType() . "'\n AND `items_id` = '" . $item->getID() . "'"); // Linked items $linkeditems = $item->getLinkedItems(); if (count($linkeditems)) { foreach ($linkeditems as $type => $tab) { foreach ($tab as $ID) { $nb += countElementsInTable('glpi_items_problems', " `itemtype` = '{$type}'\n AND `items_id` = '{$ID}'"); } } } } return self::createTabEntry(Problem::getTypeName(Session::getPluralNumber()), $nb); } } } return ''; }
/** * @covers ::countDistinctElementsInTable **/ public function testCountDistinctElementsInTable() { global $DB; //the case of using an element that is not a table is not handle in the function : //testCountElementsInTable($table, $condition="") $this->assertGreaterThan(0, countDistinctElementsInTable('glpi_configs', 'id')); $this->assertGreaterThan(0, countDistinctElementsInTable('glpi_configs', 'context')); $this->assertEquals(1, countDistinctElementsInTable('glpi_configs', 'context', "name = 'version'")); $this->assertEquals(0, countDistinctElementsInTable('glpi_configs', 'id', "context ='fakecontext'")); }