PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/mod/lesson/locallib.php

https://bitbucket.org/moodle/moodle
PHP | 5351 lines | 3222 code | 524 blank | 1605 comment | 786 complexity | 4c6febf9ff6dd19337963db1e7dd0f45 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Local library file for Lesson. These are non-standard functions that are used
  18. * only by Lesson.
  19. *
  20. * @package mod_lesson
  21. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
  23. **/
  24. /** Make sure this isn't being directly accessed */
  25. defined('MOODLE_INTERNAL') || die();
  26. /** Include the files that are required by this module */
  27. require_once($CFG->dirroot.'/course/moodleform_mod.php');
  28. require_once($CFG->dirroot . '/mod/lesson/lib.php');
  29. require_once($CFG->libdir . '/filelib.php');
  30. /** This page */
  31. define('LESSON_THISPAGE', 0);
  32. /** Next page -> any page not seen before */
  33. define("LESSON_UNSEENPAGE", 1);
  34. /** Next page -> any page not answered correctly */
  35. define("LESSON_UNANSWEREDPAGE", 2);
  36. /** Jump to Next Page */
  37. define("LESSON_NEXTPAGE", -1);
  38. /** End of Lesson */
  39. define("LESSON_EOL", -9);
  40. /** Jump to an unseen page within a branch and end of branch or end of lesson */
  41. define("LESSON_UNSEENBRANCHPAGE", -50);
  42. /** Jump to Previous Page */
  43. define("LESSON_PREVIOUSPAGE", -40);
  44. /** Jump to a random page within a branch and end of branch or end of lesson */
  45. define("LESSON_RANDOMPAGE", -60);
  46. /** Jump to a random Branch */
  47. define("LESSON_RANDOMBRANCH", -70);
  48. /** Cluster Jump */
  49. define("LESSON_CLUSTERJUMP", -80);
  50. /** Undefined */
  51. define("LESSON_UNDEFINED", -99);
  52. /** LESSON_MAX_EVENT_LENGTH = 432000 ; 5 days maximum */
  53. define("LESSON_MAX_EVENT_LENGTH", "432000");
  54. /** Answer format is HTML */
  55. define("LESSON_ANSWER_HTML", "HTML");
  56. /** Placeholder answer for all other answers. */
  57. define("LESSON_OTHER_ANSWERS", "@#wronganswer#@");
  58. //////////////////////////////////////////////////////////////////////////////////////
  59. /// Any other lesson functions go here. Each of them must have a name that
  60. /// starts with lesson_
  61. /**
  62. * Checks to see if a LESSON_CLUSTERJUMP or
  63. * a LESSON_UNSEENBRANCHPAGE is used in a lesson.
  64. *
  65. * This function is only executed when a teacher is
  66. * checking the navigation for a lesson.
  67. *
  68. * @param stdClass $lesson Id of the lesson that is to be checked.
  69. * @return boolean True or false.
  70. **/
  71. function lesson_display_teacher_warning($lesson) {
  72. global $DB;
  73. // get all of the lesson answers
  74. $params = array ("lessonid" => $lesson->id);
  75. if (!$lessonanswers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid", $params)) {
  76. // no answers, then not using cluster or unseen
  77. return false;
  78. }
  79. // just check for the first one that fulfills the requirements
  80. foreach ($lessonanswers as $lessonanswer) {
  81. if ($lessonanswer->jumpto == LESSON_CLUSTERJUMP || $lessonanswer->jumpto == LESSON_UNSEENBRANCHPAGE) {
  82. return true;
  83. }
  84. }
  85. // if no answers use either of the two jumps
  86. return false;
  87. }
  88. /**
  89. * Interprets the LESSON_UNSEENBRANCHPAGE jump.
  90. *
  91. * will return the pageid of a random unseen page that is within a branch
  92. *
  93. * @param lesson $lesson
  94. * @param int $userid Id of the user.
  95. * @param int $pageid Id of the page from which we are jumping.
  96. * @return int Id of the next page.
  97. **/
  98. function lesson_unseen_question_jump($lesson, $user, $pageid) {
  99. global $DB;
  100. // get the number of retakes
  101. if (!$retakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$user))) {
  102. $retakes = 0;
  103. }
  104. // get all the lesson_attempts aka what the user has seen
  105. if ($viewedpages = $DB->get_records("lesson_attempts", array("lessonid"=>$lesson->id, "userid"=>$user, "retry"=>$retakes), "timeseen DESC")) {
  106. foreach($viewedpages as $viewed) {
  107. $seenpages[] = $viewed->pageid;
  108. }
  109. } else {
  110. $seenpages = array();
  111. }
  112. // get the lesson pages
  113. $lessonpages = $lesson->load_all_pages();
  114. if ($pageid == LESSON_UNSEENBRANCHPAGE) { // this only happens when a student leaves in the middle of an unseen question within a branch series
  115. $pageid = $seenpages[0]; // just change the pageid to the last page viewed inside the branch table
  116. }
  117. // go up the pages till branch table
  118. while ($pageid != 0) { // this condition should never be satisfied... only happens if there are no branch tables above this page
  119. if ($lessonpages[$pageid]->qtype == LESSON_PAGE_BRANCHTABLE) {
  120. break;
  121. }
  122. $pageid = $lessonpages[$pageid]->prevpageid;
  123. }
  124. $pagesinbranch = $lesson->get_sub_pages_of($pageid, array(LESSON_PAGE_BRANCHTABLE, LESSON_PAGE_ENDOFBRANCH));
  125. // this foreach loop stores all the pages that are within the branch table but are not in the $seenpages array
  126. $unseen = array();
  127. foreach($pagesinbranch as $page) {
  128. if (!in_array($page->id, $seenpages)) {
  129. $unseen[] = $page->id;
  130. }
  131. }
  132. if(count($unseen) == 0) {
  133. if(isset($pagesinbranch)) {
  134. $temp = end($pagesinbranch);
  135. $nextpage = $temp->nextpageid; // they have seen all the pages in the branch, so go to EOB/next branch table/EOL
  136. } else {
  137. // there are no pages inside the branch, so return the next page
  138. $nextpage = $lessonpages[$pageid]->nextpageid;
  139. }
  140. if ($nextpage == 0) {
  141. return LESSON_EOL;
  142. } else {
  143. return $nextpage;
  144. }
  145. } else {
  146. return $unseen[rand(0, count($unseen)-1)]; // returns a random page id for the next page
  147. }
  148. }
  149. /**
  150. * Handles the unseen branch table jump.
  151. *
  152. * @param lesson $lesson
  153. * @param int $userid User id.
  154. * @return int Will return the page id of a branch table or end of lesson
  155. **/
  156. function lesson_unseen_branch_jump($lesson, $userid) {
  157. global $DB;
  158. if (!$retakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$userid))) {
  159. $retakes = 0;
  160. }
  161. if (!$seenbranches = $lesson->get_content_pages_viewed($retakes, $userid, 'timeseen DESC')) {
  162. print_error('cannotfindrecords', 'lesson');
  163. }
  164. // get the lesson pages
  165. $lessonpages = $lesson->load_all_pages();
  166. // this loads all the viewed branch tables into $seen until it finds the branch table with the flag
  167. // which is the branch table that starts the unseenbranch function
  168. $seen = array();
  169. foreach ($seenbranches as $seenbranch) {
  170. if (!$seenbranch->flag) {
  171. $seen[$seenbranch->pageid] = $seenbranch->pageid;
  172. } else {
  173. $start = $seenbranch->pageid;
  174. break;
  175. }
  176. }
  177. // this function searches through the lesson pages to find all the branch tables
  178. // that follow the flagged branch table
  179. $pageid = $lessonpages[$start]->nextpageid; // move down from the flagged branch table
  180. $branchtables = array();
  181. while ($pageid != 0) { // grab all of the branch table till eol
  182. if ($lessonpages[$pageid]->qtype == LESSON_PAGE_BRANCHTABLE) {
  183. $branchtables[] = $lessonpages[$pageid]->id;
  184. }
  185. $pageid = $lessonpages[$pageid]->nextpageid;
  186. }
  187. $unseen = array();
  188. foreach ($branchtables as $branchtable) {
  189. // load all of the unseen branch tables into unseen
  190. if (!array_key_exists($branchtable, $seen)) {
  191. $unseen[] = $branchtable;
  192. }
  193. }
  194. if (count($unseen) > 0) {
  195. return $unseen[rand(0, count($unseen)-1)]; // returns a random page id for the next page
  196. } else {
  197. return LESSON_EOL; // has viewed all of the branch tables
  198. }
  199. }
  200. /**
  201. * Handles the random jump between a branch table and end of branch or end of lesson (LESSON_RANDOMPAGE).
  202. *
  203. * @param lesson $lesson
  204. * @param int $pageid The id of the page that we are jumping from (?)
  205. * @return int The pageid of a random page that is within a branch table
  206. **/
  207. function lesson_random_question_jump($lesson, $pageid) {
  208. global $DB;
  209. // get the lesson pages
  210. $params = array ("lessonid" => $lesson->id);
  211. if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) {
  212. print_error('cannotfindpages', 'lesson');
  213. }
  214. // go up the pages till branch table
  215. while ($pageid != 0) { // this condition should never be satisfied... only happens if there are no branch tables above this page
  216. if ($lessonpages[$pageid]->qtype == LESSON_PAGE_BRANCHTABLE) {
  217. break;
  218. }
  219. $pageid = $lessonpages[$pageid]->prevpageid;
  220. }
  221. // get the pages within the branch
  222. $pagesinbranch = $lesson->get_sub_pages_of($pageid, array(LESSON_PAGE_BRANCHTABLE, LESSON_PAGE_ENDOFBRANCH));
  223. if(count($pagesinbranch) == 0) {
  224. // there are no pages inside the branch, so return the next page
  225. return $lessonpages[$pageid]->nextpageid;
  226. } else {
  227. return $pagesinbranch[rand(0, count($pagesinbranch)-1)]->id; // returns a random page id for the next page
  228. }
  229. }
  230. /**
  231. * Calculates a user's grade for a lesson.
  232. *
  233. * @param object $lesson The lesson that the user is taking.
  234. * @param int $retries The attempt number.
  235. * @param int $userid Id of the user (optional, default current user).
  236. * @return object { nquestions => number of questions answered
  237. attempts => number of question attempts
  238. total => max points possible
  239. earned => points earned by student
  240. grade => calculated percentage grade
  241. nmanual => number of manually graded questions
  242. manualpoints => point value for manually graded questions }
  243. */
  244. function lesson_grade($lesson, $ntries, $userid = 0) {
  245. global $USER, $DB;
  246. if (empty($userid)) {
  247. $userid = $USER->id;
  248. }
  249. // Zero out everything
  250. $ncorrect = 0;
  251. $nviewed = 0;
  252. $score = 0;
  253. $nmanual = 0;
  254. $manualpoints = 0;
  255. $thegrade = 0;
  256. $nquestions = 0;
  257. $total = 0;
  258. $earned = 0;
  259. $params = array ("lessonid" => $lesson->id, "userid" => $userid, "retry" => $ntries);
  260. if ($useranswers = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND
  261. userid = :userid AND retry = :retry", $params, "timeseen")) {
  262. // group each try with its page
  263. $attemptset = array();
  264. foreach ($useranswers as $useranswer) {
  265. $attemptset[$useranswer->pageid][] = $useranswer;
  266. }
  267. if (!empty($lesson->maxattempts)) {
  268. // Drop all attempts that go beyond max attempts for the lesson.
  269. foreach ($attemptset as $key => $set) {
  270. $attemptset[$key] = array_slice($set, 0, $lesson->maxattempts);
  271. }
  272. }
  273. // get only the pages and their answers that the user answered
  274. list($usql, $parameters) = $DB->get_in_or_equal(array_keys($attemptset));
  275. array_unshift($parameters, $lesson->id);
  276. $pages = $DB->get_records_select("lesson_pages", "lessonid = ? AND id $usql", $parameters);
  277. $answers = $DB->get_records_select("lesson_answers", "lessonid = ? AND pageid $usql", $parameters);
  278. // Number of pages answered
  279. $nquestions = count($pages);
  280. foreach ($attemptset as $attempts) {
  281. $page = lesson_page::load($pages[end($attempts)->pageid], $lesson);
  282. if ($lesson->custom) {
  283. $attempt = end($attempts);
  284. // If essay question, handle it, otherwise add to score
  285. if ($page->requires_manual_grading()) {
  286. $useranswerobj = unserialize($attempt->useranswer);
  287. if (isset($useranswerobj->score)) {
  288. $earned += $useranswerobj->score;
  289. }
  290. $nmanual++;
  291. $manualpoints += $answers[$attempt->answerid]->score;
  292. } else if (!empty($attempt->answerid)) {
  293. $earned += $page->earned_score($answers, $attempt);
  294. }
  295. } else {
  296. foreach ($attempts as $attempt) {
  297. $earned += $attempt->correct;
  298. }
  299. $attempt = end($attempts); // doesn't matter which one
  300. // If essay question, increase numbers
  301. if ($page->requires_manual_grading()) {
  302. $nmanual++;
  303. $manualpoints++;
  304. }
  305. }
  306. // Number of times answered
  307. $nviewed += count($attempts);
  308. }
  309. if ($lesson->custom) {
  310. $bestscores = array();
  311. // Find the highest possible score per page to get our total
  312. foreach ($answers as $answer) {
  313. if(!isset($bestscores[$answer->pageid])) {
  314. $bestscores[$answer->pageid] = $answer->score;
  315. } else if ($bestscores[$answer->pageid] < $answer->score) {
  316. $bestscores[$answer->pageid] = $answer->score;
  317. }
  318. }
  319. $total = array_sum($bestscores);
  320. } else {
  321. // Check to make sure the student has answered the minimum questions
  322. if ($lesson->minquestions and $nquestions < $lesson->minquestions) {
  323. // Nope, increase number viewed by the amount of unanswered questions
  324. $total = $nviewed + ($lesson->minquestions - $nquestions);
  325. } else {
  326. $total = $nviewed;
  327. }
  328. }
  329. }
  330. if ($total) { // not zero
  331. $thegrade = round(100 * $earned / $total, 5);
  332. }
  333. // Build the grade information object
  334. $gradeinfo = new stdClass;
  335. $gradeinfo->nquestions = $nquestions;
  336. $gradeinfo->attempts = $nviewed;
  337. $gradeinfo->total = $total;
  338. $gradeinfo->earned = $earned;
  339. $gradeinfo->grade = $thegrade;
  340. $gradeinfo->nmanual = $nmanual;
  341. $gradeinfo->manualpoints = $manualpoints;
  342. return $gradeinfo;
  343. }
  344. /**
  345. * Determines if a user can view the left menu. The determining factor
  346. * is whether a user has a grade greater than or equal to the lesson setting
  347. * of displayleftif
  348. *
  349. * @param object $lesson Lesson object of the current lesson
  350. * @return boolean 0 if the user cannot see, or $lesson->displayleft to keep displayleft unchanged
  351. **/
  352. function lesson_displayleftif($lesson) {
  353. global $CFG, $USER, $DB;
  354. if (!empty($lesson->displayleftif)) {
  355. // get the current user's max grade for this lesson
  356. $params = array ("userid" => $USER->id, "lessonid" => $lesson->id);
  357. if ($maxgrade = $DB->get_record_sql('SELECT userid, MAX(grade) AS maxgrade FROM {lesson_grades} WHERE userid = :userid AND lessonid = :lessonid GROUP BY userid', $params)) {
  358. if ($maxgrade->maxgrade < $lesson->displayleftif) {
  359. return 0; // turn off the displayleft
  360. }
  361. } else {
  362. return 0; // no grades
  363. }
  364. }
  365. // if we get to here, keep the original state of displayleft lesson setting
  366. return $lesson->displayleft;
  367. }
  368. /**
  369. *
  370. * @param $cm
  371. * @param $lesson
  372. * @param $page
  373. * @return unknown_type
  374. */
  375. function lesson_add_fake_blocks($page, $cm, $lesson, $timer = null) {
  376. $bc = lesson_menu_block_contents($cm->id, $lesson);
  377. if (!empty($bc)) {
  378. $regions = $page->blocks->get_regions();
  379. $firstregion = reset($regions);
  380. $page->blocks->add_fake_block($bc, $firstregion);
  381. }
  382. $bc = lesson_mediafile_block_contents($cm->id, $lesson);
  383. if (!empty($bc)) {
  384. $page->blocks->add_fake_block($bc, $page->blocks->get_default_region());
  385. }
  386. if (!empty($timer)) {
  387. $bc = lesson_clock_block_contents($cm->id, $lesson, $timer, $page);
  388. if (!empty($bc)) {
  389. $page->blocks->add_fake_block($bc, $page->blocks->get_default_region());
  390. }
  391. }
  392. }
  393. /**
  394. * If there is a media file associated with this
  395. * lesson, return a block_contents that displays it.
  396. *
  397. * @param int $cmid Course Module ID for this lesson
  398. * @param object $lesson Full lesson record object
  399. * @return block_contents
  400. **/
  401. function lesson_mediafile_block_contents($cmid, $lesson) {
  402. global $OUTPUT;
  403. if (empty($lesson->mediafile)) {
  404. return null;
  405. }
  406. $options = array();
  407. $options['menubar'] = 0;
  408. $options['location'] = 0;
  409. $options['left'] = 5;
  410. $options['top'] = 5;
  411. $options['scrollbars'] = 1;
  412. $options['resizable'] = 1;
  413. $options['width'] = $lesson->mediawidth;
  414. $options['height'] = $lesson->mediaheight;
  415. $link = new moodle_url('/mod/lesson/mediafile.php?id='.$cmid);
  416. $action = new popup_action('click', $link, 'lessonmediafile', $options);
  417. $content = $OUTPUT->action_link($link, get_string('mediafilepopup', 'lesson'), $action, array('title'=>get_string('mediafilepopup', 'lesson')));
  418. $bc = new block_contents();
  419. $bc->title = get_string('linkedmedia', 'lesson');
  420. $bc->attributes['class'] = 'mediafile block';
  421. $bc->content = $content;
  422. return $bc;
  423. }
  424. /**
  425. * If a timed lesson and not a teacher, then
  426. * return a block_contents containing the clock.
  427. *
  428. * @param int $cmid Course Module ID for this lesson
  429. * @param object $lesson Full lesson record object
  430. * @param object $timer Full timer record object
  431. * @return block_contents
  432. **/
  433. function lesson_clock_block_contents($cmid, $lesson, $timer, $page) {
  434. // Display for timed lessons and for students only
  435. $context = context_module::instance($cmid);
  436. if ($lesson->timelimit == 0 || has_capability('mod/lesson:manage', $context)) {
  437. return null;
  438. }
  439. $content = '<div id="lesson-timer">';
  440. $content .= $lesson->time_remaining($timer->starttime);
  441. $content .= '</div>';
  442. $clocksettings = array('starttime' => $timer->starttime, 'servertime' => time(), 'testlength' => $lesson->timelimit);
  443. $page->requires->data_for_js('clocksettings', $clocksettings, true);
  444. $page->requires->strings_for_js(array('timeisup'), 'lesson');
  445. $page->requires->js('/mod/lesson/timer.js');
  446. $page->requires->js_init_call('show_clock');
  447. $bc = new block_contents();
  448. $bc->title = get_string('timeremaining', 'lesson');
  449. $bc->attributes['class'] = 'clock block';
  450. $bc->content = $content;
  451. return $bc;
  452. }
  453. /**
  454. * If left menu is turned on, then this will
  455. * print the menu in a block
  456. *
  457. * @param int $cmid Course Module ID for this lesson
  458. * @param lesson $lesson Full lesson record object
  459. * @return void
  460. **/
  461. function lesson_menu_block_contents($cmid, $lesson) {
  462. global $CFG, $DB;
  463. if (!$lesson->displayleft) {
  464. return null;
  465. }
  466. $pages = $lesson->load_all_pages();
  467. foreach ($pages as $page) {
  468. if ((int)$page->prevpageid === 0) {
  469. $pageid = $page->id;
  470. break;
  471. }
  472. }
  473. $currentpageid = optional_param('pageid', $pageid, PARAM_INT);
  474. if (!$pageid || !$pages) {
  475. return null;
  476. }
  477. $content = '<a href="#maincontent" class="accesshide">' .
  478. get_string('skip', 'lesson') .
  479. "</a>\n<div class=\"menuwrapper\">\n<ul>\n";
  480. while ($pageid != 0) {
  481. $page = $pages[$pageid];
  482. // Only process branch tables with display turned on
  483. if ($page->displayinmenublock && $page->display) {
  484. if ($page->id == $currentpageid) {
  485. $content .= '<li class="selected">'.format_string($page->title,true)."</li>\n";
  486. } else {
  487. $content .= "<li class=\"notselected\"><a href=\"$CFG->wwwroot/mod/lesson/view.php?id=$cmid&amp;pageid=$page->id\">".format_string($page->title,true)."</a></li>\n";
  488. }
  489. }
  490. $pageid = $page->nextpageid;
  491. }
  492. $content .= "</ul>\n</div>\n";
  493. $bc = new block_contents();
  494. $bc->title = get_string('lessonmenu', 'lesson');
  495. $bc->attributes['class'] = 'menu block';
  496. $bc->content = $content;
  497. return $bc;
  498. }
  499. /**
  500. * Adds header buttons to the page for the lesson
  501. *
  502. * @param object $cm
  503. * @param object $context
  504. * @param bool $extraeditbuttons
  505. * @param int $lessonpageid
  506. */
  507. function lesson_add_header_buttons($cm, $context, $extraeditbuttons=false, $lessonpageid=null) {
  508. global $CFG, $PAGE, $OUTPUT;
  509. if (has_capability('mod/lesson:edit', $context) && $extraeditbuttons) {
  510. if ($lessonpageid === null) {
  511. print_error('invalidpageid', 'lesson');
  512. }
  513. if (!empty($lessonpageid) && $lessonpageid != LESSON_EOL) {
  514. $url = new moodle_url('/mod/lesson/editpage.php', array(
  515. 'id' => $cm->id,
  516. 'pageid' => $lessonpageid,
  517. 'edit' => 1,
  518. 'returnto' => $PAGE->url->out_as_local_url(false)
  519. ));
  520. $PAGE->set_button($OUTPUT->single_button($url, get_string('editpagecontent', 'lesson')));
  521. }
  522. }
  523. }
  524. /**
  525. * This is a function used to detect media types and generate html code.
  526. *
  527. * @global object $CFG
  528. * @global object $PAGE
  529. * @param object $lesson
  530. * @param object $context
  531. * @return string $code the html code of media
  532. */
  533. function lesson_get_media_html($lesson, $context) {
  534. global $CFG, $PAGE, $OUTPUT;
  535. require_once("$CFG->libdir/resourcelib.php");
  536. // get the media file link
  537. if (strpos($lesson->mediafile, '://') !== false) {
  538. $url = new moodle_url($lesson->mediafile);
  539. } else {
  540. // the timemodified is used to prevent caching problems, instead of '/' we should better read from files table and use sortorder
  541. $url = moodle_url::make_pluginfile_url($context->id, 'mod_lesson', 'mediafile', $lesson->timemodified, '/', ltrim($lesson->mediafile, '/'));
  542. }
  543. $title = $lesson->mediafile;
  544. $clicktoopen = html_writer::link($url, get_string('download'));
  545. $mimetype = resourcelib_guess_url_mimetype($url);
  546. $extension = resourcelib_get_extension($url->out(false));
  547. $mediamanager = core_media_manager::instance($PAGE);
  548. $embedoptions = array(
  549. core_media_manager::OPTION_TRUSTED => true,
  550. core_media_manager::OPTION_BLOCK => true
  551. );
  552. // find the correct type and print it out
  553. if (in_array($mimetype, array('image/gif','image/jpeg','image/png'))) { // It's an image
  554. $code = resourcelib_embed_image($url, $title);
  555. } else if ($mediamanager->can_embed_url($url, $embedoptions)) {
  556. // Media (audio/video) file.
  557. $code = $mediamanager->embed_url($url, $title, 0, 0, $embedoptions);
  558. } else {
  559. // anything else - just try object tag enlarged as much as possible
  560. $code = resourcelib_embed_general($url, $title, $clicktoopen, $mimetype);
  561. }
  562. return $code;
  563. }
  564. /**
  565. * Logic to happen when a/some group(s) has/have been deleted in a course.
  566. *
  567. * @param int $courseid The course ID.
  568. * @param int $groupid The group id if it is known
  569. * @return void
  570. */
  571. function lesson_process_group_deleted_in_course($courseid, $groupid = null) {
  572. global $DB;
  573. $params = array('courseid' => $courseid);
  574. if ($groupid) {
  575. $params['groupid'] = $groupid;
  576. // We just update the group that was deleted.
  577. $sql = "SELECT o.id, o.lessonid, o.groupid
  578. FROM {lesson_overrides} o
  579. JOIN {lesson} lesson ON lesson.id = o.lessonid
  580. WHERE lesson.course = :courseid
  581. AND o.groupid = :groupid";
  582. } else {
  583. // No groupid, we update all orphaned group overrides for all lessons in course.
  584. $sql = "SELECT o.id, o.lessonid, o.groupid
  585. FROM {lesson_overrides} o
  586. JOIN {lesson} lesson ON lesson.id = o.lessonid
  587. LEFT JOIN {groups} grp ON grp.id = o.groupid
  588. WHERE lesson.course = :courseid
  589. AND o.groupid IS NOT NULL
  590. AND grp.id IS NULL";
  591. }
  592. $records = $DB->get_records_sql($sql, $params);
  593. if (!$records) {
  594. return; // Nothing to do.
  595. }
  596. $DB->delete_records_list('lesson_overrides', 'id', array_keys($records));
  597. $cache = cache::make('mod_lesson', 'overrides');
  598. foreach ($records as $record) {
  599. $cache->delete("{$record->lessonid}_g_{$record->groupid}");
  600. }
  601. }
  602. /**
  603. * Return the overview report table and data.
  604. *
  605. * @param lesson $lesson lesson instance
  606. * @param mixed $currentgroup false if not group used, 0 for all groups, group id (int) to filter by that groups
  607. * @return mixed false if there is no information otherwise html_table and stdClass with the table and data
  608. * @since Moodle 3.3
  609. */
  610. function lesson_get_overview_report_table_and_data(lesson $lesson, $currentgroup) {
  611. global $DB, $CFG, $OUTPUT;
  612. require_once($CFG->dirroot . '/mod/lesson/pagetypes/branchtable.php');
  613. $context = $lesson->context;
  614. $cm = $lesson->cm;
  615. // Count the number of branch and question pages in this lesson.
  616. $branchcount = $DB->count_records('lesson_pages', array('lessonid' => $lesson->id, 'qtype' => LESSON_PAGE_BRANCHTABLE));
  617. $questioncount = ($DB->count_records('lesson_pages', array('lessonid' => $lesson->id)) - $branchcount);
  618. // Only load students if there attempts for this lesson.
  619. $attempts = $DB->record_exists('lesson_attempts', array('lessonid' => $lesson->id));
  620. $branches = $DB->record_exists('lesson_branch', array('lessonid' => $lesson->id));
  621. $timer = $DB->record_exists('lesson_timer', array('lessonid' => $lesson->id));
  622. if ($attempts or $branches or $timer) {
  623. list($esql, $params) = get_enrolled_sql($context, '', $currentgroup, true);
  624. list($sort, $sortparams) = users_order_by_sql('u');
  625. // TODO Does not support custom user profile fields (MDL-70456).
  626. $userfieldsapi = \core_user\fields::for_identity($context, false)->with_userpic();
  627. $ufields = $userfieldsapi->get_sql('u', false, '', '', false)->selects;
  628. $extrafields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
  629. $params['a1lessonid'] = $lesson->id;
  630. $params['b1lessonid'] = $lesson->id;
  631. $params['c1lessonid'] = $lesson->id;
  632. $sql = "SELECT DISTINCT $ufields
  633. FROM {user} u
  634. JOIN (
  635. SELECT userid, lessonid FROM {lesson_attempts} a1
  636. WHERE a1.lessonid = :a1lessonid
  637. UNION
  638. SELECT userid, lessonid FROM {lesson_branch} b1
  639. WHERE b1.lessonid = :b1lessonid
  640. UNION
  641. SELECT userid, lessonid FROM {lesson_timer} c1
  642. WHERE c1.lessonid = :c1lessonid
  643. ) a ON u.id = a.userid
  644. JOIN ($esql) ue ON ue.id = a.userid
  645. ORDER BY $sort";
  646. $students = $DB->get_recordset_sql($sql, $params);
  647. if (!$students->valid()) {
  648. $students->close();
  649. return array(false, false);
  650. }
  651. } else {
  652. return array(false, false);
  653. }
  654. if (! $grades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id), 'completed')) {
  655. $grades = array();
  656. }
  657. if (! $times = $DB->get_records('lesson_timer', array('lessonid' => $lesson->id), 'starttime')) {
  658. $times = array();
  659. }
  660. // Build an array for output.
  661. $studentdata = array();
  662. $attempts = $DB->get_recordset('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen');
  663. foreach ($attempts as $attempt) {
  664. // if the user is not in the array or if the retry number is not in the sub array, add the data for that try.
  665. if (empty($studentdata[$attempt->userid]) || empty($studentdata[$attempt->userid][$attempt->retry])) {
  666. // restore/setup defaults
  667. $n = 0;
  668. $timestart = 0;
  669. $timeend = 0;
  670. $usergrade = null;
  671. $eol = 0;
  672. // search for the grade record for this try. if not there, the nulls defined above will be used.
  673. foreach($grades as $grade) {
  674. // check to see if the grade matches the correct user
  675. if ($grade->userid == $attempt->userid) {
  676. // see if n is = to the retry
  677. if ($n == $attempt->retry) {
  678. // get grade info
  679. $usergrade = round($grade->grade, 2); // round it here so we only have to do it once
  680. break;
  681. }
  682. $n++; // if not equal, then increment n
  683. }
  684. }
  685. $n = 0;
  686. // search for the time record for this try. if not there, the nulls defined above will be used.
  687. foreach($times as $time) {
  688. // check to see if the grade matches the correct user
  689. if ($time->userid == $attempt->userid) {
  690. // see if n is = to the retry
  691. if ($n == $attempt->retry) {
  692. // get grade info
  693. $timeend = $time->lessontime;
  694. $timestart = $time->starttime;
  695. $eol = $time->completed;
  696. break;
  697. }
  698. $n++; // if not equal, then increment n
  699. }
  700. }
  701. // build up the array.
  702. // this array represents each student and all of their tries at the lesson
  703. $studentdata[$attempt->userid][$attempt->retry] = array( "timestart" => $timestart,
  704. "timeend" => $timeend,
  705. "grade" => $usergrade,
  706. "end" => $eol,
  707. "try" => $attempt->retry,
  708. "userid" => $attempt->userid);
  709. }
  710. }
  711. $attempts->close();
  712. $branches = $DB->get_recordset('lesson_branch', array('lessonid' => $lesson->id), 'timeseen');
  713. foreach ($branches as $branch) {
  714. // If the user is not in the array or if the retry number is not in the sub array, add the data for that try.
  715. if (empty($studentdata[$branch->userid]) || empty($studentdata[$branch->userid][$branch->retry])) {
  716. // Restore/setup defaults.
  717. $n = 0;
  718. $timestart = 0;
  719. $timeend = 0;
  720. $usergrade = null;
  721. $eol = 0;
  722. // Search for the time record for this try. if not there, the nulls defined above will be used.
  723. foreach ($times as $time) {
  724. // Check to see if the grade matches the correct user.
  725. if ($time->userid == $branch->userid) {
  726. // See if n is = to the retry.
  727. if ($n == $branch->retry) {
  728. // Get grade info.
  729. $timeend = $time->lessontime;
  730. $timestart = $time->starttime;
  731. $eol = $time->completed;
  732. break;
  733. }
  734. $n++; // If not equal, then increment n.
  735. }
  736. }
  737. // Build up the array.
  738. // This array represents each student and all of their tries at the lesson.
  739. $studentdata[$branch->userid][$branch->retry] = array( "timestart" => $timestart,
  740. "timeend" => $timeend,
  741. "grade" => $usergrade,
  742. "end" => $eol,
  743. "try" => $branch->retry,
  744. "userid" => $branch->userid);
  745. }
  746. }
  747. $branches->close();
  748. // Need the same thing for timed entries that were not completed.
  749. foreach ($times as $time) {
  750. $endoflesson = $time->completed;
  751. // If the time start is the same with another record then we shouldn't be adding another item to this array.
  752. if (isset($studentdata[$time->userid])) {
  753. $foundmatch = false;
  754. $n = 0;
  755. foreach ($studentdata[$time->userid] as $key => $value) {
  756. if ($value['timestart'] == $time->starttime) {
  757. // Don't add this to the array.
  758. $foundmatch = true;
  759. break;
  760. }
  761. }
  762. $n = count($studentdata[$time->userid]) + 1;
  763. if (!$foundmatch) {
  764. // Add a record.
  765. $studentdata[$time->userid][] = array(
  766. "timestart" => $time->starttime,
  767. "timeend" => $time->lessontime,
  768. "grade" => null,
  769. "end" => $endoflesson,
  770. "try" => $n,
  771. "userid" => $time->userid
  772. );
  773. }
  774. } else {
  775. $studentdata[$time->userid][] = array(
  776. "timestart" => $time->starttime,
  777. "timeend" => $time->lessontime,
  778. "grade" => null,
  779. "end" => $endoflesson,
  780. "try" => 0,
  781. "userid" => $time->userid
  782. );
  783. }
  784. }
  785. // To store all the data to be returned by the function.
  786. $data = new stdClass();
  787. // Determine if lesson should have a score.
  788. if ($branchcount > 0 AND $questioncount == 0) {
  789. // This lesson only contains content pages and is not graded.
  790. $data->lessonscored = false;
  791. } else {
  792. // This lesson is graded.
  793. $data->lessonscored = true;
  794. }
  795. // set all the stats variables
  796. $data->numofattempts = 0;
  797. $data->avescore = 0;
  798. $data->avetime = 0;
  799. $data->highscore = null;
  800. $data->lowscore = null;
  801. $data->hightime = null;
  802. $data->lowtime = null;
  803. $data->students = array();
  804. $table = new html_table();
  805. $headers = [get_string('name')];
  806. foreach ($extrafields as $field) {
  807. $headers[] = \core_user\fields::get_display_name($field);
  808. }
  809. $caneditlesson = has_capability('mod/lesson:edit', $context);
  810. $attemptsheader = get_string('attempts', 'lesson');
  811. if ($caneditlesson) {
  812. $selectall = get_string('selectallattempts', 'lesson');
  813. $deselectall = get_string('deselectallattempts', 'lesson');
  814. // Build the select/deselect all control.
  815. $selectallid = 'selectall-attempts';
  816. $mastercheckbox = new \core\output\checkbox_toggleall('lesson-attempts', true, [
  817. 'id' => $selectallid,
  818. 'name' => $selectallid,
  819. 'value' => 1,
  820. 'label' => $selectall,
  821. 'selectall' => $selectall,
  822. 'deselectall' => $deselectall,
  823. 'labelclasses' => 'form-check-label'
  824. ]);
  825. $attemptsheader = $OUTPUT->render($mastercheckbox);
  826. }
  827. $headers [] = $attemptsheader;
  828. // Set up the table object.
  829. if ($data->lessonscored) {
  830. $headers [] = get_string('highscore', 'lesson');
  831. }
  832. $colcount = count($headers);
  833. $table->head = $headers;
  834. $table->align = [];
  835. $table->align = array_pad($table->align, $colcount, 'center');
  836. $table->align[$colcount - 1] = 'left';
  837. if ($data->lessonscored) {
  838. $table->align[$colcount - 2] = 'left';
  839. }
  840. $table->attributes['class'] = 'table table-striped';
  841. // print out the $studentdata array
  842. // going through each student that has attempted the lesson, so, each student should have something to be displayed
  843. foreach ($students as $student) {
  844. // check to see if the student has attempts to print out
  845. if (array_key_exists($student->id, $studentdata)) {
  846. // set/reset some variables
  847. $attempts = array();
  848. $dataforstudent = new stdClass;
  849. $dataforstudent->attempts = array();
  850. // gather the data for each user attempt
  851. $bestgrade = 0;
  852. // $tries holds all the tries/retries a student has done
  853. $tries = $studentdata[$student->id];
  854. $studentname = fullname($student, true);
  855. foreach ($tries as $try) {
  856. $dataforstudent->attempts[] = $try;
  857. // Start to build up the checkbox and link.
  858. $attempturlparams = [
  859. 'id' => $cm->id,
  860. 'action' => 'reportdetail',
  861. 'userid' => $try['userid'],
  862. 'try' => $try['try'],
  863. ];
  864. if ($try["grade"] !== null) { // if null then not done yet
  865. // this is what the link does when the user has completed the try
  866. $timetotake = $try["timeend"] - $try["timestart"];
  867. if ($try["grade"] > $bestgrade) {
  868. $bestgrade = $try["grade"];
  869. }
  870. $attemptdata = (object)[
  871. 'grade' => $try["grade"],
  872. 'timestart' => userdate($try["timestart"]),
  873. 'duration' => format_time($timetotake),
  874. ];
  875. $attemptlinkcontents = get_string('attemptinfowithgrade', 'lesson', $attemptdata);
  876. } else {
  877. if ($try["end"]) {
  878. // User finished the lesson but has no grade. (Happens when there are only content pages).
  879. $timetotake = $try["timeend"] - $try["timestart"];
  880. $attemptdata = (object)[
  881. 'timestart' => userdate($try["timestart"]),
  882. 'duration' => format_time($timetotake),
  883. ];
  884. $attemptlinkcontents = get_string('attemptinfonograde', 'lesson', $attemptdata);
  885. } else {
  886. // This is what the link does/looks like when the user has not completed the attempt.
  887. if ($try['timestart'] !== 0) {
  888. // Teacher previews do not track time spent.
  889. $attemptlinkcontents = get_string("notcompletedwithdate", "lesson", userdate($try["timestart"]));
  890. } else {
  891. $attemptlinkcontents = get_string("notcompleted", "lesson");
  892. }
  893. $timetotake = null;
  894. }
  895. }
  896. $attempturl = new moodle_url('/mod/lesson/report.php', $attempturlparams);
  897. $attemptlink = html_writer::link($attempturl, $attemptlinkcontents, ['class' => 'lesson-attempt-link']);
  898. if ($caneditlesson) {
  899. $attemptid = 'attempt-' . $try['userid'] . '-' . $try['try'];
  900. $attemptname = 'attempts[' . $try['userid'] . '][' . $try['try'] . ']';
  901. $checkbox = new \core\output\checkbox_toggleall('lesson-attempts', false, [
  902. 'id' => $attemptid,
  903. 'name' => $attemptname,
  904. 'label' => $attemptlink
  905. ]);
  906. $attemptlink = $OUTPUT->render($checkbox);
  907. }
  908. // build up the attempts array
  909. $attempts[] = $attemptlink;
  910. // Run these lines for the stats only if the user finnished the lesson.
  911. if ($try["end"]) {
  912. // User has completed the lesson.
  913. $data->numofattempts++;
  914. $data->avetime += $timetotake;
  915. if ($timetotake > $data->hightime || $data->hightime == null) {
  916. $data->hightime = $timetotake;
  917. }
  918. if ($timetotake < $data->lowtime || $data->lowtime == null) {
  919. $data->lowtime = $timetotake;
  920. }
  921. if ($try["grade"] !== null) {
  922. // The lesson was scored.
  923. $data->avescore += $try["grade"];
  924. if ($try["grade"] > $data->highscore || $data->highscore === null) {
  925. $data->highscore = $try["grade"];
  926. }
  927. if ($try["grade"] < $data->lowscore || $data->lowscore === null) {
  928. $data->lowscore = $try["grade"];
  929. }
  930. }
  931. }
  932. }
  933. // get line breaks in after each attempt
  934. $attempts = implode("<br />\n", $attempts);
  935. $row = [$studentname];
  936. foreach ($extrafields as $field) {
  937. $row[] = $student->$field;
  938. }
  939. $row[] = $attempts;
  940. if ($data->lessonscored) {
  941. // Add the grade if the lesson is graded.
  942. $row[] = $bestgrade."%";
  943. }
  944. $table->data[] = $row;
  945. // Add the student data.
  946. $dataforstudent->id = $student->id;
  947. $dataforstudent->fullname = $studentname;
  948. $dataforstudent->bestgrade = $bestgrade;
  949. $data->students[] = $dataforstudent;
  950. }
  951. }
  952. $students->close();
  953. if ($data->numofattempts > 0) {
  954. $data->avescore = $data->avescore / $data->numofattempts;
  955. }
  956. return array($table, $data);
  957. }
  958. /**
  959. * Return information about one user attempt (including answers)
  960. * @param lesson $lesson lesson instance
  961. * @param int $userid the user id
  962. * @param int $attempt the attempt number
  963. * @return array the user answers (array) and user data stats (object)
  964. * @since Moodle 3.3
  965. */
  966. function lesson_get_user_detailed_report_data(lesson $lesson, $userid, $attempt) {
  967. global $DB;
  968. $context = $lesson->context;
  969. if (!empty($userid)) {
  970. // Apply overrides.
  971. $lesson->update_effective_access($userid);
  972. }
  973. $pageid = 0;
  974. $lessonpages = $lesson->load_all_pages();
  975. foreach ($lessonpages as $lessonpage) {
  976. if ($lessonpage->prevpageid == 0) {
  977. $pageid = $lessonpage->id;
  978. }
  979. }
  980. // now gather the stats into an object
  981. $firstpageid = $pageid;
  982. $pagestats = array();
  983. while ($pageid != 0) { // EOL
  984. $page = $lessonpages[$pageid];
  985. $params = array ("lessonid" => $lesson->id, "pageid" => $page->id);
  986. if ($allanswers = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND pageid = :pageid", $params, "timeseen")) {
  987. // get them ready for processing
  988. $orderedanswers = array();
  989. foreach ($allanswers as $singleanswer) {
  990. // ordering them like this, will help to find the single attempt record that we want to keep.
  991. $orderedanswers[$singleanswer->userid][$singleanswer->retry][] = $singleanswer;
  992. }
  993. // this is foreach user and for each try for that user, keep one attempt record
  994. foreach ($orderedanswers as $orderedanswer) {
  995. foreach($orderedanswer as $tries) {
  996. $page->stats($pagestats, $tries);
  997. }
  998. }
  999. } else {
  1000. // no one answered yet...
  1001. }
  1002. //unset($orderedanswers); initialized above now
  1003. $pageid = $page->nextpageid;
  1004. }
  1005. $manager = lesson_page_type_manager::get($lesson);
  1006. $qtypes = $manager->get_page_type_strings();
  1007. $answerpages = array();
  1008. $answerpage = "";
  1009. $pageid = $firstpageid;
  1010. // cycle through all the pages
  1011. // foreach page, add to the $answerpages[] array all the data that is needed
  1012. // from the question, the users attempt, and the statistics
  1013. // grayout pages that the user did not answer and Branch, end of branch, cluster
  1014. // and end of cluster pages
  1015. while ($pageid != 0) { // EOL
  1016. $page = $lessonpages[$pageid];
  1017. $answerpage = new stdClass;
  1018. // Keep the original page object.
  1019. $answerpage->page = $page;
  1020. $data ='';
  1021. $answerdata = new stdClass;
  1022. // Set some defaults for the answer data.
  1023. $answerdata->score = null;
  1024. $answerdata->response = null;
  1025. $answerdata->responseformat = FORMAT_PLAIN;
  1026. $answerpage->title = format_string($page->title);
  1027. $options = new stdClass;
  1028. $options->noclean = true;
  1029. $options->overflowdiv = true;
  1030. $options->context = $context;
  1031. $answerpage->contents = format_text($page->contents, $page->contentsformat, $options);
  1032. $answerpage->qtype = $qtypes[$page->qtype].$page->option_description_string();
  1033. $answerpage->grayout = $page->grayout;
  1034. $answerpage->context = $context;
  1035. if (empty($userid)) {
  1036. // there is no userid, so set these vars and display stats.
  1037. $answerpage->grayout = 0;
  1038. $useranswer = null;
  1039. } elseif ($useranswers = $DB->get_records("lesson_attempts",array("lessonid"=>$lesson->id, "userid"=>$userid, "retry"=>$attempt,"pageid"=>$page->id), "timeseen")) {
  1040. // get the user's answer for this page
  1041. // need to find the right one
  1042. $i = 0;
  1043. foreach ($useranswers as $userattempt) {
  1044. $useranswer = $userattempt;
  1045. $i++;
  1046. if ($lesson->maxattempts == $i) {
  1047. break; // reached maxattempts, break out
  1048. }
  1049. }
  1050. } else {
  1051. // user did not answer this page, gray it out and set some nulls
  1052. $answerpage->grayout = 1;
  1053. $useranswer = null;
  1054. }
  1055. $i = 0;
  1056. $n = 0;
  1057. $answerpages[] = $page->report_answers(clone($answerpage), clone($answerdata), $useranswer, $pagestats, $i, $n);
  1058. $pageid = $page->nextpageid;
  1059. }
  1060. $userstats = new stdClass;
  1061. if (!empty($userid)) {
  1062. $params = array("lessonid"=>$lesson->id, "userid"=>$userid);
  1063. $alreadycompleted = true;
  1064. if (!$grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid and userid = :userid", $params, "completed", "*", $attempt, 1)) {
  1065. $userstats->grade = -1;
  1066. $userstats->completed = -1;
  1067. $alreadycompleted = false;
  1068. } else {
  1069. $userstats->grade = current($grades);
  1070. $userstats->completed = $userstats->grade->completed;
  1071. $userstats->grade = round($userstats->grade->grade, 2);
  1072. }
  1073. if (!$times = $lesson->get_user_timers($userid, 'starttime', '*', $attempt, 1)) {
  1074. $userstats->timetotake = -1;
  1075. $alreadycompleted = false;
  1076. } else {
  1077. $userstats->timetotake = current($times);
  1078. $userstats->timetotake = $userstats->timetotake->lessontime - $userstats->timetotake->starttime;
  1079. }
  1080. if ($alreadycompleted) {
  1081. $userstats->gradeinfo = lesson_grade($lesson, $attempt, $userid);
  1082. }
  1083. }
  1084. return array($answerpages, $userstats);
  1085. }
  1086. /**
  1087. * Return user's deadline for all lessons in a course, hereby taking into account group and user overrides.
  1088. *
  1089. * @param int $courseid the course id.
  1090. * @return object An object with of all lessonsids and close unixdates in this course,
  1091. * taking into account the most lenient overrides, if existing and 0 if no close date is set.
  1092. */
  1093. function lesson_get_user_deadline($courseid) {
  1094. global $DB, $USER;
  1095. // For teacher and manager/admins return lesson's deadline.
  1096. if (has_capability('moodle/course:update', context_course::instance($courseid))) {
  1097. $sql = "SELECT lesson.id, lesson.deadline AS userdeadline
  1098. FROM {lesson} lesson
  1099. WHERE lesson.course = :courseid";
  1100. $results = $DB->get_records_sql($sql, array('courseid' => $courseid));
  1101. return $results;
  1102. }
  1103. $sql = "SELECT a.id,
  1104. COALESCE(v.userclose, v.groupclose, a.deadline, 0) AS userdeadline
  1105. FROM (
  1106. SELECT lesson.id as lessonid,
  1107. MAX(leo.deadline) AS userclose, MAX(qgo.deadline) AS groupclose
  1108. FROM {lesson} lesson
  1109. LEFT JOIN {lesson_overrides} leo on lesson.id = leo.lessonid AND leo.userid = :userid
  1110. LEFT JOIN {groups_members} gm ON gm.userid = :useringroupid
  1111. LEFT JOIN {lesson_overrides} qgo on lesson.id = qgo.lessonid AND qgo.groupid = gm.groupid
  1112. WHERE lesson.course = :courseid
  1113. GROUP BY lesson.id
  1114. ) v
  1115. JOIN {lesson} a ON a.id = v.lessonid";
  1116. $results = $DB->get_records_sql($sql, array('userid' => $USER->id, 'useringroupid' => $USER->id, 'courseid' => $courseid));
  1117. return $results;
  1118. }
  1119. /**
  1120. * Abstract class that page type's MUST inherit from.
  1121. *
  1122. * This is the abstract class that ALL add page type forms must extend.
  1123. * You will notice that all but two of the methods this class contains are final.
  1124. * Essentially the only thing that extending classes can do is extend custom_definition.
  1125. * OR if it has a special requirement on creation it can extend construction_override
  1126. *
  1127. * @abstract
  1128. * @copyright 2009 Sam Hemelryk
  1129. * @license …

Large files files are truncated, but you can click here to view the full file