Skip to content

Commit

Permalink
add method to generate another demo table (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
semteacher committed Feb 1, 2025
1 parent a59d00d commit d1eb1d9
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions tests/base_dataprovider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
use local_wunderbyte_table\filters\types\datepicker;
use local_wunderbyte_table\filters\types\standardfilter;
use local_wunderbyte_table\filters\types\hierarchicalfilter;
use local_wunderbyte_table\filters\types\intrange;
use local_wunderbyte_table\filters\types\weekdays;
use local_wunderbyte_table\local\sortables\types\standardsortable;
use moodle_exception;

Expand Down Expand Up @@ -253,7 +255,7 @@ public function test_dataprovider(string $tablecallback, array $coursedata, arra
* @return wunderbyte_table
*
*/
public function create_demo2_table() {
public function create_demo_table() {
$table = new demo_table('demotable_1');

$columns = [
Expand All @@ -272,6 +274,61 @@ public function create_demo2_table() {
$table->define_fulltextsearchcolumns(['fullname', 'shortname']);
$table->define_sortablecolumns($columns);

$intrangefilter = new intrange('fullname', "Range of numbers given in course fullname");
$table->add_filter($intrangefilter);

$weekdaysfilter = new weekdays(
'startdate',
get_string('startdate'),
'enddate',
get_string('enddate')
);
$table->add_filter($weekdaysfilter);

$standardfilter = new standardfilter('shortname', 'shortname');
$table->add_filter($standardfilter);

$table->set_filter_sql('*', "(SELECT * FROM {course} ORDER BY id ASC LIMIT 112) as s1", 'id > 1', '');

$table->pageable(true);

$table->pagesize = 20;

$table->stickyheader = false;
$table->showcountlabel = true;
$table->showdownloadbutton = true;
$table->showreloadbutton = true;
$table->showrowcountselect = true;
$table->filteronloadinactive = true;

return $table;
}

/**
* Function to create and return wunderbyte table class.
*
* @return wunderbyte_table
*
*/
public function create_demo2_table() {
$table = new demo_table('demotable_2');

$columns = [
'id' => get_string('id', 'local_wunderbyte_table'),
'fullname' => get_string('fullname'),
'shortname' => get_string('shortname'),
'action' => get_string('action'),
'startdate' => get_string('startdate'),
'enddate' => get_string('enddate'),
];

// Number of items must be equal.
$table->define_headers(array_values($columns));
$table->define_columns(array_keys($columns));

$table->define_fulltextsearchcolumns(['fullname', 'shortname']);
$table->define_sortablecolumns($columns);

$standardsortable = new standardsortable(
'enrolledusers',
'enrolledusers'
Expand Down Expand Up @@ -521,7 +578,7 @@ public static function wb_table_common_settings_provider(): array {
$standardcourses = [
[
'coursestocreate' => 10,
'fullname' => 'Test Course',
// No fullname, so default 'Test Course xx' will be applied.
'users' => $standardusers,
],
[
Expand Down

0 comments on commit d1eb1d9

Please sign in to comment.