Skip to content

Commit

Permalink
MDL-35603 - Backup - Course import selector notice
Browse files Browse the repository at this point in the history
* added new config option to determine length of courses returned by import
* added text indicator if there are more than X number of courses, similar to how the restore course list currently works
  • Loading branch information
rlorenzo committed Mar 28, 2013
1 parent d8201d4 commit c4dbfb2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
5 changes: 5 additions & 0 deletions admin/settings/courses.php
Expand Up @@ -135,6 +135,11 @@
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
$ADMIN->add('backups', $temp);

// Create a page for general import configuration and defaults.
$temp = new admin_settingpage('importgeneralsettings', new lang_string('importgeneralsettings', 'backup'), 'moodle/backup:backupcourse');
$temp->add(new admin_setting_configtext('backup/import_general_maxresults', new lang_string('importgeneralmaxresults', 'backup'), new lang_string('importgeneralmaxresults_desc', 'backup'), 10));
$ADMIN->add('backups', $temp);

// Create a page for automated backups configuration and defaults.
$temp = new admin_settingpage('automated', new lang_string('automatedsetup','backup'), 'moodle/backup:backupcourse');

Expand Down
16 changes: 15 additions & 1 deletion backup/util/ui/renderer.php
Expand Up @@ -590,8 +590,14 @@ public function render_import_course_search(import_course_search $component) {
return $output;
}

$output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_count()), array('class'=>'ics-totalresults'));
$count_str = '';
if ($component->has_more_results()) {
$count_str = get_string('morecoursesearchresults', 'backup', $component->get_count());
} else {
$count_str = get_string('totalcoursesearchresults', 'backup', $component->get_count());
}

$output .= html_writer::tag('div', $count_str, array('class'=>'ics-totalresults'));
$output .= html_writer::start_tag('div', array('class' => 'ics-results'));

$table = new html_table();
Expand All @@ -610,6 +616,14 @@ public function render_import_course_search(import_course_search $component) {
);
$table->data[] = $row;
}
if ($component->has_more_results()) {
$cell = new html_table_cell(get_string('moreresults', 'backup'));
$cell->colspan = 3;
$cell->attributes['class'] = 'notifyproblem';
$row = new html_table_row(array($cell));
$row->attributes['class'] = 'rcs-course';
$table->data[] = $row;
}
$output .= html_writer::table($table);
$output .= html_writer::end_tag('div');

Expand Down
30 changes: 23 additions & 7 deletions backup/util/ui/restore_ui_components.php
Expand Up @@ -39,7 +39,6 @@ abstract class restore_search_base implements renderable {
*/
static $VAR_SEARCH = 'search';

static $MAXRESULTS = 10;
/**
* The current search string
* @var string|null
Expand All @@ -65,6 +64,16 @@ abstract class restore_search_base implements renderable {
* @var array
*/
private $requiredcapabilities = array();
/**
* Max number of courses to return in a search.
* @var int
*/
private $maxresults = null;
/**
* Indicates if we have more than maxresults found.
* @var boolean
*/
private $has_more_results = false;

/**
* Constructor
Expand All @@ -73,6 +82,7 @@ abstract class restore_search_base implements renderable {
public function __construct(array $config=array()) {

$this->search = optional_param($this->get_varsearch(), self::DEFAULT_SEARCH, PARAM_NOTAGS);
$this->maxresults = get_config('backup', 'import_general_maxresults');

foreach ($config as $name=>$value) {
$method = 'set_'.$name;
Expand Down Expand Up @@ -177,8 +187,8 @@ final public function search() {
foreach ($this->requiredcapabilities as $cap) {
$requiredcaps[] = $cap['capability'];
}
// Iterate while we have records and haven't reached MAXRESULTS
while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
// Iterate while we have records and haven't reached $this->maxresults.
while ($totalcourses > $offs and $this->totalcount < $this->maxresults) {
$resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
foreach ($resultset as $result) {
context_instance_preload($result);
Expand All @@ -189,11 +199,14 @@ final public function search() {
continue;
}
}
$this->results[$result->id] = $result;
$this->totalcount++;
if ($this->totalcount >= self::$MAXRESULTS) {
// Check if we are over the limit.
if ($this->totalcount+1 > $this->maxresults) {
$this->has_more_results = true;
break;
}
// If not, then continue.
$this->totalcount++;
$this->results[$result->id] = $result;
}
$offs += $blocksz;
}
Expand All @@ -202,7 +215,10 @@ final public function search() {
}

final public function has_more_results() {
return $this->get_count() >= self::$MAXRESULTS;
if ($this->results === null) {
$this->search();
}
return $this->has_more_results;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lang/en/backup.php
Expand Up @@ -138,6 +138,9 @@
$string['generalsettings'] = 'General backup settings';
$string['generaluserscompletion'] = 'Include user completion information';
$string['generalusers'] = 'Include users';
$string['importgeneralsettings'] = 'General import defaults';
$string['importgeneralmaxresults'] = 'Maximum number of courses listed for import';
$string['importgeneralmaxresults_desc'] = 'This controls the number of courses that are listed during the first step of the import process';
$string['importfile'] = 'Import a backup file';
$string['importbackupstage1action'] = 'Next';
$string['importbackupstage2action'] = 'Next';
Expand Down Expand Up @@ -246,3 +249,4 @@
$string['skipmodifprevhelp'] = 'Choose whether or not to skip courses that have not been modified since previous backup';
$string['totalcategorysearchresults'] = 'Total categories: {$a}';
$string['totalcoursesearchresults'] = 'Total courses: {$a}';
$string['morecoursesearchresults'] = 'More than {$a} courses found, showing first {$a} results';

0 comments on commit c4dbfb2

Please sign in to comment.