PHPForum /models/Post.class.php

Language PHP Lines 130
MD5 Hash 227a4040f7a5da93ae5c2fb3604070d6
Repository https://github.com/HarrickZeke/PHPForum.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* 
*/
class Post
{
	private $_id;
	private $_body;
	private $_datetime;
	private $_topicId;
	private $_authorId;
	private $_orderId;

	public function __construct(array $data)
	{
		$this->hydrate($data);
	}

	public function hydrate(array $data)
	{
	  	foreach ($data as $key => $value)
	  	{
		    $method = 'set'.ucfirst($key);
	        
	        if (method_exists($this, $method))
		    {
		      	$this->$method($value);
	    	}
	  	}
	}

	public function setId($id)
	{
		$id = (int) $id;

		if(!is_int($id))
		{
			trigger_error("Id must be an integer");
			return;
		}

		$this->_id = $id;
	}

	public function setBody($body)
	{
		if(!is_string($body))
		{
			trigger_error("Body must be a string");
			return;
		}

		$this->_body = $body;
	}

	public function setTopicId($topicId)
	{
		$topicId = (int) $topicId;

		if(!is_int($topicId))
		{
			trigger_error("Author id must be an integer");
			return;
		}

		$this->_topicId = $topicId;
	}

	public function setAuthorId($authorId)
	{
		$authorId = (int) $authorId;

		if(!is_int($authorId))
		{
			trigger_error("Author id must be an integer");
			return;
		}

		$this->_authorId = $authorId;
	}

	public function setDatetime($datetime)
	{
		//TODO : check datetime
		$this->_datetime = $datetime;
	}

	public function setOrderId($orderId)
	{
		$orderId = (int) $orderId;

		if(!is_int($orderId))
		{
			trigger_error("Order must be an integer");
			return;
		}

		$this->_orderId = $orderId;
	}

	public function id()
	{
		return $this->_id;
	}
	
	public function body()
	{
		return $this->_body;
	}

	public function datetime()
	{
		return $this->_datetime;
	}

	public function topicId()
	{
		return $this->_topicId;
	}

	public function authorId()
	{
		return $this->_authorId;
	}

	public function orderId()
	{
		return $this->_orderId;
	}
}
Back to Top