Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(leaderboard): add default limit setting #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/
yarn-error.log
ui/build/
vendor/
.DS_Store
*.zip
12 changes: 12 additions & 0 deletions classes/form/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public function definition() {
$mform->addHelpButton('identitymode', 'anonymity', 'block_xp');
$mform->disabledIf('identitymode', 'enableladder', 'eq', 0);

$mform->addElement('select', 'defaultlimit', get_string('defaultlimit', 'block_xp'), [
0 => get_string('nodefaultlimit', 'block_xp'),
5 => get_string('limitton', 'block_xp', '5'),
10 => get_string('limitton', 'block_xp', '10'),
20 => get_string('limitton', 'block_xp', '20'),
30 => get_string('limitton', 'block_xp', '30'),
40 => get_string('limitton', 'block_xp', '30'),
50 => get_string('limitton', 'block_xp', '30'),
]);
$mform->addHelpButton('defaultlimit', 'defaultlimit', 'block_xp');
$mform->disabledIf('defaultlimit', 'enableladder', 'eq', 0);

$mform->addElement('select', 'neighbours', get_string('limitparticipants', 'block_xp'), [
0 => get_string('displayeveryone', 'block_xp'),
1 => get_string('displayoneneigbour', 'block_xp'),
Expand Down
1 change: 1 addition & 0 deletions classes/local/config/default_admin_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct() {
'laddercols' => 'xp,progress',
'levelsdata' => '',
'maxactionspertime' => 10,
'defaultlimit' => 0,
'neighbours' => 0,
'rankmode' => course_world_config::RANK_ON,
'timebetweensameactions' => 180,
Expand Down
1 change: 1 addition & 0 deletions classes/local/config/default_course_world_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct() {
'timebetweensameactions' => 180, // Time between similar actions.
'identitymode' => course_world_config::IDENTITY_ON, // Identity mode.
'rankmode' => course_world_config::RANK_ON, // Rank mode.
'defaultlimit' => 0,
'neighbours' => 0, // Number of neighbours to show on ladder, 0 means everyone.
'defaultfilters' => course_world_config::DEFAULT_FILTERS_MISSING, // Flag about the default filters.
'laddercols' => 'xp,progress', // Addditional columns to be displayed on the ladder.
Expand Down
17 changes: 12 additions & 5 deletions classes/local/controller/ladder_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace block_xp\local\controller;

use block_xp\local\sql\limit;
use moodle_exception;

/**
Expand Down Expand Up @@ -84,14 +85,20 @@ protected function get_leaderboard() {
*/
protected function get_table() {
global $USER;
$options = [
'context' => $this->world->get_context(),
'identitymode' => $this->world->get_config()->get('identitymode'),
'rankmode' => $this->world->get_config()->get('rankmode'),
];

if ($this->world->get_config()->get('defaultlimit') != 0) {
$options['fence'] = new limit($this->world->get_config()->get('defaultlimit'));
}

$table = new \block_xp\output\leaderboard_table(
$this->get_leaderboard(),
$this->get_renderer(),
[
'context' => $this->world->get_context(),
'identitymode' => $this->world->get_config()->get('identitymode'),
'rankmode' => $this->world->get_config()->get('rankmode'),
],
$options,
$USER->id
);
$table->show_pagesize_selector(true);
Expand Down
14 changes: 14 additions & 0 deletions classes/local/setting/default_settings_maker.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ protected function get_default_settings() {
]
));

// Default limit.
$settings[] = (new admin_setting_configselect('block_xp/defaultlimit',
get_string('defaultlimit', 'block_xp'), get_string('defaultlimit_help', 'block_xp'),
$defaults['neighbours'], [
0 => get_string('nodefaultlimit', 'block_xp'),
5 => get_string('limitton', 'block_xp', '5'),
10 => get_string('limitton', 'block_xp', '10'),
20 => get_string('limitton', 'block_xp', '20'),
30 => get_string('limitton', 'block_xp', '30'),
40 => get_string('limitton', 'block_xp', '30'),
50 => get_string('limitton', 'block_xp', '30'),
]
));

// Neighbours.
$settings[] = (new admin_setting_configselect('block_xp/neighbours',
get_string('limitparticipants', 'block_xp'), get_string('limitparticipants_help', 'block_xp'),
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<FIELD NAME="timebetweensameactions" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="180" SEQUENCE="false" COMMENT="Time required between identical actions"/>
<FIELD NAME="identitymode" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="rankmode" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="defaultlimit" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="neighbours" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="defaultfilters" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Flag for the default filters. Defaults to 1, the legacy value (DEFAULT_FILTERS_STATIC)."/>
<FIELD NAME="laddercols" TYPE="char" LENGTH="255" NOTNULL="true" DEFAULT="xp,progress" SEQUENCE="false" COMMENT="The additional columns to display in the ladder. Comma-separated list."/>
Expand Down
12 changes: 12 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,5 +562,17 @@ function xmldb_block_xp_upgrade($oldversion) {
upgrade_block_savepoint(true, 2023080702, 'xp');
}

if ($oldversion < 2023100804) {
// Define field neighbours to be added to block_xp_config.
$table = new xmldb_table('block_xp_config');
$field = new xmldb_field('defaultlimit', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', null);

if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Xp savepoint reached.
upgrade_block_savepoint(true, 2023100805, 'xp');
}

return true;
}
4 changes: 4 additions & 0 deletions lang/en/block_xp.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
$string['dismissnotice'] = 'Dismiss notice';
$string['displayeveryone'] = 'Display everyone';
$string['displaynneighbours'] = 'Display {$a} neighbours';
$string['defaultlimit'] = 'Default limit';
$string['defaultlimit_help'] = 'This setting controls a default limit of students to display in the main leaderboard. The limit is overridden setting the neighbour limit. Also, note that this setting does not apply on the [xpladder] shortcode.';
$string['nodefaultlimit'] = 'No default limit (display everyone)';
$string['limitton'] = 'Limit to {$a} students';
$string['displayoneneigbour'] = 'Display one neighbour';
$string['displayparticipantsidentity'] = 'Display participants identity';
$string['displayrank'] = 'Display rank';
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023100803;
$plugin->version = 2023100804;
$plugin->requires = 2017111300; // Moodle 3.4.0.
$plugin->component = 'block_xp';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '3.15.2';
$plugin->release = '3.15.3';
$plugin->supported = [34, 403];