module_base.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. // This file is part of the Sloodle project (www.sloodle.org)
  3. /**
  4. * This file defines the base class for Sloodle modules.
  5. * (Each module is effectively a sub-type of the Moodle module).
  6. *
  7. * @package sloodle
  8. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10. *
  11. * @contributor Peter R. Bloomfield
  12. */
  13. /**
  14. * Sloodle module base class.
  15. * An abstract class which must be overridden by sub-classes.
  16. * @package sloodle
  17. */
  18. class SloodleModule
  19. {
  20. // DATA //
  21. /**
  22. * Reference to the containing {@link SloodleSession} object.
  23. * If null, then this module is being used outwith the framework.
  24. * <b>Always check the status of the variable before using it!</b>
  25. * @var object
  26. * @access protected
  27. */
  28. var $_session = null;
  29. // FUNCTIONS //
  30. /**
  31. * Constructor - initialises the session variable
  32. * @param object &$_session A reference to the containing {@link SloodleSession} object, if available.
  33. */
  34. function SloodleModule(&$_session)
  35. {
  36. if (!is_null($_session)) $this->_session = &$_session;
  37. }
  38. /**
  39. * Loads data from the database.
  40. * Note: even if the function fails, it may still have overwritten some or all existing data in the object.
  41. * @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
  42. * @return bool True if successful, or false otherwise
  43. */
  44. function load($id)
  45. {
  46. return true;
  47. }
  48. // BACKUP AND RESTORE //
  49. /**
  50. * Backs-up secondary data regarding this module.
  51. * That includes everything except the main 'sloodle' database table for this instance.
  52. * @param object $bf Handle to the file which backup data should be written to.
  53. * @param bool $includeuserdata Indicates whether or not to backup 'user' data, i.e. any content. Most SLOODLE tools don't have any user data.
  54. * @return bool True if successful, or false on failure.
  55. */
  56. function backup($bf, $includeuserdata)
  57. {
  58. return true;
  59. }
  60. /**
  61. * Restore this module's secondary data into the database.
  62. * This ignores any member data, so can be called statically.
  63. * @param int $sloodleid The ID of the primary SLOODLE entry this restore belongs to (i.e. the ID of the record in the "sloodle" table)
  64. * @param array $info An associative array representing the XML backup information for the secondary module data
  65. * @param bool $includeuserdata Indicates whether or not to restore user data
  66. * @return bool True if successful, or false on failure.
  67. */
  68. function restore($sloodleid, $info, $includeuserdata)
  69. {
  70. return true;
  71. }
  72. // Action handlers //
  73. // The following can be extended if your module wants to be notified when another module handles something.
  74. // ...based on configuration options set on the object in question.
  75. // Developed for Awards: eg. You want the quiz to tell you that somebody has got a quiz question right
  76. // ...so that you can give them a prize.
  77. // This infrastructure isn't used anywhere else as of 2011-06-27, but it may have other applications.
  78. /**
  79. * Returns an array of names of configuration parameters which trigger some kind of action on our part.
  80. * See SloodleModuleAwards for an example of how this is used.
  81. * @return array
  82. */
  83. function ActionConfigNames() {
  84. return array();
  85. }
  86. /*
  87. TODO: Not using this yet - will be used for tracker
  88. * array $relevant_configs an array of actions that the object is interested in if the object does them
  89. * object $active_object
  90. */
  91. function HandleObjectInitializationSteps( $relevant_configs, $active_object ) {
  92. return true;
  93. }
  94. /**
  95. * param array $relevant_configs - config params and values that this module handles.
  96. * param int $controllerid: ID of controller that called us
  97. * param int $multiplier A number telling us the scale of the thing that happened.
  98. * param int $userid ID of the user involved.
  99. * param string $useruuid
  100. * param string $objectuuid
  101. * @ return false
  102. *
  103. */
  104. function ProcessActions( $relevant_configs, $controllerid, $multiplier, $userid, $useruuid, $objectuuid ) {
  105. return true;
  106. }
  107. /**
  108. * Gets the name of the user data required by this type, or an empty string if none is required.
  109. * For example, a chatroom would use the name "Messages" for user data.
  110. * Note that this should respect current language settings in Moodle.
  111. * @return string Localised name of the user data.
  112. */
  113. function get_user_data_name()
  114. {
  115. return '';
  116. }
  117. /**
  118. * Gets the number of user data records to be backed-up.
  119. * @return int A count of the number of user data records which can be backed-up.
  120. */
  121. function get_user_data_count()
  122. {
  123. return 0;
  124. }
  125. // ACCESSORS //
  126. /**
  127. * Gets the name of this module instance.
  128. * @return string The name of this controller
  129. */
  130. function get_name()
  131. {
  132. return '';
  133. }
  134. /**
  135. * Gets the intro description of this module instance, if available.
  136. * @return string The intro description of this controller
  137. */
  138. function get_intro()
  139. {
  140. return '';
  141. }
  142. /**
  143. * Gets the identifier of the course this controller belongs to.
  144. * @return mixed Course identifier. Type depends on VLE. (In Moodle, it will be an integer).
  145. */
  146. function get_course_id()
  147. {
  148. return 0;
  149. }
  150. /**
  151. * Gets the time at which this instance was created, or 0 if unknown.
  152. * @return int Timestamp
  153. */
  154. function get_creation_time()
  155. {
  156. return 0;
  157. }
  158. /**
  159. * Gets the time at which this instance was last modified, or 0 if unknown.
  160. * @return int Timestamp
  161. */
  162. function get_modification_time()
  163. {
  164. return 0;
  165. }
  166. /**
  167. * Gets the short type name of this instance.
  168. * @return string
  169. */
  170. function get_type()
  171. {
  172. return '';
  173. }
  174. /**
  175. * Gets the full type name of this instance, according to the current language pack, if available.
  176. * Note: should be overridden by sub-classes.
  177. * @return string Full type name if possible, or the short name otherwise.
  178. */
  179. function get_type_full()
  180. {
  181. return '';
  182. }
  183. }
  184. ?>