.
* ---------------------------------------------------------------------
*/
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
class Link_Itemtype extends CommonDBChild {
// From CommonDbChild
static public $itemtype = 'Link';
static public $items_id = 'links_id';
/**
* @since 0.84
**/
function getForbiddenStandardMassiveAction() {
$forbidden = parent::getForbiddenStandardMassiveAction();
$forbidden[] = 'update';
return $forbidden;
}
/**
* Print the HTML array for device on link
*
* @param $link : Link
*
* @return void
**/
static function showForLink($link) {
global $DB,$CFG_GLPI;
$links_id = $link->getField('id');
$canedit = $link->canEdit($links_id);
$rand = mt_rand();
if (!Link::canView()
|| !$link->can($links_id, READ)) {
return false;
}
$iterator = $DB->request([
'FROM' => 'glpi_links_itemtypes',
'WHERE' => ['links_id' => $links_id],
'ORDER' => 'itemtype'
]);
$types = [];
$used = [];
$numrows = count($iterator);
while ($data = $iterator->next()) {
$types[$data['id']] = $data;
$used[$data['itemtype']] = $data['itemtype'];
}
if ($canedit) {
echo "
";
}
echo "";
if ($canedit && $numrows) {
Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams = ['num_displayed' => min($_SESSION['glpilist_limit'], $numrows),
'container' => 'mass'.__CLASS__.$rand];
Html::showMassiveActions($massiveactionparams);
}
echo "
";
$header_begin = "";
$header_top = '';
$header_bottom = '';
$header_end = '';
if ($canedit && $numrows) {
$header_top .= "| ".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_top .= " | ";
$header_bottom .= "".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand);
$header_bottom .= " | ";
}
$header_end .= ""._n('Type', 'Types', 1)." | ";
$header_end .= "
";
echo $header_begin.$header_top.$header_end;
foreach ($types as $data) {
$typename = NOT_AVAILABLE;
if ($item = getItemForItemtype($data['itemtype'])) {
$typename = $item->getTypeName(1);
echo "";
if ($canedit) {
echo "| ";
Html::showMassiveActionCheckBox(__CLASS__, $data["id"]);
echo " | ";
}
echo "$typename | ";
echo "
";
}
}
echo $header_begin.$header_bottom.$header_end;
echo "
";
if ($canedit && $numrows) {
$massiveactionparams['ontop'] = false;
Html::showMassiveActions($massiveactionparams);
Html::closeForm();
}
echo "
";
}
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if (!$withtemplate) {
$nb = 0;
switch ($item->getType()) {
case 'Link' :
if ($_SESSION['glpishow_count_on_tabs']) {
$nb = countElementsInTable($this->getTable(),
['links_id' => $item->getID()]);
}
return self::createTabEntry(_n('Associated item type', 'Associated item types',
Session::getPluralNumber()), $nb);
}
}
return '';
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Link') {
self::showForLink($item);
}
return true;
}
/**
*
* Remove all associations for an itemtype
*
* @since 0.85
*
* @param string $itemtype itemtype for which all link associations must be removed
*/
static function deleteForItemtype($itemtype) {
global $DB;
$DB->delete(
self::getTable(), [
'itemtype' => ['LIKE', "%Plugin$itemtype%"]
]
);
}
}