<?php

class comments
{

	private $id;
	private $comments;
	private $replies;

	public function __construct($id)
	{
		if (!isnum($id)) return false;
		$this->id = $id;
	}

	public function get_comments($check = false)
	{
		if (!$this->comments)
		{
			global $_sql;
			$query = $_sql->query("SELECT `comments`.*, users.userName AS bySlug, users.userPublicName AS byName, users.userPic FROM `comments` INNER JOIN users ON commentBy = userId WHERE commentEntry = ".$this->id." AND commentReply = 0 ORDER BY commentTime DESC");
			if ($check)
				return $query->num_rows;
			else
				$this->comments = $query;
		}
		return $this->comments->fetch_assoc();
	}

	public function get_replies($check = false)
	{
		if (!$this->replies)
		{
			global $_sql;
			$query = $_sql->query("SELECT `comments`.*, users.userName AS bySlug, users.userPublicName AS byName, users.userPic FROM `comments` INNER JOIN users ON commentBy = userId WHERE commentReply = ".$this->id." ORDER BY commentTime DESC");
			if ($check)
				return $query->num_rows;
			$this->replies = $query;
		}
		return $this->replies->fetch_assoc();
	}



}