Last active
March 20, 2017 14:49
-
-
Save orthagh/f2ace6f39d505dedc5b99b82f352631a to your computer and use it in GitHub Desktop.
superasset_item.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PluginMypluginSuperasset_Item extends CommonDBTM { | |
static function getTypeName($nb=0) { | |
return _n('Item', 'Items', $nb); | |
} | |
/** | |
* Tabs title | |
*/ | |
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { | |
switch ($item->getType()) { | |
case "PluginMypluginSuperasset": | |
$nb = countElementsInTable(self::getTable(), "`plugin_myplugin_superassets_id` = ".$item->getID() | |
); | |
return self::createTabEntry(self::getTypeName($nb), $nb); | |
} | |
return ''; | |
} | |
/** | |
* Display tabs content | |
*/ | |
static function displayTabContentForItem(CommonGLPI $item, | |
$tabnum=1, | |
$withtemplate=0) { | |
switch ($item->getType()) { | |
case "PluginMypluginSuperasset": | |
return self::showForSuperasset($item, $withtemplate); | |
} | |
return true; | |
} | |
/** | |
* Specific function for display only items of Superasset | |
*/ | |
static function showForSuperasset(PluginMypluginSuperasset $superasset, | |
$withtemplate=0) { | |
$ID = $superasset->getID(); | |
$superasset->initForm($ID, []); | |
$superasset->showFormHeader([]); | |
echo "<tr>"; | |
class PluginMypluginSuperasset_Item extends CommonDBTM { | |
static function getTypeName($nb=0) { | |
return _n('Item', 'Items', $nb); | |
} | |
/** | |
* Tabs title | |
*/ | |
function getTabNameForItem(CommonGLPI $item, $withtemplate=0) { | |
switch ($item->getType()) { | |
case "PluginMypluginSuperasset": | |
$nb = countElementsInTable(self::getTable(), "`plugin_myplugin_superassets_id` = ".$item->getID() | |
); | |
return self::createTabEntry(self::getTypeName($nb), $nb); | |
case "Computer": | |
$nb = countElementsInTable(self::getTable(), "`items_id` = ".$item->getID() | |
); | |
return self::createTabEntry(PluginMypluginSuperasset::getTypeName($nb), $nb); | |
} | |
return ''; | |
} | |
/** | |
* Display tabs content | |
*/ | |
static function displayTabContentForItem(CommonGLPI $item, | |
$tabnum=1, | |
$withtemplate=0) { | |
switch ($item->getType()) { | |
case "PluginMypluginSuperasset": | |
return self::showForSuperasset($item, $withtemplate); | |
case "Computer": | |
return self::showForComputer($item, $withtemplate); | |
} | |
return true; | |
} | |
static function showForComputer(Computer $computer, | |
$withtemplate=0) { | |
echo "<h2>".__("List of super assets", 'myplugin')."</h2>"; | |
$superasset_items = new self; | |
$superasset = new PluginMypluginSuperasset; | |
$items = $superasset_items->find("items_id = ".$computer->GetID()); | |
echo "<table class='tab_cadre_fixe'>"; | |
foreach($items as $item) { | |
$superasset->getFromDB($item['plugin_myplugin_superassets_id']); | |
echo "<tr><td>".$superasset->getName()."</td></tr>"; | |
} | |
echo "</table>"; | |
echo "<br>"; | |
} | |
/** | |
* Specific function for display only items of Superasset | |
*/ | |
static function showForSuperasset(PluginMypluginSuperasset $superasset, | |
$withtemplate=0) { | |
$ID = $superasset->getID(); | |
$superasset->initForm($ID, []); | |
$superasset->showFormHeader([]); | |
echo "<tr>"; | |
echo "<td>Computer to associate: </td>"; | |
echo "<td>"; | |
Dropdown::show('Computer', [ | |
'name' => 'items_id' | |
]); | |
echo "</td>"; | |
echo "</tr><tr>"; | |
echo "<td>"; | |
echo Html::hidden("itemtype", ['value' => 'Computer']); | |
echo Html::hidden("plugin_myplugin_superassets_id", ['value' => $ID]); | |
echo Html::submit("Associate", ['name' => 'associate']); | |
echo "</td></tr>"; | |
echo "</table>"; | |
echo "</div>"; | |
Html::closeForm(); | |
echo "<h2>".__("List of associated items", 'myplugin')."</h2>"; | |
$superasset_items = new self; | |
$computer = new Computer; | |
$items = $superasset_items->find("plugin_myplugin_superassets_id = $ID"); | |
echo "<table class='tab_cadre_fixe'>"; | |
foreach($items as $item) { | |
$computer->getFromDB($item['items_id']); | |
echo "<tr><td>".$computer->getName()."</td></tr>"; | |
} | |
echo "</table>"; | |
echo "<br>"; | |
} | |
} | |
... | |
else if (isset($_POST["associate"])) { | |
$item = new PluginMypluginSuperasset_Item(); | |
$newID = $item->add($_POST); | |
Html::back(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment