link_category.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. namespace Link;
  3. /**
  4. * Model for link_category.
  5. *
  6. * Links can be added to a category.
  7. * A link belong to at most one category.
  8. * A link may not belong to a category.
  9. * Categories cannot be nested, i.e. it is not possible to have categories inside a category.
  10. *
  11. *
  12. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  13. * @license /license.txt
  14. */
  15. class LinkCategory
  16. {
  17. /**
  18. * @return \Link\LinkCategoryRepository
  19. */
  20. public static function repository()
  21. {
  22. return LinkCategoryRepository::instance();
  23. }
  24. /**
  25. * @return \Entity\LinkCategory
  26. */
  27. public static function create($data = null)
  28. {
  29. return new self($data);
  30. }
  31. /**
  32. * @var integer $c_id
  33. */
  34. protected $c_id;
  35. /**
  36. * @var integer $id
  37. */
  38. protected $id;
  39. /**
  40. * @var string $category_title
  41. */
  42. protected $category_title;
  43. /**
  44. * @var text $description
  45. */
  46. protected $description;
  47. /**
  48. * @var integer $display_order
  49. */
  50. protected $display_order;
  51. /**
  52. * @var integer $session_id
  53. */
  54. protected $session_id;
  55. protected $links = null;
  56. function __construct($data = null)
  57. {
  58. if ($data) {
  59. foreach ($this as $key => $value) {
  60. if (isset($data->{$key})) {
  61. $this->{$key} = $data->{$key};
  62. }
  63. }
  64. }
  65. }
  66. function __get($name)
  67. {
  68. $f = array($this, "get_$name");
  69. return call_user_func($f);
  70. }
  71. function __isset($name)
  72. {
  73. $f = array($this, "get_$name");
  74. return is_callable($f);
  75. }
  76. function __set($name, $value)
  77. {
  78. $f = array($this, "set_$name");
  79. if (!is_callable($f)) {
  80. return;
  81. }
  82. call_user_func($f, $value);
  83. }
  84. /**
  85. * Set c_id
  86. *
  87. * @param integer $value
  88. * @return LinkCategory
  89. */
  90. public function set_c_id($value)
  91. {
  92. $this->c_id = $value;
  93. return $this;
  94. }
  95. /**
  96. * Get c_id
  97. *
  98. * @return integer
  99. */
  100. public function get_c_id()
  101. {
  102. return $this->c_id;
  103. }
  104. /**
  105. * Set id
  106. *
  107. * @param integer $value
  108. * @return LinkCategory
  109. */
  110. public function set_id($value)
  111. {
  112. $this->id = $value;
  113. return $this;
  114. }
  115. /**
  116. * Get id
  117. *
  118. * @return integer
  119. */
  120. public function get_id()
  121. {
  122. return $this->id;
  123. }
  124. /**
  125. * Set category_title
  126. *
  127. * @param string $value
  128. * @return LinkCategory
  129. */
  130. public function set_category_title($value)
  131. {
  132. $value = trim($value);
  133. $this->category_title = $value;
  134. return $this;
  135. }
  136. /**
  137. * Get category_title
  138. *
  139. * @return string
  140. */
  141. public function get_category_title()
  142. {
  143. return $this->category_title;
  144. }
  145. /**
  146. * Set description
  147. *
  148. * @param text $value
  149. * @return LinkCategory
  150. */
  151. public function set_description($value)
  152. {
  153. $this->description = $value;
  154. return $this;
  155. }
  156. /**
  157. * Get description
  158. *
  159. * @return text
  160. */
  161. public function get_description()
  162. {
  163. return $this->description;
  164. }
  165. /**
  166. * Set display_order
  167. *
  168. * @param integer $value
  169. * @return LinkCategory
  170. */
  171. public function set_display_order($value)
  172. {
  173. $this->display_order = $value;
  174. return $this;
  175. }
  176. /**
  177. * Get display_order
  178. *
  179. * @return integer
  180. */
  181. public function get_display_order()
  182. {
  183. return $this->display_order;
  184. }
  185. /**
  186. * Set session_id
  187. *
  188. * @param integer $value
  189. * @return LinkCategory
  190. */
  191. public function set_session_id($value)
  192. {
  193. $this->session_id = $value;
  194. return $this;
  195. }
  196. /**
  197. * Get session_id
  198. *
  199. * @return integer
  200. */
  201. public function get_session_id()
  202. {
  203. return $this->session_id;
  204. }
  205. public function get_links()
  206. {
  207. if (is_null($this->links)) {
  208. $this->links = LinkRepository::instance()->find_by_category($this);
  209. }
  210. return $this->links;
  211. }
  212. }