link.class.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Link class definition
  5. * @package chamilo.link
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Link;
  11. /**
  12. * Model for Link/Urls
  13. *
  14. *
  15. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  16. * @license /license.txt
  17. */
  18. class Link
  19. {
  20. /**
  21. * @return \Entity\Repository\LinkRepository
  22. */
  23. public static function repository()
  24. {
  25. return \Entity\Repository\LinkRepository::instance();
  26. }
  27. /**
  28. * @return \Entity\Link
  29. */
  30. public static function create($data = null)
  31. {
  32. return new self($data);
  33. }
  34. function __construct($data = null)
  35. {
  36. if ($data) {
  37. foreach ($this as $key => $value) {
  38. if (isset($data->{$key})) {
  39. $this->{$key} = $data->{$key};
  40. }
  41. }
  42. }
  43. }
  44. function __get($name)
  45. {
  46. $f = array($this, "get_$name");
  47. return call_user_func($f);
  48. }
  49. function __isset($name)
  50. {
  51. $f = array($this, "get_$name");
  52. return is_callable($f);
  53. }
  54. function __set($name, $value)
  55. {
  56. $f = array($this, "set_$name");
  57. if (!is_callable($f)) {
  58. return;
  59. }
  60. call_user_func($f, $value);
  61. }
  62. /**
  63. * @var integer $c_id
  64. */
  65. protected $c_id;
  66. /**
  67. * @var integer $id
  68. */
  69. protected $id;
  70. /**
  71. * @var text $url
  72. */
  73. protected $url;
  74. /**
  75. * @var string $title
  76. */
  77. protected $title;
  78. /**
  79. * @var text $description
  80. */
  81. protected $description;
  82. /**
  83. * @var integer $category_id
  84. */
  85. protected $category_id;
  86. /**
  87. * @var integer $display_order
  88. */
  89. protected $display_order;
  90. /**
  91. * @var string $on_homepage
  92. */
  93. protected $on_homepage;
  94. /**
  95. * @var string $target
  96. */
  97. protected $target;
  98. /**
  99. * @var integer $session_id
  100. */
  101. protected $session_id;
  102. protected $visibility = 0;
  103. /**
  104. * Set c_id
  105. *
  106. * @param integer $value
  107. * @return Link
  108. */
  109. public function set_c_id($value)
  110. {
  111. $this->c_id = $value;
  112. return $this;
  113. }
  114. /**
  115. * Get c_id
  116. *
  117. * @return integer
  118. */
  119. public function get_c_id()
  120. {
  121. return $this->c_id;
  122. }
  123. /**
  124. * Set id
  125. *
  126. * @param integer $value
  127. * @return Link
  128. */
  129. public function set_id($value)
  130. {
  131. $this->id = $value;
  132. return $this;
  133. }
  134. /**
  135. * Get id
  136. *
  137. * @return integer
  138. */
  139. public function get_id()
  140. {
  141. return $this->id;
  142. }
  143. /**
  144. * Set url
  145. *
  146. * @param text $value
  147. * @return Link
  148. */
  149. public function set_url($value)
  150. {
  151. $this->url = $value;
  152. return $this;
  153. }
  154. /**
  155. * Get url
  156. *
  157. * @return text
  158. */
  159. public function get_url()
  160. {
  161. return $this->url;
  162. }
  163. /**
  164. * Set title
  165. *
  166. * @param string $value
  167. * @return Link
  168. */
  169. public function set_title($value)
  170. {
  171. $this->title = $value;
  172. return $this;
  173. }
  174. /**
  175. * Get title
  176. *
  177. * @return string
  178. */
  179. public function get_title()
  180. {
  181. return $this->title;
  182. }
  183. /**
  184. * Set description
  185. *
  186. * @param text $value
  187. * @return Link
  188. */
  189. public function set_description($value)
  190. {
  191. $this->description = $value;
  192. return $this;
  193. }
  194. /**
  195. * Get description
  196. *
  197. * @return text
  198. */
  199. public function get_description()
  200. {
  201. return $this->description;
  202. }
  203. /**
  204. * Set category_id
  205. *
  206. * @param integer $value
  207. * @return Link
  208. */
  209. public function set_category_id($value)
  210. {
  211. $this->category_id = $value;
  212. return $this;
  213. }
  214. /**
  215. * Get category_id
  216. *
  217. * @return integer
  218. */
  219. public function get_category_id()
  220. {
  221. return $this->category_id;
  222. }
  223. /**
  224. * Set display_order
  225. *
  226. * @param integer $value
  227. * @return Link
  228. */
  229. public function set_display_order($value)
  230. {
  231. $this->display_order = $value;
  232. return $this;
  233. }
  234. /**
  235. * Get display_order
  236. *
  237. * @return integer
  238. */
  239. public function get_display_order()
  240. {
  241. return $this->display_order;
  242. }
  243. /**
  244. * Set on_homepage
  245. *
  246. * @param string $value
  247. * @return Link
  248. */
  249. public function set_on_homepage($value)
  250. {
  251. $this->on_homepage = $value;
  252. return $this;
  253. }
  254. /**
  255. * Get on_homepage
  256. *
  257. * @return string
  258. */
  259. public function get_on_homepage()
  260. {
  261. return $this->on_homepage;
  262. }
  263. /**
  264. * Set target
  265. *
  266. * @param string $value
  267. * @return Link
  268. */
  269. public function set_target($value)
  270. {
  271. $this->target = $value;
  272. return $this;
  273. }
  274. /**
  275. * Get target
  276. *
  277. * @return string
  278. */
  279. public function get_target()
  280. {
  281. return $this->target;
  282. }
  283. /**
  284. * Set session_id
  285. *
  286. * @param integer $value
  287. * @return Link
  288. */
  289. public function set_session_id($value)
  290. {
  291. $this->session_id = $value;
  292. return $this;
  293. }
  294. /**
  295. * Get session_id
  296. *
  297. * @return integer
  298. */
  299. public function get_session_id()
  300. {
  301. return $this->session_id;
  302. }
  303. public function get_visibility()
  304. {
  305. return (int) $this->visibility;
  306. }
  307. public function set_visibility($value)
  308. {
  309. $this->visibility = (int) $value;
  310. return $this;
  311. }
  312. public function is_visible()
  313. {
  314. return $this->get_visibility() == 1;
  315. }
  316. public function is_hidden()
  317. {
  318. return $this->get_visibility() == 0;
  319. }
  320. public function validate()
  321. {
  322. $url = $this->get_url();
  323. if (empty($url)) {
  324. return false;
  325. }
  326. if (!in_array('curl', get_loaded_extensions())) {
  327. true;
  328. }
  329. $defaults = array(
  330. CURLOPT_URL => $url,
  331. CURLOPT_FOLLOWLOCATION => true,
  332. CURLOPT_HEADER => 0,
  333. CURLOPT_NOBODY => true,
  334. CURLOPT_TIMEOUT => 4,
  335. CURLOPT_RETURNTRANSFER => false
  336. );
  337. $ch = curl_init();
  338. curl_setopt_array($ch, $defaults);
  339. $result = curl_exec($ch);
  340. curl_close($ch);
  341. return $result;
  342. }
  343. }