Resource.class.php 7.0 KB

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