. */ /** * 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 NotificationsDao 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 loadMine() { $aid = $_SESSION['JC_MODULE']['AgoraId']; $uid = $_SESSION['sess_uid']; $query = "SELECT `type`, COUNT(*) AS nn FROM notifications WHERE `agora_id`=$aid AND `uid`='$uid' AND `open` < NOW() AND `close` > NOW() GROUP BY `type`"; $ret =array('Proposal'=>0,'Rollcall'=>0,'Election'=>0, 'Poll'=>0, 'RankedVote'=>0); if( $this->mysql->query($query) ) { while($row = $this->mysql->fetchArray()){ $ret[$row['type']] = $row['nn']; } return $ret; }else { return array(); } } /** * Load all CIA * * @return array of all Agorae */ public function create($pid, $type, $open, $close) { $aid = $_SESSION['JC_MODULE']['AgoraId']; $query ="INSERT INTO notifications (`agora_id`,`uid`,`pid`,`type`,`open`,`close`) SELECT '$aid', `uid`, '$pid', '$type', '$open', '$close' FROM voting_delegates WHERE agora_id=".$aid; return $this->mysql->query($query); } public function update($pid, $type, $open, $close){ $aid = $_SESSION['JC_MODULE']['AgoraId']; $query = "UPDATE notifications SET `open`='$open', `close`='$close' WHERE `pid`=$pid AND `type`='$type' AND `agora_id`=$aid"; return $this->mysql->query($query); } public function seen($pid, $type){ $aid = $_SESSION['JC_MODULE']['AgoraId']; $uid = $_SESSION['sess_uid']; $query = "DELETE FROM notifications WHERE `agora_id`=$aid AND `uid`='$uid' AND `pid`='$pid' AND `type`='$type'"; return $this->mysql->query($query); } public function exists($pid, $type){ $aid = $_SESSION['JC_MODULE']['AgoraId']; $query = "SELECT count(*) AS nn FROM notifications WHERE `agora_id`=$aid AND `pid`='$pid' AND `type`='$type'"; $this->mysql->query($query); $res = $this->mysql->fetchArray(); if ($res['nn']>0){ return true; }else{ return false; } } /** * Save or update Agorae: * @param Agorae object with the data * @return boolean true in case of success, false otherwise */ public function saveOrUpdate(IModel $model) { return ''; } public function load($key){ return ''; } } ?>