本文整理汇总了PHP中CommonDBTM::haveChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP CommonDBTM::haveChildren方法的具体用法?PHP CommonDBTM::haveChildren怎么用?PHP CommonDBTM::haveChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommonDBTM
的用法示例。
在下文中一共展示了CommonDBTM::haveChildren方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showListForItem
/**
* Display tickets for an item
*
* Will also display tickets of linked items
*
* @param $item CommonDBTM object
*
* @return nothing (display a table)
**/
static function showListForItem(CommonDBTM $item)
{
global $DB, $CFG_GLPI;
if (!Session::haveRightsOr(self::$rightname, array(self::READALL, self::READMY, self::READASSIGN, CREATE))) {
return false;
}
if ($item->isNewID($item->getID())) {
return false;
}
$restrict = '';
$order = '';
$options['reset'] = 'reset';
switch ($item->getType()) {
case 'User':
$restrict = "(`glpi_tickets_users`.`users_id` = '" . $item->getID() . "' " . " AND `glpi_tickets_users`.`type` = " . CommonITILActor::REQUESTER . ")";
$order = '`glpi_tickets`.`date_mod` DESC';
$options['reset'] = 'reset';
$options['criteria'][0]['field'] = 4;
// status
$options['criteria'][0]['searchtype'] = 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'AND';
break;
case 'SLT':
$restrict = "`slts_tto_id` = '" . $item->getID() . "'\n OR `slts_ttr_id` = '" . $item->getID() . "'";
$order = '`glpi_tickets`.`due_date` DESC';
$options['criteria'][0]['field'] = 30;
$options['criteria'][0]['searchtype'] = 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'AND';
break;
case 'Supplier':
$restrict = "(`glpi_suppliers_tickets`.`suppliers_id` = '" . $item->getID() . "' " . " AND `glpi_suppliers_tickets`.`type` = " . CommonITILActor::ASSIGN . ")";
$order = '`glpi_tickets`.`date_mod` DESC';
$options['criteria'][0]['field'] = 6;
$options['criteria'][0]['searchtype'] = 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'AND';
break;
case 'Group':
// Mini search engine
if ($item->haveChildren()) {
$tree = Session::getSavedOption(__CLASS__, 'tree', 0);
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'><th>" . __('Last tickets') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='center'>";
echo __('Child groups') . " ";
Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
} else {
$tree = 0;
}
echo "</td></tr></table>";
if ($tree) {
$restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
} else {
$restrict = "='" . $item->getID() . "'";
}
$restrict = "(`glpi_groups_tickets`.`groups_id` {$restrict}" . " AND `glpi_groups_tickets`.`type` = " . CommonITILActor::REQUESTER . ")";
$order = '`glpi_tickets`.`date_mod` DESC';
$options['criteria'][0]['field'] = 71;
$options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'AND';
break;
default:
$restrict = "(`glpi_items_tickets`.`items_id` = '" . $item->getID() . "' " . " AND `glpi_items_tickets`.`itemtype` = '" . $item->getType() . "')";
// you can only see your tickets
if (!Session::haveRight(self::$rightname, self::READALL)) {
$restrict .= " AND (`glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'\n OR (`glpi_tickets_users`.`tickets_id` = '" . $item->getID() . "'\n AND `glpi_tickets_users`.`users_id`\n = '" . Session::getLoginUserID() . "'))";
}
$order = '`glpi_tickets`.`date_mod` DESC';
$options['criteria'][0]['field'] = 12;
$options['criteria'][0]['searchtype'] = 'equals';
$options['criteria'][0]['value'] = 'all';
$options['criteria'][0]['link'] = 'AND';
$options['metacriteria'][0]['itemtype'] = $item->getType();
$options['metacriteria'][0]['field'] = Search::getOptionNumber($item->getType(), 'id');
$options['metacriteria'][0]['searchtype'] = 'equals';
$options['metacriteria'][0]['value'] = $item->getID();
$options['metacriteria'][0]['link'] = 'AND';
break;
}
$query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_tickets` " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_tickets") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']);
$result = $DB->query($query);
$number = $DB->numrows($result);
$colspan = 11;
if (count($_SESSION["glpiactiveentities"]) > 1) {
$colspan++;
}
// Ticket for the item
echo "<div class='firstbloc'>";
//.........这里部分代码省略.........
示例2: showListForItem
/**
* Display changes for an item
*
* Will also display changes of linked items
*
* @param $item CommonDBTM object
*
* @return nothing (display a table)
**/
static function showListForItem(CommonDBTM $item)
{
global $DB, $CFG_GLPI;
if (!Session::haveRight(self::$rightname, self::READALL)) {
return false;
}
if ($item->isNewID($item->getID())) {
return false;
}
$restrict = '';
$order = '';
$options['reset'] = 'reset';
switch ($item->getType()) {
case 'User':
$restrict = "(`glpi_changes_users`.`users_id` = '" . $item->getID() . "')";
$order = '`glpi_changes`.`date_mod` DESC';
$options['criteria'][0]['field'] = 4;
// status
$options['criteria'][0]['searchtype'] = 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'OR';
$options['criteria'][1]['field'] = 66;
// status
$options['criteria'][1]['searchtype'] = 'equals';
$options['criteria'][1]['value'] = $item->getID();
$options['criteria'][1]['link'] = 'OR';
$options['criteria'][5]['field'] = 5;
// status
$options['criteria'][5]['searchtype'] = 'equals';
$options['criteria'][5]['value'] = $item->getID();
$options['criteria'][5]['link'] = 'OR';
break;
case 'Supplier':
$restrict = "(`glpi_changes_suppliers`.`suppliers_id` = '" . $item->getID() . "')";
$order = '`glpi_changes`.`date_mod` DESC';
$options['criteria'][0]['field'] = 6;
$options['criteria'][0]['searchtype'] = 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'AND';
break;
case 'Group':
// Mini search engine
if ($item->haveChildren()) {
$tree = Session::getSavedOption(__CLASS__, 'tree', 0);
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_1'><th>" . __('Last changes') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='center'>";
_e('Child groups');
Dropdown::showYesNo('tree', $tree, -1, array('on_change' => 'reloadTab("start=0&tree="+this.value)'));
} else {
$tree = 0;
}
echo "</td></tr></table>";
if ($tree) {
$restrict = "IN (" . implode(',', getSonsOf('glpi_groups', $item->getID())) . ")";
} else {
$restrict = "='" . $item->getID() . "'";
}
$restrict = "(`glpi_changes_groups`.`groups_id` {$restrict}\n AND `glpi_changes_groups`.`type` = " . CommonITILActor::REQUESTER . ")";
$order = '`glpi_changes`.`date_mod` DESC';
$options['criteria'][0]['field'] = 71;
$options['criteria'][0]['searchtype'] = $tree ? 'under' : 'equals';
$options['criteria'][0]['value'] = $item->getID();
$options['criteria'][0]['link'] = 'AND';
break;
default:
$restrict = "(`items_id` = '" . $item->getID() . "'\n AND `itemtype` = '" . $item->getType() . "')";
$order = '`glpi_changes`.`date_mod` DESC';
break;
}
$query = "SELECT " . self::getCommonSelect() . "\n FROM `glpi_changes`\n LEFT JOIN `glpi_changes_items`\n ON (`glpi_changes`.`id` = `glpi_changes_items`.`changes_id`) " . self::getCommonLeftJoin() . "\n WHERE {$restrict} " . getEntitiesRestrictRequest("AND", "glpi_changes") . "\n ORDER BY {$order}\n LIMIT " . intval($_SESSION['glpilist_limit']);
$result = $DB->query($query);
$number = $DB->numrows($result);
// Ticket for the item
echo "<div class='firstbloc'><table class='tab_cadre_fixe'>";
$colspan = 11;
if (count($_SESSION["glpiactiveentities"]) > 1) {
$colspan++;
}
if ($number > 0) {
Session::initNavigateListItems('Change', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
echo "<tr><th colspan='{$colspan}'>";
//TRANS : %d is the number of problems
echo sprintf(_n('Last %d change', 'Last %d changes', $number), $number);
// echo "<span class='small_space'><a href='".$CFG_GLPI["root_doc"]."/front/ticket.php?".
// Toolbox::append_params($options,'&')."'>".__('Show all')."</a></span>";
echo "</th></tr>";
} else {
echo "<tr><th>" . __('No change found.') . "</th></tr>";
}
// Ticket list
//.........这里部分代码省略.........
示例3: processMassiveActionsForOneItemtype
/**
* @see CommonDBTM::processMassiveActionsForOneItemtype()
**/
static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
{
global $CFG_GLPI;
$action = $ma->getAction();
switch ($action) {
case 'delete':
foreach ($ids as $id) {
if ($item->can($id, DELETE)) {
if ($item->delete(array("id" => $id))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'restore':
foreach ($ids as $id) {
if ($item->can($id, PURGE)) {
if ($item->restore(array("id" => $id))) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'purge_item_but_devices':
case 'purge_but_item_linked':
case 'purge':
foreach ($ids as $id) {
if ($item->can($id, PURGE)) {
$force = 1;
// Only mark deletion for
if ($item->maybeDeleted() && $item->useDeletedToLockIfDynamic() && $item->isDynamic()) {
$force = 0;
}
$delete_array = array('id' => $id);
if ($action == 'purge_item_but_devices') {
$delete_array['keep_devices'] = true;
}
if ($item instanceof CommonDropdown) {
if ($item->haveChildren()) {
if ($action != 'purge_but_item_linked') {
$force = 0;
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage(__("You can't delete that item by massive actions, because it has sub-items"));
$ma->addMessage(__("but you can do it by the form of the item"));
continue;
}
}
if ($item->isUsed()) {
if ($action != 'purge_but_item_linked') {
$force = 0;
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage(__("You can't delete that item, because it is used for one or more items"));
$ma->addMessage(__("but you can do it by the form of the item"));
continue;
}
}
}
if ($item->delete($delete_array, $force)) {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
} else {
$ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
$ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
}
}
break;
case 'update':
if (!isset($ma->POST['search_options']) || !isset($ma->POST['search_options'][$item->getType()])) {
return false;
}
$index = $ma->POST['search_options'][$item->getType()];
$searchopt = Search::getCleanedOptions($item->getType(), UPDATE);
$input = $ma->POST;
if (isset($searchopt[$index])) {
/// Infocoms case
if (!isPluginItemType($item->getType()) && Search::isInfocomOption($item->getType(), $index)) {
$ic = new Infocom();
$link_entity_type = -1;
/// Specific entity item
if ($searchopt[$index]["table"] == "glpi_suppliers") {
$ent = new Supplier();
if ($ent->getFromDB($input[$input["field"]])) {
//.........这里部分代码省略.........