. */ /** * Plenaries Database Access Object. This class provides functionality to * load and save Plenaries title. */ require_once(FILESYSTEMROOTPATH."include/classes/IDao.php"); require_once(FILESYSTEMROOTPATH."jc/include/model/Plenaries.php"); class PlenariesDao implements IDao { /** MySQL object */ private $mysql; /** * Default constructor */ public function __construct(MySQL $mysql) { $this->mysql = $mysql; } /** * Load Plenaries by id * * @param id * @return */ public function load($id) { $query = "SELECT * FROM plenaries WHERE `id`='".$id."'"; if( $this->mysql->query($query) ) { return new Plenaries($this->mysql->fetchArray()); }else { return array(); } } /** * Load all Plenaries of the current Agora * * @return array of plenaries */ public function loadAll() { $aid = $_SESSION['JC_MODULE']['AgoraId']; $query = "SELECT p.id, p.name, p.number, p.open, p.close, p.status FROM plenaries p INNER JOIN agorae a ON p.agoraId=a.id WHERE agoraId =".$aid." ORDER BY p.`close` DESC"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['name']= $row['name'].' Plenary'; $row['number']= ' Plenary '.$row['number']; $row['date']= date('d M Y', strtotime( $row['open'] ) ); $row['open']= date('H:i:s', strtotime( $row['open'] ) ); $row['close']= date('H:i:s', strtotime( $row['close'] ) ); $row['status'] = ( $row['status'] ? "Closed" : "Open" ); $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } /** * Load all Plenary names of the current Agora * * @return array of plenaries */ public function loadAllNames() { $aid = $_SESSION['JC_MODULE']['AgoraId']; $query = "SELECT id, name, number, open FROM plenaries WHERE agoraId =".$aid; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $txt = 'Plenary '.$row['number'].' ('; $txt .= date('d M Y', strtotime( $row['open'] ) ); $txt .=', '.$row['name'].')'; $ret[ $row['id'] ] = $txt; } return $ret; }else { return array(); } } /** * Save or update Plenaries: * create one Plenary before opening proposals! * @param Plenaries object with the data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $plenaries) { $query=""; $recordID=$plenaries->getId(); if($recordID==NULL) { $query.="INSERT INTO `plenaries` SET "; $query .="`agoraId` = '".$_SESSION['JC_MODULE']['AgoraId']."', "; $query .="`status` = '0',"; } else { $query.="UPDATE `plenaries` SET "; $query .="`status` = '".$this->mysql->escape($plenaries->getStatus())."',"; } $query .="`name` = '".$this->mysql->escape($plenaries->getName())."', "; $query .="`number` = '".$this->mysql->escape($plenaries->getNumber())."', "; $query .="`open` = '".$this->mysql->escape($plenaries->getOpen())."', "; $query .="`close` = '".$this->mysql->escape($plenaries->getClose())."'"; if($recordID!=NULL) { $query.=" where `id` = ".$recordID; } //echo $query; return $this->mysql->query($query); } } ?>