. */ /** * 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/Proposals.php"); require_once(FILESYSTEMROOTPATH."jc/images/Image_link.php"); class ProposalsDao implements IDao { /** MySQL object */ private $mysql; /*todo*/ /*load proposals by agora!*/ /*by proposers*/ /** * Default constructor */ public function __construct(MySQL $mysql) { $this->mysql = $mysql; } /** * Load Proposals by id * * @param id * @return */ public function load($id) { $query = "SELECT * FROM `proposals` WHERE `id`='".$id."'"; if( $this->mysql->query($query) ) { return new Proposals($this->mysql->fetchArray()); }else { return array(); } } /** * Load all Proposals * * @return array of all Agorae */ public function loadAll() { $query = "SELECT * FROM `proposals`"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $ret[ $row['id'] ] = new Proposals($row); } return $ret; }else { return array(); } } public function loadActions($agora_id) { /* $status = array( 0 => '-', 1 => 'Saved', 2 => 'Changes Required', 3 => 'Submitted', 4 => 'JC Rejected', 5 => 'JC Accepted', 6 => 'Withdrawn', 7 => 'Prytanium', 8 => 'Plenary', 9 => 'Agora Rejected', 10 => 'Agora Accepted' ); $actions = array( 0 => '-', 1 => '-', 2 => '-', // review? 3 => 'Review', 4 => '-', // review? 5 => 'Go to Prytanium', //withdraw? 6 => '-', 7 => 'Go to Plenary', 8 => 'Manage Voting', 9 => '-', 10 => '-' ); */ $query = "SELECT * FROM `proposals` WHERE `agora_id`='$agora_id' AND `status`>1"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $action = '-'; if ($row['status']=='Submitted' || $row['status']=='JC Rejected' || $row['status']=='Withdrawn'){ $action = 'Review'; $action .= '|Edit'; } elseif ($row['status']=='JC Accepted'){ $action = 'Review'; $action .= '|Go To Prytanium'; $action .= '|Edit'; } elseif($row['status']=='Prytanium'){ $action = 'Go To Plennary'; $action .= '|Edit'; } elseif($row['status']=='Plenary'||$row['status']=='Agora Accepted'||$row['status']=='Agora Rejected'){ $action = 'Manage Voting'; } $row['action'] = $action; $row['view_all']=img_view('view_public.php?proposal_id='.$row['id']); $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadSubmittedByAgora($agora_id) { $query = 'SELECT * FROM `proposals` WHERE `agora_id`="'.$agora_id.'" AND `status`!="Saved"'; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['review']='Review'; $row['edit']='Edit'; if($row['status']=='Agora Accepted' || $row['status']=='Agora Rejected'){ $row['review']='-'; $row['edit']='-'; } $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadJCAcceptedByAgora($agora_id) { $query = 'SELECT * FROM `proposals` WHERE `agora_id`="'.$agora_id.'" AND `status` NOT IN ("Saved", "Submitted", "JC Rejected", "Changes Required")'; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['view']=img_view('view_proposal2.php?proposal_id='.$row['id']); $row['view_all']=img_view('view_public.php?proposal_id='.$row['id']); $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadAgoraAccepted($agora_id) { $query = 'SELECT * FROM `proposals` WHERE `agora_id`="'.$agora_id.'" AND `status`="Agora Accepted")'; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadByUID_Agora($uid, $agora_id) { $query = "SELECT * FROM `proposals` WHERE `proposer_uid`='".$uid."' AND `agora_id`=".$agora_id; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { //$row['view']='View'; $row['view']=img_view('view_proposal1.php?proposal_id='.$row['id']); if ($row['status']=='Saved' || $row['status']=='Changes Required'){ // $row['edit']='Edit'; // $row['delete']='Delete'; $row['edit']=img_edit('create_proposal1.php?proposal_id='.$row['id']); $row['delete']=img_del('create_proposal4.php?proposal_id='.$row['id']); }else{ $row['edit']='-'; $row['delete']='-'; } $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadGoToPrytanium($agora_id){ $query = "SELECT * FROM `proposals` WHERE `agora_id`='".$agora_id."' AND `status`='Accepted'"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['prytanium']='Go To Prytanium!'; $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadGoToPlennary($agora_id){ $query = "SELECT * FROM `proposals` WHERE `agora_id`='".$agora_id."' AND `status`='Prytanium'"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['prytanium']='Go To Plennary!'; $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function loadOpen(){ $aid = $_SESSION['JC_MODULE']['AgoraId'] ; $query = "SELECT p.id, p.title, pm.open, pm.close, pm.closemysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { $row['view']='view'; $row['vote']='Vote'; $row['check']='Check'; if($row['hasClosed']==0){ $row['vote']=''.$row['vote'].''; $row['title'] = ''.$row['title'].''; } $ret[ $row['id'] ] = $row; } return $ret; }else { return array(); } } public function delete(Proposals $proposal){ $query = 'DELETE FROM `proposals` WHERE `id`='.$proposal->getId(); $res = $this->mysql->query($query); $query2 = 'DELETE FROM `proposals_sentences` WHERE `proposal_id`='.$proposal->getId(); $this->mysql->query($query2); return $res; } /** * Save or update Proposals: * @param Proposals object with the data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $proposal) { $query=""; $recordID=$proposal->getId(); if($recordID==NULL) { $query.="INSERT INTO `proposals` SET "; } else { $query.="UPDATE `proposals` SET "; } $query .="`proposer_uid` = '".$this->mysql->escape($proposal->getProposer_uid())."', "; $query .="`agora_id` = '".$this->mysql->escape($proposal->getAgora_id())."', "; $query .="`proposers` = '".$this->mysql->escape($proposal->getProposers())."', "; $query .="`title` = '".$this->mysql->escape($proposal->getTitle())."', "; $query .="`motivation` = '".$this->mysql->escape($proposal->getMotivation())."', "; $query .="`status` = '".$this->mysql->escape($proposal->getStatus())."', "; $query .="`jc_comment` = '".$this->mysql->escape($proposal->getJc_comment())."', "; $query .="`submit_date` = '".$this->mysql->escape($proposal->getSubmit_date())."'"; if($recordID!=NULL) { $query.=" where `id` = ".$recordID; } //echo $query; return $this->mysql->query($query); } } ?>