Skip to content

Commit

Permalink
Merge branch 'MDL-34006_m29v6' of https://github.com/sbourget/moodle
Browse files Browse the repository at this point in the history
Conflicts:
	mod/lesson/version.php
	mod/lesson/db/upgrade.php
	mod/lesson/db/install.xml
  • Loading branch information
danpoltawski committed Mar 3, 2015
2 parents 6d46e3a + 60742fd commit 6a4caa0
Show file tree
Hide file tree
Showing 9 changed files with 491 additions and 33 deletions.
2 changes: 1 addition & 1 deletion mod/lesson/backup/moodle2/backup_lesson_stepslib.php
Expand Up @@ -119,7 +119,7 @@ protected function define_structure() {
// and user.
$branches = new backup_nested_element('branches');
$branch = new backup_nested_element('branch', array('id'), array(
'userid','retry','flag','timeseen'
'userid', 'retry', 'flag', 'timeseen', 'nextpageid'
));

// The lesson_grades table
Expand Down
11 changes: 11 additions & 0 deletions mod/lesson/backup/moodle2/restore_lesson_stepslib.php
Expand Up @@ -233,6 +233,17 @@ protected function after_execute() {
}
$rs->close();

// Remap all the restored 'nextpageid' fields now that we have all the pages and their mappings.
$rs = $DB->get_recordset('lesson_branch', array('lessonid' => $this->task->get_activityid()),
'', 'id, nextpageid');
foreach ($rs as $answer) {
if ($answer->nextpageid > 0) {
$answer->nextpageid = $this->get_mappingid('lesson_page', $answer->nextpageid);
$DB->update_record('lesson_branch', $answer);
}
}
$rs->close();

// Re-map the dependency and activitylink information
// If a depency or activitylink has no mapping in the backup data then it could either be a duplication of a
// lesson, or a backup/restore of a single lesson. We have no way to determine which and whether this is the
Expand Down
5 changes: 3 additions & 2 deletions mod/lesson/db/install.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/lesson/db" VERSION="20120122" COMMENT="XMLDB file for Moodle mod/lesson"
<XMLDB PATH="mod/lesson/db" VERSION="20150303" COMMENT="XMLDB file for Moodle mod/lesson"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -10,7 +10,7 @@
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" />
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="practice" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="modattempts" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="usepassword" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down Expand Up @@ -165,6 +165,7 @@
<FIELD NAME="retry" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="flag" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeseen" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="nextpageid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
16 changes: 16 additions & 0 deletions mod/lesson/db/upgrade.php
Expand Up @@ -137,5 +137,21 @@ function xmldb_lesson_upgrade($oldversion) {
// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2014122900, 'lesson');
}

if ($oldversion < 2015030300) {

// Define field nextpageid to be added to lesson_branch.
$table = new xmldb_table('lesson_branch');
$field = new xmldb_field('nextpageid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'timeseen');

// Conditionally launch add field nextpageid.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Lesson savepoint reached.
upgrade_mod_savepoint(true, 2015030300, 'lesson');
}

return true;
}
24 changes: 13 additions & 11 deletions mod/lesson/pagetypes/branchtable.php
Expand Up @@ -173,15 +173,6 @@ public function check_answer() {
} else {
$retries = 0;
}
$branch = new stdClass;
$branch->lessonid = $this->lesson->id;
$branch->userid = $USER->id;
$branch->pageid = $this->properties->id;
$branch->retry = $retries;
$branch->flag = $branchflag;
$branch->timeseen = time();

$DB->insert_record("lesson_branch", $branch);

// this is called when jumping to random from a branch table
$context = context_module::instance($PAGE->cm->id);
Expand All @@ -207,8 +198,19 @@ public function check_answer() {
} elseif ($newpageid == LESSON_RANDOMBRANCH) {
$newpageid = lesson_unseen_branch_jump($this->lesson, $USER->id);
}
// no need to record anything in lesson_attempts
redirect(new moodle_url('/mod/lesson/view.php', array('id'=>$PAGE->cm->id,'pageid'=>$newpageid)));

// Record this page in lesson_branch.
$branch = new stdClass;
$branch->lessonid = $this->lesson->id;
$branch->userid = $USER->id;
$branch->pageid = $this->properties->id;
$branch->retry = $retries;
$branch->flag = $branchflag;
$branch->timeseen = time();
$branch->nextpageid = $newpageid;
$DB->insert_record("lesson_branch", $branch);

redirect(new moodle_url('/mod/lesson/view.php', array('id' => $PAGE->cm->id, 'pageid' => $newpageid)));
}

public function display_answers(html_table $table) {
Expand Down
Expand Up @@ -60,6 +60,9 @@ Feature: Set end of lesson reached as a completion condition for a lesson
And I hover "//li[contains(concat(' ', normalize-space(@class), ' '), ' modtype_lesson ')]/descendant::img[@alt='Not completed: Test lesson']" "xpath_element"
And I follow "Course 1"
And I follow "Test lesson"
And I should see "You have seen more than one page of this lesson already."
And I should see "Do you want to start at the last page you saw?"
And I follow "No"
And I press "Next page"
And I press "Next page"
And I follow "Course 1"
Expand Down

0 comments on commit 6a4caa0

Please sign in to comment.