. * * Comments & Questions @ joris.veenhuis@aegee.org */ /** * CIA Database Access Object. This class provides functionality to * load and save CIA sentences. */ require_once(FILESYSTEMROOTPATH."include/classes/IDao.php"); require_once(FILESYSTEMROOTPATH."jc/include/model/Comments.php"); class CommentsDao implements IDao { /** MySQL object */ private $mysql; /** * Default constructor */ public function __construct(MySQL $mysql) { $this->mysql = $mysql; } public function load($id) { $query = "SELECT * FROM comments WHERE `id`='".$id; if( $this->mysql->query($query) ) { return new Comments($this->mysql->fetchArray()); } else { return array(); } } /** * Load Comments object by id * * @param id * @return */ public function loadByPID($proposal) { $notjc = ''; if(!isset( $_SESSION['sess_access_bodyCodes']['XJU']['JC_MANAGE'] )) $notjc = "AND deleted <> 1"; //JC can view deleted posts $query = "SELECT * FROM comments WHERE `proposal_id`='".$proposal."' $notjc ORDER BY id ASC"; if( $this->mysql->query($query) ) { $ret = array(); while( $row = $this->mysql->fetchAssoc() ) { $ret[ $row['id'] ] = $row; } return $ret; } else { return array(); } } public function saveOrUpdate(IModel $comment) { if($comment->getId()==NULL) { $query = "INSERT INTO `comments` SET "; } else { $query = "UPDATE `comments` SET "; } $query .="`commenter_uid` = '".$this->mysql->escape($comment->getCommenter_uid())."', "; $query .="`proposal_id` = '".$this->mysql->escape($comment->getProposal_id())."', "; $query .="`time` = '".$this->mysql->escape($comment->getTime())."', "; $query .="`text` = '".trim($this->mysql->escape($comment->getText()))."', "; $query .="`deleted` = '".$this->mysql->escape($comment->getDeleted())."'"; if($comment->getId()!=NULL) { $query.=" where `id` = ".$comment->getId(); } return $this->mysql->query($query); } public function delete($comment_id) { /*OOP: c=load($id) - c-setDeleted(1) - save(c)*/ $query = "UPDATE comments SET deleted = 1 WHERE `id`=".$comment_id; return $this->mysql->query($query); } public function approve($comment_id) { /*OOP: c=load($id) - c->setDeleted(0) - save(c)*/ $query = "UPDATE comments SET deleted = 0 WHERE `id`=".$comment_id; return $this->mysql->query($query); } public function checkdouble(IModel $comment) { $query = "select id FROM comments WHERE `proposal_id` = '".$this->mysql->escape($comment->getProposal_id())."' AND commenter_uid = '".$this->mysql->escape($comment->getCommenter_uid())."' AND text = '".trim($this->mysql->escape($comment->getText()))."' AND time > ".(time()-60*60); $this->mysql->query($query); return $this->mysql->getNumRows(); } public function checkspam(IModel $comment) {//Gives back the number of posts made on that proposal in the last 10 minutes, so you still have to check whether that number is okay! $query = "select id FROM comments WHERE `proposal_id` = '".$this->mysql->escape($comment->getProposal_id())."' AND commenter_uid = '".$this->mysql->escape($comment->getCommenter_uid())."' AND time > ".(time()-60*10); $this->mysql->query($query); return $this->mysql->getNumRows(); } } ?>