本文整理汇总了PHP中Alert::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Alert::delete方法的具体用法?PHP Alert::delete怎么用?PHP Alert::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alert
的用法示例。
在下文中一共展示了Alert::delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* Get alerts.
*
* <code>
* // Get all alerts
* $messages = Alert::get();
*
* // Get error alerts
* $error_messages = Alert::get(Alert::ERROR);
*
* // Get error and alert alerts
* $messages = Alert::get(array(Alert::ERROR, Alert::ALERT));
* </code>
*
* @param mixed $type alert type (e.g. Alert::SUCCESS, array(Alert::ERROR, Alert::ALERT))
* @param bool $delete delete the alerts?
*
* @return array
*
* @uses Session::instance
*/
public static function get($type = null, $delete = false)
{
$alerts = Session::instance()->get(Alert::$_session_key);
if ($alerts === null) {
return array();
}
if ($type !== null) {
// Will hold the filtered set of alerts to return
$return = array();
// Store the remainder in case `delete` or `get_once` is called
$remainder = array();
foreach ($alerts as $alert) {
if ($alert['type'] === $type or is_array($type) and in_array($alert['type'], $type)) {
$return[] = $alert;
} else {
$remainder[] = $alert;
}
}
if (empty($return)) {
// No alerts of '$type' to return
return array();
}
$alerts = $return;
}
if ($delete === true) {
if (empty($remainder) or $type === null) {
// Nothing to save, delete the key from memory
Alert::delete();
} else {
// Override alerts with the remainder to simulate a deletion
Session::instance()->set(Alert::$_session_key, $remainder);
}
}
return $alerts;
}
示例2: cronConsumable
/**
* Cron action on consumables : alert if a stock is behind the threshold
*
* @param $task to log, if NULL display (default NULL)
*
* @return 0 : nothing to do 1 : done with success
**/
static function cronConsumable($task = NULL)
{
global $DB, $CFG_GLPI;
$cron_status = 1;
if ($CFG_GLPI["use_mailing"]) {
$message = array();
$items = array();
$alert = new Alert();
foreach (Entity::getEntitiesToNotify('consumables_alert_repeat') as $entity => $repeat) {
$query_alert = "SELECT `glpi_consumableitems`.`id` AS consID,\n `glpi_consumableitems`.`entities_id` AS entity,\n `glpi_consumableitems`.`ref` AS ref,\n `glpi_consumableitems`.`name` AS name,\n `glpi_consumableitems`.`alarm_threshold` AS threshold,\n `glpi_alerts`.`id` AS alertID,\n `glpi_alerts`.`date`\n FROM `glpi_consumableitems`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_consumableitems`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype`='ConsumableItem')\n WHERE `glpi_consumableitems`.`is_deleted` = '0'\n AND `glpi_consumableitems`.`alarm_threshold` >= '0'\n AND `glpi_consumableitems`.`entities_id` = '" . $entity . "'\n AND (`glpi_alerts`.`date` IS NULL\n OR (`glpi_alerts`.date+{$repeat}) < CURRENT_TIMESTAMP());";
$message = "";
$items = array();
foreach ($DB->request($query_alert) as $consumable) {
if (($unused = Consumable::getUnusedNumber($consumable["consID"])) <= $consumable["threshold"]) {
// define message alert
//TRANS: %1$s is the consumable name, %2$s its reference, %3$d the remaining number
$message .= sprintf(__('Threshold of alarm reached for the type of consumable: %1$s - Reference %2$s - Remaining %3$d'), $consumable['name'], $consumable['ref'], $unused);
$message .= '<br>';
$items[$consumable["consID"]] = $consumable;
// if alert exists -> delete
if (!empty($consumable["alertID"])) {
$alert->delete(array("id" => $consumable["alertID"]));
}
}
}
if (!empty($items)) {
$options['entities_id'] = $entity;
$options['items'] = $items;
if (NotificationEvent::raiseEvent('alert', new ConsumableItem(), $options)) {
if ($task) {
$task->log(Dropdown::getDropdownName("glpi_entities", $entity) . " : {$message}\n");
$task->addVolume(1);
} else {
Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . " : {$message}");
}
$input["type"] = Alert::THRESHOLD;
$input["itemtype"] = 'ConsumableItem';
// add alerts
foreach ($items as $ID => $consumable) {
$input["items_id"] = $ID;
$alert->add($input);
unset($alert->fields['id']);
}
} else {
$entityname = Dropdown::getDropdownName('glpi_entities', $entity);
//TRANS: %s is entity name
$msg = sprintf(__('%s: send consumable alert failed'), $entityname);
if ($task) {
$task->log($msg);
} else {
Session::addMessageAfterRedirect($msg, false, ERROR);
}
}
}
}
}
return $cron_status;
}
示例3: cronCartridge
/**
* Cron action on cartridges : alert if a stock is behind the threshold
*
* @param $task for log, display informations if NULL?
*
* @return 0 : nothing to do 1 : done with success
*
**/
static function cronCartridge($task = NULL)
{
global $DB, $CFG_GLPI, $LANG;
$cron_status = 1;
if ($CFG_GLPI["use_mailing"]) {
$message = array();
$alert = new Alert();
foreach (Entity::getEntitiesToNotify('cartridges_alert_repeat') as $entity => $repeat) {
// if you change this query, please don't forget to also change in showDebug()
$query_alert = "SELECT `glpi_cartridgeitems`.`id` AS cartID,\n `glpi_cartridgeitems`.`entities_id` AS entity,\n `glpi_cartridgeitems`.`ref` AS cartref,\n `glpi_cartridgeitems`.`name` AS cartname,\n `glpi_cartridgeitems`.`alarm_threshold` AS threshold,\n `glpi_alerts`.`id` AS alertID,\n `glpi_alerts`.`date`\n FROM `glpi_cartridgeitems`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_cartridgeitems`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'CartridgeItem')\n WHERE `glpi_cartridgeitems`.`is_deleted` = '0'\n AND `glpi_cartridgeitems`.`alarm_threshold` >= '0'\n AND `glpi_cartridgeitems`.`entities_id` = '" . $entity . "'\n AND (`glpi_alerts`.`date` IS NULL\n OR (`glpi_alerts`.date+{$repeat}) < CURRENT_TIMESTAMP());";
$message = "";
$items = array();
foreach ($DB->request($query_alert) as $cartridge) {
if (($unused = Cartridge::getUnusedNumber($cartridge["cartID"])) <= $cartridge["threshold"]) {
// define message alert
$message .= $LANG['mailing'][35] . " " . $cartridge["cartname"] . " - " . $LANG['consumables'][2] . " : " . $cartridge["cartref"] . " - " . $LANG['software'][20] . " : " . $unused . "<br>";
$items[$cartridge["cartID"]] = $cartridge;
// if alert exists -> delete
if (!empty($cartridge["alertID"])) {
$alert->delete(array("id" => $cartridge["alertID"]));
}
}
}
if (!empty($items)) {
$options['entities_id'] = $entity;
$options['cartridges'] = $items;
if (NotificationEvent::raiseEvent('alert', new Cartridge(), $options)) {
if ($task) {
$task->log(Dropdown::getDropdownName("glpi_entities", $entity) . " : {$message}\n");
$task->addVolume(1);
} else {
addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . " : {$message}");
}
$input["type"] = Alert::THRESHOLD;
$input["itemtype"] = 'CartridgeItem';
// add alerts
foreach ($items as $ID => $consumable) {
$input["items_id"] = $ID;
$alert->add($input);
unset($alert->fields['id']);
}
} else {
if ($task) {
$task->log(Dropdown::getDropdownName("glpi_entities", $entity) . " : Send cartidge alert failed\n");
} else {
addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . " : Send cartidge alert failed", false, ERROR);
}
}
}
}
}
}