<?php
	require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'class.api.php');

	class API_COMMENT extends API
	{
		var $commentid = 0;
		var $questionid = 0;
		var $name = '';
		var $email = '';
		var $content = '';
		var $status = '';
		var $posted = 0;

		var $fields = array (
			'commentid',
			'questionid',
			'name',
			'email',
			'content',
			'status',
			'posted',
		);

		var $pk = 'commentid';

		/**
		* create
		* Add a comment entry to the database. The parent function is overridden
		* so that we can set the posted var here
		*
		* @return bool Was the creation a success ?
		*/
		function create()
		{
			$_POST['posted'] = date('Y-m-d H:i:s');
			return parent::create();
		}

		/**
		* validate_commentid
		*
		* Ensure the comment id is a pos int
		*
		* @param string $var
		*
		* @return bool
		*/
		function validate_commentid($var)
		{
			return $this->is_positive_int($var);
		}

		/**
		* validate_questionid
		*
		* Ensure the questionid is a pos int
		*
		* @param string $var
		*
		* @return bool
		*/
		function validate_questionid($var)
		{
			return $this->is_positive_int($var);
		}

		/**
		* validate_name
		*
		* Ensure the name isn't too long
		*
		* @param string $var
		*
		* @return bool
		*/
		function validate_name($var)
		{
			return (strlen($var) <= 100);
		}

		/**
		* validate_email
		*
		* Ensure the email, if specified, is valid
		*
		* @param string $var
		*
		* @return bool
		*/
		function validate_email($var)
		{
			if (empty($var)) {
				return true;
			}

			return is_email_address($var);
		}

		/**
		* validate_status
		*
		* Ensure the status is valid
		*
		* @param string $var
		*
		* @return bool
		*/
		function validate_status($var)
		{
			$valid_status = array (
				'pending',
				'approved',
				'disapproved',
			);

			return in_array($var, $valid_status);
		}

		/**
		* validate_posted
		*
		* Ensure the posted var is in the standard date format
		*
		* @param string $var
		*
		* @return bool
		*/
		function validate_posted($var)
		{
			return $this->is_standard_date($var);
		}

	}

?>
