本文整理汇总了PHP中getItemForItemtype函数的典型用法代码示例。如果您正苦于以下问题:PHP getItemForItemtype函数的具体用法?PHP getItemForItemtype怎么用?PHP getItemForItemtype使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getItemForItemtype函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canUpdateItem
function canUpdateItem()
{
if (isset($this->fields['itemtype']) && ($item = getItemForItemtype($this->fields['itemtype']))) {
return Session::haveRight($item::$rightname, UPDATENOTE);
}
return false;
}
示例2: beforeAdd
static function beforeAdd(Ticket $ticket)
{
global $DB;
if (!is_array($ticket->input) || !count($ticket->input)) {
// Already cancel by another plugin
return false;
}
//Toolbox::logDebug("PluginBehaviorsTicket::beforeAdd(), Ticket=", $ticket);
$config = PluginBehaviorsConfig::getInstance();
if ($config->getField('tickets_id_format')) {
$max = 0;
$sql = 'SELECT MAX( id ) AS max
FROM `glpi_tickets`';
foreach ($DB->request($sql) as $data) {
$max = $data['max'];
}
$want = date($config->getField('tickets_id_format'));
if ($max < $want) {
$DB->query("ALTER TABLE `glpi_tickets` AUTO_INCREMENT={$want}");
}
}
if (!isset($ticket->input['_auto_import']) && isset($_SESSION['glpiactiveprofile']['interface']) && $_SESSION['glpiactiveprofile']['interface'] == 'central') {
if ($config->getField('is_requester_mandatory') && !$ticket->input['_users_id_requester'] && (!isset($ticket->input['_users_id_requester_notif']['alternative_email']) || empty($ticket->input['_users_id_requester_notif']['alternative_email']))) {
Session::addMessageAfterRedirect(__('Requester is mandatory', 'behaviors'), true, ERROR);
$ticket->input = array();
return true;
}
}
if ($config->getField('use_requester_item_group') && isset($ticket->input['itemtype']) && isset($ticket->input['items_id']) && $ticket->input['items_id'] > 0 && ($item = getItemForItemtype($ticket->input['itemtype'])) && (!isset($ticket->input['_groups_id_requester']) || $ticket->input['_groups_id_requester'] <= 0)) {
if ($item->isField('groups_id') && $item->getFromDB($ticket->input['items_id'])) {
$ticket->input['_groups_id_requester'] = $item->getField('groups_id');
}
}
// No Auto set Import for external source -> Duplicate from Ticket->prepareInputForAdd()
if (!isset($ticket->input['_auto_import'])) {
if (!isset($ticket->input['_users_id_requester'])) {
if ($uid = Session::getLoginUserID()) {
$ticket->input['_users_id_requester'] = $uid;
}
}
}
if ($config->getField('use_requester_user_group') && isset($ticket->input['_users_id_requester']) && $ticket->input['_users_id_requester'] > 0 && (!isset($ticket->input['_groups_id_requester']) || $ticket->input['_groups_id_requester'] <= 0)) {
if ($config->getField('use_requester_user_group') == 1) {
// First group
$ticket->input['_groups_id_requester'] = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], true);
} else {
// All groups
$g = PluginBehaviorsUser::getRequesterGroup($ticket->input['entities_id'], $ticket->input['_users_id_requester'], false);
if (count($g)) {
$ticket->input['_groups_id_requester'] = array_shift($g);
}
if (count($g)) {
$ticket->input['_additional_groups_requesters'] = $g;
}
}
}
// Toolbox::logDebug("PluginBehaviorsTicket::beforeAdd(), Updated input=", $ticket->input);
}
示例3: replayRulesOnExistingDB
/**
* @see RuleCollection::replayRulesOnExistingDB()
**/
function replayRulesOnExistingDB($offset = 0, $maxtime = 0, $items = array(), $params = array())
{
global $DB;
// Model check : need to check using manufacturer extra data so specific function
if (strpos($this->item_table, 'models')) {
return $this->replayRulesOnExistingDBForModel($offset, $maxtime);
}
if (isCommandLine()) {
printf(__('Replay rules on existing database started on %s') . "\n", date("r"));
}
// Get All items
$Sql = "SELECT *\n FROM `" . $this->item_table . "`";
if ($offset) {
$Sql .= " LIMIT " . intval($offset) . ",999999999";
}
$result = $DB->query($Sql);
$nb = $DB->numrows($result) + $offset;
$i = $offset;
if ($result && $nb > $offset) {
// Step to refresh progressbar
$step = $nb > 20 ? floor($nb / 20) : 1;
$send = array();
$send["tablename"] = $this->item_table;
while ($data = $DB->fetch_assoc($result)) {
if (!($i % $step)) {
if (isCommandLine()) {
//TRANS: %1$s is a row, %2$s is total rows
printf(__('Replay rules on existing database: %1$s/%2$s') . "\r", $i, $nb);
} else {
Html::changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
}
}
//Replay Type dictionnary
$ID = Dropdown::importExternal(getItemTypeForTable($this->item_table), addslashes($data["name"]), -1, array(), addslashes($data["comment"]));
if ($data['id'] != $ID) {
$tomove[$data['id']] = $ID;
$type = GetItemTypeForTable($this->item_table);
if ($dropdown = getItemForItemtype($type)) {
$dropdown->delete(array('id' => $data['id'], '_replace_by' => $ID));
}
}
$i++;
if ($maxtime) {
$crt = explode(" ", microtime());
if ($crt[0] + $crt[1] > $maxtime) {
break;
}
}
}
// end while
}
if (isCommandLine()) {
printf(__('Replay rules on existing database started on %s') . "\n", date("r"));
} else {
Html::changeProgressBarPosition($i, $nb, "{$i} / {$nb}");
}
return $i == $nb ? -1 : $i;
}
示例4: getSubName
function getSubName()
{
$itemtype = $this->getParameterValue();
if ($itemtype && ($item = getItemForItemtype($itemtype))) {
$name = $item->getTypeName();
} else {
// All
return '';
}
return " " . $this->getCriteriaLabel() . " : " . $name;
}
示例5: __construct
function __construct($name, $title, $itemtype, $options = array())
{
parent::__construct($name, $title, $options);
$this->obj = getItemForItemtype($itemtype);
if (isset($options['with_comment'])) {
$this->with_comment = $options['with_comment'];
}
if (isset($options['with_navigate'])) {
$this->with_navigate = $options['with_navigate'];
Session::initNavigateListItems($this->obj->getType(), _n('Report', 'Reports', 2));
}
}
示例6: surveilleResa
static function surveilleResa($task)
{
global $DB, $CFG_GLPI;
$valreturn = 0;
$temps = time();
$temps -= $temps % MINUTE_TIMESTAMP;
$begin = date("Y-m-d H:i:s", $temps);
$end = date("Y-m-d H:i:s", $temps + 5 * MINUTE_TIMESTAMP);
$left = "";
$where = "";
$listResaTraitee = array();
foreach ($CFG_GLPI["reservation_types"] as $itemtype) {
if (!($item = getItemForItemtype($itemtype))) {
continue;
}
$itemtable = getTableForItemType($itemtype);
$otherserial = "'' AS otherserial";
if ($item->isField('otherserial')) {
$otherserial = "`{$itemtable}`.`otherserial`";
}
if (isset($begin) && isset($end)) {
$left = "LEFT JOIN `glpi_reservations`\n ON (`glpi_reservationitems`.`id` = `glpi_reservations`.`reservationitems_id`\n AND '" . $begin . "' <= `glpi_reservations`.`end`\n AND '" . $end . "' >= `glpi_reservations`.`end`)";
$where = " AND `glpi_reservations`.`id` IS NOT NULL ";
}
$query = "SELECT `glpi_reservationitems`.`id`,\n`glpi_reservationitems`.`comment`,\n`{$itemtable}`.`name` AS name,\n`{$itemtable}`.`entities_id` AS entities_id,\n{$otherserial},\n`glpi_reservations`.`id` AS resaid,\n`glpi_reservations`.`comment`,\n`glpi_reservations`.`begin`,\n`glpi_reservations`.`end`,\n`glpi_users`.`name` AS username,\n`glpi_reservationitems`.`items_id` AS items_id\nFROM `glpi_reservationitems`\n{$left}\nINNER JOIN `{$itemtable}`\nON (`glpi_reservationitems`.`itemtype` = '{$itemtype}'\n AND `glpi_reservationitems`.`items_id` = `{$itemtable}`.`id`)\nLEFT JOIN `glpi_users` \nON (`glpi_reservations`.`users_id` = `glpi_users`.`id`)\nWHERE `glpi_reservationitems`.`is_active` = '1'\nAND `glpi_reservationitems`.`is_deleted` = '0'\nAND `{$itemtable}`.`is_deleted` = '0'\n{$where} " . "ORDER BY username,\n`{$itemtable}`.`entities_id`,\n`{$itemtable}`.`name`";
if ($result = $DB->query($query)) {
while ($row = $DB->fetch_assoc($result)) {
$query = "SELECT * FROM `glpi_plugin_reservation_manageresa` WHERE `resaid` = " . $row["resaid"];
//on insere la reservation seulement si elle n'est pas deja presente dans la table
if ($res = $DB->query($query)) {
if (!$DB->numrows($res)) {
$query = "INSERT INTO `glpi_plugin_reservation_manageresa` (`resaid`, `matid`, `date_theorique`, `itemtype`) VALUES ('" . $row["resaid"] . "','" . $row["items_id"] . "','" . $row['end'] . "','" . $itemtype . "');";
$DB->query($query) or die("error on 'insert' into glpi_plugin_reservation_manageresa lors du cron/ hash: " . $DB->error());
}
}
}
}
}
//on va prolonger toutes les resa managées qui n'ont pas de date de retour
$query = "SELECT * FROM `glpi_plugin_reservation_manageresa` WHERE date_return is NULL;";
if ($result = $DB->query($query)) {
while ($row = $DB->fetch_assoc($result)) {
$newEnd = $temps + 5 * MINUTE_TIMESTAMP;
$task->log("prolongation de la reservation numero " . $row['resaid']);
// prolongation de la vrai resa
self::verifDisponibiliteAndMailIGS($task, $row['itemtype'], $row['matid'], $row['resaid'], $begin, date("Y-m-d H:i:s", $newEnd));
$query = "UPDATE `glpi_reservations` SET `end`='" . date("Y-m-d H:i:s", $newEnd) . "' WHERE `id`='" . $row["resaid"] . "';";
$DB->query($query) or die("error on 'update' into glpi_reservations lors du cron : " . $DB->error());
$valreturn++;
}
}
return $valreturn;
}
示例7: displayValue
function displayValue($output_type, $row)
{
if (!isset($row[$this->name]) || !$row[$this->name]) {
return '';
}
if (!($value = getItemForItemtype($row[$this->name]))) {
return $value;
}
if (is_null($this->obj) || get_class($this->obj) != $row[$this->name]) {
$this->obj = new $row[$this->name]();
}
return $this->obj->getTypeName();
}
示例8: showPreferences
static function showPreferences()
{
global $DB, $CFG_GLPI, $PLUGIN_HOOKS;
$target = Toolbox::getItemTypeFormURL(__CLASS__);
$pref = new self();
echo "<div class='center' id='pdf_type'>";
foreach ($PLUGIN_HOOKS['plugin_pdf'] as $type => $plug) {
if (!($item = getItemForItemtype($type))) {
continue;
}
if ($item->canView()) {
$pref->menu($item, $target);
}
}
echo "</div>";
}
示例9: displayValue
function displayValue($output_type, $row)
{
if (!isset($row[$this->name]) || !$row[$this->name]) {
return '';
}
if (isset($row[$this->nametype]) && $row[$this->nametype] && (is_null($this->obj) || $this->obj->getType() != $row[$this->nametype])) {
if (!($this->obj = getItemForItemtype($row[$this->nametype]))) {
$this->obj = NULL;
}
}
if (!$this->obj || !$this->obj->getFromDB($row[$this->name])) {
return 'ID #' . $row[$this->name];
}
if ($output_type == Search::HTML_OUTPUT) {
return $this->obj->getLink($this->with_comment);
}
return $this->obj->getNameID();
}
示例10: getDatasForTemplate
/**
* Get all data needed for template processing
*
* @param $event
* @param $options array
**/
function getDatasForTemplate($event, $options = array())
{
$events = $this->getAllEvents();
$this->datas['##infocom.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
$this->datas['##infocom.action##'] = $events[$event];
foreach ($options['items'] as $id => $item) {
$tmp = array();
if ($obj = getItemForItemtype($item['itemtype'])) {
$tmp['##infocom.itemtype##'] = $obj->getTypeName(1);
$tmp['##infocom.item##'] = $item['item_name'];
$tmp['##infocom.expirationdate##'] = $item['warrantyexpiration'];
$tmp['##infocom.url##'] = $this->formatURL($options['additionnaloption']['usertype'], $item['itemtype'] . "_" . $item['items_id'] . "_Infocom");
}
$this->datas['infocoms'][] = $tmp;
}
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->datas[$tag])) {
$this->datas[$tag] = $values['label'];
}
}
}
示例11: getDatasForTemplate
/**
* Get all data needed for template processing
*
* @param $event
* @param $options array
**/
function getDatasForTemplate($event, $options = array())
{
global $CFG_GLPI;
$events = $this->getAllEvents();
$this->datas['##infocom.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
$this->datas['##infocom.action##'] = $events[$event];
foreach ($options['items'] as $id => $item) {
$tmp = array();
if ($obj = getItemForItemtype($item['itemtype'])) {
$tmp['##infocom.itemtype##'] = $obj->getTypeName(1);
$tmp['##infocom.item##'] = $item['item_name'];
$tmp['##infocom.expirationdate##'] = $item['warrantyexpiration'];
$tmp['##infocom.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=" . strtolower($item['itemtype']) . "_" . $item['items_id'] . "_Infocom");
}
$this->datas['infocoms'][] = $tmp;
}
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->datas[$tag])) {
$this->datas[$tag] = $values['label'];
}
}
}
示例12: getDatasForTemplate
/**
* Get all data needed for template processing
*
* @param $event
* @param $options array
**/
function getDatasForTemplate($event, $options = array())
{
//User who tries to add or update an item in DB
$action = $options['action_user'] ? __('Add the item') : __('Update the item');
$this->datas['##unicity.action_type##'] = $action;
$this->datas['##unicity.action_user##'] = $options['action_user'];
$this->datas['##unicity.date##'] = Html::convDateTime($options['date']);
if ($item = getItemForItemtype($options['itemtype'])) {
$this->datas['##unicity.itemtype##'] = $item->getTypeName(1);
$this->datas['##unicity.message##'] = Html::clean($item->getUnicityErrorMessage($options['label'], $options['field'], $options['double']));
}
$this->datas['##unicity.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']);
if ($options['refuse']) {
$this->datas['##unicity.action##'] = __('Record into the database denied');
} else {
$this->datas['##unicity.action##'] = __('Item successfully added but duplicate record on');
}
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
if (!isset($this->datas[$tag])) {
$this->datas[$tag] = $values['label'];
}
}
}
示例13: getHelpdeskItemtypes
/**
* @since version 0.85
**/
static function getHelpdeskItemtypes()
{
global $CFG_GLPI;
$values = array();
foreach ($CFG_GLPI["ticket_types"] as $key => $itemtype) {
if ($item = getItemForItemtype($itemtype)) {
$values[$itemtype] = $item->getTypeName();
} else {
unset($CFG_GLPI["ticket_types"][$key]);
}
}
return $values;
}
示例14: key
if (isset($_POST["sub_type"]) && class_exists($_POST["sub_type"])) {
if (!isset($_POST["field"])) {
$_POST["field"] = key(Rule::getActionsByType($_POST["sub_type"]));
}
if (!($item = getItemForItemtype($_POST["sub_type"]))) {
exit;
}
if (!isset($_POST[$item->getRuleIdField()])) {
exit;
}
// Existing action
if ($_POST['ruleactions_id'] > 0) {
$already_used = false;
} else {
// New action
$ra = getItemForItemtype($item->getRuleActionClass());
$used = $ra->getAlreadyUsedForRuleID($_POST[$item->getRuleIdField()], $item->getType());
$already_used = in_array($_POST["field"], $used);
}
echo "<table width='100%'><tr><td width='30%'>";
$action_type = '';
if (isset($_POST["action_type"])) {
$action_type = $_POST["action_type"];
}
$randaction = RuleAction::dropdownActions(array('subtype' => $_POST["sub_type"], 'name' => "action_type", 'field' => $_POST["field"], 'value' => $action_type, 'alreadyused' => $already_used));
echo "</td><td>";
echo "<span id='action_type_span{$randaction}'>\n";
echo "</span>\n";
$paramsaction = array('action_type' => '__VALUE__', 'field' => $_POST["field"], 'sub_type' => $_POST["sub_type"], $item->getForeignKeyField() => $_POST[$item->getForeignKeyField()]);
Ajax::updateItemOnSelectEvent("dropdown_action_type{$randaction}", "action_type_span{$randaction}", $CFG_GLPI["root_doc"] . "/ajax/ruleactionvalue.php", $paramsaction);
if (isset($_POST['value'])) {
示例15: getInstantiation
/**
* \brief get the instantiation of the current NetworkPort
* The instantiation rely on the instantiation_type field and the id of the NetworkPort. If the
* network port exists, but not its instantiation, then, the instantiation will be empty.
*
* @since version 0.84
*
* @return the instantiation object or false if the type of instantiation is not known
**/
function getInstantiation()
{
if (isset($this->fields['instantiation_type']) && in_array($this->fields['instantiation_type'], self::getNetworkPortInstantiations())) {
if ($instantiation = getItemForItemtype($this->fields['instantiation_type'])) {
if (!$instantiation->getFromDB($this->getID())) {
if (!$instantiation->getEmpty()) {
unset($instantiation);
return false;
}
}
return $instantiation;
}
}
return false;
}