linkfactory.class.php 3.0 KB

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