Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit c4dbfb2c91e8eb5466f1f8a40d841837bf5e3d66 1 parent d8201d4
Rex Lorenzo rlorenzo authored
5 admin/settings/courses.php
@@ -135,6 +135,11 @@
135 135 $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)));
136 136 $ADMIN->add('backups', $temp);
137 137
  138 + // Create a page for general import configuration and defaults.
  139 + $temp = new admin_settingpage('importgeneralsettings', new lang_string('importgeneralsettings', 'backup'), 'moodle/backup:backupcourse');
  140 + $temp->add(new admin_setting_configtext('backup/import_general_maxresults', new lang_string('importgeneralmaxresults', 'backup'), new lang_string('importgeneralmaxresults_desc', 'backup'), 10));
  141 + $ADMIN->add('backups', $temp);
  142 +
138 143 // Create a page for automated backups configuration and defaults.
139 144 $temp = new admin_settingpage('automated', new lang_string('automatedsetup','backup'), 'moodle/backup:backupcourse');
140 145
16 backup/util/ui/renderer.php
@@ -590,8 +590,14 @@ public function render_import_course_search(import_course_search $component) {
590 590 return $output;
591 591 }
592 592
593   - $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_count()), array('class'=>'ics-totalresults'));
  593 + $count_str = '';
  594 + if ($component->has_more_results()) {
  595 + $count_str = get_string('morecoursesearchresults', 'backup', $component->get_count());
  596 + } else {
  597 + $count_str = get_string('totalcoursesearchresults', 'backup', $component->get_count());
  598 + }
594 599
  600 + $output .= html_writer::tag('div', $count_str, array('class'=>'ics-totalresults'));
595 601 $output .= html_writer::start_tag('div', array('class' => 'ics-results'));
596 602
597 603 $table = new html_table();
@@ -610,6 +616,14 @@ public function render_import_course_search(import_course_search $component) {
610 616 );
611 617 $table->data[] = $row;
612 618 }
  619 + if ($component->has_more_results()) {
  620 + $cell = new html_table_cell(get_string('moreresults', 'backup'));
  621 + $cell->colspan = 3;
  622 + $cell->attributes['class'] = 'notifyproblem';
  623 + $row = new html_table_row(array($cell));
  624 + $row->attributes['class'] = 'rcs-course';
  625 + $table->data[] = $row;
  626 + }
613 627 $output .= html_writer::table($table);
614 628 $output .= html_writer::end_tag('div');
615 629
30 backup/util/ui/restore_ui_components.php
@@ -39,7 +39,6 @@
39 39 */
40 40 static $VAR_SEARCH = 'search';
41 41
42   - static $MAXRESULTS = 10;
43 42 /**
44 43 * The current search string
45 44 * @var string|null
@@ -65,6 +64,16 @@
65 64 * @var array
66 65 */
67 66 private $requiredcapabilities = array();
  67 + /**
  68 + * Max number of courses to return in a search.
  69 + * @var int
  70 + */
  71 + private $maxresults = null;
  72 + /**
  73 + * Indicates if we have more than maxresults found.
  74 + * @var boolean
  75 + */
  76 + private $has_more_results = false;
68 77
69 78 /**
70 79 * Constructor
@@ -73,6 +82,7 @@
73 82 public function __construct(array $config=array()) {
74 83
75 84 $this->search = optional_param($this->get_varsearch(), self::DEFAULT_SEARCH, PARAM_NOTAGS);
  85 + $this->maxresults = get_config('backup', 'import_general_maxresults');
76 86
77 87 foreach ($config as $name=>$value) {
78 88 $method = 'set_'.$name;
@@ -177,8 +187,8 @@ public function __construct(array $config=array()) {
177 187 foreach ($this->requiredcapabilities as $cap) {
178 188 $requiredcaps[] = $cap['capability'];
179 189 }
180   - // Iterate while we have records and haven't reached MAXRESULTS
181   - while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
  190 + // Iterate while we have records and haven't reached $this->maxresults.
  191 + while ($totalcourses > $offs and $this->totalcount < $this->maxresults) {
182 192 $resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
183 193 foreach ($resultset as $result) {
184 194 context_instance_preload($result);
@@ -189,11 +199,14 @@ public function __construct(array $config=array()) {
189 199 continue;
190 200 }
191 201 }
192   - $this->results[$result->id] = $result;
193   - $this->totalcount++;
194   - if ($this->totalcount >= self::$MAXRESULTS) {
  202 + // Check if we are over the limit.
  203 + if ($this->totalcount+1 > $this->maxresults) {
  204 + $this->has_more_results = true;
195 205 break;
196 206 }
  207 + // If not, then continue.
  208 + $this->totalcount++;
  209 + $this->results[$result->id] = $result;
197 210 }
198 211 $offs += $blocksz;
199 212 }
@@ -202,7 +215,10 @@ public function __construct(array $config=array()) {
202 215 }
203 216
204 217 final public function has_more_results() {
205   - return $this->get_count() >= self::$MAXRESULTS;
  218 + if ($this->results === null) {
  219 + $this->search();
  220 + }
  221 + return $this->has_more_results;
206 222 }
207 223
208 224 /**
4 lang/en/backup.php
@@ -138,6 +138,9 @@
138 138 $string['generalsettings'] = 'General backup settings';
139 139 $string['generaluserscompletion'] = 'Include user completion information';
140 140 $string['generalusers'] = 'Include users';
  141 +$string['importgeneralsettings'] = 'General import defaults';
  142 +$string['importgeneralmaxresults'] = 'Maximum number of courses listed for import';
  143 +$string['importgeneralmaxresults_desc'] = 'This controls the number of courses that are listed during the first step of the import process';
141 144 $string['importfile'] = 'Import a backup file';
142 145 $string['importbackupstage1action'] = 'Next';
143 146 $string['importbackupstage2action'] = 'Next';
@@ -246,3 +249,4 @@
246 249 $string['skipmodifprevhelp'] = 'Choose whether or not to skip courses that have not been modified since previous backup';
247 250 $string['totalcategorysearchresults'] = 'Total categories: {$a}';
248 251 $string['totalcoursesearchresults'] = 'Total courses: {$a}';
  252 +$string['morecoursesearchresults'] = 'More than {$a} courses found, showing first {$a} results';

0 comments on commit c4dbfb2

Please sign in to comment.
Something went wrong with that request. Please try again.