本文整理汇总了PHP中Contract_Item::getItemsForContract方法的典型用法代码示例。如果您正苦于以下问题:PHP Contract_Item::getItemsForContract方法的具体用法?PHP Contract_Item::getItemsForContract怎么用?PHP Contract_Item::getItemsForContract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contract_Item
的用法示例。
在下文中一共展示了Contract_Item::getItemsForContract方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cronContract
/**
* Cron action on contracts : alert depending of the config : on notice and expire
*
* @param $task for log, if NULL display (default NULL)
**/
static function cronContract($task = NULL)
{
global $DB, $CFG_GLPI;
if (!$CFG_GLPI["use_mailing"]) {
return 0;
}
$message = array();
$items_notice = array();
$items_end = array();
$cron_status = 0;
$contract_infos[Alert::END] = array();
$contract_infos[Alert::NOTICE] = array();
$contract_messages = array();
foreach (Entity::getEntitiesToNotify('use_contracts_alert') as $entity => $value) {
$before = Entity::getUsedConfig('send_contracts_alert_before_delay', $entity);
$query_notice = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Contract'\n AND `glpi_alerts`.`type`='" . Alert::NOTICE . "')\n WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::NOTICE) . ") >'0'\n AND `glpi_contracts`.`is_deleted` = '0'\n AND `glpi_contracts`.`begin_date` IS NOT NULL\n AND `glpi_contracts`.`duration` <> '0'\n AND `glpi_contracts`.`notice` <> '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL `glpi_contracts`.`duration` MONTH),\n CURDATE()) > '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL (`glpi_contracts`.`duration`\n -`glpi_contracts`.`notice`) MONTH),\n CURDATE()) < '{$before}'\n AND `glpi_alerts`.`date` IS NULL\n AND `glpi_contracts`.`entities_id` = '" . $entity . "'";
$query_end = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Contract'\n AND `glpi_alerts`.`type`='" . Alert::END . "')\n WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::END) . ") > '0'\n AND `glpi_contracts`.`is_deleted` = '0'\n AND `glpi_contracts`.`begin_date` IS NOT NULL\n AND `glpi_contracts`.`duration` <> '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL (`glpi_contracts`.`duration`) MONTH),\n CURDATE()) < '{$before}'\n AND `glpi_alerts`.`date` IS NULL\n AND `glpi_contracts`.`entities_id` = '" . $entity . "'";
$querys = array('notice' => $query_notice, 'end' => $query_end);
foreach ($querys as $type => $query) {
foreach ($DB->request($query) as $data) {
$entity = $data['entities_id'];
$message = sprintf(__('%1$s: %2$s') . "<br>\n", $data["name"], Infocom::getWarrantyExpir($data["begin_date"], $data["duration"], $data["notice"]));
$contract_infos[$type][$entity][$data['id']] = $data;
if (!isset($contract_messages[$type][$entity])) {
switch ($type) {
case 'notice':
$contract_messages[$type][$entity] = __('Contract entered in notice time') . "<br>";
break;
case 'end':
$contract_messages[$type][$entity] = __('Contract ended') . "<br>";
break;
}
}
$contract_messages[$type][$entity] .= $message;
}
}
// Get contrats with periodicity alerts
$query_periodicity = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n WHERE `glpi_contracts`.`alert` & " . pow(2, Alert::PERIODICITY) . " > '0'\n AND `glpi_contracts`.`entities_id` = '" . $entity . "' ";
// Foreach ones :
foreach ($DB->request($query_periodicity) as $data) {
$entity = $data['entities_id'];
// Compute end date + 12 month : do not send alerts after
$end_alert = date('Y-m-d', strtotime($data['begin_date'] . " +" . ($data['duration'] + 12) . " month"));
if (!empty($data['begin_date']) && $data['periodicity'] && $end_alert > date('Y-m-d')) {
$todo = array('periodicity' => Alert::PERIODICITY);
if ($data['alert'] & pow(2, Alert::NOTICE)) {
$todo['periodicitynotice'] = Alert::NOTICE;
}
// Get previous alerts
foreach ($todo as $type => $event) {
$previous_alerts[$type] = Alert::getAlertDate(__CLASS__, $data['id'], $event);
}
// compute next alert date based on already send alerts (or not)
foreach ($todo as $type => $event) {
$next_alerts[$type] = date('Y-m-d', strtotime($data['begin_date'] . " -" . $before . " day"));
if ($type == Alert::NOTICE) {
$next_alerts[$type] = date('Y-m-d', strtotime($next_alerts[$type] . " -" . $data['notice'] . " month"));
}
$today_limit = date('Y-m-d', strtotime(date('Y-m-d') . " -" . $data['periodicity'] . " month"));
// Init previous by begin date if not set
if (empty($previous_alerts[$type])) {
$previous_alerts[$type] = $today_limit;
}
while ($next_alerts[$type] < $previous_alerts[$type] && $next_alerts[$type] < $end_alert) {
$next_alerts[$type] = date('Y-m-d', strtotime($next_alerts[$type] . " +" . $data['periodicity'] . " month"));
}
// If this date is passed : clean alerts and send again
if ($next_alerts[$type] <= date('Y-m-d')) {
$alert = new Alert();
$alert->clear(__CLASS__, $data['id'], $event);
$real_alert_date = date('Y-m-d', strtotime($next_alerts[$type] . " +" . $before . " day"));
$message = sprintf(__('%1$s: %2$s') . "<br>\n", $data["name"], Html::convDate($real_alert_date));
$data['alert_date'] = $real_alert_date;
$data['items'] = Contract_Item::getItemsForContract($data['id'], $entity);
$contract_infos[$type][$entity][$data['id']] = $data;
switch ($type) {
case 'periodicitynotice':
$contract_messages[$type][$entity] = __('Contract entered in notice time for period') . "<br>";
break;
case 'periodicity':
$contract_messages[$type][$entity] = __('Contract period ended') . "<br>";
break;
}
$contract_messages[$type][$entity] .= $message;
}
}
}
}
}
foreach (array('notice' => Alert::NOTICE, 'end' => Alert::END, 'periodicity' => Alert::PERIODICITY, 'periodicitynotice' => Alert::NOTICE) as $event => $type) {
if (isset($contract_infos[$event]) && count($contract_infos[$event])) {
foreach ($contract_infos[$event] as $entity => $contracts) {
if (NotificationEvent::raiseEvent($event, new self(), array('entities_id' => $entity, 'items' => $contracts))) {
$message = $contract_messages[$event][$entity];
$cron_status = 1;
//.........这里部分代码省略.........