Resource.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. define('RESOURCE_DOCUMENT', 'document');
  4. define('RESOURCE_GLOSSARY', 'glossary');
  5. define('RESOURCE_EVENT', 'calendar_event');
  6. define('RESOURCE_LINK', 'link');
  7. define('RESOURCE_COURSEDESCRIPTION', 'course_description');
  8. define('RESOURCE_LEARNPATH', 'learnpath');
  9. define('RESOURCE_ANNOUNCEMENT', 'announcement');
  10. define('RESOURCE_FORUM', 'forum');
  11. define('RESOURCE_FORUMTOPIC', 'thread');
  12. define('RESOURCE_FORUMPOST', 'post');
  13. define('RESOURCE_QUIZ', 'quiz');
  14. define('RESOURCE_TEST_CATEGORY', 'test_category');
  15. define('RESOURCE_QUIZQUESTION', 'Exercise_Question');
  16. define('RESOURCE_TOOL_INTRO', 'Tool introduction');
  17. define('RESOURCE_LINKCATEGORY', 'Link_Category');
  18. define('RESOURCE_FORUMCATEGORY', 'Forum_Category');
  19. define('RESOURCE_SCORM', 'Scorm');
  20. define('RESOURCE_SURVEY', 'survey');
  21. define('RESOURCE_SURVEYQUESTION', 'survey_question');
  22. define('RESOURCE_SURVEYINVITATION', 'survey_invitation');
  23. define('RESOURCE_WIKI', 'wiki');
  24. define('RESOURCE_THEMATIC', 'thematic');
  25. define('RESOURCE_ATTENDANCE', 'attendance');
  26. define('RESOURCE_WORK', 'work');
  27. /**
  28. * Class Resource
  29. * Representation of a resource in a Chamilo-course.
  30. * This is a base class of which real resource-classes (for Links,
  31. * Documents,...) should be derived.
  32. * @author Bart Mollet <bart.mollet@hogent.be>s
  33. * @package chamilo.backup
  34. * @todo Use the gloabaly defined constants voor tools and remove the RESOURCE_*
  35. * constants
  36. */
  37. class Resource
  38. {
  39. /**
  40. * The id from this resource in the source course
  41. */
  42. public $source_id;
  43. /**
  44. * The id from this resource in the destination course
  45. */
  46. public $destination_id;
  47. /**
  48. * The type of this resource
  49. */
  50. public $type;
  51. /**
  52. * Linked resources
  53. */
  54. public $linked_resources;
  55. /**
  56. * The properties of this resource
  57. */
  58. public $item_properties;
  59. public $obj = null;
  60. /**
  61. * Create a new Resource
  62. * @param int $id The id of this resource in the source course.
  63. * @param constant $type The type of this resource.
  64. */
  65. function Resource($id, $type)
  66. {
  67. $this->source_id = $id;
  68. $this->type = $type;
  69. $this->destination_id = -1;
  70. $this->linked_resources = array();
  71. $this->item_properties = array();
  72. }
  73. /**
  74. * Add linked resource
  75. */
  76. function add_linked_resource($type, $id) {
  77. $this->linked_resources[$type][] = $id;
  78. }
  79. /**
  80. * Get linked resources
  81. */
  82. function get_linked_resources() {
  83. return $this->linked_resources;
  84. }
  85. /**
  86. * Checks if this resource links to a given resource
  87. */
  88. function links_to(& $resource) {
  89. $type = $resource->get_type();
  90. if (isset($this->linked_resources[$type]) &&
  91. is_array($this->linked_resources[$type])
  92. ) {
  93. return in_array(
  94. $resource->get_id(),
  95. $this->linked_resources[$type]
  96. );
  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 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. case RESOURCE_DOCUMENT:
  128. return TOOL_DOCUMENT;
  129. case RESOURCE_LINK:
  130. return TOOL_LINK;
  131. case RESOURCE_EVENT:
  132. return TOOL_CALENDAR_EVENT;
  133. case RESOURCE_COURSEDESCRIPTION:
  134. return TOOL_COURSE_DESCRIPTION;
  135. case RESOURCE_LEARNPATH:
  136. return TOOL_LEARNPATH;
  137. case RESOURCE_ANNOUNCEMENT:
  138. return TOOL_ANNOUNCEMENT;
  139. case RESOURCE_FORUMCATEGORY:
  140. 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.
  141. case RESOURCE_FORUM:
  142. return TOOL_FORUM;
  143. case RESOURCE_FORUMTOPIC:
  144. if ($for_item_property_table) {
  145. return 'forum_thread'; // Ivan, 29-AUG-2009: A hardcoded value that the "Forums" tool stores in the item property table.
  146. }
  147. return TOOL_THREAD;
  148. case RESOURCE_FORUMPOST:
  149. return TOOL_POST;
  150. case RESOURCE_QUIZ:
  151. return TOOL_QUIZ;
  152. case RESOURCE_TEST_CATEGORY:
  153. return TOOL_TEST_CATEGORY;
  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. case RESOURCE_WORK:
  177. return TOOL_STUDENTPUBLICATION;
  178. default:
  179. return null;
  180. }
  181. }
  182. /**
  183. * Set the destination id
  184. * @param int $id The id of this resource in the destination course.
  185. */
  186. function set_new_id($id)
  187. {
  188. $this->destination_id = $id;
  189. }
  190. /**
  191. * Check if this resource is allready restored in the destination course.
  192. * @return bool true if allready restored (i.e. destination_id is set).
  193. */
  194. function is_restored()
  195. {
  196. return $this->destination_id > -1;
  197. }
  198. /**
  199. * Show this resource
  200. */
  201. function show()
  202. {
  203. //echo 'RESOURCE: '.$this->get_id().' '.$type[$this->get_type()].' ';
  204. }
  205. }