PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/models/Post.class.php

https://github.com/HarrickZeke/PHPForum
PHP | 130 lines | 102 code | 24 blank | 4 comment | 6 complexity | 227a4040f7a5da93ae5c2fb3604070d6 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. */
  5. class Post
  6. {
  7. private $_id;
  8. private $_body;
  9. private $_datetime;
  10. private $_topicId;
  11. private $_authorId;
  12. private $_orderId;
  13. public function __construct(array $data)
  14. {
  15. $this->hydrate($data);
  16. }
  17. public function hydrate(array $data)
  18. {
  19. foreach ($data as $key => $value)
  20. {
  21. $method = 'set'.ucfirst($key);
  22. if (method_exists($this, $method))
  23. {
  24. $this->$method($value);
  25. }
  26. }
  27. }
  28. public function setId($id)
  29. {
  30. $id = (int) $id;
  31. if(!is_int($id))
  32. {
  33. trigger_error("Id must be an integer");
  34. return;
  35. }
  36. $this->_id = $id;
  37. }
  38. public function setBody($body)
  39. {
  40. if(!is_string($body))
  41. {
  42. trigger_error("Body must be a string");
  43. return;
  44. }
  45. $this->_body = $body;
  46. }
  47. public function setTopicId($topicId)
  48. {
  49. $topicId = (int) $topicId;
  50. if(!is_int($topicId))
  51. {
  52. trigger_error("Author id must be an integer");
  53. return;
  54. }
  55. $this->_topicId = $topicId;
  56. }
  57. public function setAuthorId($authorId)
  58. {
  59. $authorId = (int) $authorId;
  60. if(!is_int($authorId))
  61. {
  62. trigger_error("Author id must be an integer");
  63. return;
  64. }
  65. $this->_authorId = $authorId;
  66. }
  67. public function setDatetime($datetime)
  68. {
  69. //TODO : check datetime
  70. $this->_datetime = $datetime;
  71. }
  72. public function setOrderId($orderId)
  73. {
  74. $orderId = (int) $orderId;
  75. if(!is_int($orderId))
  76. {
  77. trigger_error("Order must be an integer");
  78. return;
  79. }
  80. $this->_orderId = $orderId;
  81. }
  82. public function id()
  83. {
  84. return $this->_id;
  85. }
  86. public function body()
  87. {
  88. return $this->_body;
  89. }
  90. public function datetime()
  91. {
  92. return $this->_datetime;
  93. }
  94. public function topicId()
  95. {
  96. return $this->_topicId;
  97. }
  98. public function authorId()
  99. {
  100. return $this->_authorId;
  101. }
  102. public function orderId()
  103. {
  104. return $this->_orderId;
  105. }
  106. }