Skip to content
Merged
4 changes: 2 additions & 2 deletions .github/workflows/gha.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.4']
moodle-branch: ['MOODLE_401_STABLE']
php: ['8.1']
moodle-branch: ['MOODLE_404_STABLE']
database: [mariadb]

steps:
Expand Down
2 changes: 0 additions & 2 deletions lbplanner/classes/helpers/plan_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public static function get_plan(int $planid): array {
return [
'name' => $plan->name,
'planid' => $planid,
'enableek' => $plan->enableek,
'deadlines' => self::get_deadlines($planid),
'members' => $members,
];
Expand All @@ -200,7 +199,6 @@ public static function plan_structure(): external_single_structure {
[
'name' => new external_value(PARAM_TEXT, 'Name of the plan'),
'planid' => new external_value(PARAM_INT, 'ID of the plan'),
'enableek' => new external_value(PARAM_BOOL, 'Whether EK is enabled'),
'deadlines' => new external_multiple_structure(
new external_single_structure(
[
Expand Down
37 changes: 17 additions & 20 deletions lbplanner/classes/model/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

namespace local_lbplanner\model;

use coding_exception;
use core\context\system as context_system;
use core_external\{external_single_structure, external_value};
use user_picture;
Expand Down Expand Up @@ -60,9 +59,14 @@ class user {
public string $colorblindness;

/**
* @var int $displaytaskcount The display task count the user has selected in the app.
* @var bool $displaytaskcount The display task count the user has selected in the app.
*/
public int $displaytaskcount;
public bool $displaytaskcount;

/**
* @var bool $ekenabled Whether the user wants to see EK or not.
*/
public bool $ekenabled;

/**
* @var ?\stdClass $mdluser the cached moodle user
Expand Down Expand Up @@ -90,21 +94,24 @@ class user {
* @param int $mdlid ID of the moodle user
* @param string $theme user-chosen theme
* @param string $colorblindness user's colorblindness
* @param int $displaytaskcount user's display task count
* @param bool $displaytaskcount user's display task count
* @param bool $ekenabled whether the user wants to see EK modules
*/
public function __construct(
int $lbpid,
int $mdlid,
string $theme,
string $colorblindness,
int $displaytaskcount
bool $displaytaskcount,
bool $ekenabled = false
) {
global $USER;
$this->lbpid = $lbpid;
$this->mdlid = $mdlid;
$this->set_theme($theme);
$this->set_colorblindness($colorblindness);
$this->set_displaytaskcount($displaytaskcount);
$this->displaytaskcount = $displaytaskcount;
$this->ekenabled = $ekenabled;
$this->planid = null;
$this->pfp = null;
$this->capabilitybitmask = null;
Expand All @@ -123,7 +130,7 @@ public function __construct(
* @return user a representation of this user and its data
*/
public static function from_db(object $obj): self {
return new self($obj->id, $obj->userid, $obj->theme, $obj->colorblindness, $obj->displaytaskcount);
return new self($obj->id, $obj->userid, $obj->theme, $obj->colorblindness, $obj->displaytaskcount, $obj->ekenabled);
}

/**
Expand All @@ -137,18 +144,6 @@ public function set_fresh(int $lbpid): void {
$this->lbpid = $lbpid;
}

/**
* Sets display task count
* @param int $count display task count
* @throws \coding_exception if $count <= 0
*/
public function set_displaytaskcount(int $count): void {
if ($count <= 0) {
throw new \coding_exception('User\'s Display Task Count cannot be <= 0');
}
$this->displaytaskcount = $count;
}

/**
* Sets colorblindness
* @param string $cbn colorblindness
Expand Down Expand Up @@ -323,6 +318,7 @@ public function prepare_for_api(): array {
$this->prepare_for_api_short(),
[
'theme' => $this->theme,
'ekenabled' => $this->ekenabled,
'planid' => $this->get_planid(),
'colorblindness' => $this->colorblindness,
'displaytaskcount' => $this->displaytaskcount,
Expand All @@ -344,10 +340,11 @@ public static function api_structure(): external_single_structure {
'firstname' => new external_value(PARAM_TEXT, 'The firstname of the user'),
'lastname' => new external_value(PARAM_TEXT, 'The lastname of the user'),
'theme' => new external_value(PARAM_TEXT, 'The theme the user has selected'),
'ekenabled' => new external_value(PARAM_BOOL, 'Whether the user wants to see EK modules'),
'profileimageurl' => new external_value(PARAM_URL, 'The url of the profile image'),
'planid' => new external_value(PARAM_INT, 'The id of the plan the user is assigned to'),
'colorblindness' => new external_value(PARAM_TEXT, 'The colorblindness of the user'),
'displaytaskcount' => new external_value(PARAM_INT, 'If the user has the taskcount-enabled 1-yes 0-no'),
'displaytaskcount' => new external_value(PARAM_BOOL, 'Whether the user has the taskcount enabled'),
'capabilities' => new external_value(PARAM_INT, 'The capabilities of the user represented as a bitmask value'),
'vintage' => new external_value(PARAM_TEXT, 'The vintage of the user', VALUE_DEFAULT),
'email' => new external_value(PARAM_TEXT, 'The email address of the user'),
Expand Down
4 changes: 2 additions & 2 deletions lbplanner/db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<FIELD NAME="theme" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the theme the user has selected in the app." />
<FIELD NAME="colorblindness" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The colorblindness the user has selected in the app." />
<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"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
Expand Down Expand Up @@ -62,7 +63,6 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="name" TYPE="text" NOTNULL="true" SEQUENCE="false" />
<FIELD NAME="enableek" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
Expand Down Expand Up @@ -101,7 +101,7 @@
<FIELD NAME="duration" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="The duration of the slot in school units"/>
<FIELD NAME="weekday" TYPE="int" LENGTH="1" NOTNULL="true" SEQUENCE="false" COMMENT="The day of the week, starting with monday at 1"/>
<FIELD NAME="room" TYPE="char" LENGTH="7" NOTNULL="true" SEQUENCE="false" COMMENT="The name of the associated room"/>
<FIELD NAME="size" TYPE="int" LENGTH="3" SEQUENCE="false" COMMENT="The amount of students that can fitin this slot"/>
<FIELD NAME="size" TYPE="int" LENGTH="3" NOTNULL="true" SEQUENCE="false" COMMENT="The amount of students that can fitin this slot"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
19 changes: 19 additions & 0 deletions lbplanner/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,31 @@
* @return bool true
*/
function xmldb_local_lbplanner_upgrade($oldversion): bool {
global $DB;
$dbman = $DB->get_manager();

if ($oldversion < 2024022700) {
config_helper::add_customfield();
}
if ($oldversion < 20250117) {
unset_config('defaultactiveyear', 'local_lbplanner');
}
if ($oldversion < 2025012201) {
$usertable = new xmldb_table('local_lbplanner_users');
$plantable = new xmldb_table('local_lbplanner_plans');
$fieldlanguage = new xmldb_field('language');
$fieldenableek = new xmldb_field('enableek');
$dbman->drop_field($usertable, $fieldlanguage);
$dbman->drop_field($plantable, $fieldenableek);
$fieldekenabled = new xmldb_field(
name: 'ekenabled',
type: XMLDB_TYPE_INTEGER,
precision: '1',
notnull: XMLDB_NOTNULL,
default: 0,
);
$dbman->add_field($usertable, $fieldekenabled);
}
return true;
}

6 changes: 3 additions & 3 deletions lbplanner/lang/en/local_lbplanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

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

$string['pluginname'] = 'LB Planner';
$string['lb_planner:student'] = 'LB Planner Student';
$string['lb_planner:teacher'] = 'LB Planner Teacher';
$string['lb_planner:admin'] = 'LB Planner Admin';
$string['lb_planner:manager'] = 'LB Planner Manager';
$string['lb_planner:student'] = 'LB Planner Student';
$string['lb_planner:teacher'] = 'LB Planner Teacher';
$string['pluginname'] = 'LB Planner';
2 changes: 1 addition & 1 deletion lbplanner/services/plan/get_plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function get_plan_parameters(): external_function_parameters {
* @return array
*/
public static function get_plan(): array {
global $DB, $USER;
global $USER;

$planid = plan_helper::get_plan_id($USER->id);

Expand Down
13 changes: 2 additions & 11 deletions lbplanner/services/plan/update_plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,22 @@ public static function update_plan_parameters(): external_function_parameters {
null,
NULL_NOT_ALLOWED
),
'enableek' => new external_value(
PARAM_BOOL,
'Whether EK is enabled for the plan',
VALUE_REQUIRED,
null,
NULL_NOT_ALLOWED
),
]);
}

/**
* Update the plan details.
*
* @param string $planname Name of the Plan
* @param bool $enableek Whether EK is enabled for the plan
* @return void
* @throws Exception when access denied
*/
public static function update_plan(string $planname, bool $enableek) {
public static function update_plan(string $planname) {
global $DB, $USER;

self::validate_parameters(
self::update_plan_parameters(),
['planname' => $planname, 'enableek' => $enableek]
['planname' => $planname]
);

$planid = plan_helper::get_plan_id($USER->id);
Expand All @@ -75,7 +67,6 @@ public static function update_plan(string $planname, bool $enableek) {

$plan = $DB->get_record(plan_helper::TABLE, ['id' => $planid], '*', MUST_EXIST);
$plan->name = $planname;
$plan->enableek = $enableek;

$DB->update_record(plan_helper::TABLE, $plan);
}
Expand Down
3 changes: 1 addition & 2 deletions lbplanner/services/user/get_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use moodle_exception;

use local_lbplanner\helpers\{user_helper, plan_helper, notifications_helper};
use local_lbplanner\enums\{PLAN_EK, PLAN_ACCESS_TYPE, NOTIF_TRIGGER};
use local_lbplanner\enums\{PLAN_ACCESS_TYPE, NOTIF_TRIGGER};
use local_lbplanner\model\user;

/**
Expand Down Expand Up @@ -64,7 +64,6 @@ public static function get_user(): array {
// Create empty plan for newly registered user.
$plan = new \stdClass();
$plan->name = 'Plan for ' . $USER->username;
$plan->enableek = PLAN_EK::ENABLED;
$planid = $DB->insert_record(plan_helper::TABLE, $plan);
$lbplanneruser->set_planid($planid);

Expand Down
24 changes: 17 additions & 7 deletions lbplanner/services/user/update_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,30 @@ public static function update_user_parameters(): external_function_parameters {
VALUE_DEFAULT,
null),
'displaytaskcount' => new external_value(
PARAM_INT,
'If the user has the taskcount-enabled 1-yes 0-no',
PARAM_BOOL,
'Whether the user has the taskcount enabled',
VALUE_DEFAULT,
null),
'ekenabled' => new external_value(
PARAM_BOOL,
'Whether the user wants to see EK modules',
VALUE_DEFAULT,
null),
]);
}

/**
* Updates the given user in the lbplanner DB
* @param string $theme The theme the user has selected
* @param string $colorblindness The colorblindness the user has selected
* @param int $displaytaskcount The displaytaskcount the user has selected
* @param ?string $theme The theme the user has selected
* @param ?string $colorblindness The colorblindness the user has selected
* @param ?bool $displaytaskcount The displaytaskcount the user has selected
* @param ?bool $ekenabled whether the user wants to see EK modules
* @return array The updated user
* @throws moodle_exception
* @throws dml_exception
* @throws invalid_parameter_exception
*/
public static function update_user($theme, $colorblindness, $displaytaskcount): array {
public static function update_user(?string $theme, ?string $colorblindness, ?bool $displaytaskcount, ?bool $ekenabled): array {
global $DB, $USER;

self::validate_parameters(
Expand All @@ -72,6 +78,7 @@ public static function update_user($theme, $colorblindness, $displaytaskcount):
'theme' => $theme,
'colorblindness' => $colorblindness,
'displaytaskcount' => $displaytaskcount,
'ekenabled' => $ekenabled,
]
);

Expand All @@ -87,7 +94,10 @@ public static function update_user($theme, $colorblindness, $displaytaskcount):
$user->set_theme($theme);
}
if ($displaytaskcount !== null) {
$user->set_displaytaskcount($displaytaskcount);
$user->displaytaskcount = $displaytaskcount;
}
if ($ekenabled !== null) {
$user->ekenabled = $ekenabled;
}

$DB->update_record(user_helper::LB_PLANNER_USER_TABLE, $user->prepare_for_db());
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

$plugin->component = 'local_lbplanner';
$plugin->release = 'Alpha v.'.$release;
$plugin->version = 2025011800;
$plugin->version = 2025012201;
$plugin->dependencies = [
// Depend upon version 2023110600 of local_modcustomfields.
'local_modcustomfields' => 2023110600,
Expand Down
Loading