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.
190 righe
6.0 KiB
190 righe
6.0 KiB
<?php |
|
|
|
require_once "IDataClass.php"; |
|
|
|
/** |
|
* Description of News |
|
* |
|
* @author Anselmo |
|
*/ |
|
class News extends DataClass { |
|
|
|
//put your code here |
|
const TABLE_NAME = "NEWS"; |
|
const SEQ_NAME = "NEWS_ID_SEQ"; |
|
const SP_ = "SPNEWSSAVE"; |
|
|
|
public $ID = 0; // Primary key |
|
public $TITOLO = ""; |
|
public $TESTO = ""; |
|
public $DATA = ""; |
|
public $STATO = 0; |
|
public $ID_CATEGORIA = 0; |
|
public $CANCELLATO = 0; |
|
public $ID_UTENTE_INSERIMENTO = 0; |
|
public $DATA_INSERIMENTO = null; |
|
public $ID_UTENTE_MODIFICA = 0; |
|
public $DATA_MODIFICA = null; |
|
public $Allegati = array(); |
|
|
|
public function __construct($src = null) { |
|
global $con; |
|
if ($src == null) |
|
return; |
|
if (is_array($src)) { |
|
if (isset($src['ID']) && $src['ID'] > 0) { |
|
$this->_loadAndFillObject($src['ID'], self::TABLE_NAME, $src); |
|
} else { |
|
$this->_loadByRow($src, $stripSlashes); |
|
} |
|
} elseif (intval($src)) { |
|
|
|
$sql = "SELECT * FROM " . self::TABLE_NAME . " WHERE ID = :id"; |
|
$query = $con->prepare($sql); |
|
$query->bindParam(":id", $src); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
//$it[0]['TESTO'] = stream_get_contents($it[0]['TESTO']); |
|
$it[0]['TESTO'] = stream_get_contents($it[0]['TESTO']); |
|
Utils::FillObjectFromRow($this, $it[0]); |
|
} catch (Exception $exc) { |
|
$exc->getMessage(); |
|
} |
|
} |
|
if ($this->ID > 0) { |
|
$this->Allegati = Allegati::LoadByNews($this->ID); |
|
} |
|
} |
|
|
|
/** |
|
* Restituisce il totale Delle news |
|
* |
|
* @param bool $filter Se specificato, filtra i comune in funzione dei parametri specificati in esso specificato |
|
* @return int |
|
*/ |
|
public static function Count($filter = null) { |
|
return parent::_count(self::TABLE_NAME, $filter); |
|
} |
|
|
|
public static function LoadDataTable($searchQuery = "", $searchArray = array(), $columnName = array(), $columnSortOrder = array(), $start = 0, $offset = 0) { |
|
|
|
return parent::_loadDataTable(self::TABLE_NAME, $searchQuery, $searchArray, $columnName, $columnSortOrder, $start, $offset); |
|
} |
|
|
|
public function Save() { |
|
global $con, $LoggedAccount; |
|
// 1,2,3,4,5,6,7,8,9,0,1 |
|
$sql = "CALL " . self::SP_ . " (?,?,?,?,?,?,?,?,?,?,?)"; |
|
|
|
$query = $con->prepare($sql); |
|
$query->bindParam(1, $this->ID); |
|
$query->bindParam(2, $this->TITOLO); |
|
$query->bindParam(3, $this->TESTO); |
|
$query->bindParam(4, $this->DATA); |
|
$query->bindParam(5, $this->STATO); |
|
$query->bindParam(6, $this->ID_CATEGORIA); |
|
$query->bindParam(7, $this->CANCELLATO); |
|
$query->bindParam(8, ($this->ID > 0 ? 0 : $LoggedAccount->ID)); |
|
$query->bindParam(9, $this->DATA_INSERIMENTO); |
|
$query->bindParam(10, ($this->ID > 0 ? $LoggedAccount->ID : 0)); |
|
$query->bindParam(11, $this->DATA_MODIFICA); |
|
|
|
try { |
|
$it = parent::_Save($query); |
|
} catch (Exception $exc) { |
|
|
|
$it['descrizioneErrore'] = $exc->getMessage(); |
|
} |
|
return $it; |
|
} |
|
|
|
public function Load($id_categoria = 0, $cancellato = 0) { |
|
global $con; |
|
$where = ""; |
|
$order = " ORDER BY DATA"; |
|
if (intval($cancellato) >= 0) |
|
$where .= ($where == "" ? "" : " AND ") . "CANCELLATO = :cancellato"; |
|
if (intval($id_categoria) >= 0) |
|
$where .= ($where == "" ? "" : " AND ") . "ID_CATEGORIA = :id_categoria"; |
|
|
|
$sql = "SELECT * FROM " . self::TABLE_NAME; |
|
if ($where != "") |
|
$sql .= " WHERE $where $order"; |
|
$query = $con->prepare($sql); |
|
if (intval($cancellato) >= 0) |
|
$query->bindParam(":CANCELLATO", intval($cancellato)); |
|
if (intval($id_categoria) >= 0) |
|
$query->bindParam(":ID_CATEGORIA", intval($id_categoria)); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
$it['esito'] = -999; |
|
$it['descrizioneErrore'] = $exc->getMessage(); |
|
} |
|
|
|
return $it; |
|
} |
|
|
|
public function LoadAll($cancellato = 0) { |
|
global $con; |
|
$where = ""; |
|
$order = " ORDER BY DATA"; |
|
if (intval($cancellato) >= 0) |
|
$where .= ($where == "" ? "" : " AND ") . "CANCELLATO = :cancellato AND STATO=1"; |
|
$sql = "SELECT * FROM " . self::TABLE_NAME; |
|
if ($where != "") |
|
$sql .= " WHERE $where $order"; |
|
$query = $con->prepare($sql); |
|
if (intval($cancellato) >= 0) |
|
$query->bindParam(":CANCELLATO", intval($cancellato)); |
|
if (intval($id_categoria) >= 0) |
|
$query->bindParam(":ID_CATEGORIA", intval($id_categoria)); |
|
try { |
|
$query->execute(); |
|
$it = $query->fetchAll(PDO::FETCH_ASSOC); |
|
} catch (Exception $exc) { |
|
$it['esito'] = -999; |
|
$it['descrizioneErrore'] = $exc->getMessage(); |
|
} |
|
|
|
return $it; |
|
} |
|
|
|
public function Delete() { |
|
return parent::_Delete(self::TABLE_NAME, "ID = " . $this->ID); |
|
} |
|
|
|
/** |
|
* Elimina l'oggetto corrente dal database e restituisce TRUE se ha successo |
|
* |
|
* @return bool Risultato booleano dell'operazione |
|
*/ |
|
public function LogicalDelete() { |
|
return parent::_LogicalDelete(self::TABLE_NAME, "ID = " . $this->ID); |
|
} |
|
|
|
/** |
|
* Funzione per la visualizzazione dei logs |
|
* @param type $record |
|
* @param type $campo |
|
*/ |
|
public function Parse(&$record, $campo = "") { |
|
$props = get_class_vars(get_class($this)); |
|
switch ($campo) { |
|
|
|
default: |
|
array_push($record, array("Campo" => $campo, "Valore" => $this->$campo)); |
|
break; |
|
} |
|
} |
|
|
|
public function getFullText() { |
|
if (is_resource($this->TESTO)) { |
|
$this->TESTO = stream_get_contents($this->TESTO); |
|
} |
|
return ($this->TESTO); |
|
} |
|
|
|
}
|
|
|