Skip to content

Commit

Permalink
MDL-20204 converted paging_bar to new coding style + fixed regression…
Browse files Browse the repository at this point in the history
…s from recent commits
  • Loading branch information
skodak committed Feb 17, 2010
1 parent 28eb401 commit 929d7a8
Show file tree
Hide file tree
Showing 28 changed files with 103 additions and 147 deletions.
3 changes: 1 addition & 2 deletions admin/mnet/access_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@
echo $OUTPUT->table($table);
echo '<p>&nbsp;</p>';
$baseurl = new moodle_url('/admin/mnet/access_control.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage));
$pagingbar = moodle_paging_bar::make($aclcount, $page, $perpage, $baseurl);
echo $OUTPUT->paging_bar($pagingbar);
echo $OUTPUT->paging_bar($aclcount, $page, $perpage, $baseurl);
}


Expand Down
2 changes: 1 addition & 1 deletion admin/report/configlog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}

$baseurl = new moodle_url('index.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage));
echo $OUTPUT->paging_bar(moodle_paging_bar::make($changescount, $page, $perpage, $baseurl));
echo $OUTPUT->paging_bar($changescount, $page, $perpage, $baseurl);

$override = new object();
$override->firstname = 'firstname';
Expand Down
4 changes: 2 additions & 2 deletions admin/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
$strall = get_string('all');

$baseurl = new moodle_url('user.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage));
echo $OUTPUT->paging_bar(moodle_paging_bar::make($usercount, $page, $perpage, $baseurl));
echo $OUTPUT->paging_bar($usercount, $page, $perpage, $baseurl);

flush();

Expand Down Expand Up @@ -299,7 +299,7 @@
}
if (!empty($table)) {
echo $OUTPUT->table($table);
echo $OUTPUT->paging_bar(moodle_paging_bar::make($usercount, $page, $perpage, $baseurl));
echo $OUTPUT->paging_bar($usercount, $page, $perpage, $baseurl);
if (has_capability('moodle/user:create', $sitecontext)) {
echo $OUTPUT->heading('<a href="'.$securewwwroot.'/user/editadvanced.php?id=-1">'.get_string('addnewuser').'</a>');
}
Expand Down
6 changes: 3 additions & 3 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,11 @@ public function print_entries() {
}

$entries = $this->get_entries($start, $limit);
$pagingbar = moodle_paging_bar::make($totalentries, $page, $limit, $this->get_baseurl());
$pagingbar = new paging_bar($totalentries, $page, $limit, $this->get_baseurl());
$pagingbar->pagevar = 'blogpage';
$blogheaders = blog_get_headers();

echo $OUTPUT->paging_bar($pagingbar);
echo $OUTPUT->render($pagingbar);

/* TODO RSS link
if ($CFG->enablerssfeeds) {
Expand Down Expand Up @@ -854,7 +854,7 @@ public function print_entries() {
$count++;
}

echo $OUTPUT->paging_bar($pagingbar);
echo $OUTPUT->render($pagingbar);

if (!$count) {
print '<br /><div style="text-align:center">'. get_string('noentriesyet', 'blog') .'</div><br />';
Expand Down
2 changes: 1 addition & 1 deletion comment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function print_comments($page=0) {
$table->data[] = array($checkbox, $c->username, $c->content, $action);
}
echo $OUTPUT->table($table);
echo $OUTPUT->paging_bar(moodle_paging_bar::make($count, $page, $this->perpage, $CFG->wwwroot.'/comment/index.php'));
echo $OUTPUT->paging_bar($count, $page, $this->perpage, $CFG->wwwroot.'/comment/index.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion course/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
echo $OUTPUT->box_end();

} else {
echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "category.php?id=$category->id&perpage=$perpage"));
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "/mod/course/category.php?id=$category->id&perpage=$perpage");

$strcourses = get_string('courses');
$strselect = get_string('select');
Expand Down
8 changes: 4 additions & 4 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per
print_string("displayingrecords", "", $totalcount);
echo "</div>\n";

echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");

$table = new html_table();
$table->classes = array('logtable','generalbox','boxaligncenter');
Expand Down Expand Up @@ -420,7 +420,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per
}

echo $OUTPUT->table($table);
echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
}


Expand Down Expand Up @@ -457,7 +457,7 @@ function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC",
print_string("displayingrecords", "", $totalcount);
echo "</div>\n";

echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");

echo "<table class=\"logtable\" cellpadding=\"3\" cellspacing=\"0\">\n";
echo "<tr>";
Expand Down Expand Up @@ -524,7 +524,7 @@ function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC",
}
echo "</table>\n";

echo $OUTPUT->paging_bar(moodle_paging_bar::make($totalcount, $page, $perpage, "$url&perpage=$perpage"));
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage");
}


Expand Down
3 changes: 1 addition & 2 deletions course/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@
*/
function print_navigation_bar($totalcount,$page,$perpage,$encodedsearch,$modulelink) {
global $OUTPUT;
$pagingbar = moodle_paging_bar::make($totalcount, $page, $perpage, "search.php?search=$encodedsearch".$modulelink."&perpage=$perpage");
echo $OUTPUT->paging_bar($pagingbar);
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, "search.php?search=$encodedsearch".$modulelink."&perpage=$perpage");

//display
if ($perpage != 99999 && $totalcount > $perpage) {
Expand Down
4 changes: 2 additions & 2 deletions grade/report/grader/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
$studentsperpage = $report->get_pref('studentsperpage');
// Don't use paging if studentsperpage is empty or 0 at course AND site levels
if (!empty($studentsperpage)) {
echo $OUTPUT->paging_bar(moodle_paging_bar::make($numusers, $report->page, $studentsperpage, $report->pbarurl));
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
}

$reporthtml = $report->get_grade_table();
Expand All @@ -176,6 +176,6 @@

// prints paging bar at bottom for large pages
if (!empty($studentsperpage) && $studentsperpage >= 20) {
echo $OUTPUT->paging_bar(moodle_paging_bar::make($numusers, $report->page, $studentsperpage, $report->pbarurl));
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
}
echo $OUTPUT->footer();
4 changes: 2 additions & 2 deletions grade/report/grader/quickedit_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
$studentsperpage = $report->get_pref('studentsperpage');
// Don't use paging if studentsperpage is empty or 0 at course AND site levels
if (!empty($studentsperpage)) {
echo $OUTPUT->paging_bar(moodle_paging_bar::make($numusers, $report->page, $studentsperpage, $report->pbarurl));
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
}

/// TODO Print links to previous - next grade items in this course
Expand All @@ -110,7 +110,7 @@

// prints paging bar at bottom for large pages
if (!empty($studentsperpage) && $studentsperpage >= 20) {
echo $OUTPUT->paging_bar(moodle_paging_bar::make($numusers, $report->page, $studentsperpage, $report->pbarurl));
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
}

echo $OUTPUT->footer();
Expand Down
2 changes: 1 addition & 1 deletion lib/commentlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function get_pagination($page = 0) {
}
if (!empty(self::$nonjs)) {
// used in non-js interface
return $OUTPUT->paging_bar(moodle_paging_bar::make($count, $page, $CFG->commentsperpage, $this->link));
return $OUTPUT->paging_bar($count, $page, $CFG->commentsperpage, $this->link);
} else {
// return ajax paging bar
$str = '';
Expand Down
8 changes: 4 additions & 4 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2971,15 +2971,15 @@ function doc_link($path='', $text='', $iconpath='ignored') {
function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
global $OUTPUT;

debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->paging_bar($pagingbar).');
debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');

if (empty($nocurr)) {
debugging('the feature of parameter $nocurr has been removed from the moodle_paging_bar');
debugging('the feature of parameter $nocurr has been removed from the paging_bar');
}

$pagingbar = moodle_paging_bar::make($totalcount, $page, $perpage, $baseurl);
$pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
$pagingbar->pagevar = $pagevar;
$output = $OUTPUT->paging_bar($pagingbar);
$output = $OUTPUT->render($pagingbar);

if ($return) {
return $output;
Expand Down
56 changes: 26 additions & 30 deletions lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ public function prepare(renderer_base $output, moodle_page $page, $target) {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
class moodle_paging_bar extends html_component {
class paging_bar implements renderable {
/**
* @var int $maxdisplay The maximum number of pagelinks to display
*/
Expand All @@ -1726,7 +1726,7 @@ class moodle_paging_bar extends html_component {
/**
* @var int $page The page you are currently viewing
*/
public $page = 0;
public $page;
/**
* @var int $perpage The number of entries that should be shown per page
*/
Expand All @@ -1739,7 +1739,7 @@ class moodle_paging_bar extends html_component {
/**
* @var string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
*/
public $pagevar = 'page';
public $pagevar;
/**
* @var string $previouslink A HTML link representing the "previous" page
*/
Expand All @@ -1761,32 +1761,46 @@ class moodle_paging_bar extends html_component {
*/
public $pagelinks = array();

/**
* Constructor paging_bar with only the required params.
*
* @param int $totalcount Thetotal number of entries available to be paged through
* @param int $page The page you are currently viewing
* @param int $perpage The number of entries that should be shown per page
* @param string|moodle_url $baseurl url of the current page, the $pagevar parameter is added
* @param string $pagevar name of page parameter that holds the page number
*/
public function __construct($totalcount, $page, $perpage, $baseurl, $pagevar = 'page') {
$this->totalcount = $totalcount;
$this->page = $page;
$this->perpage = $perpage;
$this->baseurl = $baseurl;
$this->pagevar = $pagevar;
}

/**
* @see lib/html_component#prepare()
* @return void
*/
public function prepare(renderer_base $output, moodle_page $page, $target) {
if (!isset($this->totalcount) || is_null($this->totalcount)) {
throw new coding_exception('moodle_paging_bar requires a totalcount value.');
throw new coding_exception('paging_bar requires a totalcount value.');
}
if (!isset($this->page) || is_null($this->page)) {
throw new coding_exception('moodle_paging_bar requires a page value.');
throw new coding_exception('paging_bar requires a page value.');
}
if (empty($this->perpage)) {
throw new coding_exception('moodle_paging_bar requires a perpage value.');
throw new coding_exception('paging_bar requires a perpage value.');
}
if (empty($this->baseurl)) {
throw new coding_exception('moodle_paging_bar requires a baseurl value.');
}
if (!($this->baseurl instanceof moodle_url)) {
$this->baseurl = new moodle_url($this->baseurl);
throw new coding_exception('paging_bar requires a baseurl value.');
}

if ($this->totalcount > $this->perpage) {
$pagenum = $this->page - 1;

if ($this->page > 0) {
$this->previouslink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>$pagenum)), array('class'=>'previous'), get_string('previous'));
$this->previouslink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>$pagenum)), get_string('previous'), array('class'=>'previous'));
}

if ($this->perpage > 0) {
Expand All @@ -1798,7 +1812,7 @@ public function prepare(renderer_base $output, moodle_page $page, $target) {
if ($this->page > 15) {
$startpage = $this->page - 10;

$this->firstlink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>0)), array('class'=>'first'), '1');
$this->firstlink = html_writer::link(new moodle_url($this->baseurl, array($this->pagevar=>0)), '1', array('class'=>'first'));
} else {
$startpage = 0;
}
Expand Down Expand Up @@ -1832,24 +1846,6 @@ public function prepare(renderer_base $output, moodle_page $page, $target) {
}
}
}

/**
* Shortcut for initialising a moodle_paging_bar with only the required params.
*
* @param int $totalcount Thetotal number of entries available to be paged through
* @param int $page The page you are currently viewing
* @param int $perpage The number of entries that should be shown per page
* @param mixed $baseurl If this is a string then it is the url which will be appended with $pagevar, an equals sign and the page number.
* If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
*/
public static function make($totalcount, $page, $perpage, $baseurl) {
$pagingbar = new moodle_paging_bar();
$pagingbar->totalcount = $totalcount;
$pagingbar->page = $page;
$pagingbar->perpage = $perpage;
$pagingbar->baseurl = $baseurl;
return $pagingbar;
}
}


Expand Down
18 changes: 16 additions & 2 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1743,10 +1743,24 @@ public function continue_button($url) {
/**
* Prints a single paging bar to provide access to other pages (usually in a search)
*
* @param string|moodle_url $link The url the button goes to.
* @param int $totalcount Thetotal number of entries available to be paged through
* @param int $page The page you are currently viewing
* @param int $perpage The number of entries that should be shown per page
* @param string|moodle_url $baseurl url of the current page, the $pagevar parameter is added
* @param string $pagevar name of page parameter that holds the page number
* @return string the HTML to output.
*/
public function paging_bar($pagingbar) {
public function paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar = 'page') {
$pb = new paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar);
return $this->render($pb);
}

/**
* Internal implementation of paging bar rendering.
* @param paging_bar $pagingbar
* @return string
*/
protected function render_paging_bar(paging_bar $pagingbar) {
$output = '';
$pagingbar = clone($pagingbar);
$pagingbar->prepare($this, $this->page, $this->target);
Expand Down
32 changes: 0 additions & 32 deletions lib/simpletest/testoutputlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,38 +567,6 @@ public function test_error_text_blank() {
$this->assertEqual('', $html);
}

public function test_paging_bar() {
global $CFG;

$totalcount = 5;
$perpage = 4;
$page = 1;
$baseurl = new moodle_url('/index.php');
$pagevar = 'mypage';

$pagingbar = new moodle_paging_bar();
$pagingbar->totalcount = $totalcount;
$pagingbar->page = $page;
$pagingbar->perpage = $perpage;
$pagingbar->baseurl = $baseurl;
$pagingbar->pagevar = $pagevar;

$originalbar = clone($pagingbar);

$html = $this->renderer->paging_bar($pagingbar);

$this->assert(new ContainsTagWithAttribute('div', 'class', 'paging'), $html);
// the 'Previous' link
$this->assert(new ContainsTagWithAttributes('a', array('class' => 'previous', 'href' => $baseurl->out().'?mypage=0')), $html);
// the numeric link to the previous page '1' (does not have the 'previous' class)
$this->assert(new ContainsTagWithAttributes('a', array('href' => $baseurl->out().'?mypage=0'), array('class' => 'previous')), $html);
// no link to the current page, it's the last page
$expectation = new ContainsTagWithAttributes('a', array('href' => $baseurl->out().'?mypage=1'), array());
$this->assertFalse($expectation->test($html));

// TODO test with more different parameters
}

public function test_html_list() {
$htmllist = new html_list();
$data = array('item1', 'item2', array('item1-1', 'item1-2'));
Expand Down
8 changes: 4 additions & 4 deletions lib/tablelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,9 @@ function finish_html(){
echo $this->download_buttons();
}
if($this->use_pages) {
$pagingbar = moodle_paging_bar::make($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
$pagingbar = new paging_bar($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
$pagingbar->pagevar = $this->request[TABLE_VAR_PAGE];
echo $OUTPUT->paging_bar($pagingbar);
echo $OUTPUT->render($pagingbar);
}
}
}
Expand Down Expand Up @@ -1140,9 +1140,9 @@ function start_html(){

// Paging bar
if($this->use_pages) {
$pagingbar = moodle_paging_bar::make($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
$pagingbar = new paging_bar($this->totalrows, $this->currpage, $this->pagesize, $this->baseurl);
$pagingbar->pagevar = $this->request[TABLE_VAR_PAGE];
echo $OUTPUT->paging_bar($pagingbar);
echo $OUTPUT->render($pagingbar);
}

if(in_array(TABLE_P_TOP, $this->showdownloadbuttonsat)) {
Expand Down
Loading

0 comments on commit 929d7a8

Please sign in to comment.