Merge branch 'ticket-13814-mailAlertUpdate' into develop

This commit is contained in:
Marion Muszynski 2017-08-22 11:35:59 +02:00
commit 2c541bfd6b

View File

@ -0,0 +1,119 @@
<?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_send;
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_send' => '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_send'] = pSQL($this->date_last_send);
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"
);
}
}