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. * @return array
  21. */
  22. public static function load(
  23. $id = null,
  24. $type = null,
  25. $ref_id = null,
  26. $user_id = null,
  27. $course_code = null,
  28. $category_id = null,
  29. $visible = null
  30. ) {
  31. return AbstractLink::load(
  32. $id,
  33. $type,
  34. $ref_id,
  35. $user_id,
  36. $course_code,
  37. $category_id,
  38. $visible
  39. );
  40. }
  41. /**
  42. * Get the link object referring to an evaluation
  43. */
  44. public function get_evaluation_link($eval_id)
  45. {
  46. $links = AbstractLink::load(null, null, $eval_id);
  47. foreach ($links as $link) {
  48. if (is_a($link, 'EvalLink')) {
  49. return $link;
  50. }
  51. }
  52. return null;
  53. }
  54. /**
  55. * Find links by name
  56. * @param string $name_mask search string
  57. * @return array link objects matching the search criterium
  58. */
  59. public function find_links($name_mask, $selectcat)
  60. {
  61. return AbstractLink::find_links($name_mask, $selectcat);
  62. }
  63. /**
  64. * Static method to create specific link objects
  65. * @param $type link type
  66. */
  67. public static function create($type)
  68. {
  69. $type = intval($type);
  70. switch ($type) {
  71. case LINK_EXERCISE:
  72. return new ExerciseLink();
  73. case LINK_HOTPOTATOES:
  74. return new ExerciseLink(1);
  75. case LINK_DROPBOX:
  76. return new DropboxLink();
  77. case LINK_STUDENTPUBLICATION:
  78. return new StudentPublicationLink();
  79. case LINK_LEARNPATH:
  80. return new LearnpathLink();
  81. case LINK_FORUM_THREAD:
  82. return new ForumThreadLink();
  83. case LINK_ATTENDANCE:
  84. return new AttendanceLink();
  85. case LINK_SURVEY:
  86. return new SurveyLink();
  87. }
  88. return null;
  89. }
  90. /**
  91. * Return an array of all known link types
  92. * @return array
  93. */
  94. public static function get_all_types()
  95. {
  96. //LINK_DROPBOX,
  97. return array(
  98. LINK_EXERCISE,
  99. //LINK_DROPBOX,
  100. LINK_HOTPOTATOES,
  101. LINK_STUDENTPUBLICATION,
  102. LINK_LEARNPATH,
  103. LINK_FORUM_THREAD,
  104. LINK_ATTENDANCE,
  105. LINK_SURVEY
  106. );
  107. }
  108. public function delete()
  109. {
  110. }
  111. }