Resource.class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * General resources backup script
  5. * @package chamilo.backup
  6. */
  7. /**
  8. * Definition of all possible resource-types
  9. */
  10. define('RESOURCE_DOCUMENT', 'document');
  11. define('RESOURCE_GLOSSARY', 'glossary');
  12. define('RESOURCE_EVENT', 'calendar_event');
  13. define('RESOURCE_LINK', 'link');
  14. define('RESOURCE_COURSEDESCRIPTION', 'course_description');
  15. define('RESOURCE_LEARNPATH', 'learnpath');
  16. define('RESOURCE_ANNOUNCEMENT', 'announcement');
  17. define('RESOURCE_FORUM', 'forum');
  18. define('RESOURCE_FORUMTOPIC', 'thread');
  19. define('RESOURCE_FORUMPOST', 'post');
  20. define('RESOURCE_QUIZ', 'quiz');
  21. define('RESOURCE_QUIZQUESTION', 'Exercise_Question');
  22. define('RESOURCE_TOOL_INTRO', 'Tool introduction');
  23. define('RESOURCE_LINKCATEGORY', 'Link_Category');
  24. define('RESOURCE_FORUMCATEGORY', 'Forum_Category');
  25. define('RESOURCE_SCORM', 'Scorm');
  26. define('RESOURCE_SURVEY','survey');
  27. define('RESOURCE_SURVEYQUESTION','survey_question');
  28. define('RESOURCE_SURVEYINVITATION','survey_invitation');
  29. define('RESOURCE_WIKI','wiki');
  30. define('RESOURCE_THEMATIC','thematic');
  31. define('RESOURCE_ATTENDANCE','attendance');
  32. /**
  33. * Representation of a resource in a Chamilo-course.
  34. * This is a base class of which real resource-classes (for Links,
  35. * Documents,...) should be derived.
  36. * @author Bart Mollet <bart.mollet@hogent.be>s
  37. * @package chamilo.backup
  38. * @todo Use the gloabaly defined constants voor tools and remove the RESOURCE_*
  39. * constants
  40. */
  41. class Resource
  42. {
  43. /**
  44. * The id from this resource in the source course
  45. */
  46. var $source_id;
  47. /**
  48. * The id from this resource in the destination course
  49. */
  50. var $destination_id;
  51. /**
  52. * The type of this resource
  53. */
  54. var $type;
  55. /**
  56. * Linked resources
  57. */
  58. var $linked_resources;
  59. /**
  60. * The properties of this resource
  61. */
  62. var $item_properties;
  63. /**
  64. * Create a new Resource
  65. * @param int $id The id of this resource in the source course.
  66. * @param constant $type The type of this resource.
  67. */
  68. function Resource($id, $type) {
  69. $this->source_id = $id;
  70. $this->type = $type;
  71. $this->destination_id = -1;
  72. $this->linked_resources = array ();
  73. $this->item_properties = array ();
  74. }
  75. /**
  76. * Add linked resource
  77. */
  78. function add_linked_resource($type, $id)
  79. {
  80. $this->linked_resources[$type][] = $id;
  81. }
  82. /**
  83. * Get linked resources
  84. */
  85. function get_linked_resources()
  86. {
  87. return $this->linked_resources;
  88. }
  89. /**
  90. * Checks if this resource links to a given resource
  91. */
  92. function links_to(& $resource)
  93. {
  94. if (is_array($this->linked_resources[$resource->get_type()]))
  95. {
  96. return in_array($resource->get_id(), $this->linked_resources[$resource->get_type()]);
  97. }
  98. return false;
  99. }
  100. /**
  101. * Returns the id of this resource.
  102. * @return int The id of this resource in the source course.
  103. */
  104. function get_id()
  105. {
  106. return $this->source_id;
  107. }
  108. /**
  109. * Resturns the type of this resource
  110. * @return constant The type.
  111. */
  112. function get_type()
  113. {
  114. return $this->type;
  115. }
  116. /**
  117. * Get the constant which defines the tool of this resource. This is
  118. * used in the item_properties table.
  119. * @param bool $for_item_property_table (optional) Added by Ivan, 29-AUG-2009: A parameter for resolving differencies between defined TOOL_* constants and hardcoded strings that are stored in the database.
  120. * Example: The constant TOOL_THREAD is defined in the main_api.lib.php with the value 'thread', but the "Forums" tool records in the field 'tool' in the item property table the hardcoded value 'forum_thread'.
  121. * @todo once the RESOURCE_* constants are replaced by the globally
  122. * defined TOOL_* constants, this function will be replaced by get_type()
  123. */
  124. function get_tool($for_item_property_table = true)
  125. {
  126. switch($this->get_type())
  127. {
  128. case RESOURCE_DOCUMENT:
  129. return TOOL_DOCUMENT;
  130. case RESOURCE_LINK:
  131. return TOOL_LINK;
  132. case RESOURCE_EVENT:
  133. return TOOL_CALENDAR_EVENT;
  134. case RESOURCE_COURSEDESCRIPTION:
  135. return TOOL_COURSE_DESCRIPTION;
  136. case RESOURCE_LEARNPATH:
  137. return TOOL_LEARNPATH;
  138. case RESOURCE_ANNOUNCEMENT:
  139. return TOOL_ANNOUNCEMENT;
  140. case RESOURCE_FORUMCATEGORY:
  141. return 'forum_category'; // Ivan, 29-AUG-2009: A constant like TOOL_FORUM_CATEGORY is missing in main_api.lib.php. Such a constant has been defined in the forum tool for local needs.
  142. case RESOURCE_FORUM:
  143. return TOOL_FORUM;
  144. case RESOURCE_FORUMTOPIC:
  145. if ($for_item_property_table)
  146. {
  147. return 'forum_thread'; // Ivan, 29-AUG-2009: A hardcoded value that the "Forums" tool stores in the item property table.
  148. }
  149. return TOOL_THREAD;
  150. case RESOURCE_FORUMPOST:
  151. return TOOL_POST;
  152. case RESOURCE_QUIZ:
  153. return TOOL_QUIZ;
  154. //case RESOURCE_QUIZQUESTION: //no corresponding global constant
  155. // return TOOL_QUIZ_QUESTION;
  156. //case RESOURCE_TOOL_INTRO:
  157. // return TOOL_INTRO;
  158. //case RESOURCE_LINKCATEGORY:
  159. // return TOOL_LINK_CATEGORY;
  160. //case RESOURCE_SCORM:
  161. // return TOOL_SCORM_DOCUMENT;
  162. case RESOURCE_SURVEY:
  163. return TOOL_SURVEY;
  164. //case RESOURCE_SURVEYQUESTION:
  165. // return TOOL_SURVEY_QUESTION;
  166. //case RESOURCE_SURVEYINVITATION:
  167. // return TOOL_SURVEY_INVITATION;
  168. case RESOURCE_GLOSSARY:
  169. return TOOL_GLOSSARY;
  170. case RESOURCE_WIKI:
  171. return TOOL_WIKI;
  172. case RESOURCE_THEMATIC:
  173. return TOOL_COURSE_PROGRESS;
  174. case RESOURCE_ATTENDANCE:
  175. return TOOL_ATTENDANCE;
  176. default:
  177. return null;
  178. }
  179. }
  180. /**
  181. * Set the destination id
  182. * @param int $id The id of this resource in the destination course.
  183. */
  184. function set_new_id($id)
  185. {
  186. $this->destination_id = $id;
  187. }
  188. /**
  189. * Check if this resource is allready restored in the destination course.
  190. * @return bool true if allready restored (i.e. destination_id is set).
  191. */
  192. function is_restored()
  193. {
  194. return $this->destination_id > -1;
  195. }
  196. /**
  197. * Show this resource
  198. */
  199. function show()
  200. {
  201. //echo 'RESOURCE: '.$this->get_id().' '.$type[$this->get_type()].' ';
  202. }
  203. }