MDL-57759 mod_lesson: Handle offline attempts in view and WS
- Notify the user if there are previous offline attempts - Set the offline attempts and return additional information via Web Services
This commit is contained in:
@@ -118,7 +118,7 @@ class mod_lesson_external extends external_api {
|
||||
'maxanswers', 'maxattempts', 'review', 'nextpagedefault', 'feedback', 'minquestions',
|
||||
'maxpages', 'timelimit', 'retake', 'mediafile', 'mediaheight', 'mediawidth',
|
||||
'mediaclose', 'slideshow', 'width', 'height', 'bgcolor', 'displayleft', 'displayleftif',
|
||||
'progressbar');
|
||||
'progressbar', 'allowofflineattempts');
|
||||
|
||||
// Fields only for managers.
|
||||
if ($lesson->can_manage()) {
|
||||
@@ -199,6 +199,8 @@ class mod_lesson_external extends external_api {
|
||||
VALUE_OPTIONAL),
|
||||
'completiontimespent' => new external_value(PARAM_INT, 'Student must do this activity at least for',
|
||||
VALUE_OPTIONAL),
|
||||
'allowofflineattempts' => new external_value(PARAM_INT, 'Whether to allow the lesson to be attempted
|
||||
offline in the mobile app', VALUE_OPTIONAL),
|
||||
'visible' => new external_value(PARAM_INT, 'Visible?', VALUE_OPTIONAL),
|
||||
'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL),
|
||||
'groupingid' => new external_value(PARAM_INT, 'Grouping id', VALUE_OPTIONAL),
|
||||
@@ -959,6 +961,7 @@ class mod_lesson_external extends external_api {
|
||||
'starttime' => new external_value(PARAM_INT, 'First access time for a new timer session'),
|
||||
'lessontime' => new external_value(PARAM_INT, 'Last access time to the lesson during the timer session'),
|
||||
'completed' => new external_value(PARAM_INT, 'If the lesson for this timer was completed'),
|
||||
'timemodifiedoffline' => new external_value(PARAM_INT, 'Last modified time via webservices.'),
|
||||
),
|
||||
'The timers'
|
||||
)
|
||||
@@ -1332,8 +1335,9 @@ class mod_lesson_external extends external_api {
|
||||
'answerfiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_answers', $a->id),
|
||||
'responsefiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_responses', $a->id),
|
||||
);
|
||||
// For managers, return all the information (including scoring, jumps).
|
||||
if ($lesson->can_manage()) {
|
||||
// For managers, return all the information (including correct answers, jumps).
|
||||
// If the teacher enabled offline attempts, this information will be downloaded too.
|
||||
if ($lesson->can_manage() || $lesson->allowofflineattempts) {
|
||||
$extraproperties = array('jumpto', 'grade', 'score', 'flags', 'timecreated', 'timemodified');
|
||||
foreach ($extraproperties as $prop) {
|
||||
$answer[$prop] = $a->{$prop};
|
||||
|
||||
@@ -359,6 +359,7 @@ $string['numberofpagesviewed'] = 'Number of questions answered: {$a}';
|
||||
$string['numberofpagesviewedheader'] = 'Number of questions answered';
|
||||
$string['numberofpagesviewednotice'] = 'Number of questions answered: {$a->nquestions} (You should answer at least {$a->minquestions})';
|
||||
$string['numerical'] = 'Numerical';
|
||||
$string['offlinedatamessage'] = 'You have worked on this attempt using a mobile device. Data was last saved to this site {$a} ago. Please check that you do not have any unsaved work.';
|
||||
$string['ongoing'] = 'Display ongoing score';
|
||||
$string['ongoing_help'] = 'If enabled, each page will display the student\'s current points earned out of the total possible thus far.';
|
||||
$string['ongoingcustom'] = 'You have earned {$a->score} point(s) out of {$a->currenthigh} point(s) thus far.';
|
||||
|
||||
+13
-3
@@ -1448,6 +1448,7 @@ abstract class lesson_add_page_form_base extends moodleform {
|
||||
* @property int $available Timestamp of when this lesson becomes available
|
||||
* @property int $deadline Timestamp of when this lesson is no longer available
|
||||
* @property int $timemodified Timestamp when lesson was last modified
|
||||
* @property int $allowofflineattempts Whether to allow the lesson to be attempted offline in the mobile app
|
||||
*
|
||||
* These properties are calculated
|
||||
* @property int $firstpageid Id of the first page of this lesson (prevpageid=0)
|
||||
@@ -2035,11 +2036,16 @@ class lesson extends lesson_base {
|
||||
$event->trigger();
|
||||
|
||||
$USER->startlesson[$this->properties->id] = true;
|
||||
|
||||
$timenow = time();
|
||||
$startlesson = new stdClass;
|
||||
$startlesson->lessonid = $this->properties->id;
|
||||
$startlesson->userid = $USER->id;
|
||||
$startlesson->starttime = time();
|
||||
$startlesson->lessontime = time();
|
||||
$startlesson->starttime = $timenow;
|
||||
$startlesson->lessontime = $timenow;
|
||||
if (WS_SERVER) {
|
||||
$startlesson->timemodifiedoffline = $timenow;
|
||||
}
|
||||
$DB->insert_record('lesson_timer', $startlesson);
|
||||
if ($this->properties->timelimit) {
|
||||
$this->add_message(get_string('timelimitwarning', 'lesson', format_time($this->properties->timelimit)), 'center');
|
||||
@@ -2095,7 +2101,11 @@ class lesson extends lesson_base {
|
||||
}
|
||||
}
|
||||
|
||||
$timer->lessontime = time();
|
||||
$timenow = time();
|
||||
$timer->lessontime = $timenow;
|
||||
if (WS_SERVER) {
|
||||
$timer->timemodifiedoffline = $timenow;
|
||||
}
|
||||
$timer->completed = $endreached;
|
||||
$DB->update_record('lesson_timer', $timer);
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase {
|
||||
'maxanswers', 'maxattempts', 'review', 'nextpagedefault', 'feedback', 'minquestions',
|
||||
'maxpages', 'timelimit', 'retake', 'mediafile', 'mediafiles', 'mediaheight', 'mediawidth',
|
||||
'mediaclose', 'slideshow', 'width', 'height', 'bgcolor', 'displayleft', 'displayleftif',
|
||||
'progressbar');
|
||||
'progressbar', 'allowofflineattempts');
|
||||
|
||||
// Add expected coursemodule and data.
|
||||
$lesson1 = $this->lesson;
|
||||
@@ -661,6 +661,7 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase {
|
||||
$timer1->completed = 1;
|
||||
$timer1->starttime = time() - WEEKSECS;
|
||||
$timer1->lessontime = time();
|
||||
$timer1->timemodifiedoffline = time();
|
||||
$timer1->id = $DB->insert_record("lesson_timer", $timer1);
|
||||
|
||||
$timer2 = new stdClass;
|
||||
@@ -669,6 +670,7 @@ class mod_lesson_external_testcase extends externallib_advanced_testcase {
|
||||
$timer2->completed = 0;
|
||||
$timer2->starttime = time() - DAYSECS;
|
||||
$timer2->lessontime = time() + 1;
|
||||
$timer2->timemodifiedoffline = time() + 1;
|
||||
$timer2->id = $DB->insert_record("lesson_timer", $timer2);
|
||||
|
||||
// Test retrieve timers.
|
||||
|
||||
@@ -121,6 +121,16 @@ if (empty($pageid)) {
|
||||
|
||||
$lastpageseen = $lesson->get_last_page_seen($retries);
|
||||
|
||||
// Check if the lesson was attempted in an external device like the mobile app.
|
||||
// This check makes sense only when the lesson allows offline attempts.
|
||||
if ($lesson->allowofflineattempts && $timers = $lesson->get_user_timers($USER->id, 'starttime DESC', '*', 0, 1)) {
|
||||
$timer = current($timers);
|
||||
if (!empty($timer->timemodifiedoffline)) {
|
||||
$lasttime = format_time(time() - $timer->timemodifiedoffline);
|
||||
$lesson->add_message(get_string('offlinedatamessage', 'lesson', $lasttime), 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if end of lesson was reached.
|
||||
if (($lastpageseen !== false && ($lastpageseen != LESSON_EOL))) {
|
||||
// End not reached. Check if the user left.
|
||||
|
||||
Reference in New Issue
Block a user