linkfactory.class.php 3.0 KB

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