linkfactory.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class LinkFactory
  5. * Factory for link objects
  6. * @author Bert Steppé
  7. * @package chamilo.gradebook
  8. */
  9. class LinkFactory
  10. {
  11. /**
  12. * Retrieve links and return them as an array of extensions of AbstractLink.
  13. * @param int $id link id
  14. * @param int $type link type
  15. * @param int $ref_id reference id
  16. * @param int $user_id user id (link owner)
  17. * @param string $course_code course code
  18. * @param int $category_id parent category
  19. * @param int $visible visible
  20. */
  21. public static function load(
  22. $id = null,
  23. $type = null,
  24. $ref_id = null,
  25. $user_id = null,
  26. $course_code = null,
  27. $category_id = null,
  28. $visible = null
  29. ) {
  30. return AbstractLink::load(
  31. $id,
  32. $type,
  33. $ref_id,
  34. $user_id,
  35. $course_code,
  36. $category_id,
  37. $visible
  38. );
  39. }
  40. /**
  41. * Get the link object referring to an evaluation
  42. */
  43. public function get_evaluation_link($eval_id)
  44. {
  45. $links = AbstractLink :: load(null, null, $eval_id);
  46. foreach ($links as $link) {
  47. if (is_a($link, 'EvalLink')) {
  48. return $link;
  49. }
  50. }
  51. return null;
  52. }
  53. /**
  54. * Find links by name
  55. * @param string $name_mask search string
  56. * @return array link objects matching the search criterium
  57. */
  58. public function find_links($name_mask,$selectcat)
  59. {
  60. return AbstractLink::find_links($name_mask, $selectcat);
  61. }
  62. /**
  63. * Static method to create specific link objects
  64. * @param $type link type
  65. */
  66. public static function create($type)
  67. {
  68. $type = intval($type);
  69. switch ($type) {
  70. case LINK_EXERCISE:
  71. return new ExerciseLink();
  72. case LINK_HOTPOTATOES:
  73. return new ExerciseLink(1);
  74. case LINK_DROPBOX:
  75. return new DropboxLink();
  76. case LINK_STUDENTPUBLICATION:
  77. return new StudentPublicationLink();
  78. case LINK_LEARNPATH:
  79. return new LearnpathLink();
  80. case LINK_FORUM_THREAD:
  81. return new ForumThreadLink();
  82. case LINK_ATTENDANCE:
  83. return new AttendanceLink();
  84. case LINK_SURVEY:
  85. return new SurveyLink();
  86. }
  87. return null;
  88. }
  89. /**
  90. * Return an array of all known link types
  91. * @return array
  92. */
  93. public static function get_all_types()
  94. {
  95. //LINK_DROPBOX,
  96. return array (
  97. LINK_EXERCISE,
  98. //LINK_DROPBOX,
  99. LINK_HOTPOTATOES,
  100. LINK_STUDENTPUBLICATION,
  101. LINK_LEARNPATH,
  102. LINK_FORUM_THREAD,
  103. LINK_ATTENDANCE,
  104. LINK_SURVEY
  105. );
  106. }
  107. public function delete()
  108. {
  109. }
  110. }