PageRenderTime 309ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/models/Topic.class.php

https://github.com/HarrickZeke/PHPForum
PHP | 137 lines | 108 code | 26 blank | 3 comment | 7 complexity | 7d30ade5eea2692b2d9417ac1dc5901e MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. */
  5. class Topic
  6. {
  7. private $_id;
  8. private $_name;
  9. private $_description;
  10. private $_authorId;
  11. private $_orderId;
  12. private $_categoryId;
  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 setName($name)
  39. {
  40. if(!is_string($name))
  41. {
  42. trigger_error("Name must be a string");
  43. return;
  44. }
  45. $this->_name = $name;
  46. }
  47. public function setDescription($description)
  48. {
  49. if(!is_string($description))
  50. {
  51. trigger_error("Description must be a string");
  52. return;
  53. }
  54. $this->_description = $description;
  55. }
  56. public function setAuthorId($authorId)
  57. {
  58. $authorId = (int) $authorId;
  59. if(!is_int($authorId))
  60. {
  61. trigger_error("Author id must be an integer");
  62. return;
  63. }
  64. $this->_authorId = $authorId;
  65. }
  66. public function setOrderId($orderId)
  67. {
  68. $orderId = (int) $orderId;
  69. if(!is_int($orderId))
  70. {
  71. trigger_error("Order id must be an integer");
  72. return;
  73. }
  74. $this->_orderId = $orderId;
  75. }
  76. public function setCategoryId($categoryId)
  77. {
  78. $categoryId = (int) $categoryId;
  79. if(!is_int($categoryId))
  80. {
  81. trigger_error("Category id must be an integer");
  82. return;
  83. }
  84. $this->_categoryId = $categoryId;
  85. }
  86. public function id()
  87. {
  88. return $this->_id;
  89. }
  90. public function name()
  91. {
  92. return $this->_name;
  93. }
  94. public function description()
  95. {
  96. return $this->_description;
  97. }
  98. public function authorId()
  99. {
  100. return $this->_authorId;
  101. }
  102. public function orderId()
  103. {
  104. return $this->_orderId;
  105. }
  106. public function categoryId()
  107. {
  108. return $this->_categoryId;
  109. }
  110. }
  111. ?>