Resource.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. define('RESOURCE_WORK', 'work');
  33. /**
  34. * Representation of a resource in a Chamilo-course.
  35. * This is a base class of which real resource-classes (for Links,
  36. * Documents,...) should be derived.
  37. * @author Bart Mollet <bart.mollet@hogent.be>s
  38. * @package chamilo.backup
  39. * @todo Use the gloabaly defined constants voor tools and remove the RESOURCE_*
  40. * constants
  41. */
  42. class Resource
  43. {
  44. /**
  45. * The id from this resource in the source course
  46. */
  47. public $source_id;
  48. /**
  49. * The id from this resource in the destination course
  50. */
  51. public $destination_id;
  52. /**
  53. * The type of this resource
  54. */
  55. public $type;
  56. /**
  57. * Linked resources
  58. */
  59. public $linked_resources;
  60. /**
  61. * The properties of this resource
  62. */
  63. public $item_properties;
  64. public $obj = null;
  65. /**
  66. * Create a new Resource
  67. * @param int $id The id of this resource in the source course.
  68. * @param constant $type The type of this resource.
  69. */
  70. function Resource($id, $type)
  71. {
  72. $this->source_id = $id;
  73. $this->type = $type;
  74. $this->destination_id = -1;
  75. $this->linked_resources = array();
  76. $this->item_properties = array();
  77. }
  78. /**
  79. * Add linked resource
  80. */
  81. function add_linked_resource($type, $id)
  82. {
  83. $this->linked_resources[$type][] = $id;
  84. }
  85. /**
  86. * Get linked resources
  87. */
  88. function get_linked_resources()
  89. {
  90. return $this->linked_resources;
  91. }
  92. /**
  93. * Checks if this resource links to a given resource
  94. */
  95. function links_to(& $resource)
  96. {
  97. if (isset($this->linked_resources[$resource->get_type()]) && is_array(
  98. $this->linked_resources[$resource->get_type()]
  99. )
  100. ) {
  101. return in_array($resource->get_id(), $this->linked_resources[$resource->get_type()]);
  102. }
  103. return false;
  104. }
  105. /**
  106. * Returns the id of this resource.
  107. * @return int The id of this resource in the source course.
  108. */
  109. function get_id()
  110. {
  111. return $this->source_id;
  112. }
  113. /**
  114. * Resturns the type of this resource
  115. * @return constant The type.
  116. */
  117. function get_type()
  118. {
  119. return $this->type;
  120. }
  121. /**
  122. * Get the constant which defines the tool of this resource. This is
  123. * used in the item_properties table.
  124. * @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.
  125. * Example: The constant TOOL_THREAD is defined in the 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'.
  126. * @todo once the RESOURCE_* constants are replaced by the globally
  127. * defined TOOL_* constants, this function will be replaced by get_type()
  128. */
  129. function get_tool($for_item_property_table = true)
  130. {
  131. switch ($this->get_type()) {
  132. case RESOURCE_DOCUMENT:
  133. return TOOL_DOCUMENT;
  134. case RESOURCE_LINK:
  135. return TOOL_LINK;
  136. case RESOURCE_EVENT:
  137. return TOOL_CALENDAR_EVENT;
  138. case RESOURCE_COURSEDESCRIPTION:
  139. return TOOL_COURSE_DESCRIPTION;
  140. case RESOURCE_LEARNPATH:
  141. return TOOL_LEARNPATH;
  142. case RESOURCE_ANNOUNCEMENT:
  143. return TOOL_ANNOUNCEMENT;
  144. case RESOURCE_FORUMCATEGORY:
  145. return 'forum_category'; // Ivan, 29-AUG-2009: A constant like TOOL_FORUM_CATEGORY is missing in api.lib.php. Such a constant has been defined in the forum tool for local needs.
  146. case RESOURCE_FORUM:
  147. return TOOL_FORUM;
  148. case RESOURCE_FORUMTOPIC:
  149. if ($for_item_property_table) {
  150. return 'forum_thread'; // Ivan, 29-AUG-2009: A hardcoded value that the "Forums" tool stores in the item property table.
  151. }
  152. return TOOL_THREAD;
  153. case RESOURCE_FORUMPOST:
  154. return TOOL_POST;
  155. case RESOURCE_QUIZ:
  156. return TOOL_QUIZ;
  157. //case RESOURCE_QUIZQUESTION: //no corresponding global constant
  158. // return TOOL_QUIZ_QUESTION;
  159. //case RESOURCE_TOOL_INTRO:
  160. // return TOOL_INTRO;
  161. //case RESOURCE_LINKCATEGORY:
  162. // return TOOL_LINK_CATEGORY;
  163. //case RESOURCE_SCORM:
  164. // return TOOL_SCORM_DOCUMENT;
  165. case RESOURCE_SURVEY:
  166. return TOOL_SURVEY;
  167. //case RESOURCE_SURVEYQUESTION:
  168. // return TOOL_SURVEY_QUESTION;
  169. //case RESOURCE_SURVEYINVITATION:
  170. // return TOOL_SURVEY_INVITATION;
  171. case RESOURCE_GLOSSARY:
  172. return TOOL_GLOSSARY;
  173. case RESOURCE_WIKI:
  174. return TOOL_WIKI;
  175. case RESOURCE_THEMATIC:
  176. return TOOL_COURSE_PROGRESS;
  177. case RESOURCE_ATTENDANCE:
  178. return TOOL_ATTENDANCE;
  179. case RESOURCE_WORK:
  180. return TOOL_STUDENTPUBLICATION;
  181. default:
  182. return null;
  183. }
  184. }
  185. /**
  186. * Set the destination id
  187. * @param int $id The id of this resource in the destination course.
  188. */
  189. function set_new_id($id)
  190. {
  191. $this->destination_id = $id;
  192. }
  193. /**
  194. * Check if this resource is allready restored in the destination course.
  195. * @return bool true if allready restored (i.e. destination_id is set).
  196. */
  197. function is_restored()
  198. {
  199. return $this->destination_id > -1;
  200. }
  201. /**
  202. * Show this resource
  203. */
  204. function show()
  205. {
  206. //echo 'RESOURCE: '.$this->get_id().' '.$type[$this->get_type()].' ';
  207. }
  208. }