Exemple #1
0
 public function create_content($lesson, $record = array())
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/lesson/locallib.php';
     $now = time();
     $this->pagecount++;
     $record = (array) $record + array('lessonid' => $lesson->id, 'title' => 'Lesson page ' . $this->pagecount, 'timecreated' => $now, 'qtype' => 20, 'pageid' => 0);
     if (!isset($record['contents_editor'])) {
         $record['contents_editor'] = array('text' => 'Contents of lesson page ' . $this->pagecount, 'format' => FORMAT_MOODLE, 'itemid' => 0);
     }
     $context = context_module::instance($lesson->cmid);
     $page = lesson_page::create((object) $record, new lesson($lesson), $context, $CFG->maxbytes);
     return $DB->get_record('lesson_pages', array('id' => $page->id), '*', MUST_EXIST);
 }
Exemple #2
0
    $data = new stdClass();
    $data->id = $cm->id;
    $data->pageid = $pageid;
    if ($qtype) {
        //TODO: the handling of form for the selection of question type is a bloody hack! (skodak)
        $data->qtype = $qtype;
    }
    $data = file_prepare_standard_editor($data, 'contents', $editoroptions, null);
    $mform->set_data($data);
    $PAGE->navbar->add(get_string('addanewpage', 'lesson'), $PAGE->url);
    if ($qtype !== 'unknown') {
        $PAGE->navbar->add(get_string($mform->qtypestring, 'lesson'));
    }
}
if ($data = $mform->get_data()) {
    require_sesskey();
    if ($edit) {
        $data->lessonid = $data->id;
        $data->id = $data->pageid;
        unset($data->pageid);
        unset($data->edit);
        $editpage->update($data, $context, $PAGE->course->maxbytes);
    } else {
        $editpage = lesson_page::create($data, $lesson, $context, $PAGE->course->maxbytes);
    }
    redirect($returnto);
}
$lessonoutput = $PAGE->get_renderer('mod_lesson');
echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('edit', 'lesson'));
$mform->display();
echo $lessonoutput->footer();
Exemple #3
0
 /**
  * Create shortanswer question pages.
  * @param object $lesson
  * @param array $record
  * @return int
  */
 public function create_question_numeric($lesson, $record = array())
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/mod/lesson/locallib.php';
     $now = time();
     $this->pagecount++;
     $record = (array) $record + array('lessonid' => $lesson->id, 'title' => 'Lesson numerical question ' . $this->pagecount, 'timecreated' => $now, 'qtype' => 8, 'pageid' => 0);
     if (!isset($record['contents_editor'])) {
         $record['contents_editor'] = array('text' => 'Numerical question ' . $this->pagecount, 'format' => FORMAT_HTML, 'itemid' => 0);
     }
     // First Answer (correct).
     if (!isset($record['answer_editor'][0])) {
         $record['answer_editor'][0] = array('text' => $this->pagecount, 'format' => FORMAT_MOODLE);
     }
     if (!isset($record['jumpto'][0])) {
         $record['jumpto'][0] = LESSON_NEXTPAGE;
     }
     $context = context_module::instance($lesson->cmid);
     $page = lesson_page::create((object) $record, new lesson($lesson), $context, $CFG->maxbytes);
     return $DB->get_record('lesson_pages', array('id' => $page->id), '*', MUST_EXIST);
 }
Exemple #4
0
 /**
  * Duplicate the lesson page.
  *
  * @param  int $pageid Page ID of the page to duplicate.
  * @return void.
  */
 public function duplicate_page($pageid)
 {
     global $PAGE;
     $cm = get_coursemodule_from_instance('lesson', $this->properties->id, $this->properties->course);
     $context = context_module::instance($cm->id);
     // Load the page.
     $page = $this->load_page($pageid);
     $properties = $page->properties();
     // The create method checks to see if these properties are set and if not sets them to zero, hence the unsetting here.
     if (!$properties->qoption) {
         unset($properties->qoption);
     }
     if (!$properties->layout) {
         unset($properties->layout);
     }
     if (!$properties->display) {
         unset($properties->display);
     }
     $properties->pageid = $pageid;
     // Add text and format into the format required to create a new page.
     $properties->contents_editor = array('text' => $properties->contents, 'format' => $properties->contentsformat);
     $answers = $page->get_answers();
     // Answers need to be added to $properties.
     $i = 0;
     $answerids = array();
     foreach ($answers as $answer) {
         // Needs to be rearranged to work with the create function.
         $properties->answer_editor[$i] = array('text' => $answer->answer, 'format' => $answer->answerformat);
         $properties->response_editor[$i] = array('text' => $answer->response, 'format' => $answer->responseformat);
         $answerids[] = $answer->id;
         $properties->jumpto[$i] = $answer->jumpto;
         $properties->score[$i] = $answer->score;
         $i++;
     }
     // Create the duplicate page.
     $newlessonpage = lesson_page::create($properties, $this, $context, $PAGE->course->maxbytes);
     $newanswers = $newlessonpage->get_answers();
     // Copy over the file areas as well.
     $this->copy_page_files('page_contents', $pageid, $newlessonpage->id, $context->id);
     $j = 0;
     foreach ($newanswers as $answer) {
         if (isset($answer->answer) && strpos($answer->answer, '@@PLUGINFILE@@') !== false) {
             $this->copy_page_files('page_answers', $answerids[$j], $answer->id, $context->id);
         }
         if (isset($answer->response) && !is_array($answer->response) && strpos($answer->response, '@@PLUGINFILE@@') !== false) {
             $this->copy_page_files('page_responses', $answerids[$j], $answer->id, $context->id);
         }
         $j++;
     }
 }