Skip to content

Commit

Permalink
MDL-35603 - Backup - Course import/restore max results
Browse files Browse the repository at this point in the history
* Unified UI for import and restore course search
  • Loading branch information
rlorenzo committed Mar 28, 2013
1 parent fe33d24 commit 1936dbe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
25 changes: 24 additions & 1 deletion backup/util/ui/renderer.php
Expand Up @@ -521,6 +521,15 @@ public function render_restore_course_search(restore_course_search $component) {
$url = $component->get_url();

$output = html_writer::start_tag('div', array('class' => 'restore-course-search'));

$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'=>'rcs-totalresults'));
$output .= html_writer::start_tag('div', array('class' => 'rcs-results'));

$table = new html_table();
Expand Down Expand Up @@ -590,8 +599,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 +625,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
21 changes: 16 additions & 5 deletions backup/util/ui/restore_ui_components.php
Expand Up @@ -65,6 +65,11 @@ abstract class restore_search_base implements renderable {
* @var array
*/
private $requiredcapabilities = array();
/**
* Indicates if we have more than maxresults found.
* @var boolean
*/
private $has_more_results = false;

/**
* Constructor
Expand Down Expand Up @@ -177,7 +182,7 @@ final public function search() {
foreach ($this->requiredcapabilities as $cap) {
$requiredcaps[] = $cap['capability'];
}
// Iterate while we have records and haven't reached MAXRESULTS
// Iterate while we have records and haven't reached $this->maxresults.
while ($totalcourses > $offs and $this->totalcount < self::$MAXRESULTS) {
$resultset = $DB->get_records_sql($sql, $params, $offs, $blocksz);
foreach ($resultset as $result) {
Expand All @@ -189,11 +194,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 > self::$MAXRESULTS) {
$this->has_more_results = true;
break;
}
// If not, then continue.
$this->totalcount++;
$this->results[$result->id] = $result;
}
$offs += $blocksz;
}
Expand All @@ -202,7 +210,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
1 change: 1 addition & 0 deletions lang/en/backup.php
Expand Up @@ -247,3 +247,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 1936dbe

Please sign in to comment.