File phpboost/event/AdministratorAlert.class.php
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169:
<?php
/**
* This class represents an alert which must be sent to the administrator.
* It allows to the module developers to handle the administrator alerts.
* The administrator alerts can be in the administration panel and can be used when you want to signal an important event to the administrator(s).
* @package PHPBoost
* @subpackage Event
* @copyright © 2005-2019 PHPBoost
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
* @author Benoit SAUTEL <ben.popeye@phpboost.com>
* @version PHPBoost 5.2 - last update: 2018 11 07
* @since PHPBoost 2.0 - 2008 08 27
* @contributor Julien BRISWALTER <j1.seth@phpboost.com>
* @contributor Arnaud GENET <elenwii@phpboost.com>
*/
class AdministratorAlert extends Event
{
//Priority levels
//High emergency, critical
const ADMIN_ALERT_VERY_LOW_PRIORITY = 1;
//Emergency, important
const ADMIN_ALERT_LOW_PRIORITY = 2;
//Medium
const ADMIN_ALERT_MEDIUM_PRIORITY = 3;
//Low priority
const ADMIN_ALERT_HIGH_PRIORITY = 4;
//Very low priority
const ADMIN_ALERT_VERY_HIGH_PRIORITY = 5;
//Alert status (boolean)
//Unread alert
const ADMIN_ALERT_STATUS_UNREAD = Event::EVENT_STATUS_UNREAD;
//Processed alert
const ADMIN_ALERT_STATUS_PROCESSED = Event::EVENT_STATUS_PROCESSED;
/**
* @var int Priority of the alert
*/
private $priority = self::ADMIN_ALERT_MEDIUM_PRIORITY;
/**
* @var string Properties of the alert (string field of unlimited length) which can for example contain a serializes array of object.
*/
private $properties = '';
/**
* Builds an AdministratorAlert object.
*/
public function __construct()
{
parent::__construct();
$this->priority = self::ADMIN_ALERT_MEDIUM_PRIORITY;
$this->properties = '';
}
/**
* Builds an alert from its whole parameters.
* @param int $id Identifier of the alert.
* @param string $entitled Entitled of the alert.
* @param string $properties Properties of the alert.
* @param string $fixing_url Fixing url.
* @param int $current_status Alert status.
* @param Date $creation_date Alert creation date?
* @param int $id_in_module Id in module field.
* @param string $identifier Identifier of the alert.
* @param string $type Type of the alert.
* @param int $priority Priority of the alert.
*/
public function build($id, $entitled, $properties, $fixing_url, $current_status, $creation_date, $id_in_module, $identifier, $type, $priority)
{
parent::build_event($id, $entitled, $fixing_url, $current_status, $creation_date, $id_in_module, $identifier, $type);
$this->set_priority($priority);
$this->set_properties($properties);
}
/**
* Gets the priority of the alert.
* @return int One of those values:
* <ul>
* <li>AdministratorAlert::ADMIN_ALERT_VERY_LOW_PRIORITY Very low priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY Low priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY Medium priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY High priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_VERY_HIGH_PRIORITY Very high priority</li>
* </ul>
*/
public function get_priority()
{
return $this->priority;
}
/**
* Gets the alert properties.
* @return string The properties.
*/
public function get_properties()
{
return $this->properties;
}
/**
* Sets the priority of the alert.
* @param int $priority The priority, it must be one of those values:
* <ul>
* <li>AdministratorAlert::ADMIN_ALERT_VERY_LOW_PRIORITY Very low priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_LOW_PRIORITY Low priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_MEDIUM_PRIORITY Medium priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_HIGH_PRIORITY High priority</li>
* <li>AdministratorAlert::ADMIN_ALERT_VERY_HIGH_PRIORITY Very high priority</li>
* </ul>
*/
public function set_priority($priority)
{
$priority = intval($priority);
if ($priority >= self::ADMIN_ALERT_VERY_LOW_PRIORITY && $priority <= self::ADMIN_ALERT_VERY_HIGH_PRIORITY)
{
$this->priority = $priority;
}
else
{
$this->priority = self::ADMIN_ALERT_MEDIUM_PRIORITY;
}
}
/**
* Sets the properties of the alert.
* @param string $properties Properties.
*/
public function set_properties($properties)
{
//If properties has the good type
if (is_string($properties))
{
$this->properties = $properties;
}
}
/**
* Gets the priority name. It's automatically translater to the user language, ready to be displayed.
* @return string The priority name.
*/
public function get_priority_name()
{
$admin_lang = LangLoader::get('admin');
switch ($this->priority)
{
case self::ADMIN_ALERT_VERY_LOW_PRIORITY:
return $admin_lang['priority_very_low'];
break;
case self::ADMIN_ALERT_LOW_PRIORITY:
return $admin_lang['priority_low'];
break;
case self::ADMIN_ALERT_MEDIUM_PRIORITY:
return $admin_lang['priority_medium'];
break;
case self::ADMIN_ALERT_HIGH_PRIORITY:
return $admin_lang['priority_high'];
break;
case self::ADMIN_ALERT_VERY_HIGH_PRIORITY:
return $admin_lang['priority_very_high'];
break;
default:
return $admin_lang['priority_medium'];
}
}
}
?>