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/restore max results

* Unified UI for import and restore course search
  • Loading branch information...
commit 13c708233eb081c7c9a200819a08d6023186e1ab 1 parent 5a2c3ec
Rex Lorenzo rlorenzo authored rlorenzo committed
25 backup/util/ui/renderer.php
@@ -521,6 +521,15 @@ public function render_restore_course_search(restore_course_search $component) {
521 521 $url = $component->get_url();
522 522
523 523 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
  524 +
  525 + $count_str = '';
  526 + if ($component->has_more_results()) {
  527 + $count_str = get_string('morecoursesearchresults', 'backup', $component->get_count());
  528 + } else {
  529 + $count_str = get_string('totalcoursesearchresults', 'backup', $component->get_count());
  530 + }
  531 +
  532 + $output .= html_writer::tag('div', $count_str, array('class'=>'rcs-totalresults'));
524 533 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
525 534
526 535 $table = new html_table();
@@ -590,8 +599,14 @@ public function render_import_course_search(import_course_search $component) {
590 599 return $output;
591 600 }
592 601
593   - $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_count()), array('class'=>'ics-totalresults'));
  602 + $count_str = '';
  603 + if ($component->has_more_results()) {
  604 + $count_str = get_string('morecoursesearchresults', 'backup', $component->get_count());
  605 + } else {
  606 + $count_str = get_string('totalcoursesearchresults', 'backup', $component->get_count());
  607 + }
594 608
  609 + $output .= html_writer::tag('div', $count_str, array('class'=>'ics-totalresults'));
595 610 $output .= html_writer::start_tag('div', array('class' => 'ics-results'));
596 611
597 612 $table = new html_table();
@@ -610,6 +625,14 @@ public function render_import_course_search(import_course_search $component) {
610 625 );
611 626 $table->data[] = $row;
612 627 }
  628 + if ($component->has_more_results()) {
  629 + $cell = new html_table_cell(get_string('moreresults', 'backup'));
  630 + $cell->colspan = 3;
  631 + $cell->attributes['class'] = 'notifyproblem';
  632 + $row = new html_table_row(array($cell));
  633 + $row->attributes['class'] = 'rcs-course';
  634 + $table->data[] = $row;
  635 + }
613 636 $output .= html_writer::table($table);
614 637 $output .= html_writer::end_tag('div');
615 638
21 backup/util/ui/restore_ui_components.php
@@ -65,6 +65,11 @@
65 65 * @var array
66 66 */
67 67 private $requiredcapabilities = array();
  68 + /**
  69 + * Indicates if we have more than maxresults found.
  70 + * @var boolean
  71 + */
  72 + private $has_more_results = false;
68 73
69 74 /**
70 75 * Constructor
@@ -177,7 +182,7 @@ public function __construct(array $config=array()) {
177 182 foreach ($this->requiredcapabilities as $cap) {
178 183 $requiredcaps[] = $cap['capability'];
179 184 }
180   - // Iterate while we have records and haven't reached MAXRESULTS
  185 + // Iterate while we have records and haven't reached $this->maxresults.
181 186 while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
182 187 $resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
183 188 foreach ($resultset as $result) {
@@ -188,11 +193,14 @@ public function __construct(array $config=array()) {
188 193 continue;
189 194 }
190 195 }
191   - $this->results[$result->id] = $result;
192   - $this->totalcount++;
193   - if ($this->totalcount >= self::$MAXRESULTS) {
  196 + // Check if we are over the limit.
  197 + if ($this->totalcount+1 > self::$MAXRESULTS) {
  198 + $this->has_more_results = true;
194 199 break;
195 200 }
  201 + // If not, then continue.
  202 + $this->totalcount++;
  203 + $this->results[$result->id] = $result;
196 204 }
197 205 $offs += $blocksz;
198 206 }
@@ -201,7 +209,10 @@ public function __construct(array $config=array()) {
201 209 }
202 210
203 211 final public function has_more_results() {
204   - return $this->get_count() >= self::$MAXRESULTS;
  212 + if ($this->results === null) {
  213 + $this->search();
  214 + }
  215 + return $this->has_more_results;
205 216 }
206 217
207 218 /**
1  lang/en/backup.php
@@ -240,3 +240,4 @@
240 240 $string['setting_keep_groups_and_groupings'] = 'Keep current groups and groupings';
241 241 $string['totalcategorysearchresults'] = 'Total categories: {$a}';
242 242 $string['totalcoursesearchresults'] = 'Total courses: {$a}';
  243 +$string['morecoursesearchresults'] = 'More than {$a} courses found, showing first {$a} results';

0 comments on commit 13c7082

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