/** * Deletes a lesson_page from the database as well as any associated records. * @final * @return bool */ public final function delete() { global $DB; // first delete all the associated records... $DB->delete_records("lesson_attempts", array("pageid" => $this->properties->id)); // ...now delete the answers... $DB->delete_records("lesson_answers", array("pageid" => $this->properties->id)); // ..and the page itself $DB->delete_records("lesson_pages", array("id" => $this->properties->id)); // Delete files associated with this page. $cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course); $context = context_module::instance($cm->id); $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_lesson', 'page_contents', $this->properties->id); $fs->delete_area_files($context->id, 'mod_lesson', 'page_answers', $this->properties->id); $fs->delete_area_files($context->id, 'mod_lesson', 'page_responses', $this->properties->id); // repair the hole in the linkage if (!$this->properties->prevpageid && !$this->properties->nextpageid) { //This is the only page, no repair needed } elseif (!$this->properties->prevpageid) { // this is the first page... $page = $this->lesson->load_page($this->properties->nextpageid); $page->move(null, 0); } elseif (!$this->properties->nextpageid) { // this is the last page... $page = $this->lesson->load_page($this->properties->prevpageid); $page->move(0); } else { // page is in the middle... $prevpage = $this->lesson->load_page($this->properties->prevpageid); $nextpage = $this->lesson->load_page($this->properties->nextpageid); $prevpage->move($nextpage->id); $nextpage->move(null, $prevpage->id); } return true; }
/** * Deletes a lesson_page from the database as well as any associated records. * @final * @return bool */ final public function delete() { global $DB; // first delete all the associated records... $DB->delete_records("lesson_attempts", array("pageid" => $this->properties->id)); // ...now delete the answers... $DB->delete_records("lesson_answers", array("pageid" => $this->properties->id)); // ..and the page itself $DB->delete_records("lesson_pages", array("id" => $this->properties->id)); // repair the hole in the linkage if (!$this->properties->prevpageid && !$this->properties->nextpageid) { //This is the only page, no repair needed } elseif (!$this->properties->prevpageid) { // this is the first page... $page = $this->lesson->load_page($this->properties->nextpageid); $page->move(null, 0); } elseif (!$this->properties->nextpageid) { // this is the last page... $page = $this->lesson->load_page($this->properties->prevpageid); $page->move(0); } else { // page is in the middle... $prevpage = $this->lesson->load_page($this->properties->prevpageid); $nextpage = $this->lesson->load_page($this->properties->nextpageid); $prevpage->move($nextpage->id); $nextpage->move(null, $prevpage->id); } return true; }
/** * Deletes a lesson_page from the database as well as any associated records. * @final * @return bool */ public final function delete() { global $DB; $cm = get_coursemodule_from_instance('lesson', $this->lesson->id, $this->lesson->course); $context = context_module::instance($cm->id); // Delete files associated with attempts. $fs = get_file_storage(); if ($attempts = $DB->get_records('lesson_attempts', array("pageid" => $this->properties->id))) { foreach ($attempts as $attempt) { $fs->delete_area_files($context->id, 'mod_lesson', 'essay_responses', $attempt->id); } } // Then delete all the associated records... $DB->delete_records("lesson_attempts", array("pageid" => $this->properties->id)); $DB->delete_records("lesson_branch", array("pageid" => $this->properties->id)); // ...now delete the answers... $DB->delete_records("lesson_answers", array("pageid" => $this->properties->id)); // ..and the page itself $DB->delete_records("lesson_pages", array("id" => $this->properties->id)); // Trigger an event: page deleted. $eventparams = array('context' => $context, 'objectid' => $this->properties->id, 'other' => array('pagetype' => $this->get_typestring())); $event = \mod_lesson\event\page_deleted::create($eventparams); $event->add_record_snapshot('lesson_pages', $this->properties); $event->trigger(); // Delete files associated with this page. $fs->delete_area_files($context->id, 'mod_lesson', 'page_contents', $this->properties->id); $fs->delete_area_files($context->id, 'mod_lesson', 'page_answers', $this->properties->id); $fs->delete_area_files($context->id, 'mod_lesson', 'page_responses', $this->properties->id); // repair the hole in the linkage if (!$this->properties->prevpageid && !$this->properties->nextpageid) { //This is the only page, no repair needed } elseif (!$this->properties->prevpageid) { // this is the first page... $page = $this->lesson->load_page($this->properties->nextpageid); $page->move(null, 0); } elseif (!$this->properties->nextpageid) { // this is the last page... $page = $this->lesson->load_page($this->properties->prevpageid); $page->move(0); } else { // page is in the middle... $prevpage = $this->lesson->load_page($this->properties->prevpageid); $nextpage = $this->lesson->load_page($this->properties->nextpageid); $prevpage->move($nextpage->id); $nextpage->move(null, $prevpage->id); } return true; }
$url = new moodle_url('/mod/lesson/lesson.php', array('id'=>$id,'action'=>$action)); $PAGE->set_url($url); $context = context_module::instance($cm->id); require_capability('mod/lesson:edit', $context); require_sesskey(); $lessonoutput = $PAGE->get_renderer('mod_lesson'); /// Process the action switch ($action) { case 'confirmdelete': $PAGE->navbar->add(get_string($action, 'lesson')); $thispage = $lesson->load_page($pageid); echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('deletingpage', 'lesson', format_string($thispage->title))); echo $OUTPUT->heading(get_string("deletingpage", "lesson", format_string($thispage->title))); // print the jumps to this page $params = array("lessonid" => $lesson->id, "pageid" => $pageid); if ($answers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid AND jumpto = :pageid + 1", $params)) { echo $OUTPUT->heading(get_string("thefollowingpagesjumptothispage", "lesson")); echo "<p align=\"center\">\n"; foreach ($answers as $answer) { if (!$title = $DB->get_field("lesson_pages", "title", array("id" => $answer->pageid))) { print_error('cannotfindpagetitle', 'lesson'); } echo $title."<br />\n"; } }
$url->param('mode', $mode); } $PAGE->set_url($url); /// Handle any preprocessing before header is printed - based on $mode switch ($mode) { case 'grade': // Grading form - get the necessary data require_sesskey(); $attemptid = required_param('attemptid', PARAM_INT); if (!$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid))) { print_error('cannotfindattempt', 'lesson'); } $page = $lesson->load_page($attempt->pageid); if (!$user = $DB->get_record('user', array('id' => $attempt->userid))) { print_error('cannotfinduser', 'lesson'); } if (!$answer = $DB->get_record('lesson_answers', array('lessonid' => $lesson->id, 'pageid' => $page->id))) { print_error('cannotfindanswer', 'lesson'); } break; case 'update': require_sesskey(); $mform = new essay_grading_form(); if ($form = $mform->get_data()) { if (optional_param('cancel', false, PARAM_RAW)) { redirect("$CFG->wwwroot/mod/lesson/essay.php?id=$cm->id");