linkfactory.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // Please do not change existing values, they are used in the database !
  15. define('LINK_EXERCISE', 1);
  16. define('LINK_DROPBOX', 2);
  17. define('LINK_STUDENTPUBLICATION', 3);
  18. define('LINK_LEARNPATH', 4);
  19. define('LINK_FORUM_THREAD', 5);
  20. //define('LINK_WORK',6);
  21. define('LINK_ATTENDANCE', 7);
  22. define('LINK_SURVEY', 8);
  23. require_once 'gradebookitem.class.php';
  24. require_once 'abstractlink.class.php';
  25. require_once 'exerciselink.class.php';
  26. require_once 'evallink.class.php';
  27. require_once 'dropboxlink.class.php';
  28. require_once 'studentpublicationlink.class.php';
  29. require_once 'learnpathlink.class.php';
  30. require_once 'forumthreadlink.class.php';
  31. require_once 'attendancelink.class.php';
  32. require_once 'surveylink.class.php';
  33. /**
  34. * Factory for link objects
  35. * @author Bert Steppé
  36. * @package chamilo.gradebook
  37. */
  38. class LinkFactory
  39. {
  40. /**
  41. * Retrieve links and return them as an array of extensions of AbstractLink.
  42. * @param $id link id
  43. * @param $type link type
  44. * @param $ref_id reference id
  45. * @param $user_id user id (link owner)
  46. * @param $course_code course code
  47. * @param $category_id parent category
  48. * @param $visible visible
  49. */
  50. public function load ($id = null, $type = null, $ref_id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null) {
  51. return AbstractLink::load($id, $type, $ref_id, $user_id, $course_code, $category_id, $visible);
  52. }
  53. /**
  54. * Get the link object referring to an evaluation
  55. */
  56. public function get_evaluation_link ($eval_id) {
  57. $links = AbstractLink :: load(null, null, $eval_id);
  58. foreach ($links as $link) {
  59. if (is_a($link, 'EvalLink')) {
  60. return $link;
  61. }
  62. }
  63. return null;
  64. }
  65. /**
  66. * Find links by name
  67. * @param string $name_mask search string
  68. * @return array link objects matching the search criterium
  69. */
  70. public function find_links ($name_mask,$selectcat) {
  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 function create ($type) {
  78. switch ($type) {
  79. case LINK_EXERCISE:
  80. return new ExerciseLink();
  81. case LINK_DROPBOX:
  82. return new DropboxLink();
  83. case LINK_STUDENTPUBLICATION:
  84. return new StudentPublicationLink();
  85. case LINK_LEARNPATH:
  86. return new LearnpathLink();
  87. case LINK_FORUM_THREAD:
  88. return new ForumThreadLink();
  89. case LINK_ATTENDANCE:
  90. return new AttendanceLink();
  91. case LINK_SURVEY:
  92. return new SurveyLink();
  93. }
  94. return null;
  95. }
  96. /**
  97. * Return an array of all known link types
  98. */
  99. public function get_all_types () {
  100. //LINK_DROPBOX,
  101. return array (LINK_EXERCISE,
  102. //LINK_DROPBOX,
  103. LINK_STUDENTPUBLICATION,
  104. LINK_LEARNPATH,
  105. LINK_FORUM_THREAD,
  106. LINK_ATTENDANCE,
  107. LINK_SURVEY
  108. );
  109. }
  110. public function delete() {
  111. }
  112. }