Resource.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. // $Id: Resource.class.php 9246 2006-09-25 13:24:53Z bmol $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Bart Mollet (bart.mollet@hogent.be)
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. * All possible resource-types
  23. */
  24. define('RESOURCE_LINK', 'Link');
  25. define('RESOURCE_TOOL_INTRO', 'Tool introduction');
  26. define('RESOURCE_EVENT', 'Agenda');
  27. define('RESOURCE_ANNOUNCEMENT', 'Ad_Valvas');
  28. define('RESOURCE_LINKCATEGORY', 'Link_Category');
  29. define('RESOURCE_DOCUMENT', 'Document');
  30. define('RESOURCE_COURSEDESCRIPTION', 'Course_Description');
  31. define('RESOURCE_FORUMCATEGORY', 'Forum_Category');
  32. define('RESOURCE_FORUM', 'Forum');
  33. define('RESOURCE_FORUMTOPIC', 'Thread');
  34. define('RESOURCE_FORUMPOST', 'Post');
  35. define('RESOURCE_QUIZQUESTION', 'Exercise_Question');
  36. define('RESOURCE_QUIZ', 'Exercise');
  37. define('RESOURCE_LEARNPATH', 'Learnpath');
  38. define('RESOURCE_SCORM', 'Scorm');
  39. /**
  40. * Representation of a resource in a Dokeos-course.
  41. * This is a base class of which real resource-classes (for Links,
  42. * Documents,...) should be derived.
  43. * @author Bart Mollet <bart.mollet@hogent.be>s
  44. * @package dokeos.backup
  45. * @todo Use the gloabaly defined constants voor tools and remove the RESOURCE_*
  46. * constants
  47. */
  48. class Resource
  49. {
  50. /**
  51. * The id from this resource in the source course
  52. */
  53. var $source_id;
  54. /**
  55. * The id from this resource in the destination course
  56. */
  57. var $destination_id;
  58. /**
  59. * The type of this resource
  60. */
  61. var $type;
  62. /**
  63. * Linked resources
  64. */
  65. var $linked_resources;
  66. /**
  67. * The properties of this resource
  68. */
  69. var $item_properties;
  70. /**
  71. * Create a new Resource
  72. * @param int $id The id of this resource in the source course.
  73. * @param constant $type The type of this resource.
  74. */
  75. function Resource($id, $type)
  76. {
  77. $this->source_id = $id;
  78. $this->type = $type;
  79. $this->destination_id = -1;
  80. $this->linked_resources = array ();
  81. $this->item_properties = array ();
  82. }
  83. /**
  84. * Add linked resource
  85. */
  86. function add_linked_resource($type, $id)
  87. {
  88. $this->linked_resources[$type][] = $id;
  89. }
  90. /**
  91. * Get linked resources
  92. */
  93. function get_linked_resources()
  94. {
  95. return $this->linked_resources;
  96. }
  97. /**
  98. * Checks if this resource links to a given resource
  99. */
  100. function links_to(& $resource)
  101. {
  102. if (is_array($this->linked_resources[$resource->get_type()]))
  103. {
  104. return in_array($resource->get_id(), $this->linked_resources[$resource->get_type()]);
  105. }
  106. return false;
  107. }
  108. /**
  109. * Returns the id of this resource.
  110. * @return int The id of this resource in the source course.
  111. */
  112. function get_id()
  113. {
  114. return $this->source_id;
  115. }
  116. /**
  117. * Resturns the type of this resource
  118. * @return constant The type.
  119. */
  120. function get_type()
  121. {
  122. return $this->type;
  123. }
  124. /**
  125. * Get the constant which defines the tool of this resource. This is
  126. * used in the item_properties table.
  127. * @todo once the RESOURCE_* constants are replaced by the globally
  128. * defined TOOL_* constants, this function will be replaced by get_type()
  129. */
  130. function get_tool()
  131. {
  132. switch($this->get_type())
  133. {
  134. case RESOURCE_DOCUMENT:
  135. return TOOL_DOCUMENT;
  136. case RESOURCE_LINK:
  137. return TOOL_LINK;
  138. case RESOURCE_EVENT:
  139. return TOOL_CALENDAR_EVENT;
  140. case RESOURCE_FORUM:
  141. return TOOL_BB_FORUM;
  142. case RESOURCE_FORUMTOPIC:
  143. return TOOL_BB_THREAD;
  144. case RESOURCE_FORUMPOST:
  145. return TOOL_BB_POST;
  146. case RESOURCE_ANNOUNCEMENT:
  147. return TOOL_ANNOUNCEMENT;
  148. case RESOURCE_QUIZ:
  149. return TOOL_QUIZ;
  150. default:
  151. return null;
  152. }
  153. }
  154. /**
  155. * Set the destination id
  156. * @param int $id The id of this resource in the destination course.
  157. */
  158. function set_new_id($id)
  159. {
  160. $this->destination_id = $id;
  161. }
  162. /**
  163. * Check if this resource is allready restored in the destination course.
  164. * @return bool true if allready restored (i.e. destination_id is set).
  165. */
  166. function is_restored()
  167. {
  168. return $this->destination_id > -1;
  169. }
  170. /**
  171. * Show this resource
  172. */
  173. function show()
  174. {
  175. //echo 'RESOURCE: '.$this->get_id().' '.$type[$this->get_type()].' ';
  176. }
  177. }