lib.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. /**
  3. * Library of interface functions and constants for module nasatlx
  4. *
  5. * All the core Moodle functions, neeeded to allow the module to work
  6. * integrated in Moodle should be placed here.
  7. * All the nasatlx specific functions, needed to implement all the module
  8. * logic, should go to locallib.php. This will help to save some memory when
  9. * Moodle is performing actions across all modules.
  10. *
  11. * @package mod_nasatlx
  12. * @copyright 2014 LInE - http://line.ime.usp.br
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  14. */
  15. defined('MOODLE_INTERNAL') || die();
  16. /** example constant */
  17. //define('NEWMODULE_ULTIMATE_ANSWER', 42);
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // Moodle core API //
  20. ////////////////////////////////////////////////////////////////////////////////
  21. /**
  22. * Returns the information on whether the module supports a feature
  23. *
  24. * @see plugin_supports() in lib/moodlelib.php
  25. * @param string $feature FEATURE_xx constant for requested feature
  26. * @return mixed true if the feature is supported, null if unknown
  27. */
  28. function nasatlx_supports($feature) {
  29. switch($feature) {
  30. case FEATURE_MOD_INTRO: return true;
  31. case FEATURE_SHOW_DESCRIPTION: return true;
  32. default: return null;
  33. }
  34. }
  35. /**
  36. * Saves a new instance of the nasatlx into the database
  37. *
  38. * Given an object containing all the necessary data,
  39. * (defined by the form in mod_form.php) this function
  40. * will create a new instance and return the id number
  41. * of the new instance.
  42. *
  43. * @param object $nasatlx An object from the form in mod_form.php
  44. * @param mod_nasatlx_mod_form $mform
  45. * @return int The id of the newly inserted nasatlx record
  46. */
  47. function nasatlx_add_instance(stdClass $nasatlx, mod_nasatlx_mod_form $mform = null) {
  48. global $DB;
  49. $nasatlx->timecreated = time();
  50. # You may have to add extra stuff in here #
  51. return $DB->insert_record('nasatlx', $nasatlx);
  52. }
  53. /**
  54. * Updates an instance of the nasatlx in the database
  55. *
  56. * Given an object containing all the necessary data,
  57. * (defined by the form in mod_form.php) this function
  58. * will update an existing instance with new data.
  59. *
  60. * @param object $nasatlx An object from the form in mod_form.php
  61. * @param mod_nasatlx_mod_form $mform
  62. * @return boolean Success/Fail
  63. */
  64. function nasatlx_update_instance(stdClass $nasatlx, mod_nasatlx_mod_form $mform = null) {
  65. global $DB;
  66. $nasatlx->timemodified = time();
  67. $nasatlx->id = $nasatlx->instance;
  68. # You may have to add extra stuff in here #
  69. return $DB->update_record('nasatlx', $nasatlx);
  70. }
  71. /**
  72. * Removes an instance of the nasatlx from the database
  73. *
  74. * Given an ID of an instance of this module,
  75. * this function will permanently delete the instance
  76. * and any data that depends on it.
  77. *
  78. * @param int $id Id of the module instance
  79. * @return boolean Success/Failure
  80. */
  81. function nasatlx_delete_instance($id) {
  82. global $DB;
  83. if (! $nasatlx = $DB->get_record('nasatlx', array('id' => $id))) {
  84. return false;
  85. }
  86. # Delete any dependent records here #
  87. $DB->delete_records('nasatlx', array('id' => $nasatlx->id));
  88. return true;
  89. }
  90. /**
  91. * Returns a small object with summary information about what a
  92. * user has done with a given particular instance of this module
  93. * Used for user activity reports.
  94. * $return->time = the time they did it
  95. * $return->info = a short text description
  96. *
  97. * @return stdClass|null
  98. */
  99. function nasatlx_user_outline($course, $user, $mod, $nasatlx) {
  100. $return = new stdClass();
  101. $return->time = 0;
  102. $return->info = '';
  103. return $return;
  104. }
  105. /**
  106. * Prints a detailed representation of what a user has done with
  107. * a given particular instance of this module, for user activity reports.
  108. *
  109. * @param stdClass $course the current course record
  110. * @param stdClass $user the record of the user we are generating report for
  111. * @param cm_info $mod course module info
  112. * @param stdClass $nasatlx the module instance record
  113. * @return void, is supposed to echp directly
  114. */
  115. function nasatlx_user_complete($course, $user, $mod, $nasatlx) {
  116. }
  117. /**
  118. * Given a course and a time, this module should find recent activity
  119. * that has occurred in nasatlx activities and print it out.
  120. * Return true if there was output, or false is there was none.
  121. *
  122. * @return boolean
  123. */
  124. function nasatlx_print_recent_activity($course, $viewfullnames, $timestart) {
  125. return false; // True if anything was printed, otherwise false
  126. }
  127. /**
  128. * Prepares the recent activity data
  129. *
  130. * This callback function is supposed to populate the passed array with
  131. * custom activity records. These records are then rendered into HTML via
  132. * {@link nasatlx_print_recent_mod_activity()}.
  133. *
  134. * @param array $activities sequentially indexed array of objects with the 'cmid' property
  135. * @param int $index the index in the $activities to use for the next record
  136. * @param int $timestart append activity since this time
  137. * @param int $courseid the id of the course we produce the report for
  138. * @param int $cmid course module id
  139. * @param int $userid check for a particular user's activity only, defaults to 0 (all users)
  140. * @param int $groupid check for a particular group's activity only, defaults to 0 (all groups)
  141. * @return void adds items into $activities and increases $index
  142. */
  143. function nasatlx_get_recent_mod_activity(&$activities, &$index, $timestart, $courseid, $cmid, $userid=0, $groupid=0) {
  144. }
  145. /**
  146. * Prints single activity item prepared by {@see nasatlx_get_recent_mod_activity()}
  147. * @return void
  148. */
  149. function nasatlx_print_recent_mod_activity($activity, $courseid, $detail, $modnames, $viewfullnames) {
  150. }
  151. /**
  152. * Function to be run periodically according to the moodle cron
  153. * This function searches for things that need to be done, such
  154. * as sending out mail, toggling flags etc ...
  155. *
  156. * @return boolean
  157. * @todo Finish documenting this function
  158. **/
  159. function nasatlx_cron () {
  160. return true;
  161. }
  162. /**
  163. * Returns all other caps used in the module
  164. *
  165. * @example return array('moodle/site:accessallgroups');
  166. * @return array
  167. */
  168. function nasatlx_get_extra_capabilities() {
  169. return array();
  170. }
  171. ////////////////////////////////////////////////////////////////////////////////
  172. // Gradebook API //
  173. ////////////////////////////////////////////////////////////////////////////////
  174. /**
  175. * Is a given scale used by the instance of nasatlx?
  176. *
  177. * This function returns if a scale is being used by one nasatlx
  178. * if it has support for grading and scales. Commented code should be
  179. * modified if necessary. See forum, glossary or journal modules
  180. * as reference.
  181. *
  182. * @param int $nasatlxid ID of an instance of this module
  183. * @return bool true if the scale is used by the given nasatlx instance
  184. */
  185. function nasatlx_scale_used($nasatlxid, $scaleid) {
  186. global $DB;
  187. /** @example */
  188. if ($scaleid and $DB->record_exists('nasatlx', array('id' => $nasatlxid, 'grade' => -$scaleid))) {
  189. return true;
  190. } else {
  191. return false;
  192. }
  193. }
  194. /**
  195. * Checks if scale is being used by any instance of nasatlx.
  196. *
  197. * This is used to find out if scale used anywhere.
  198. *
  199. * @param $scaleid int
  200. * @return boolean true if the scale is used by any nasatlx instance
  201. */
  202. function nasatlx_scale_used_anywhere($scaleid) {
  203. global $DB;
  204. /** @example */
  205. if ($scaleid and $DB->record_exists('nasatlx', array('grade' => -$scaleid))) {
  206. return true;
  207. } else {
  208. return false;
  209. }
  210. }
  211. /**
  212. * Creates or updates grade item for the give nasatlx instance
  213. *
  214. * Needed by grade_update_mod_grades() in lib/gradelib.php
  215. *
  216. * @param stdClass $nasatlx instance object with extra cmidnumber and modname property
  217. * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
  218. * @return void
  219. */
  220. function nasatlx_grade_item_update(stdClass $nasatlx, $grades=null) {
  221. global $CFG;
  222. require_once($CFG->libdir.'/gradelib.php');
  223. /** @example */
  224. $item = array();
  225. $item['itemname'] = clean_param($nasatlx->name, PARAM_NOTAGS);
  226. $item['gradetype'] = GRADE_TYPE_VALUE;
  227. $item['grademax'] = $nasatlx->grade;
  228. $item['grademin'] = 0;
  229. grade_update('mod/nasatlx', $nasatlx->course, 'mod', 'nasatlx', $nasatlx->id, 0, null, $item);
  230. }
  231. /**
  232. * Update nasatlx grades in the gradebook
  233. *
  234. * Needed by grade_update_mod_grades() in lib/gradelib.php
  235. *
  236. * @param stdClass $nasatlx instance object with extra cmidnumber and modname property
  237. * @param int $userid update grade of specific user only, 0 means all participants
  238. * @return void
  239. */
  240. function nasatlx_update_grades(stdClass $nasatlx, $userid = 0) {
  241. global $CFG, $DB;
  242. require_once($CFG->libdir.'/gradelib.php');
  243. /** @example */
  244. $grades = array(); // populate array of grade objects indexed by userid
  245. grade_update('mod/nasatlx', $nasatlx->course, 'mod', 'nasatlx', $nasatlx->id, 0, $grades);
  246. }
  247. ////////////////////////////////////////////////////////////////////////////////
  248. // File API //
  249. ////////////////////////////////////////////////////////////////////////////////
  250. /**
  251. * Returns the lists of all browsable file areas within the given module context
  252. *
  253. * The file area 'intro' for the activity introduction field is added automatically
  254. * by {@link file_browser::get_file_info_context_module()}
  255. *
  256. * @param stdClass $course
  257. * @param stdClass $cm
  258. * @param stdClass $context
  259. * @return array of [(string)filearea] => (string)description
  260. */
  261. function nasatlx_get_file_areas($course, $cm, $context) {
  262. return array();
  263. }
  264. /**
  265. * File browsing support for nasatlx file areas
  266. *
  267. * @package mod_nasatlx
  268. * @category files
  269. *
  270. * @param file_browser $browser
  271. * @param array $areas
  272. * @param stdClass $course
  273. * @param stdClass $cm
  274. * @param stdClass $context
  275. * @param string $filearea
  276. * @param int $itemid
  277. * @param string $filepath
  278. * @param string $filename
  279. * @return file_info instance or null if not found
  280. */
  281. function nasatlx_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
  282. return null;
  283. }
  284. /**
  285. * Serves the files from the nasatlx file areas
  286. *
  287. * @package mod_nasatlx
  288. * @category files
  289. *
  290. * @param stdClass $course the course object
  291. * @param stdClass $cm the course module object
  292. * @param stdClass $context the nasatlx's context
  293. * @param string $filearea the name of the file area
  294. * @param array $args extra arguments (itemid, path)
  295. * @param bool $forcedownload whether or not force download
  296. * @param array $options additional options affecting the file serving
  297. */
  298. function nasatlx_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options=array()) {
  299. global $DB, $CFG;
  300. if ($context->contextlevel != CONTEXT_MODULE) {
  301. send_file_not_found();
  302. }
  303. require_login($course, true, $cm);
  304. send_file_not_found();
  305. }
  306. ////////////////////////////////////////////////////////////////////////////////
  307. // Navigation API //
  308. ////////////////////////////////////////////////////////////////////////////////
  309. /**
  310. * Extends the global navigation tree by adding nasatlx nodes if there is a relevant content
  311. *
  312. * This can be called by an AJAX request so do not rely on $PAGE as it might not be set up properly.
  313. *
  314. * @param navigation_node $navref An object representing the navigation tree node of the nasatlx module instance
  315. * @param stdClass $course
  316. * @param stdClass $module
  317. * @param cm_info $cm
  318. */
  319. function nasatlx_extend_navigation(navigation_node $navref, stdclass $course, stdclass $module, cm_info $cm) {
  320. }
  321. /**
  322. * Extends the settings navigation with the nasatlx settings
  323. *
  324. * This function is called when the context for the page is a nasatlx module. This is not called by AJAX
  325. * so it is safe to rely on the $PAGE.
  326. *
  327. * @param settings_navigation $settingsnav {@link settings_navigation}
  328. * @param navigation_node $nasatlxnode {@link navigation_node}
  329. */
  330. function nasatlx_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $nasatlxnode=null) {
  331. }