本文整理汇总了PHP中lesson_page类的典型用法代码示例。如果您正苦于以下问题:PHP lesson_page类的具体用法?PHP lesson_page怎么用?PHP lesson_page使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了lesson_page类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: display_page
/**
* Returns HTML to display a page to the user
* @param lesson $lesson
* @param lesson_page $page
* @param object $attempt
* @return string
*/
public function display_page(lesson $lesson, lesson_page $page, $attempt)
{
// We need to buffer here as there is an mforms display call
ob_start();
echo $page->display($this, $attempt);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
示例5: create
/**
* Given an object of properties and a page created answer(s) and saves them
* in the database.
*
* @param stdClass $properties
* @param lesson_page $page
* @return array
*/
public static function create($properties, lesson_page $page)
{
return $page->create_answers($properties);
}
示例6: create_from_lesson_page
/**
* Create instance of event.
*
* @param \lesson_page $lessonpage
* @param \context_module $context
* @return page_updated
*/
public static function create_from_lesson_page(\lesson_page $lessonpage, \context_module $context)
{
$data = array('context' => $context, 'objectid' => $lessonpage->properties()->id, 'other' => array('pagetype' => $lessonpage->get_typestring()));
return self::create($data);
}
示例7: check_answer
public function check_answer()
{
global $DB, $CFG;
$formattextdefoptions = new stdClass();
$formattextdefoptions->noclean = true;
$formattextdefoptions->para = false;
$answers = $this->get_answers();
shuffle($answers);
$params = array('answers' => $answers, 'lessonid' => $this->lesson->id, 'contents' => $this->get_contents());
$mform = new lesson_display_answer_form_truefalse($CFG->wwwroot . '/mod/lesson/continue.php', $params);
$data = $mform->get_data();
require_sesskey();
$result = parent::check_answer();
if (empty($data->answerid)) {
$result->noanswer = true;
return $result;
}
$result->answerid = $data->answerid;
$answer = $DB->get_record("lesson_answers", array("id" => $result->answerid), '*', MUST_EXIST);
if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
$result->correctanswer = true;
}
if ($this->lesson->custom) {
if ($answer->score > 0) {
$result->correctanswer = true;
} else {
$result->correctanswer = false;
}
}
$result->newpageid = $answer->jumpto;
$result->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
$result->studentanswer = $result->userresponse = $answer->answer;
return $result;
}
示例8: check_answer
public function check_answer()
{
global $PAGE, $CFG;
$result = parent::check_answer();
$result->isessayquestion = true;
$mform = new lesson_display_answer_form_essay($CFG->wwwroot . '/mod/lesson/continue.php', array('contents' => $this->get_contents()));
$data = $mform->get_data();
require_sesskey();
if (!$data) {
redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
}
$studentanswer = $data->answer['text'];
if (trim($studentanswer) === '') {
$result->noanswer = true;
return $result;
}
$answers = $this->get_answers();
foreach ($answers as $answer) {
$result->answerid = $answer->id;
$result->newpageid = $answer->jumpto;
}
$userresponse = new stdClass();
$userresponse->sent = 0;
$userresponse->graded = 0;
$userresponse->score = 0;
$userresponse->answer = $studentanswer;
$userresponse->response = "";
$result->userresponse = serialize($userresponse);
$result->studentanswer = s($studentanswer);
return $result;
}
示例9: check_answer
public function check_answer() {
global $CFG;
$result = parent::check_answer();
$mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents()));
$data = $mform->get_data();
require_sesskey();
// set defaults
$result->response = '';
$result->newpageid = 0;
if (isset($data->answer)) {
// just doing default PARAM_RAW, not doing PARAM_INT because it could be a float
$result->useranswer = (float)$data->answer;
} else {
$result->noanswer = true;
return $result;
}
$result->studentanswer = $result->userresponse = $result->useranswer;
$answers = $this->get_answers();
foreach ($answers as $answer) {
if (strpos($answer->answer, ':')) {
// there's a pairs of values
list($min, $max) = explode(':', $answer->answer);
$minimum = (float) $min;
$maximum = (float) $max;
} else {
// there's only one value
$minimum = (float) $answer->answer;
$maximum = $minimum;
}
if (($result->useranswer >= $minimum) && ($result->useranswer <= $maximum)) {
$result->newpageid = $answer->jumpto;
$result->response = trim($answer->response);
if ($this->lesson->jumpto_is_correct($this->properties->id, $result->newpageid)) {
$result->correctanswer = true;
}
if ($this->lesson->custom) {
if ($answer->score > 0) {
$result->correctanswer = true;
} else {
$result->correctanswer = false;
}
}
$result->answerid = $answer->id;
return $result;
}
}
return $result;
}
示例10: report_answers
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n)
{
global $PAGE;
$answers = $this->get_answers();
$formattextdefoptions = new stdClass();
$formattextdefoptions->para = false;
//I'll use it widely in this page
foreach ($answers as $answer) {
$answer = parent::rewrite_answers_urls($answer, false);
if ($useranswer == null && $i == 0) {
// I have the $i == 0 because it is easier to blast through it all at once.
if (isset($pagestats[$this->properties->id])) {
$stats = $pagestats[$this->properties->id];
$total = $stats["total"];
unset($stats["total"]);
foreach ($stats as $valentered => $ntimes) {
$data = '<input type="text" size="50" disabled="disabled" readonly="readonly" value="' . s($valentered) . '" />';
$percent = $ntimes / $total * 100;
$percent = round($percent, 2);
$percent .= "% " . get_string("enteredthis", "lesson");
$answerdata->answers[] = array($data, $percent);
}
} else {
$answerdata->answers[] = array(get_string("nooneansweredthisquestion", "lesson"), " ");
}
$i++;
} else {
if ($useranswer != null && ($answer->id == $useranswer->answerid || $answer == end($answers))) {
// get in here when what the user entered is not one of the answers
$data = '<input type="text" size="50" disabled="disabled" readonly="readonly" value="' . s($useranswer->useranswer) . '">';
if (isset($pagestats[$this->properties->id][$useranswer->useranswer])) {
$percent = $pagestats[$this->properties->id][$useranswer->useranswer] / $pagestats[$this->properties->id]["total"] * 100;
$percent = round($percent, 2);
$percent .= "% " . get_string("enteredthis", "lesson");
} else {
$percent = get_string("nooneenteredthis", "lesson");
}
$answerdata->answers[] = array($data, $percent);
if ($answer->id == $useranswer->answerid) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
$answerdata->response = get_string("thatsthewronganswer", "lesson");
}
} else {
$answerdata->response = $answer->response;
}
if ($this->lesson->custom) {
$answerdata->score = get_string("pointsearned", "lesson") . ": " . $answer->score;
} elseif ($useranswer->correct) {
$answerdata->score = get_string("receivedcredit", "lesson");
} else {
$answerdata->score = get_string("didnotreceivecredit", "lesson");
}
// We have found the correct answer, do not process any more answers.
$answerpage->answerdata = $answerdata;
break;
} else {
$answerdata->response = get_string("thatsthewronganswer", "lesson");
if ($this->lesson->custom) {
$answerdata->score = get_string("pointsearned", "lesson") . ": 0";
} else {
$answerdata->score = get_string("didnotreceivecredit", "lesson");
}
}
}
}
$answerpage->answerdata = $answerdata;
}
return $answerpage;
}
示例11: display_answers
public function display_answers(html_table $table)
{
$answers = $this->get_answers();
$options = new stdClass();
$options->noclean = true;
$options->para = false;
$i = 1;
$n = 0;
foreach ($answers as $answer) {
$answer = parent::rewrite_answers_urls($answer);
if ($n < 2) {
if ($answer->answer != null) {
$cells = array();
if ($n == 0) {
$cells[] = "<span class=\"label\">" . get_string("correctresponse", "lesson") . '</span>';
} else {
$cells[] = "<span class=\"label\">" . get_string("wrongresponse", "lesson") . '</span>';
}
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
$table->data[] = new html_table_row($cells);
}
if ($n == 0) {
$cells = array();
$cells[] = '<span class="label">' . get_string("correctanswerscore", "lesson") . "</span>: ";
$cells[] = $answer->score;
$table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = '<span class="label">' . get_string("correctanswerjump", "lesson") . "</span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
$table->data[] = new html_table_row($cells);
} elseif ($n == 1) {
$cells = array();
$cells[] = '<span class="label">' . get_string("wronganswerscore", "lesson") . "</span>: ";
$cells[] = $answer->score;
$table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = '<span class="label">' . get_string("wronganswerjump", "lesson") . "</span>: ";
$cells[] = $this->get_jump_name($answer->jumpto);
$table->data[] = new html_table_row($cells);
}
if ($n === 0) {
$table->data[count($table->data) - 1]->cells[0]->style = 'width:20%;';
}
$n++;
$i--;
} else {
$cells = array();
if ($this->lesson->custom && $answer->score > 0) {
// if the score is > 0, then it is correct
$cells[] = '<span class="labelcorrect">' . get_string("answer", "lesson") . " {$i}</span>: \n";
} else {
if ($this->lesson->custom) {
$cells[] = '<span class="label">' . get_string("answer", "lesson") . " {$i}</span>: \n";
} else {
if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) {
$cells[] = '<span class="labelcorrect">' . get_string("answer", "lesson") . " {$i}</span>: \n";
} else {
$cells[] = '<span class="label">' . get_string("answer", "lesson") . " {$i}</span>: \n";
}
}
}
$cells[] = format_text($answer->answer, $answer->answerformat, $options);
$table->data[] = new html_table_row($cells);
$cells = array();
$cells[] = '<span class="label">' . get_string("matchesanswer", "lesson") . " {$i}</span>: ";
$cells[] = format_text($answer->response, $answer->responseformat, $options);
$table->data[] = new html_table_row($cells);
}
$i++;
}
return $table;
}
示例12: option_description_string
public function option_description_string()
{
if ($this->properties->qoption) {
return " - " . get_string("multianswer", "lesson");
}
return parent::option_description_string();
}
示例13: report_answers
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n)
{
$answers = $this->get_answers();
$formattextdefoptions = new stdClass();
//I'll use it widely in this page
$formattextdefoptions->para = false;
$formattextdefoptions->noclean = true;
$formattextdefoptions->context = $answerpage->context;
foreach ($answers as $answer) {
$answer = parent::rewrite_answers_urls($answer);
if ($this->properties->qoption) {
if ($useranswer == null) {
$userresponse = array();
} else {
$userresponse = explode(",", $useranswer->useranswer);
}
if (in_array($answer->id, $userresponse)) {
// make checked
$data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[{$i}]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
if (!isset($answerdata->response)) {
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
$answerdata->response = get_string("thatsthewronganswer", "lesson");
}
} else {
$answerdata->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
}
}
if (!isset($answerdata->score)) {
if ($this->lesson->custom) {
$answerdata->score = get_string("pointsearned", "lesson") . ": " . $answer->score;
} elseif ($useranswer->correct) {
$answerdata->score = get_string("receivedcredit", "lesson");
} else {
$answerdata->score = get_string("didnotreceivecredit", "lesson");
}
}
} else {
// unchecked
$data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[{$i}]\" value=\"0\" disabled=\"disabled\" />";
}
if ($answer->score > 0 && $this->lesson->custom || $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom) {
$data .= "<div class=highlight>" . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . "</div>";
} else {
$data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
}
} else {
if ($useranswer != null and $answer->id == $useranswer->answerid) {
// make checked
$data = "<input readonly=\"readonly\" disabled=\"disabled\" name=\"answer[{$i}]\" checked=\"checked\" type=\"checkbox\" value=\"1\" />";
if ($answer->response == null) {
if ($useranswer->correct) {
$answerdata->response = get_string("thatsthecorrectanswer", "lesson");
} else {
$answerdata->response = get_string("thatsthewronganswer", "lesson");
}
} else {
$answerdata->response = format_text($answer->response, $answer->responseformat, $formattextdefoptions);
}
if ($this->lesson->custom) {
$answerdata->score = get_string("pointsearned", "lesson") . ": " . $answer->score;
} elseif ($useranswer->correct) {
$answerdata->score = get_string("receivedcredit", "lesson");
} else {
$answerdata->score = get_string("didnotreceivecredit", "lesson");
}
} else {
// unchecked
$data = "<input type=\"checkbox\" readonly=\"readonly\" name=\"answer[{$i}]\" value=\"0\" disabled=\"disabled\" />";
}
if ($answer->score > 0 && $this->lesson->custom || $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto) && !$this->lesson->custom) {
$data .= "<div class=\"highlight\">" . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . "</div>";
} else {
$data .= format_text($answer->answer, $answer->answerformat, $formattextdefoptions);
}
}
if (isset($pagestats[$this->properties->id][$answer->id])) {
$percent = $pagestats[$this->properties->id][$answer->id] / $pagestats[$this->properties->id]["total"] * 100;
$percent = round($percent, 2);
$percent .= "% " . get_string("checkedthisone", "lesson");
} else {
$percent = get_string("noonecheckedthis", "lesson");
}
$answerdata->answers[] = array($data, $percent);
$answerpage->answerdata = $answerdata;
}
return $answerpage;
}
示例14: check_answer
public function check_answer()
{
global $CFG, $PAGE;
$formattextdefoptions = new stdClass();
$formattextdefoptions->noclean = true;
$formattextdefoptions->para = false;
$result = parent::check_answer();
$mform = $this->make_answer_form();
$data = $mform->get_data();
require_sesskey();
if (!$data) {
redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
}
$response = $data->response;
$getanswers = $this->get_answers();
$correct = array_shift($getanswers);
$wrong = array_shift($getanswers);
$answers = array();
foreach ($getanswers as $key => $answer) {
if ($answer->answer !== '' or $answer->response !== '') {
$answers[$answer->id] = $answer;
}
}
// get the user's exact responses for record keeping
$hits = 0;
$userresponse = array();
foreach ($response as $id => $value) {
if ($value == '') {
$result->noanswer = true;
return $result;
}
$value = htmlspecialchars_decode($value);
$userresponse[] = $value;
// Make sure the user's answer exists in question's answer
if (array_key_exists($id, $answers)) {
$answer = $answers[$id];
$result->studentanswer .= '<br />' . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . ' = ' . $value;
if (trim($answer->response) == trim($value)) {
$hits++;
}
}
}
$result->userresponse = implode(",", $userresponse);
if ($hits == count($answers)) {
$result->correctanswer = true;
$result->response = format_text($correct->answer, $correct->answerformat, $formattextdefoptions);
$result->answerid = $correct->id;
$result->newpageid = $correct->jumpto;
} else {
$result->correctanswer = false;
$result->response = format_text($wrong->answer, $wrong->answerformat, $formattextdefoptions);
$result->answerid = $wrong->id;
$result->newpageid = $wrong->jumpto;
}
return $result;
}
示例15: check_answer
public function check_answer()
{
global $CFG, $PAGE;
$formattextdefoptions = new stdClass();
$formattextdefoptions->noclean = true;
$formattextdefoptions->para = false;
$result = parent::check_answer();
$mform = $this->make_answer_form();
$data = $mform->get_data();
require_sesskey();
if (!$data) {
redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $this->properties->id)));
}
$response = $data->response;
if (!is_array($response)) {
$result->noanswer = true;
return $result;
}
$answers = $this->get_answers();
$correct = array_shift($answers);
$wrong = array_shift($answers);
foreach ($answers as $key => $answer) {
if ($answer->answer === '' or $answer->response === '') {
// incomplete option!
unset($answers[$key]);
}
}
// get he users exact responses for record keeping
$hits = 0;
$userresponse = array();
foreach ($response as $key => $value) {
foreach ($answers as $answer) {
if ($value === $answer->response) {
$userresponse[] = $answer->id;
}
if ((int) $answer->id === (int) $key) {
$result->studentanswer .= '<br />' . format_text($answer->answer, $answer->answerformat, $formattextdefoptions) . ' = ' . $value;
}
if ((int) $answer->id === (int) $key and $value === $answer->response) {
$hits++;
}
}
}
$result->userresponse = implode(",", $userresponse);
if ($hits == count($answers)) {
$result->correctanswer = true;
$result->response = format_text($correct->answer, $correct->answerformat, $formattextdefoptions);
$result->answerid = $correct->id;
$result->newpageid = $correct->jumpto;
} else {
$result->correctanswer = false;
$result->response = format_text($wrong->answer, $wrong->answerformat, $formattextdefoptions);
$result->answerid = $wrong->id;
$result->newpageid = $wrong->jumpto;
}
return $result;
}