link_category.class.php 4.3 KB

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