<commit_before><?php
class commentHandler{
	private $commentArray;

	/** Se userHAndler.class.php*/
	function __construct() {
		$sql = "SELECT * FROM " . settings::getDbPrefix(). "comments ORDER BY time DESC";
		
		/*** fetch into an PDOStatement object ***/
		$stmt = settings::getDatabase() -> query($sql);
		$stmt->execute();

		/*** fetch into the animals class ***/
		$this -> commentArray = $stmt -> fetchALL(PDO::FETCH_CLASS, 'comment');
	}
	
	/** Henter ut kommentarer gitt av postId */
	public function getCommentsForPost($postId, $users){
		$tempArray = array();
		
		foreach ($this->commentArray as $comment) {
			if ($postId == $comment->getPostId() && $comment->getPageId() == NULL) {
				$user = $users->getUserById($comment->getAuthorId());
				$tempArray[] = array('time' => date("r", $comment->getTime()),
					'author' => htmlentities($user->getFirstname()) . " " . htmlentities($user->getLastname()),
					'content' => htmlentities($comment->getContent()));
			}
		}

		return $tempArray;

	}
	
	/** Henter ut kommentarer gitt av pageId */
	public function getCommentsForPage($pageId, $users){
		$tempArray = array();
		
		foreach ($this->commentArray as $comment) {
			if ($pageId == $comment->getPageId() && $comment->getPostId() == NULL) {
				$user = $users->getUserById($comment->getAuthorId());
				$tempArray[] = array('time' => date("r", $comment->getTime()),
					'author' => htmlentities($user->getFirstname()) . " " . htmlentities($user->getLastname()),
					'content' => htmlentities($comment->getContent()));
			}
		}
		return $tempArray;
	}
	
	/** Legger til en ny kommentar. */
	public function addComment($postid, $page_id, $desc, $a_id){
		$this->commentArray[] = new comment($postid, $page_id, time(), $desc, $a_id);
	}
}

class comment{
	private $post_id;
	private $page_id;
	private $time;
	private $content;
	private $author_id;

	function __construct($post_id=null, $page_id=null, $time=null, $desc=null, $a_id=null) {
		if ($time != null || $a_id != null || $desc != null) {
			$this->post_id = $post_id;
			$this->page_id = $page_id;
			$this->time = $time;
			$this->content = $desc;
			$this->author_id = $a_id;
		
			$this->save(true);
		}
	}

	public function getPostId(){
		return $this->post_id;
	}

	public function getPageId(){
		return $this->page_id;
	}

	public function getTime(){
		return $this->time;
	}

	public function getContent(){
		return $this->content;
	}
	
	public function getAuthorId(){
		return $this->author_id;
	}
	
	private function save($new = false){
		/*** The SQL SELECT statement ***/
		if($new) {
			$sql = "INSERT INTO " . settings::getDbPrefix() . "comments " . 
			"(page_id, post_id, time, author_id, content) " . 
			"VALUES (:page_id, :post_id, :time, :author_id, :content);";
		} else {
			$sql = "UPDATE " . settings::getDbPrefix() . "comments " .
			"SET post_id=:post_id, page_id=:page_id, time=:time, author_id=:author_id, content=:content " . 
        	"WHERE id=:id";
		}
		
		/*** fetch into an PDOStatement object ***/
		$stmt = settings::getDatabase()->prepare($sql);

		/*** fetch into the animals class ***/
		if ($new){
			$stmt -> execute(array(':post_id'=>$this -> post_id,
								':page_id'=>$this -> page_id,
								':time'=>$this -> time,
								':author_id'=>$this -> author_id,
								':content'=>$this -> content));
		} else {
			$stmt -> execute(array(':id'=>$this -> id,
								':post_id'=>$this -> post_id,
								':page_id'=>$this -> page_id,
								':time'=>$this -> time,
								':author_id'=>$this -> author_id,
								':content'=>$this -> content));
		}
	}
}
?><commit_msg>snur kommentarsystemet på hode<commit_after><?php
class commentHandler{
	private $commentArray;

	/** Se userHAndler.class.php*/
	function __construct() {
		$sql = "SELECT * FROM " . settings::getDbPrefix(). "comments ORDER BY time ASC";
		
		/*** fetch into an PDOStatement object ***/
		$stmt = settings::getDatabase() -> query($sql);
		$stmt->execute();

		/*** fetch into the animals class ***/
		$this -> commentArray = $stmt -> fetchALL(PDO::FETCH_CLASS, 'comment');
	}
	
	/** Henter ut kommentarer gitt av postId */
	public function getCommentsForPost($postId, $users){
		$tempArray = array();
		
		foreach ($this->commentArray as $comment) {
			if ($postId == $comment->getPostId() && $comment->getPageId() == NULL) {
				$user = $users->getUserById($comment->getAuthorId());
				$tempArray[] = array('time' => date("r", $comment->getTime()),
					'author' => htmlentities($user->getFirstname()) . " " . htmlentities($user->getLastname()),
					'content' => htmlentities($comment->getContent()));
			}
		}

		return $tempArray;

	}
	
	/** Henter ut kommentarer gitt av pageId */
	public function getCommentsForPage($pageId, $users){
		$tempArray = array();
		
		foreach ($this->commentArray as $comment) {
			if ($pageId == $comment->getPageId() && $comment->getPostId() == NULL) {
				$user = $users->getUserById($comment->getAuthorId());
				$tempArray[] = array('time' => date("r", $comment->getTime()),
					'author' => htmlentities($user->getFirstname()) . " " . htmlentities($user->getLastname()),
					'content' => htmlentities($comment->getContent()));
			}
		}
		return $tempArray;
	}
	
	/** Legger til en ny kommentar. */
	public function addComment($postid, $page_id, $desc, $a_id){
		$this->commentArray[] = new comment($postid, $page_id, time(), $desc, $a_id);
	}
}

class comment{
	private $post_id;
	private $page_id;
	private $time;
	private $content;
	private $author_id;

	function __construct($post_id=null, $page_id=null, $time=null, $desc=null, $a_id=null) {
		if ($time != null || $a_id != null || $desc != null) {
			$this->post_id = $post_id;
			$this->page_id = $page_id;
			$this->time = $time;
			$this->content = $desc;
			$this->author_id = $a_id;
		
			$this->save(true);
		}
	}

	public function getPostId(){
		return $this->post_id;
	}

	public function getPageId(){
		return $this->page_id;
	}

	public function getTime(){
		return $this->time;
	}

	public function getContent(){
		return $this->content;
	}
	
	public function getAuthorId(){
		return $this->author_id;
	}
	
	private function save($new = false){
		/*** The SQL SELECT statement ***/
		if($new) {
			$sql = "INSERT INTO " . settings::getDbPrefix() . "comments " . 
			"(page_id, post_id, time, author_id, content) " . 
			"VALUES (:page_id, :post_id, :time, :author_id, :content);";
		} else {
			$sql = "UPDATE " . settings::getDbPrefix() . "comments " .
			"SET post_id=:post_id, page_id=:page_id, time=:time, author_id=:author_id, content=:content " . 
        	"WHERE id=:id";
		}
		
		/*** fetch into an PDOStatement object ***/
		$stmt = settings::getDatabase()->prepare($sql);

		/*** fetch into the animals class ***/
		if ($new){
			$stmt -> execute(array(':post_id'=>$this -> post_id,
								':page_id'=>$this -> page_id,
								':time'=>$this -> time,
								':author_id'=>$this -> author_id,
								':content'=>$this -> content));
		} else {
			$stmt -> execute(array(':id'=>$this -> id,
								':post_id'=>$this -> post_id,
								':page_id'=>$this -> page_id,
								':time'=>$this -> time,
								':author_id'=>$this -> author_id,
								':content'=>$this -> content));
		}
	}
}
?>
{'fraction_non_alphanumeric': 0.1928648068669528, 'fraction_numerical': 0.0, 'mean_word_length': 3.142777777777778, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1541606', 'n_tokens_mistral': 2928, 'n_tokens_neox': 2512, 'n_words': 525}