linkfactory.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. // To add your new link type here:
  11. // - define a unique type id
  12. // - add include
  13. // - change create() and get_all_types()
  14. require_once 'gradebookitem.class.php';
  15. require_once 'abstractlink.class.php';
  16. require_once 'exerciselink.class.php';
  17. require_once 'evallink.class.php';
  18. require_once 'dropboxlink.class.php';
  19. require_once 'studentpublicationlink.class.php';
  20. require_once 'learnpathlink.class.php';
  21. require_once 'forumthreadlink.class.php';
  22. require_once 'attendancelink.class.php';
  23. require_once 'surveylink.class.php';
  24. /**
  25. * Factory for link objects
  26. * @author Bert Steppé
  27. * @package chamilo.gradebook
  28. */
  29. class LinkFactory
  30. {
  31. /**
  32. * Retrieve links and return them as an array of extensions of AbstractLink.
  33. * @param $id link id
  34. * @param $type link type
  35. * @param $ref_id reference id
  36. * @param $user_id user id (link owner)
  37. * @param $course_code course code
  38. * @param $category_id parent category
  39. * @param $visible visible
  40. */
  41. public static function load ($id = null, $type = null, $ref_id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) {
  42. return AbstractLink::load($id, $type, $ref_id, $user_id, $course_code, $category_id, $visible);
  43. }
  44. /**
  45. * Get the link object referring to an evaluation
  46. */
  47. public function get_evaluation_link ($eval_id) {
  48. $links = AbstractLink :: load(null, null, $eval_id);
  49. foreach ($links as $link) {
  50. if (is_a($link, 'EvalLink')) {
  51. return $link;
  52. }
  53. }
  54. return null;
  55. }
  56. /**
  57. * Find links by name
  58. * @param string $name_mask search string
  59. * @return array link objects matching the search criterium
  60. */
  61. public function find_links ($name_mask,$selectcat) {
  62. return AbstractLink::find_links($name_mask,$selectcat);
  63. }
  64. /**
  65. * Static method to create specific link objects
  66. * @param $type link type
  67. */
  68. public static function create ($type) {
  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. */
  93. public static function get_all_types () {
  94. //LINK_DROPBOX,
  95. return array (LINK_EXERCISE,
  96. //LINK_DROPBOX,
  97. LINK_HOTPOTATOES,
  98. LINK_STUDENTPUBLICATION,
  99. LINK_LEARNPATH,
  100. LINK_FORUM_THREAD,
  101. LINK_ATTENDANCE,
  102. LINK_SURVEY
  103. );
  104. }
  105. public function delete() {
  106. }
  107. }