Exemple #1
0
 /**
  * Creates a new lesson_page within the database and returns the correct pagetype
  * object to use to interact with the new lesson
  *
  * @final
  * @static
  * @param object $properties
  * @param lesson $lesson
  * @return lesson_page Specialised object that extends lesson_page
  */
 public static final function create($properties, lesson $lesson, $context, $maxbytes)
 {
     global $DB;
     $newpage = new stdClass();
     $newpage->title = $properties->title;
     $newpage->contents = $properties->contents_editor['text'];
     $newpage->contentsformat = $properties->contents_editor['format'];
     $newpage->lessonid = $lesson->id;
     $newpage->timecreated = time();
     $newpage->qtype = $properties->qtype;
     $newpage->qoption = isset($properties->qoption) ? 1 : 0;
     $newpage->layout = isset($properties->layout) ? 1 : 0;
     $newpage->display = isset($properties->display) ? 1 : 0;
     $newpage->prevpageid = 0;
     // this is a first page
     $newpage->nextpageid = 0;
     // this is the only page
     if ($properties->pageid) {
         $prevpage = $DB->get_record("lesson_pages", array("id" => $properties->pageid), 'id, nextpageid');
         if (!$prevpage) {
             print_error('cannotfindpages', 'lesson');
         }
         $newpage->prevpageid = $prevpage->id;
         $newpage->nextpageid = $prevpage->nextpageid;
     } else {
         $nextpage = $DB->get_record('lesson_pages', array('lessonid' => $lesson->id, 'prevpageid' => 0), 'id');
         if ($nextpage) {
             // This is the first page, there are existing pages put this at the start
             $newpage->nextpageid = $nextpage->id;
         }
     }
     $newpage->id = $DB->insert_record("lesson_pages", $newpage);
     $editor = new stdClass();
     $editor->id = $newpage->id;
     $editor->contents_editor = $properties->contents_editor;
     $editor = file_postupdate_standard_editor($editor, 'contents', array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $maxbytes), $context, 'mod_lesson', 'page_contents', $editor->id);
     $DB->update_record("lesson_pages", $editor);
     if ($newpage->prevpageid > 0) {
         $DB->set_field("lesson_pages", "nextpageid", $newpage->id, array("id" => $newpage->prevpageid));
     }
     if ($newpage->nextpageid > 0) {
         $DB->set_field("lesson_pages", "prevpageid", $newpage->id, array("id" => $newpage->nextpageid));
     }
     $page = lesson_page::load($newpage, $lesson);
     $page->create_answers($properties);
     $lesson->add_message(get_string('insertedpage', 'lesson') . ': ' . format_string($newpage->title, true), 'notifysuccess');
     return $page;
 }
Exemple #2
0
$edit = optional_param('edit', false, PARAM_BOOL);
$returnto = optional_param('returnto', null, PARAM_URL);
if (empty($returnto)) {
    $returnto = new moodle_url('/mod/lesson/edit.php', array('id' => $id));
    $returnto->set_anchor('lesson-' . $pageid);
}
$cm = get_coursemodule_from_id('lesson', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$lesson = new lesson($DB->get_record('lesson', array('id' => $cm->instance), '*', MUST_EXIST));
require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/lesson:edit', $context);
$PAGE->set_url('/mod/lesson/editpage.php', array('pageid' => $pageid, 'id' => $id, 'qtype' => $qtype));
$PAGE->set_pagelayout('admin');
if ($edit) {
    $editpage = lesson_page::load($pageid, $lesson);
    $qtype = $editpage->qtype;
    $edit = true;
} else {
    $edit = false;
}
$jumpto = lesson_page::get_jumptooptions($pageid, $lesson);
$manager = lesson_page_type_manager::get($lesson);
$editoroptions = array('noclean' => true, 'maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes);
// If the previous page was the Question type selection form, this form
// will have a different name (e.g. _qf__lesson_add_page_form_selection
// versus _qf__lesson_add_page_form_multichoice). This causes confusion
// in moodleform::_process_submission because the array key check doesn't
// tie up with the current form name, which in turn means the "submitted"
// check ends up evaluating as false, thus it's not possible to check whether
// the Question type selection was cancelled. For this reason, a dummy form