Skip to content
Merged
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
55 changes: 55 additions & 0 deletions lbplanner/classes/enums/CAPABILITY_FLAG_ORNONE.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
// This file is part of the local_lbplanner.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* capability flag
*
* @package local_lbplanner
* @subpackage enums
* @copyright 2025 Pallasys
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/

namespace local_lbplanner\enums;

// TODO: revert to native enums once we migrate to php8.

use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG};

/**
* Bitmappable flags for capabilities a user can have.
* Also includes 0 for the lack of any capabilities.
*/
class CAPABILITY_FLAG_ORNONE extends CAPABILITY_FLAG {
/**
* Absence of any CAPABILITY.
*/
const NONE = 0;

/**
* matches a flag to its capability string
* @param int $num the bitmappable flag
* @return string the capability string
* @throws \coding_exception if $num === 0 (not an actual capability)
* @link CAPABILITY
*/
public static function to_capability(int $num): string {
if ($num === 0) { // TODO: put in translation strings.
throw new \coding_exception('0 means the absence of capabilities, and thus cannot be converted to a capability');
}
return parent::to_capability($num);
}
}
2 changes: 1 addition & 1 deletion lbplanner/classes/helpers/user_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function get_user(int $userid): user {
}

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

Expand Down
18 changes: 16 additions & 2 deletions lbplanner/classes/model/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use core\context\system as context_system;
use core_external\{external_single_structure, external_value};
use user_picture;
use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG, KANBANCOL_TYPE_ORNONE};
use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG, KANBANCOL_TYPE_ORNONE, CAPABILITY_FLAG_ORNONE};
use local_lbplanner\helpers\{plan_helper, user_helper};

/**
Expand Down Expand Up @@ -70,6 +70,12 @@ class user {
*/
public bool $showcolumncolors;

/**
* @var ?int $defaultcapabilityview Which capability's view to show in app per default.
* @see CAPABILITY_FLAG_ORNONE
*/
public ?int $defaultcapabilityview;

/**
* @var ?string $automovecompletedtasks what kanban column to move completed tasks to (null → don't move)
* @see KANBANCOL_TYPE
Expand Down Expand Up @@ -117,6 +123,7 @@ class user {
'displaytaskcount',
'ekenabled',
'showcolumncolors',
'defaultcapabilityview',
'automovecompletedtasks',
'automovesubmittedtasks',
'automoveoverduetasks',
Expand All @@ -131,6 +138,7 @@ class user {
* @param bool $displaytaskcount user's display task count
* @param bool $ekenabled whether the user wants to see EK modules
* @param bool $showcolumncolors whether column colors should show in kanban board
* @param ?int $defaultcapabilityview Which capability's view to show in app per default
* @param ?string $automovecompletedtasks what kanban column to move completed tasks to (null → don't move)
* @param ?string $automovesubmittedtasks what kanban column to move submitted tasks to (null → don't move)
* @param ?string $automoveoverduetasks what kanban column to move overdue tasks to (null → don't move)
Expand All @@ -143,6 +151,7 @@ public function __construct(
bool $displaytaskcount,
bool $ekenabled,
bool $showcolumncolors,
int $defaultcapabilityview,
?string $automovecompletedtasks,
?string $automovesubmittedtasks,
?string $automoveoverduetasks,
Expand Down Expand Up @@ -309,7 +318,7 @@ public function get_capabilitybitmask(): int {
* Prepares data for the DB endpoint.
* doesn't set ID if it's 0
*
* @return object a representation of this course and its data
* @return object a representation of this user and its data
*/
public function prepare_for_db(): object {
$obj = new \stdClass();
Expand Down Expand Up @@ -388,6 +397,7 @@ public function prepare_for_api(): array {
'colorblindness' => $this->colorblindness,
'displaytaskcount' => $this->displaytaskcount,
'showcolumncolors' => $this->showcolumncolors,
'defaultcapabilityview' => $this->defaultcapabilityview,
'automovecompletedtasks' => $this->automovecompletedtasks ?? KANBANCOL_TYPE_ORNONE::NONE,
'automovesubmittedtasks' => $this->automovesubmittedtasks ?? KANBANCOL_TYPE_ORNONE::NONE,
'automoveoverduetasks' => $this->automoveoverduetasks ?? KANBANCOL_TYPE_ORNONE::NONE,
Expand Down Expand Up @@ -415,6 +425,10 @@ public static function api_structure(): external_single_structure {
'colorblindness' => new external_value(PARAM_TEXT, 'The colorblindness of the user'),
'displaytaskcount' => new external_value(PARAM_BOOL, 'Whether the user has the taskcount enabled'),
'showcolumncolors' => new external_value(PARAM_BOOL, 'Whether column colors should show in kanban board'),
'defaultcapabilityview' => new external_value(
PARAM_INT,
'Which capability\'s view to show in app per default ' . CAPABILITY_FLAG_ORNONE::format()
),
'automovecompletedtasks' => new external_value(
PARAM_TEXT,
'The kanban column to move a task to if completed ' . KANBANCOL_TYPE_ORNONE::format()
Expand Down
1 change: 1 addition & 0 deletions lbplanner/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<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." />
<FIELD NAME="ekenabled" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Whether the user wants to see EK modules"/>
<FIELD NAME="showcolumncolors" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Whether column colors should show in kanban board"/>
<FIELD NAME="defaultcapabilityview" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" DEFAULT="0" COMMENT="Which capability's view to show in app per default"/>
<FIELD NAME="automovecompletedtasks" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The kanban column to move a task to if completed"/>
<FIELD NAME="automovesubmittedtasks" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The kanban column to move a task to if submitted"/>
<FIELD NAME="automoveoverduetasks" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="The kanban column to move a task to if overdue"/>
Expand Down
7 changes: 7 additions & 0 deletions lbplanner/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,12 @@ function xmldb_local_lbplanner_upgrade($oldversion): bool {

upgrade_plugin_savepoint(true, 202510090000, 'local', 'lbplanner');
}
if ($oldversion < 202511210000) {
$table = new xmldb_table('local_lbplanner_users');
$f5 = new xmldb_field('defaultcapabilityview', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, false, 0, 'showcolumncolors');
$dbman->add_field($table, $f5);

upgrade_plugin_savepoint(true, 202511210000, 'local', 'lbplanner');
}
return true;
}
15 changes: 14 additions & 1 deletion lbplanner/services/user/update_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use dml_exception;
use local_lbplanner\helpers\user_helper;
use local_lbplanner\model\user;
use local_lbplanner\enums\KANBANCOL_TYPE_ORNONE;
use local_lbplanner\enums\{KANBANCOL_TYPE_ORNONE, CAPABILITY_FLAG_ORNONE};

/**
* Update current user settings. null values or unset parameters are left unmodified.
Expand Down Expand Up @@ -74,6 +74,13 @@ public static function update_user_parameters(): external_function_parameters {
null,
NULL_ALLOWED
),
'defaultcapabilityview' => new external_value(
PARAM_INT,
'Which capability\'s view to show in app per default ' . CAPABILITY_FLAG_ORNONE::format(),
VALUE_DEFAULT,
null,
NULL_ALLOWED
),
'automovecompletedtasks' => new external_value(
PARAM_TEXT,
'The kanban column to move a task to if completed ' . KANBANCOL_TYPE_ORNONE::format(),
Expand Down Expand Up @@ -105,6 +112,7 @@ public static function update_user_parameters(): external_function_parameters {
* @param ?bool $displaytaskcount The displaytaskcount the user has selected
* @param ?bool $ekenabled whether the user wants to see EK modules
* @param ?bool $showcolumncolors whether column colors should show in kanban board
* @param ?int $defaultcapabilityview Which capability's view to show in app per default
* @param ?string $automovecompletedtasks what kanban column to move completed tasks to ("" → don't move)
* @param ?string $automovesubmittedtasks what kanban column to move submitted tasks to ("" → don't move)
* @param ?string $automoveoverduetasks what kanban column to move overdue tasks to ("" → don't move)
Expand All @@ -119,6 +127,7 @@ public static function update_user(
?bool $displaytaskcount,
?bool $ekenabled,
?bool $showcolumncolors,
?int $defaultcapabilityview,
?string $automovecompletedtasks,
?string $automovesubmittedtasks,
?string $automoveoverduetasks,
Expand All @@ -133,6 +142,7 @@ public static function update_user(
'displaytaskcount' => $displaytaskcount,
'ekenabled' => $ekenabled,
'showcolumncolors' => $showcolumncolors,
'defaultcapabilityview' => $defaultcapabilityview,
'automovecompletedtasks' => $automovecompletedtasks,
'automovesubmittedtasks' => $automovesubmittedtasks,
'automoveoverduetasks' => $automoveoverduetasks,
Expand All @@ -159,6 +169,9 @@ public static function update_user(
if ($showcolumncolors !== null) {
$user->showcolumncolors = $showcolumncolors;
}
if ($defaultcapabilityview !== null) {
$user->defaultcapabilityview = CAPABILITY_FLAG_ORNONE::from($defaultcapabilityview);
}
foreach (['automovecompletedtasks', 'automovesubmittedtasks', 'automoveoverduetasks'] as $propname) {
if ($$propname !== null) {
if ($$propname === KANBANCOL_TYPE_ORNONE::NONE) {
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
$plugin->maturity = MATURITY_BETA;
$plugin->component = 'local_lbplanner';
$plugin->release = '1.1.11';
$plugin->version = 202510190000;
$plugin->version = 202511210000;
$plugin->dependencies = [
// Depend upon version 2023110600 of local_modcustomfields.
'local_modcustomfields' => 2023110600,
Expand Down
Loading