Skip to content

Commit

Permalink
CONTRIB-4429 Fix conflict with other blocks, tidy code and remove non…
Browse files Browse the repository at this point in the history
…-English languages
  • Loading branch information
Michael de Raadt committed Oct 28, 2013
1 parent dd04436 commit 83a2bd2
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 1,178 deletions.
18 changes: 9 additions & 9 deletions backup/moodle2/restore_progress_block_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,40 @@
class restore_progress_block_task extends restore_block_task {

/**
* Translates the backed up configuration data for the target course modules
* Translates the backed up configuration data for the target course modules.
*
* @global type $DB
*/
public function after_restore() {
global $DB;

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

//Restored course id
// Get restored course id.
$courseid = $this->get_courseid();

if ($configdata = $DB->get_field('block_instances', 'configdata', array('id' => $id))) {
$config = (array)unserialize(base64_decode($configdata));

// Translate the old config information to the target course values
// Translate the old config information to the target course values.
foreach ($config as $key => $value) {
$matches = array();
preg_match('/monitor_(\D+)(\d+)/', $key, $matches);
if ($value == 1 && !empty($matches)) {
$module = $matches[1];
$instance = $matches[2];

// Find a matching module in the target course
// Find a matching module in the target course.
if ($cm = get_coursemodule_from_instance($module, $instance)) {

// Get new cm and instance
// Get new cm and instance.
$newitem = restore_dbops::get_backup_ids_record(
$this->get_restoreid(), "course_module", $cm->id);
$newcm = get_coursemodule_from_id($module, $newitem->newitemid);
$newinstance = $newcm->instance;

// Set new config
// Set new config.
$config["monitor_$module$newinstance"] =
$config["monitor_$module$instance"];
$config["locked_$module$newinstance"] =
Expand All @@ -75,7 +75,7 @@ public function after_restore() {
$config["action_$module$newinstance"] =
$config["action_$module$instance"];

// Unset old config
// Unset old config.
unset($config["monitor_$module$instance"]);
unset($config["locked_$module$instance"]);
unset($config["date_time_$module$instance"]);
Expand All @@ -84,7 +84,7 @@ public function after_restore() {
}
}

// Save everything back to DB
// Save everything back to DB.
$configdata = base64_encode(serialize((object)$config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $id));
}
Expand Down
58 changes: 25 additions & 33 deletions block_progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public function init() {
}

/**
* Constrols the block title based on instance configuration
* Controls the block title based on instance configuration
*
* @return bool
*/
public function specialization() {
if (isset($this->config->progressTitle) && trim($this->config->progressTitle)!='') {
if (isset($this->config->progressTitle) && trim($this->config->progressTitle) != '') {
$this->title = format_string($this->config->progressTitle);
}
}
Expand All @@ -71,11 +71,11 @@ public function instance_allow_multiple() {
*/
public function applicable_formats() {
return array(
'course-view' => true,
'site' => false,
'mod' => false,
'my' => false
);
'course-view' => true,
'site' => false,
'mod' => false,
'my' => false
);
}

/**
Expand All @@ -84,19 +84,17 @@ public function applicable_formats() {
* @return string
*/
public function get_content() {
global $USER, $COURSE, $CFG, $OUTPUT;

// Access to settings needed
global $USER, $COURSE, $CFG, $DB, $OUTPUT;

// If content has already been generated, don't waste time generating it again
// If content has already been generated, don't waste time generating it again.
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';

// Check if any activities/resources have been created
// Check if any activities/resources have been created.
$modules = modules_in_use();
if (empty($modules)) {
if (has_capability('moodle/block:edit', $this->context)) {
Expand All @@ -105,43 +103,37 @@ public function get_content() {
return $this->content;
}

// Check if activities/resources have been selected in config
// Check if activities/resources have been selected in config.
$events = event_information($this->config, $modules);
if ($events===null || $events===0) {
if ($events === null || $events === 0) {
if (has_capability('moodle/block:edit', $this->context)) {
$this->content->text .= get_string('no_events_message', 'block_progress');
if($USER->editing) {
$parameters = array('id'=>$COURSE->id, 'sesskey'=>sesskey(),
'bui_editid'=>$this->instance->id);
if ($USER->editing) {
$parameters = array('id' => $COURSE->id, 'sesskey' => sesskey(),
'bui_editid' => $this->instance->id);
$url = new moodle_url('/course/view.php', $parameters);
$label = get_string('selectitemstobeadded', 'block_progress');
$this->content->text .= $OUTPUT->single_button($url, $label);
if ($events===0) {
if ($events === 0) {
$url->param('turnallon', '1');
$label = get_string('addallcurrentitems', 'block_progress');
$this->content->text .= $OUTPUT->single_button($url, $label);
}
}
}
return $this->content;
}
else if (empty($events)) {
} else if (empty($events)) {
if (has_capability('moodle/block:edit', $this->context)) {
$this->content->text .= get_string('no_visible_events_message', 'block_progress');
}
return $this->content;
}

// Display progress bar
else {
$attempts = get_attempts($modules, $this->config, $events, $USER->id,
$this->instance->id);
$this->content->text =
progress_bar($modules, $this->config, $events, $USER->id,
$this->instance->id, $attempts);
}
// Display progress bar.
$attempts = get_attempts($modules, $this->config, $events, $USER->id, $this->instance->id);
$this->content->text = progress_bar($modules, $this->config, $events, $USER->id, $this->instance->id, $attempts);

// Organise access to JS
// Organise access to JS.
$jsmodule = array(
'name' => 'block_progress',
'fullpath' => '/blocks/progress/module.js',
Expand All @@ -150,14 +142,14 @@ public function get_content() {
array('time_expected', 'block_progress'),
),
);
$displaydate = (!isset($this->config->orderby) || $this->config->orderby=='orderbytime') &&
(!isset($this->config->displayNow) || $this->config->displayNow==1);
$displaydate = (!isset($this->config->orderby) || $this->config->orderby == 'orderbytime') &&
(!isset($this->config->displayNow) || $this->config->displayNow == 1);
$arguments = array($CFG->wwwroot, array_keys($modules), $displaydate);
$this->page->requires->js_init_call('M.block_progress.init', $arguments, false, $jsmodule);

// Allow teachers to access the overview page
// Allow teachers to access the overview page.
if (has_capability('block/progress:overview', $this->context)) {
$parameters = array('id' => $this->instance->id, 'courseid' => $COURSE->id);
$parameters = array('progressbarid' => $this->instance->id, 'courseid' => $COURSE->id);
$url = new moodle_url('/blocks/progress/overview.php', $parameters);
$label = get_string('overview', 'block_progress');
$options = array('class' => 'overviewButton');
Expand Down
11 changes: 5 additions & 6 deletions db/upgrade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -46,18 +45,18 @@
function xmldb_block_progress_upgrade($oldversion, $block) {
global $DB;

// Fix bad filtering on posted_to values
if($oldversion>=2013073000 && $oldversion<2013080500) {
$configs = $DB->get_records('block_instances', array('blockname'=>'progress'));
// Fix bad filtering on posted_to values.
if ($oldversion >= 2013073000 && $oldversion < 2013080500) {
$configs = $DB->get_records('block_instances', array('blockname' => 'progress'));
foreach ($configs as $blockid => $blockrecord) {
$config = (array)unserialize(base64_decode($blockrecord->configdata));
foreach ($config as $key => $value) {
if($value == 'postedto') {
if ($value == 'postedto') {
$config[$key] = 'posted_to';
}
}
$configdata = base64_encode(serialize((object)$config));
$DB->set_field('block_instances', 'configdata', $configdata, array('id'=>$blockid));
$DB->set_field('block_instances', 'configdata', $configdata, array('id' => $blockid));
}
}

Expand Down
Loading

0 comments on commit 83a2bd2

Please sign in to comment.