本文整理汇总了PHP中lesson_page::create方法的典型用法代码示例。如果您正苦于以下问题:PHP lesson_page::create方法的具体用法?PHP lesson_page::create怎么用?PHP lesson_page::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lesson_page
的用法示例。
在下文中一共展示了lesson_page::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_content
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);
}
示例2: stdClass
$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();
示例3: create_question_numeric
/**
* 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);
}
示例4: duplicate_page
/**
* 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++;
}
}