/models/Post.class.php
PHP | 130 lines | 102 code | 24 blank | 4 comment | 6 complexity | 227a4040f7a5da93ae5c2fb3604070d6 MD5 | raw file
- <?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;
- }
- }