Frage

We are trying to apply pagination concept on Course Category list page in our MOODLE website and we have got success in it. But while displaying it shows the same course on every page. We are able to set how much number of topics/categories should be shown on each page, and same number of categories are shown. But each page shows the same topic. Please help if somebody has applied pagination into their MOODLE website.

War es hilfreich?

Lösung 2

The list of courses within a category are already paginated.

So I'm guessing you mean the list of categories? You can use a flexible table with pagination

http://docs.moodle.org/dev/lib/tablelib.php

You can also display one section of a course by going to course -> edit settings -> Course format -> Course Layout -> show one section per page.

But if you want to display some of the sections - not just one - then you probably need to have a look at designing a course format

http://docs.moodle.org/dev/Course_formats

Andere Tipps

There is no generic way to add pagination to different pages in Moodle - there is a general '$OUTPUT->paging_bar' function, which will generate the output for a paging bar, but it is then up to your own code to decide what to do with the 'page' parameter that is then passed on to the PHP script.

Usually the code looks something like this:

$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT);
...
$count = $DB->count_records_sql('Some SQL query to count the number of results');
$start = $page * $perpage;
if ($start > $count) {
    $page = 0;
    $start = 0;
}
$results = $DB->get_records_sql('Some SQL query to get the results', array(parameters for query), $start, $perpage); // Start at result '$start' and return '$perpage' results.

Alternatively, if this is not possible, you can get all the results and then use array_slice:

$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT);
...
$results = $DB->get_records_sql('Some SQL query to get the results', array(params for query));
$start = $page * $perpage;
if ($start > count($results)) {
    $page = 0;
    $start = 0;
}
$results = array_slice($results, $start, $perpage, true);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top