123 lines
3.3 KiB
PHP
123 lines
3.3 KiB
PHP
<?php
|
|
|
|
class AntAlert extends ObjectModel
|
|
{
|
|
|
|
public $id_alert;
|
|
public $enabled;
|
|
public $id_contact;
|
|
public $limit;
|
|
public $hours;
|
|
public $date_add;
|
|
public $date_upd;
|
|
public $date_last_sent;
|
|
public $date_last_check;
|
|
|
|
protected $fieldsRequired = array('id_contact','limit','hours');
|
|
protected $fieldsValidate = array(
|
|
'id_alert' => 'isUnsignedId',
|
|
'enabled' => 'isBool',
|
|
'id_contact' => 'isUnsignedId',
|
|
'limit' => 'isInt',
|
|
'hours' => 'isInt',
|
|
'date_add' => 'isDate',
|
|
'date_upd' => 'isDate',
|
|
'date_last_sent' => 'isDate',
|
|
'date_last_check' => 'isDate',
|
|
);
|
|
|
|
protected $table = 'ant_alert';
|
|
protected $identifier = 'id_alert';
|
|
|
|
|
|
public function getFields()
|
|
{
|
|
parent::validateFields();
|
|
|
|
$fields['id_alert'] = (int)$this->id_alert;
|
|
$fields['enabled'] = (int)$this->enabled;
|
|
$fields['id_contact'] = (int)$this->id_contact;
|
|
$fields['limit'] = (int)$this->limit;
|
|
$fields['hours'] = (int)$this->hours;
|
|
$fields['date_add'] = pSQL($this->date_add);
|
|
$fields['date_upd'] = pSQL($this->date_upd);
|
|
$fields['date_last_sent'] = pSQL($this->date_last_sent);
|
|
$fields['date_last_check'] = pSQL($this->date_last_check);
|
|
|
|
return $fields;
|
|
}
|
|
|
|
public function delete()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get demands
|
|
* @param $states array get only demands in specific states
|
|
* @return Array Groups
|
|
*/
|
|
public static function getAlerts($enabled = true, $where = false)
|
|
{
|
|
if($where){
|
|
return Db::getInstance()->executeS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'ant_alert` at
|
|
WHERE '.$where.'
|
|
'.($enabled ? ' AND at.`enabled` = 1' : '').'
|
|
');
|
|
} else {
|
|
return Db::getInstance()->executeS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'ant_alert` at
|
|
WHERE 1
|
|
'.($enabled ? ' AND at.`enabled` = 1' : '').'
|
|
');
|
|
}
|
|
}
|
|
|
|
public function save($nullValues = false, $autodate = true)
|
|
{
|
|
if (parent::save($nullValues,$autodate)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static function getAlertByContact($id_contact)
|
|
{
|
|
$id = Db::getInstance()->getValue("
|
|
SELECT `id_alert`
|
|
FROM `"._DB_PREFIX_."ant_alert`
|
|
WHERE `id_contact` = " .(int)$id_contact
|
|
);
|
|
if($id) {
|
|
return new AntAlert((int)$id);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function getAlreadyUsedContacts()
|
|
{
|
|
$id_contacts = array();
|
|
foreach(Db::getInstance()->executeS("
|
|
SELECT DISTINCT `id_contact`
|
|
FROM `"._DB_PREFIX_."ant_alert`"
|
|
) as $row){
|
|
$id_contacts[(int)$row['id_contact']] = (int)$row['id_contact'];
|
|
}
|
|
|
|
return $id_contacts;
|
|
}
|
|
|
|
public static function isExistAndEnabled($id_contact)
|
|
{
|
|
return Db::getInstance()->getValue("
|
|
SELECT `id_alert`
|
|
FROM `"._DB_PREFIX_."ant_alert`
|
|
WHERE `id_contact` = " .(int)$id_contact."
|
|
AND `enabled` = 1"
|
|
);
|
|
}
|
|
}
|
|
|