';
$content .= $lesson->time_remaining($timer->starttime);
$content .= '
';
$clocksettings = array('starttime' => $timer->starttime, 'servertime' => time(), 'testlength' => $lesson->timelimit);
$page->requires->data_for_js('clocksettings', $clocksettings, true);
$page->requires->strings_for_js(array('timeisup'), 'lesson');
$page->requires->js('/mod/lesson/timer.js');
$page->requires->js_init_call('show_clock');
$bc = new block_contents();
$bc->title = get_string('timeremaining', 'lesson');
$bc->attributes['class'] = 'clock block';
$bc->content = $content;
return $bc;
}
/**
* If left menu is turned on, then this will
* print the menu in a block
*
* @param int $cmid Course Module ID for this lesson
* @param lesson $lesson Full lesson record object
* @return void
**/
function lesson_menu_block_contents($cmid, $lesson) {
global $CFG, $DB;
if (!$lesson->displayleft) {
return null;
}
$pages = $lesson->load_all_pages();
foreach ($pages as $page) {
if ((int)$page->prevpageid === 0) {
$pageid = $page->id;
break;
}
}
$currentpageid = optional_param('pageid', $pageid, PARAM_INT);
if (!$pageid || !$pages) {
return null;
}
$content = ''
. get_string("youranswer", "lesson").' :
';
// Create a table containing the answers and responses.
$table = new html_table();
// Multianswer allowed.
if ($this->properties->qoption) {
$studentanswerarray = explode(self::MULTIANSWER_DELIMITER, $result->studentanswer);
$responsearr = explode(self::MULTIANSWER_DELIMITER, $result->response);
$studentanswerresponse = array_combine($studentanswerarray, $responsearr);
foreach ($studentanswerresponse as $answer => $response) {
// Add a table row containing the answer.
$studentanswer = $this->format_answer($answer, $context, $result->studentanswerformat, $options);
$table->data[] = array($studentanswer);
// If the response exists, add a table row containing the response. If not, add en empty row.
if (!empty(trim($response))) {
$studentresponse = isset($result->responseformat) ?
$this->format_response($response, $context, $result->responseformat, $options) : $response;
$studentresponsecontent = html_writer::div('' . get_string("response", "lesson") .
':
' . $studentresponse, $class);
$table->data[] = array($studentresponsecontent);
} else {
$table->data[] = array('');
}
}
} else {
// Add a table row containing the answer.
$studentanswer = $this->format_answer($result->studentanswer, $context, $result->studentanswerformat, $options);
$table->data[] = array($studentanswer);
// If the response exists, add a table row containing the response. If not, add en empty row.
if (!empty(trim($result->response))) {
$studentresponse = isset($result->responseformat) ?
$this->format_response($result->response, $context, $result->responseformat,
$result->answerid, $options) : $result->response;
$studentresponsecontent = html_writer::div('' . get_string("response", "lesson") .
':
' . $studentresponse, $class);
$table->data[] = array($studentresponsecontent);
} else {
$table->data[] = array('');
}
}
$result->feedback .= html_writer::table($table).'
';
}
}
return $result;
}
/**
* Formats the answer. Override for custom formatting.
*
* @param string $answer
* @param context $context
* @param int $answerformat
* @return string Returns formatted string
*/
public function format_answer($answer, $context, $answerformat, $options = []) {
if (is_object($options)) {
$options = (array) $options;
}
if (empty($options['context'])) {
$options['context'] = $context;
}
if (empty($options['para'])) {
$options['para'] = true;
}
return format_text($answer, $answerformat, $options);
}
/**
* Formats the response
*
* @param string $response
* @param context $context
* @param int $responseformat
* @param int $answerid
* @param stdClass $options
* @return string Returns formatted string
*/
private function format_response($response, $context, $responseformat, $answerid, $options) {
$convertstudentresponse = file_rewrite_pluginfile_urls($response, 'pluginfile.php',
$context->id, 'mod_lesson', 'page_responses', $answerid);
return format_text($convertstudentresponse, $responseformat, $options);
}
/**
* Returns the string for a jump name
*
* @final
* @param int $jumpto Jump code or page ID
* @return string
**/
final protected function get_jump_name($jumpto) {
global $DB;
static $jumpnames = array();
if (!array_key_exists($jumpto, $jumpnames)) {
if ($jumpto == LESSON_THISPAGE) {
$jumptitle = get_string('thispage', 'lesson');
} elseif ($jumpto == LESSON_NEXTPAGE) {
$jumptitle = get_string('nextpage', 'lesson');
} elseif ($jumpto == LESSON_EOL) {
$jumptitle = get_string('endoflesson', 'lesson');
} elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) {
$jumptitle = get_string('unseenpageinbranch', 'lesson');
} elseif ($jumpto == LESSON_PREVIOUSPAGE) {
$jumptitle = get_string('previouspage', 'lesson');
} elseif ($jumpto == LESSON_RANDOMPAGE) {
$jumptitle = get_string('randompageinbranch', 'lesson');
} elseif ($jumpto == LESSON_RANDOMBRANCH) {
$jumptitle = get_string('randombranch', 'lesson');
} elseif ($jumpto == LESSON_CLUSTERJUMP) {
$jumptitle = get_string('clusterjump', 'lesson');
} else {
if (!$jumptitle = $DB->get_field('lesson_pages', 'title', array('id' => $jumpto))) {
$jumptitle = '