. */ /** * Agorae Database Access Object. This class provides functionality to * load and save Agorae title. */ require_once(FILESYSTEMROOTPATH."include/classes/IDao.php"); require_once(FILESYSTEMROOTPATH."jc/include/model/Agorae.php"); class AgoraeDao implements IDao { /** MySQL object */ private $mysql; /** * Default constructor */ public function __construct(MySQL $mysql) { $this->mysql = $mysql; } /** * Load Agorae by id * * @param id * @return */ public function load($id) { $query = "SELECT * FROM agorae WHERE `id`='".$id."'"; if( $this->mysql->query($query) ) { return new Agorae($this->mysql->fetchArray()); }else { return array(); } } /** * Load all CIA * * @return array of all Agorae */ public function loadAll() { $bool = array(0=>'No',1=>'Yes'); $query = "SELECT * FROM `agorae` ORDER BY `id` DESC"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['edit']= 'Edit'; $row['proposals']= 'Proposals'; $row['setup'] = 'Setup'; $row['active2'] = $bool[$row['active']]; $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } /*get the latest inserted Agora (should be the one for new proposals)*/ public function getLatestAgora(){ $query = "SELECT * FROM `agorae` WHERE `active` = 1 ORDER BY id DESC LIMIT 0,1"; if ($this->mysql->query($query)){ return new Agorae($this->mysql->fetchArray()); } else{ return array(); } } public function activate($id){ $q1 = "UPDATE `agorae` SET `active` = 0 WHERE `active` = 1"; $q2 = "UPDATE `agorae` SET `active` = 1 WHERE `id` = ".$id; if ($this->mysql->query($q1) && $this->mysql->query($q2)){ return true; } else{ return false; } } /** * Save or update Agorae: * create one Agora before opening proposals! * @param Agorae object with the data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $agorae) { $query=""; $recordID=$agorae->getId(); if($recordID==NULL) { $query.="INSERT INTO `agorae` SET "; } else { $query.="UPDATE `agorae` SET "; } $query .="`agora` = '".$this->mysql->escape($agorae->getAgora())."', "; $query .="`cia_version_name` = '".$this->mysql->escape($agorae->getCia_version_name())."', "; $query .="`open` = '".$this->mysql->escape($agorae->getOpen())."', "; $query .="`close` = '".$this->mysql->escape($agorae->getClose())."', "; $query .="`a_open` = '".$this->mysql->escape($agorae->getA_open())."', "; $query .="`a_close` = '".$this->mysql->escape($agorae->getA_close())."', "; $query .="`changes_deadline` = '".$this->mysql->escape($agorae->getChanges_deadline())."', "; $query .="`active` = '".$this->mysql->escape($agorae->getActive())."', "; $query .="`updated` = '".$this->mysql->escape($agorae->getUpdated())."'"; if($recordID!=NULL) { $query.=" where `id` = ".$recordID; } //echo $query; return $this->mysql->query($query); } //list jc members public function get_JC_Chair($backlink){ $query = "SELECT * FROM `users_special` WHERE `role` = 'JC/Chair'"; if ($this->mysql->query($query)){ $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['jc_uid'] = $row['uid']; $HTML_FORM = '
'; $row['remove']= $HTML_FORM; $ret[ ] = $row; } return $ret; } else{ return array(); } } //add jc member public function add_JC_Chair($uid){ $uid = $this->mysql->escape($uid); $query2 = "INSERT INTO `users_special` SET `role`='JC/Chair', `uid`='$uid'"; return $this->mysql->query($query2); } //remove jc member public function remove_JC_Chair($jc_id){ $jc_id = $this->mysql->escape($jc_id); $query = "DELETE FROM `users_special` WHERE `id`='$jc_id'"; return $this->mysql->query($query); } } ?>