Permalink
Browse files

MDL-35603 - Backup - Course import selector notice

* 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...
1 parent d8201d4 commit c4dbfb2c91e8eb5466f1f8a40d841837bf5e3d66 @rlorenzo rlorenzo committed Feb 13, 2013
Showing with 47 additions and 8 deletions.
  1. +5 −0 admin/settings/courses.php
  2. +15 −1 backup/util/ui/renderer.php
  3. +23 −7 backup/util/ui/restore_ui_components.php
  4. +4 −0 lang/en/backup.php
View
5 admin/settings/courses.php
@@ -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');
View
16 backup/util/ui/renderer.php
@@ -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();
@@ -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');
View
30 backup/util/ui/restore_ui_components.php
@@ -39,7 +39,6 @@
*/
static $VAR_SEARCH = 'search';
- static $MAXRESULTS = 10;
/**
* The current search string
* @var string|null
@@ -65,6 +64,16 @@
* @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
@@ -73,6 +82,7 @@
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;
@@ -177,8 +187,8 @@ public function __construct(array $config=array()) {
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);
@@ -189,11 +199,14 @@ public function __construct(array $config=array()) {
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;
}
@@ -202,7 +215,10 @@ public function __construct(array $config=array()) {
}
final public function has_more_results() {
- return $this->get_count() >= self::$MAXRESULTS;
+ if ($this->results === null) {
+ $this->search();
+ }
+ return $this->has_more_results;
}
/**
View
4 lang/en/backup.php
@@ -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';
@@ -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.