Skip to content

Commit

Permalink
MDL-48969 Block: Disable and migrate quiz_results block
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourget committed Mar 19, 2015
1 parent d6383f6 commit 846f6dc
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,36 @@ public function get_configdata_encoded_attributes() {
public function after_restore() {
global $DB;

// Get the blockid
// Get the blockid.
$blockid = $this->get_blockid();

// Extract block configdata and update it to point to the new quiz
// Extract block configdata and update it to point to the new quiz.
if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $blockid))) {
$config = unserialize(base64_decode($configdata));
if (!empty($config->quizid)) {
// Get quiz mapping and replace it in config
// Get quiz mapping and replace it in config.
if ($quizmap = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $config->quizid)) {
$config->quizid = $quizmap->newitemid;
$configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
$config->activityparent = 'quiz';
$config->activityparentid = $quizmap->newitemid;

// Set the decimal valuue as appropriate.
if ($config->gradeformat == 1) {
// This block is using percentages, do not display any decimal places.
$config->decimalpoints = 0;
} else {
// Get the decimal value from the corresponding quiz.
$config->decimalpoints = $DB->get_field('quiz', 'decimalpoints', array('id' => $config->activityparentid));
}

// Get the grade_items record to set the activitygradeitemid.
$info = $DB->get_record('grade_items',
array('iteminstance' => $config->activityparentid, 'itemmodule' => $config->activityparent));
$config->activitygradeitemid = $info->id;
unset($config->quizid);

// Save the new configuration and update the record.
$DB->set_field('block_instances', 'configdata', base64_encode(serialize($config)), array('id' => $blockid));
$DB->set_field('block_instances', 'blockname', 'activity_results', array('id' => $blockid));
}
}
}
Expand Down
Loading

0 comments on commit 846f6dc

Please sign in to comment.