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.
117 righe
4.1 KiB
117 righe
4.1 KiB
<? |
|
Class consulenza { |
|
|
|
private $db; |
|
public $info; |
|
|
|
public static function getStati() { |
|
global $beRoot; |
|
return jsonToArray($beRoot."/consulenza/stati.json"); |
|
} |
|
|
|
private function __construct() |
|
{ |
|
global $pdo; |
|
$this->db = $pdo; |
|
} |
|
|
|
public static function init($id) { |
|
$consulenza = self::getList(["b_consulenze.codice"=>$id]); |
|
if (count($consulenza) === 1) { |
|
$istance = new consulenza; |
|
$istance->info = $consulenza[0]; |
|
return $istance; |
|
} |
|
} |
|
|
|
public function getMessaggi() { |
|
return $this->db->go("SELECT * FROM b_consulenze_conversazioni WHERE codice_consulenza = :codice",[":codice"=>$this->info["codice"]])->fetchAll(PDO::FETCH_ASSOC); |
|
} |
|
|
|
public static function checkLimite($gestore) { |
|
$return = 0; |
|
global $pdo; |
|
if (!$_SESSION["utente"]->readOnly) { |
|
$pacchetti = $pdo->go("SELECT SUM(pacchetto) AS totale, MIN(data_inizio) AS inizio, MAX(data_fine) AS fine FROM b_pacchetti_quesiti WHERE codice_ente = :codice_ente |
|
AND data_inizio <= CURDATE() AND data_fine >= CURDATE() GROUP BY codice_ente",[":codice_ente"=>$gestore])->fetch(PDO::FETCH_ASSOC); |
|
if (!empty($pacchetti)) { |
|
$bind = $pacchetti; |
|
$bind[":codice_gestore"] = $gestore; |
|
unset($bind["totale"]); |
|
$quesiti = $pdo->go("SELECT codice FROM b_consulenze WHERE codice_gestore = :codice_gestore AND timestamp_creazione >= :inizio AND timestamp_creazione <= :fine ",$bind); |
|
$return = $pacchetti["totale"] - $quesiti->rowCount(); |
|
} |
|
} |
|
return ($return > 0); |
|
} |
|
|
|
public static function getList($filters=[],$order=["b_consulenze.codice"=>"DESC"],$start=0,$length=1) { |
|
global $pdo; |
|
$select = "SELECT b_consulenze.* "; |
|
$from = " FROM b_consulenze "; |
|
$bind = []; |
|
if (isset($_SESSION["ente"])) { |
|
$bind = [":codice_gestore"=>$_SESSION["ente"]->codice]; |
|
$where = " WHERE b_consulenze.codice_gestore = :codice_gestore "; |
|
} else { |
|
$where = " WHERE b_consulenze.stato > 0 "; |
|
if ($_SESSION["utente"]->gerarchia == 99) { |
|
$bind =[":gruppo" => $_SESSION["utente"]->getInfo()["gruppo_consulenza"]]; |
|
$where .= " AND b_consulenze.gruppo = :gruppo "; |
|
} |
|
} |
|
if (!empty($filters)) { |
|
$keys = ["b_consulenze.titolo"]; |
|
$addWhere = []; |
|
foreach($keys AS $key) { |
|
if (isset($filters[$key]) || isset($filters["*"])) { |
|
$value = $filters[$key] ?? $filters["*"]; |
|
$sudd = suddivisione_pdo($value,$key); |
|
if (!empty($sudd)) { |
|
$bind = $bind + $sudd["bind"]; |
|
$addWhere[] = $sudd["sql"]; |
|
} |
|
} |
|
} |
|
if (!empty($addWhere)) { |
|
$where .= " AND (" . implode(" OR ",$addWhere) . ") "; |
|
} |
|
if (isset($filters["b_consulenze.stato"])) { |
|
$bind[":stato"] = (int)$filters["b_consulenze.stato"]; |
|
$where .= " AND b_consulenze.stato = :stato "; |
|
} |
|
if (isset($filters["b_consulenze.codice"])) { |
|
$bind[":codice"] = (int)$filters["b_consulenze.codice"]; |
|
$where .= " AND b_consulenze.codice = :codice "; |
|
} |
|
} |
|
$sort = " ORDER BY b_consulenze.codice DESC "; |
|
if (!empty($order)) { |
|
$keys = ["b_consulenze.codice","b_consulenze.stato","b_consulenze.titolo","b_consulenze.timestamp"]; |
|
$sortArray = []; |
|
foreach($keys AS $key) { |
|
if (isset($order[$key])) { |
|
if (strcmp($order[$key],"ASC") === 0) { |
|
$sortArray[] = "{$key} ASC"; |
|
} else { |
|
$sortArray[] = "{$key} DESC"; |
|
} |
|
} |
|
} |
|
if (!empty($sortArray)) { |
|
$sort = " ORDER BY " . implode(",",$sortArray); |
|
} |
|
} |
|
$limit = ""; |
|
if (is_numeric($start) && is_numeric($length) && $length > 0) { |
|
$start = (int)$start; |
|
$length = (int)$length; |
|
$limit = " LIMIT {$start}, {$length}"; |
|
} |
|
$result = $pdo->go($select.$from.$where.$sort.$limit,$bind)->fetchAll(PDO::FETCH_ASSOC); |
|
return $result; |
|
} |
|
|
|
|
|
} |
|
?>
|