Merge branch 'MDL-48962' of git://github.com/jmvedrine/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2015-03-03 23:36:50 +01:00
commit 0967a20d02
13 changed files with 75 additions and 43 deletions

View File

@ -72,7 +72,7 @@ class backup_lesson_activity_structure_step extends backup_activity_structure_st
'course', 'name', 'practice', 'modattempts', 'usepassword', 'password',
'dependency', 'conditions', 'grade', 'custom', 'ongoing', 'usemaxgrade',
'maxanswers', 'maxattempts', 'review', 'nextpagedefault', 'feedback',
'minquestions', 'maxpages', 'timed', 'maxtime', 'retake', 'activitylink',
'minquestions', 'maxpages', 'timelimit', 'retake', 'activitylink',
'mediafile', 'mediaheight', 'mediawidth', 'mediaclose', 'slideshow',
'width', 'height', 'bgcolor', 'displayleft', 'displayleftif', 'progressbar',
'showhighscores', 'maxhighscores', 'available', 'deadline', 'timemodified',

View File

@ -77,6 +77,14 @@ class restore_lesson_activity_structure_step extends restore_activity_structure_
$data->completionendreached = 0;
}
// Compatibility with old backups with maxtime and timed fields.
if (!isset($data->timelimit)) {
if (isset($data->timed) && isset($data->maxtime) && $data->timed) {
$data->timelimit = 60 * $data->maxtime;
} else {
$data->timelimit = 0;
}
}
// insert the lesson record
$newitemid = $DB->insert_record('lesson', $data);
// immediately after inserting "activity" record, call this

View File

@ -50,8 +50,8 @@ $PAGE->navbar->add(get_string('continue', 'lesson'));
if (!$canmanage) {
$lesson->displayleft = lesson_displayleftif($lesson);
$timer = $lesson->update_timer();
if ($lesson->timed) {
$timeleft = ($timer->starttime + $lesson->maxtime * 60) - time();
if ($lesson->timelimit) {
$timeleft = ($timer->starttime + $lesson->timelimit) - time();
if ($timeleft <= 0) {
// Out of time
$lesson->add_message(get_string('eolstudentoutoftime', 'lesson'));
@ -157,7 +157,7 @@ if ($canmanage) {
$lesson->add_message(get_string("teacherjumpwarning", "lesson", $warningvars));
}
// Inform teacher that s/he will not see the timer
if ($lesson->timed) {
if ($lesson->timelimit) {
$lesson->add_message(get_string("teachertimerwarning", "lesson"));
}
}

View File

@ -28,8 +28,7 @@
<FIELD NAME="feedback" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="minquestions" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="maxpages" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timed" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="maxtime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timelimit" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="retake" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="activitylink" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="mediafile" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Local file path or full external URL"/>

View File

@ -178,5 +178,44 @@ function xmldb_lesson_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2015030301, 'lesson');
}
if ($oldversion < 2015030400) {
// Creating new field timelimit in lesson table.
$table = new xmldb_table('lesson');
$field = new xmldb_field('timelimit', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'maxpages');
// Conditionally launch add field timelimit.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2015030400, 'lesson');
}
if ($oldversion < 2015030401) {
// Convert maxtime (minutes) to timelimit (seconds).
$table = new xmldb_table('lesson');
$oldfield = new xmldb_field('maxtime');
$newfield = new xmldb_field('timelimit');
if ($dbman->field_exists($table, $oldfield) && $dbman->field_exists($table, $newfield)) {
$sql = 'UPDATE {lesson} SET timelimit = 60 * maxtime';
$DB->execute($sql);
// Drop field maxtime.
$dbman->drop_field($table, $oldfield);
}
$oldfield = new xmldb_field('timed');
if ($dbman->field_exists($table, $oldfield) && $dbman->field_exists($table, $newfield)) {
// Set timelimit to 0 for non timed lessons.
$DB->set_field_select('lesson', 'timelimit', 0, 'timed = 0');
// Drop field timed.
$dbman->drop_field($table, $oldfield);
}
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2015030401, 'lesson');
}
return true;
}

View File

@ -261,8 +261,6 @@ $string['maximumnumberofanswersbranches_help'] = 'This setting specifies the max
$string['maximumnumberofattempts'] = 'Maximum number of attempts';
$string['maximumnumberofattempts_help'] = 'This setting specifies the maximum number of attempts allowed for each question. If answered incorrectly repeatedly, when the maximum is reached, the next page of the lesson is displayed.';
$string['maximumnumberofattemptsreached'] = 'Maximum number of attempts reached - Moving to next page';
$string['maxtime'] = 'Time limit (minutes)';
$string['maxtimewarning'] = 'You have {$a} minute(s) to finish the lesson.';
$string['mediaclose'] = 'Show close button:';
$string['mediafile'] = 'File pop-up';
$string['mediafile_help'] = 'To include a pop-up window at the beginning of a lesson, choose the appropriate file to display. Every lesson page will include a link to re-open the pop-up if necessary.';
@ -435,6 +433,9 @@ $string['thatsthewronganswer'] = 'That\'s the wrong answer';
$string['thefollowingpagesjumptothispage'] = 'The following pages jump to this page';
$string['thispage'] = 'This page';
$string['timeisup'] = 'Time is up';
$string['timelimit'] = 'Time limit';
$string['timelimit_help'] = 'If enabled, a warning about the time limit is displayed at the beginning of the lesson and a countdown timer is displayed. Answer given after time is elapsed aren\'t graded';
$string['timelimitwarning'] = 'You have {$a} to finish the lesson.';
$string['timeremaining'] = 'Time remaining';
$string['timespenterror'] = 'Spend at least {$a} minutes in the lesson';
$string['timespentminutes'] = 'Time spent (minutes)';

View File

@ -523,8 +523,8 @@ function lesson_process_pre_save(&$lesson) {
$lesson->timemodified = time();
if (empty($lesson->timed)) {
$lesson->timed = 0;
if (empty($lesson->timelimit)) {
$lesson->timelimit = 0;
}
if (empty($lesson->timespent) or !is_numeric($lesson->timespent) or $lesson->timespent < 0) {
$lesson->timespent = 0;

View File

@ -486,7 +486,7 @@ function lesson_mediafile_block_contents($cmid, $lesson) {
function lesson_clock_block_contents($cmid, $lesson, $timer, $page) {
// Display for timed lessons and for students only
$context = context_module::instance($cmid);
if(!$lesson->timed || has_capability('mod/lesson:manage', $context)) {
if ($lesson->timelimit == 0 || has_capability('mod/lesson:manage', $context)) {
return null;
}
@ -494,7 +494,7 @@ function lesson_clock_block_contents($cmid, $lesson, $timer, $page) {
$content .= $lesson->time_remaining($timer->starttime);
$content .= '</div>';
$clocksettings = array('starttime'=>$timer->starttime, 'servertime'=>time(),'testlength'=>($lesson->maxtime * 60));
$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');
@ -1241,8 +1241,8 @@ class lesson extends lesson_base {
$startlesson->starttime = time();
$startlesson->lessontime = time();
$DB->insert_record('lesson_timer', $startlesson);
if ($this->properties->timed) {
$this->add_message(get_string('maxtimewarning', 'lesson', $this->properties->maxtime), 'center');
if ($this->properties->timelimit) {
$this->add_message(get_string('timelimitwarning', 'lesson', format_time($this->properties->timelimit)), 'center');
}
return true;
}
@ -1412,7 +1412,7 @@ class lesson extends lesson_base {
* @return string
*/
public function time_remaining($starttime) {
$timeleft = $starttime + $this->maxtime * 60 - time();
$timeleft = $starttime + $this->timelimit - time();
$hours = floor($timeleft/3600);
$timeleft = $timeleft - ($hours * 3600);
$minutes = floor($timeleft/60);

View File

@ -171,22 +171,11 @@ class mod_lesson_mod_form extends moodleform_mod {
$mform->addElement('date_time_selector', 'deadline', get_string('deadline', 'lesson'), array('optional'=>true));
$mform->setDefault('deadline', 0);
// Create a text box that can be enabled/disabled for lesson time limit
$timedgrp = array();
$timedgrp[] = &$mform->createElement('text', 'maxtime');
$timedgrp[] = &$mform->createElement('checkbox', 'timed', '', get_string('enable'));
$mform->addGroup($timedgrp, 'timedgrp', get_string('maxtime', 'lesson'), array(' '), false);
$mform->disabledIf('timedgrp', 'timed');
// Add numeric rule to text field
$timedgrprules = array();
$timedgrprules['maxtime'][] = array(null, 'numeric', null, 'client');
$mform->addGroupRule('timedgrp', $timedgrprules);
// Rest of group setup
$mform->setDefault('timed', 0);
$mform->setDefault('maxtime', 20);
$mform->setType('maxtime', PARAM_INT);
// Time limit.
$mform->addElement('duration', 'timelimit', get_string('timelimit', 'lesson'),
array('optional' => true));
$mform->addHelpButton('timelimit', 'timelimit', 'lesson');
$mform->setDefault('timelimit', 1200);
$mform->addElement('selectyesno', 'usepassword', get_string('usepassword', 'lesson'));
$mform->addHelpButton('usepassword', 'usepassword', 'lesson');
@ -334,9 +323,6 @@ class mod_lesson_mod_form extends moodleform_mod {
function validation($data, $files) {
$errors = parent::validation($data, $files);
if (empty($data['maxtime']) and !empty($data['timed'])) {
$errors['timedgrp'] = get_string('err_numeric', 'form');
}
if (!empty($data['usepassword']) && empty($data['password'])) {
$errors['password'] = get_string('emptypassword', 'lesson');
}

View File

@ -23,8 +23,7 @@ Feature: A teacher can set a time limit for a lesson
And I add a "Lesson" to section "1" and I fill the form with:
| Name | Test lesson |
| Description | Test lesson description |
| timed | 1 |
| maxtime | 1 |
| timelimit | 60 |
And I follow "Test lesson"
And I follow "Add a content page"
And I set the following fields to these values:

View File

@ -11,7 +11,7 @@
// echo "<script type=\"text/javascript\">\n";
// echo "var starttime = ". $timer->starttime . ";\n";
// echo "var servertime = ". time() . ";\n";
// echo "var testlength = ". $lesson->maxtime * 60 .";\n";
// echo "var testlength = ". $lesson->timelimit .";\n";
// echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
// echo "window.onload = function () { show_clock(); }";
// echo "</script>\n";

View File

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015030301; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2015030401; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014110400; // Requires this Moodle version
$plugin->component = 'mod_lesson'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;

View File

@ -240,7 +240,7 @@ if (empty($pageid)) {
|| $DB->count_records('lesson_branch', array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $retries)) > 0) {
echo $lessonoutput->header($lesson, $cm, '', false, null, get_string('leftduringtimedsession', 'lesson'));
if ($lesson->timed) {
if ($lesson->timelimit) {
if ($lesson->retake) {
$continuelink = new single_button(new moodle_url('/mod/lesson/view.php',
array('id' => $cm->id, 'pageid' => $lesson->firstpageid, 'startlastseen' => 'no')),
@ -325,8 +325,8 @@ if ($pageid != LESSON_EOL) {
$restart = ($continue && $startlastseen == 'yes');
$timer = $lesson->update_timer($continue, $restart);
if ($lesson->timed) {
$timeleft = ($timer->starttime + $lesson->maxtime * 60) - time();
if ($lesson->timelimit) {
$timeleft = $timer->starttime + $lesson->timelimit - time();
if ($timeleft <= 0) {
// Out of time
$lesson->add_message(get_string('eolstudentoutoftime', 'lesson'));
@ -363,7 +363,7 @@ if ($pageid != LESSON_EOL) {
}
} else {
$timer = null;
if ($lesson->timed) {
if ($lesson->timelimit) {
$lesson->add_message(get_string('teachertimerwarning', 'lesson'));
}
if (lesson_display_teacher_warning($lesson)) {
@ -510,7 +510,7 @@ if ($pageid != LESSON_EOL) {
$DB->delete_records("lesson_attempts", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries));
}
} else {
if ($lesson->timed) {
if ($lesson->timelimit) {
if ($outoftime == 'normal') {
$grade = new stdClass();
$grade->lessonid = $lesson->id;