. */ require_once(FILESYSTEMROOTPATH."include/classes/IDao.php"); require_once(FILESYSTEMROOTPATH."jc/include/model/Candidates.php"); require_once(FILESYSTEMROOTPATH."jc/images/Image_link.php"); class CandidatesDao 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 `candidates2` WHERE `id`='".$id."'"; if( $this->mysql->query($query) ) { return new Candidates($this->mysql->fetchArray()); }else { return array(); } } public function loadByElection($election_id) { $elections = $GLOBALS['ClassFactory']->getElectionsService()->load($election_id); $query = 'SELECT * FROM `candidates2` WHERE `election_id`="'.$election_id.'"'; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchArray() ) { if (date("Y-m-d H:i:s") > $elections->getOpen()) { $row['edit'] = '-'; $row['delete'] = '-'; } else { //$row['edit'] = 'Edit'; //$row['delete'] = 'Delete'; $row['edit'] = img_edit('candidates2.php?id='.$row['id'].'&eid='.$row['election_id']); $row['delete'] = img_del('candidates3.php?id='.$row['id']); } $row['link2']=''.$row['link'].''; $ret[$row['id']] = $row; } return $ret; }else { return array(); } } public function delete(Candidates $candidate){ $query = 'DELETE FROM `candidates2` WHERE `id`='.$candidate->getId(); return $this->mysql->query($query); } /** * Save or update Candidates: * @param object with the data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $candidate) { $query=""; $recordID=$candidate->getId(); if($recordID==NULL) { $query.="INSERT INTO `candidates2` SET "; } else { $query.="UPDATE `candidates2` SET "; } $query .="`candidate_uid` = '".$this->mysql->escape($candidate->getCandidate_uid())."', "; $query .="`name` = '".$this->mysql->escape($candidate->getName())."', "; $query .="`surname` = '".$this->mysql->escape($candidate->getSurname())."', "; $query .="`election_id` = '".$this->mysql->escape($candidate->getElection_id())."', "; $query .="`link` = '".$this->mysql->escape($candidate->getLink())."', "; $query .="`votes` = '".$this->mysql->escape($candidate->getVotes())."'"; if($recordID!=NULL) { $query.=" where `id` = ".$recordID; } //echo $query; return $this->mysql->query($query); } } ?>