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.
188 righe
5.3 KiB
188 righe
5.3 KiB
<?php |
|
|
|
require_once ROOT . "/lib/classes/IDataClass.php"; |
|
|
|
class Aeroporti extends DataClass { |
|
|
|
const TABLE_NAME = "AEROPORTI"; |
|
const VIEW = "VIEW_TRATTE"; |
|
|
|
public $CODICE = null; |
|
public $NOME = null; |
|
public $REGIONE = 0; |
|
|
|
public function __construct($src = null) { |
|
global $con; |
|
$stripSlashes = false; |
|
if ($src == null) { |
|
return; |
|
} |
|
if (is_array($src)) { |
|
$this->_loadByRow($src, $stripSlashes); |
|
} elseif (is_string($src)) { |
|
// Carichiamo tramite ID |
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE CODICE = :CODICE"; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":CODICE", $src); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
Utils::FillObjectFromRow($this, $it[0]); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* |
|
* @param $CODICE |
|
* @return array |
|
*/ |
|
public function LoadByCodice($CODICE) { |
|
global $con; |
|
|
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE CODICE = :CODICE"; |
|
$query = $con->prepare($sql); |
|
$it = array(); |
|
$query->bindParam(":CODICE", $CODICE); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
Utils::FillObjectFromRow($this, $it[0]); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
return $it; |
|
} |
|
|
|
|
|
/** |
|
* Restituisce la liste di tutti gli aeroporti |
|
* @return array |
|
*/ |
|
public static function ListAeroporti($regione = '') { |
|
global $con; |
|
$filter = ''; |
|
if (!empty($regione)) { |
|
$filter = " WHERE REGIONE = :regione "; |
|
} |
|
$sql = "SELECT * FROM " . self::TABLE_NAME. ' '.$filter.' order by REGIONE, NOME'; |
|
$query = $con->prepare($sql); |
|
if (!empty($regione)) { |
|
$query->bindParam(":regione", $regione); |
|
} |
|
$return = array(); |
|
try { |
|
$query->execute(); |
|
$return = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
return $return; |
|
} |
|
|
|
|
|
/** |
|
* Restituisce tutte le possibili destinazioni dell'aeroporto di partenza |
|
* @param $CODICE_A |
|
* @return array |
|
*/ |
|
public static function ListDestinazione($CODICE_A) { |
|
global $con; |
|
$sql = "SELECT * FROM " . self::VIEW . " WHERE CODICE_A = :CODICE_A"; |
|
$query = $con->prepare($sql); |
|
$return = array(); |
|
$query->bindParam(":CODICE_A", $CODICE_A); |
|
try { |
|
$query->execute(); |
|
$return = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
return $return; |
|
} |
|
|
|
|
|
|
|
public static function autocomplete($string = '', $regione = null) { |
|
global $con; |
|
$return = array(); |
|
|
|
$filter = ''; |
|
$searchFix = ''; |
|
if (!empty($regione)) { |
|
$filter = " REGIONE = :regione AND "; |
|
} |
|
$string = "%" . strtolower($string) . "%"; |
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE " . $filter . " LOWER(NOME) LIKE :term ".$searchFix." ORDER BY REGIONE, NOME"; |
|
|
|
$query = $con->prepare($sql); |
|
if (!empty($regione)) { |
|
$query->bindParam(":regione", $regione); |
|
} |
|
$query->bindParam(":term", $string); |
|
try { |
|
$query->execute(); |
|
while ($it = $query->fetch(PDO::FETCH_ASSOC)) { |
|
$descrizione = $it['NOME']; |
|
$row['id'] = $descrizione; |
|
$row['text'] = $descrizione; |
|
$row['label'] = $descrizione; |
|
$row['codice'] = $it['CODICE']; |
|
array_push($return, $row); |
|
} |
|
} catch (Exception $exc) { |
|
echo $exc->getMessage(); |
|
} |
|
|
|
return $return; |
|
} |
|
|
|
|
|
public static function autocompleteRitorno($string = '', $codice_a = null) { |
|
global $con; |
|
$return = array(); |
|
|
|
$filter = ''; |
|
$searchFix = ''; |
|
if (!empty($codice_a)) { |
|
$filter = " A_CODICE = :codice_a AND "; |
|
}else{ |
|
return $return; |
|
} |
|
$string = "%" . strtolower($string) . "%"; |
|
$sql = "SELECT * FROM " . self::VIEW . " WHERE " . $filter . " LOWER(R_NOME) LIKE :term ".$searchFix." ORDER BY R_NOME"; |
|
|
|
$query = $con->prepare($sql); |
|
if (!empty($codice_a)) { |
|
$query->bindParam(":codice_a", $codice_a); |
|
} |
|
$query->bindParam(":term", $string); |
|
try { |
|
$query->execute(); |
|
while ($it = $query->fetch(PDO::FETCH_ASSOC)) { |
|
$descrizione = $it['R_NOME']; |
|
$row['id'] = $descrizione; |
|
$row['text'] = $descrizione; |
|
$row['label'] = $descrizione; |
|
$row['codice'] = $it['R_CODICE']; |
|
array_push($return, $row); |
|
} |
|
} catch (Exception $exc) { |
|
echo $exc->getMessage(); |
|
} |
|
|
|
return $return; |
|
} |
|
|
|
|
|
|
|
|
|
public function Parse(&$record, $campo = "") { |
|
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); |
|
} |
|
|
|
|
|
|
|
} |