Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
91 righe
3.0 KiB
91 righe
3.0 KiB
<?php |
|
Class AlertAnac { |
|
|
|
/** |
|
* Restituisce le gravità di errore disponibili |
|
* |
|
* @return Array |
|
*/ |
|
public static function gravita() : Array { |
|
return [ |
|
"danger" => [ |
|
"label" => "Critico", |
|
"color" => "#C00", |
|
"icon" => "fa fa-exclamation-triangle" |
|
], |
|
"warning" => [ |
|
"label" => "Avviso", |
|
"color" => "#FC0", |
|
"icon" => "fa fa-exclamation-circle" |
|
], |
|
"info" => [ |
|
"label" => "Informazione", |
|
"color" => "#0CF", |
|
"icon" => "fa fa-info-circle" |
|
] |
|
]; |
|
} |
|
|
|
/** |
|
* Restituisce l'elenco degli avvisi disponibili |
|
* |
|
* @param Int|null $id Specifica l'id di un avviso specifico |
|
* @param boolean $active Specifica se restituire solo gli avvisi attivi per stato o per validità temporale |
|
* @return void |
|
*/ |
|
public static function get(Int $id = null, Bool $active = false) : Array { |
|
|
|
global $pdo; |
|
$sql = "SELECT * FROM b_alert_anac WHERE codice > 0 "; |
|
$bind = []; |
|
if (isset($_SESSION["ente"])) { |
|
$sql .= " AND (codice_ente = :ente OR codice_ente = 0 OR codice_ente IS NULL) "; |
|
$bind[":ente"] = $_SESSION["ente"]->codice; |
|
} |
|
if ($active) { |
|
$sql .= " AND attivo = 'S' AND (inizio IS NULL OR inizio < now()) AND (fine IS NULL OR fine > now())"; |
|
} |
|
if ($id) { |
|
$sql .= " AND codice = :id "; |
|
$bind[":id"] = $id; |
|
} |
|
$return = $pdo->go($sql,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
if (!empty($id)) { |
|
$return = reset($return); |
|
} |
|
return $return; |
|
} |
|
|
|
|
|
public static function save(Array $data) { |
|
$data["codice_ente"] = $_SESSION["ente"]->codice ?? 0; |
|
$salva = new salva(); |
|
$salva->debug = false; |
|
$salva->nome_tabella = "b_alert_anac"; |
|
$salva->operazione = empty($data["codice"]) ? "INSERT" : "UPDATE"; |
|
$salva->oggetto = $data; |
|
return $salva->save(); |
|
} |
|
|
|
/** |
|
* Attiva o disattiva l'avviso - Restituisce lo stato così come modificato S: Attivo N: Disattivo |
|
* |
|
* @param Int $id |
|
* @return String |
|
*/ |
|
public static function toggle(Int $id) : ?String { |
|
$alert = self::get($id); |
|
if (!empty($alert)) { |
|
if ($alert["attivo"] == "N") { |
|
$alert["attivo"] = "S"; |
|
} else { |
|
$alert["attivo"] = "N"; |
|
} |
|
if (self::save(["codice"=>$alert["codice"],"attivo"=>$alert["attivo"]])) { |
|
|
|
return $alert["attivo"]; |
|
} |
|
} |
|
return null; |
|
} |
|
} |