本文整理汇总了PHP中CommonDBTM::canAddItem方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonDBTM::canAddItem方法的具体用法?PHP CommonDBTM::canAddItem怎么用?PHP CommonDBTM::canAddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonDBTM
的用法示例。
在下文中一共展示了CommonDBTM::canAddItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showListForItem
/**
* @since version 0.90
*
* @param $item
* @param $withtemplate (default '')
* @param $options array
*/
static function showListForItem(CommonDBTM $item, $withtemplate = '', $options = array())
{
global $DB, $CFG_GLPI;
//default options
$params['rand'] = mt_rand();
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key] = $val;
}
}
$canedit = $item->canAddItem('Document') && Document::canView();
$columns = array('name' => __('Name'), 'entity' => __('Entity'), 'filename' => __('File'), 'link' => __('Web link'), 'headings' => __('Heading'), 'mime' => __('MIME type'));
if ($CFG_GLPI['use_rich_text']) {
$columns['tag'] = __('Tag');
}
$columns['assocdate'] = __('Date');
if (isset($_GET["order"]) && $_GET["order"] == "ASC") {
$order = "ASC";
} else {
$order = "DESC";
}
if (isset($_GET["sort"]) && !empty($_GET["sort"]) && isset($columns[$_GET["sort"]])) {
$sort = "`" . $_GET["sort"] . "`";
} else {
$sort = "`assocdate`";
}
if (empty($withtemplate)) {
$withtemplate = 0;
}
$linkparam = '';
if (get_class($item) == 'Ticket') {
$linkparam = "&tickets_id=" . $item->fields['id'];
}
$query = "SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`documents_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`items_id` = '" . $item->getID() . "'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`= '0' ";
}
// Document : search links in both order using union
if ($item->getType() == 'Document') {
$query .= "UNION\n SELECT `glpi_documents_items`.`id` AS assocID,\n `glpi_documents_items`.`date_mod` AS assocdate,\n `glpi_entities`.`id` AS entityID,\n `glpi_entities`.`completename` AS entity,\n `glpi_documentcategories`.`completename` AS headings,\n `glpi_documents`.*\n FROM `glpi_documents_items`\n LEFT JOIN `glpi_documents`\n ON (`glpi_documents_items`.`items_id`=`glpi_documents`.`id`)\n LEFT JOIN `glpi_entities`\n ON (`glpi_documents`.`entities_id`=`glpi_entities`.`id`)\n LEFT JOIN `glpi_documentcategories`\n ON (`glpi_documents`.`documentcategories_id`=`glpi_documentcategories`.`id`)\n WHERE `glpi_documents_items`.`documents_id` = '" . $item->getID() . "'\n AND `glpi_documents_items`.`itemtype` = '" . $item->getType() . "' ";
if (Session::getLoginUserID()) {
$query .= getEntitiesRestrictRequest(" AND", "glpi_documents", '', '', true);
} else {
// Anonymous access from FAQ
$query .= " AND `glpi_documents`.`entities_id`='0' ";
}
}
$query .= " ORDER BY {$sort} {$order}";
$result = $DB->query($query);
$number = $DB->numrows($result);
$i = 0;
$documents = array();
$used = array();
if ($numrows = $DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$documents[$data['assocID']] = $data;
$used[$data['id']] = $data['id'];
}
}
echo "<div class='spaced'>";
if ($canedit && $number && $withtemplate < 2) {
Html::openMassiveActionsForm('mass' . __CLASS__ . $params['rand']);
$massiveactionparams = array('num_displayed' => $number, 'container' => 'mass' . __CLASS__ . $params['rand']);
Html::showMassiveActions($massiveactionparams);
}
$sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>";
echo "<table class='tab_cadre_fixehov'>";
$header_begin = "<tr>";
$header_top = '';
$header_bottom = '';
$header_end = '';
if ($canedit && $number && $withtemplate < 2) {
$header_top .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $params['rand']);
$header_top .= "</th>";
$header_bottom .= "<th width='11'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $params['rand']);
$header_bottom .= "</th>";
}
foreach ($columns as $key => $val) {
$header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>";
}
$header_end .= "</tr>";
echo $header_begin . $header_top . $header_end;
$used = array();
if ($number) {
// Don't use this for document associated to document
// To not loose navigation list for current document
if ($item->getType() != 'Document') {
Session::initNavigateListItems('Document', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
}
$document = new Document();
//.........这里部分代码省略.........