Skip to content

Commit 024f75e

Browse files
authored
feat: User setting "default capability app view" (#102)
preliminary work for EDUPL-15
1 parent 5375626 commit 024f75e

File tree

7 files changed

+95
-5
lines changed

7 files changed

+95
-5
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
// This file is part of the local_lbplanner.
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* capability flag
19+
*
20+
* @package local_lbplanner
21+
* @subpackage enums
22+
* @copyright 2025 Pallasys
23+
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
24+
*/
25+
26+
namespace local_lbplanner\enums;
27+
28+
// TODO: revert to native enums once we migrate to php8.
29+
30+
use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG};
31+
32+
/**
33+
* Bitmappable flags for capabilities a user can have.
34+
* Also includes 0 for the lack of any capabilities.
35+
*/
36+
class CAPABILITY_FLAG_ORNONE extends CAPABILITY_FLAG {
37+
/**
38+
* Absence of any CAPABILITY.
39+
*/
40+
const NONE = 0;
41+
42+
/**
43+
* matches a flag to its capability string
44+
* @param int $num the bitmappable flag
45+
* @return string the capability string
46+
* @throws \coding_exception if $num === 0 (not an actual capability)
47+
* @link CAPABILITY
48+
*/
49+
public static function to_capability(int $num): string {
50+
if ($num === 0) { // TODO: put in translation strings.
51+
throw new \coding_exception('0 means the absence of capabilities, and thus cannot be converted to a capability');
52+
}
53+
return parent::to_capability($num);
54+
}
55+
}

lbplanner/classes/helpers/user_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function get_user(int $userid): user {
7373
}
7474

7575
// Register user if not found.
76-
$eduplanneruser = new user(0, $userid, 'default', 'none', 1, false, true, null, null, null);
76+
$eduplanneruser = new user(0, $userid, 'default', 'none', 1, false, true, 0, null, null, null);
7777
$epid = $DB->insert_record(self::EDUPLANNER_USER_TABLE, $eduplanneruser->prepare_for_db());
7878
$eduplanneruser->set_fresh($epid);
7979

lbplanner/classes/model/user.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use core\context\system as context_system;
2929
use core_external\{external_single_structure, external_value};
3030
use user_picture;
31-
use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG, KANBANCOL_TYPE_ORNONE};
31+
use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG, KANBANCOL_TYPE_ORNONE, CAPABILITY_FLAG_ORNONE};
3232
use local_lbplanner\helpers\{plan_helper, user_helper};
3333

3434
/**
@@ -70,6 +70,12 @@ class user {
7070
*/
7171
public bool $showcolumncolors;
7272

73+
/**
74+
* @var ?int $defaultcapabilityview Which capability's view to show in app per default.
75+
* @see CAPABILITY_FLAG_ORNONE
76+
*/
77+
public ?int $defaultcapabilityview;
78+
7379
/**
7480
* @var ?string $automovecompletedtasks what kanban column to move completed tasks to (null → don't move)
7581
* @see KANBANCOL_TYPE
@@ -117,6 +123,7 @@ class user {
117123
'displaytaskcount',
118124
'ekenabled',
119125
'showcolumncolors',
126+
'defaultcapabilityview',
120127
'automovecompletedtasks',
121128
'automovesubmittedtasks',
122129
'automoveoverduetasks',
@@ -131,6 +138,7 @@ class user {
131138
* @param bool $displaytaskcount user's display task count
132139
* @param bool $ekenabled whether the user wants to see EK modules
133140
* @param bool $showcolumncolors whether column colors should show in kanban board
141+
* @param ?int $defaultcapabilityview Which capability's view to show in app per default
134142
* @param ?string $automovecompletedtasks what kanban column to move completed tasks to (null → don't move)
135143
* @param ?string $automovesubmittedtasks what kanban column to move submitted tasks to (null → don't move)
136144
* @param ?string $automoveoverduetasks what kanban column to move overdue tasks to (null → don't move)
@@ -143,6 +151,7 @@ public function __construct(
143151
bool $displaytaskcount,
144152
bool $ekenabled,
145153
bool $showcolumncolors,
154+
int $defaultcapabilityview,
146155
?string $automovecompletedtasks,
147156
?string $automovesubmittedtasks,
148157
?string $automoveoverduetasks,
@@ -309,7 +318,7 @@ public function get_capabilitybitmask(): int {
309318
* Prepares data for the DB endpoint.
310319
* doesn't set ID if it's 0
311320
*
312-
* @return object a representation of this course and its data
321+
* @return object a representation of this user and its data
313322
*/
314323
public function prepare_for_db(): object {
315324
$obj = new \stdClass();
@@ -388,6 +397,7 @@ public function prepare_for_api(): array {
388397
'colorblindness' => $this->colorblindness,
389398
'displaytaskcount' => $this->displaytaskcount,
390399
'showcolumncolors' => $this->showcolumncolors,
400+
'defaultcapabilityview' => $this->defaultcapabilityview,
391401
'automovecompletedtasks' => $this->automovecompletedtasks ?? KANBANCOL_TYPE_ORNONE::NONE,
392402
'automovesubmittedtasks' => $this->automovesubmittedtasks ?? KANBANCOL_TYPE_ORNONE::NONE,
393403
'automoveoverduetasks' => $this->automoveoverduetasks ?? KANBANCOL_TYPE_ORNONE::NONE,
@@ -415,6 +425,10 @@ public static function api_structure(): external_single_structure {
415425
'colorblindness' => new external_value(PARAM_TEXT, 'The colorblindness of the user'),
416426
'displaytaskcount' => new external_value(PARAM_BOOL, 'Whether the user has the taskcount enabled'),
417427
'showcolumncolors' => new external_value(PARAM_BOOL, 'Whether column colors should show in kanban board'),
428+
'defaultcapabilityview' => new external_value(
429+
PARAM_INT,
430+
'Which capability\'s view to show in app per default ' . CAPABILITY_FLAG_ORNONE::format()
431+
),
418432
'automovecompletedtasks' => new external_value(
419433
PARAM_TEXT,
420434
'The kanban column to move a task to if completed ' . KANBANCOL_TYPE_ORNONE::format()

lbplanner/db/install.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<FIELD NAME="displaytaskcount" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="The display task count the user has selected in the app." />
1010
<FIELD NAME="ekenabled" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Whether the user wants to see EK modules"/>
1111
<FIELD NAME="showcolumncolors" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Whether column colors should show in kanban board"/>
12+
<FIELD NAME="defaultcapabilityview" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Which capability's view to show in app per default"/>
1213
<FIELD NAME="automovecompletedtasks" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The kanban column to move a task to if completed"/>
1314
<FIELD NAME="automovesubmittedtasks" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The kanban column to move a task to if submitted"/>
1415
<FIELD NAME="automoveoverduetasks" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The kanban column to move a task to if overdue"/>

lbplanner/db/upgrade.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,12 @@ function xmldb_local_lbplanner_upgrade($oldversion): bool {
104104

105105
upgrade_plugin_savepoint(true, 202510090000, 'local', 'lbplanner');
106106
}
107+
if ($oldversion < 202511210000) {
108+
$table = new xmldb_table('local_lbplanner_users');
109+
$f5 = new xmldb_field('defaultcapabilityview', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, false, 0, 'showcolumncolors');
110+
$dbman->add_field($table, $f5);
111+
112+
upgrade_plugin_savepoint(true, 202511210000, 'local', 'lbplanner');
113+
}
107114
return true;
108115
}

lbplanner/services/user/update_user.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use dml_exception;
2323
use local_lbplanner\helpers\user_helper;
2424
use local_lbplanner\model\user;
25-
use local_lbplanner\enums\KANBANCOL_TYPE_ORNONE;
25+
use local_lbplanner\enums\{KANBANCOL_TYPE_ORNONE, CAPABILITY_FLAG_ORNONE};
2626

2727
/**
2828
* Update current user settings. null values or unset parameters are left unmodified.
@@ -74,6 +74,13 @@ public static function update_user_parameters(): external_function_parameters {
7474
null,
7575
NULL_ALLOWED
7676
),
77+
'defaultcapabilityview' => new external_value(
78+
PARAM_INT,
79+
'Which capability\'s view to show in app per default ' . CAPABILITY_FLAG_ORNONE::format(),
80+
VALUE_DEFAULT,
81+
null,
82+
NULL_ALLOWED
83+
),
7784
'automovecompletedtasks' => new external_value(
7885
PARAM_TEXT,
7986
'The kanban column to move a task to if completed ' . KANBANCOL_TYPE_ORNONE::format(),
@@ -105,6 +112,7 @@ public static function update_user_parameters(): external_function_parameters {
105112
* @param ?bool $displaytaskcount The displaytaskcount the user has selected
106113
* @param ?bool $ekenabled whether the user wants to see EK modules
107114
* @param ?bool $showcolumncolors whether column colors should show in kanban board
115+
* @param ?int $defaultcapabilityview Which capability's view to show in app per default
108116
* @param ?string $automovecompletedtasks what kanban column to move completed tasks to ("" → don't move)
109117
* @param ?string $automovesubmittedtasks what kanban column to move submitted tasks to ("" → don't move)
110118
* @param ?string $automoveoverduetasks what kanban column to move overdue tasks to ("" → don't move)
@@ -119,6 +127,7 @@ public static function update_user(
119127
?bool $displaytaskcount,
120128
?bool $ekenabled,
121129
?bool $showcolumncolors,
130+
?int $defaultcapabilityview,
122131
?string $automovecompletedtasks,
123132
?string $automovesubmittedtasks,
124133
?string $automoveoverduetasks,
@@ -133,6 +142,7 @@ public static function update_user(
133142
'displaytaskcount' => $displaytaskcount,
134143
'ekenabled' => $ekenabled,
135144
'showcolumncolors' => $showcolumncolors,
145+
'defaultcapabilityview' => $defaultcapabilityview,
136146
'automovecompletedtasks' => $automovecompletedtasks,
137147
'automovesubmittedtasks' => $automovesubmittedtasks,
138148
'automoveoverduetasks' => $automoveoverduetasks,
@@ -159,6 +169,9 @@ public static function update_user(
159169
if ($showcolumncolors !== null) {
160170
$user->showcolumncolors = $showcolumncolors;
161171
}
172+
if ($defaultcapabilityview !== null) {
173+
$user->defaultcapabilityview = CAPABILITY_FLAG_ORNONE::from($defaultcapabilityview);
174+
}
162175
foreach (['automovecompletedtasks', 'automovesubmittedtasks', 'automoveoverduetasks'] as $propname) {
163176
if ($$propname !== null) {
164177
if ($$propname === KANBANCOL_TYPE_ORNONE::NONE) {

lbplanner/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
$plugin->maturity = MATURITY_BETA;
3131
$plugin->component = 'local_lbplanner';
3232
$plugin->release = '1.1.11';
33-
$plugin->version = 202510190000;
33+
$plugin->version = 202511210000;
3434
$plugin->dependencies = [
3535
// Depend upon version 2023110600 of local_modcustomfields.
3636
'local_modcustomfields' => 2023110600,

0 commit comments

Comments
 (0)