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
3 changes: 0 additions & 3 deletions lbplanner/classes/helpers/config_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use core_customfield\category_controller;
use customfield_select\field_controller;
use local_modcustomfields\customfield\mod_handler;

use local_lbplanner\enums\SETTINGS;

/**
Expand All @@ -40,9 +39,7 @@ public static function add_customfield(): void {
// Check if the category is already created and only create it if it doesn't exist.
// Check if plugin "modcustomfields" is installed and create the category and the custom field.
if (self::get_category_id() === -1) {

if (array_key_exists('modcustomfields', core_component::get_plugin_list('local'))) {

$handler = mod_handler::create();
$categoryid = $handler->create_category('LB Planer');

Expand Down
14 changes: 7 additions & 7 deletions lbplanner/classes/helpers/course_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use DateTimeImmutable;
use dml_exception;
use dml_write_exception;

use local_lbplanner\model\course;

/**
Expand All @@ -34,7 +33,6 @@
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class course_helper {

/**
* The course table used by the LP
*/
Expand Down Expand Up @@ -99,8 +97,8 @@ public static function get_eduplanner_courses(bool $onlyenrolled): array {
But their perf is so abysmal that we have to roll our own function.
The code is largely leaned on how these functions work internally, optimized for our purposes. */
if ($onlyenrolled) {
$mdlcourses = $DB->get_records_sql("
SELECT c.* FROM {course} c
$mdlcourses = $DB->get_records_sql(
"SELECT c.* FROM {course} c
INNER JOIN {enrol} e ON e.courseid = c.id
INNER JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)
INNER JOIN {tag_instance} ti ON (ti.itemid = c.id)
Expand Down Expand Up @@ -129,8 +127,8 @@ public static function get_eduplanner_courses(bool $onlyenrolled): array {
]
);
} else {
$mdlcourses = $DB->get_records_sql("
SELECT c.* FROM {course} c
$mdlcourses = $DB->get_records_sql(
"SELECT c.* FROM {course} c
INNER JOIN {tag_instance} ti ON (ti.itemid = c.id)
WHERE (
c.enddate > :courseexpiredate
Expand All @@ -156,7 +154,9 @@ public static function get_eduplanner_courses(bool $onlyenrolled): array {
} else {
// IF not create an Object to be put into the Eduplanner database.
$fetchedcourse = new course(
0, $courseid, $userid,
0,
$courseid,
$userid,
course::prepare_shortname($mdlcourse->shortname),
self::COLORS[array_rand(self::COLORS)],
false,
Expand Down
3 changes: 1 addition & 2 deletions lbplanner/classes/helpers/invite_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class invite_helper {

/**
* Returns the data structure of an invite.
*
Expand All @@ -55,7 +54,7 @@ public static function structure(): external_single_structure {
public static function assert_invite_pending(int $status) {
if ($status !== PLAN_INVITE_STATE::PENDING) {
$name = PLAN_INVITE_STATE::name_from($status);
throw new \moodle_exception('Invite already '.$name);
throw new \moodle_exception("Invite already {$name}");
}
}
}
6 changes: 4 additions & 2 deletions lbplanner/classes/helpers/kanban_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class kanban_helper {

/**
* Table for storing kanban board entries.
*/
Expand Down Expand Up @@ -76,7 +75,10 @@ public static function set_entry(kanbanentry $entry): void {
$DB->delete_records(self::TABLE, ['userid' => $entry->userid, 'cmid' => $entry->cmid]);
} catch (\dml_exception $e) {
// Needed for low-reporting contexts such as a prod server.
echo 'error while trying to delete preexisting kanban entries: '.$e->getMessage()."\nFurther info:\n".$e->debuginfo;
echo 'error while trying to delete preexisting kanban entries: '
. $e->getMessage()
. "\nFurther info:\n"
. $e->debuginfo;
var_dump($entry);
throw $e;
}
Expand Down
1 change: 0 additions & 1 deletion lbplanner/classes/helpers/modules_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* Contains helper functions for working with modules.
*/
class modules_helper {

/**
* Table where modules are stored.
*/
Expand Down
8 changes: 5 additions & 3 deletions lbplanner/classes/helpers/plan_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public static function get_owner(int $planid): int {

$owner = $DB->get_field(
self::ACCESS_TABLE,
'userid', ['planid' => $planid, 'accesstype' => PLAN_ACCESS_TYPE::OWNER]
'userid',
['planid' => $planid, 'accesstype' => PLAN_ACCESS_TYPE::OWNER]
);

return intval($owner);
Expand Down Expand Up @@ -277,7 +278,9 @@ public static function remove_user(int $planid, int $userid, int $removeuserid):

$oldaccess = $DB->get_record(
self::ACCESS_TABLE,
['planid' => $planid, 'userid' => $removeuserid], '*', MUST_EXIST
['planid' => $planid, 'userid' => $removeuserid],
'*',
MUST_EXIST
);

$oldaccess->planid = $newplanid;
Expand Down Expand Up @@ -342,4 +345,3 @@ public static function timestamp_localtime_to_utc(int $localts) {
->getTimestamp();
}
}

16 changes: 7 additions & 9 deletions lbplanner/classes/helpers/slot_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
namespace local_lbplanner\helpers;

use core\context\system as context_system;

use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use local_lbplanner\enums\CAPABILITY;
use local_lbplanner\enums\WEEKDAY;
use local_lbplanner\enums\{CAPABILITY, WEEKDAY};
use local_lbplanner\model\{slot, reservation, slot_filter};

/**
Expand Down Expand Up @@ -62,8 +60,8 @@ class slot_helper {
'14:10',
'15:10',
'16:00',
'17:00', // All units after this point are 45min long instead of the usual 50.
'17:45', // We will assume 50min anyway because it's easier that way.
'17:00', // All units after this point are 45min long instead of the usual 50.
'17:45', // We will assume 50min anyway because it's easier that way.
'18:45',
'19:30',
'20:15',
Expand Down Expand Up @@ -119,8 +117,8 @@ public static function get_supervisor_slots(int $supervisorid): array {
global $DB;

$slots = $DB->get_records_sql(
'SELECT slot.* FROM {'.self::TABLE_SLOTS.'} as slot '.
'INNER JOIN {'.self::TABLE_SUPERVISORS.'} as supervisor ON supervisor.slotid=slot.id '.
'SELECT slot.* FROM {' . self::TABLE_SLOTS . '} as slot ' .
'INNER JOIN {' . self::TABLE_SUPERVISORS . '} as supervisor ON supervisor.slotid=slot.id ' .
'WHERE supervisor.userid=?',
[$supervisorid]
);
Expand Down Expand Up @@ -332,7 +330,7 @@ public static function filter_slots_for_time(array $allslots, int $range): array
public static function calculate_slot_datetime(slot $slot, DateTimeImmutable $now): DateTimeImmutable {
$slotdaytime = self::SCHOOL_UNITS[$slot->startunit];
// Move to next day this weekday occurs (doesn't move if it's the same as today).
$slotdatetime = $now->modify('this '.WEEKDAY::name_from($slot->weekday)." {$slotdaytime}");
$slotdatetime = $now->modify('this ' . WEEKDAY::name_from($slot->weekday) . " {$slotdaytime}");
if ($slotdatetime === false) {
throw new \coding_exception('error while calculating slot datetime');
}
Expand All @@ -357,7 +355,7 @@ public static function amend_date_with_unit_time(int $unit, DateTimeInterface $d
$utctz = new DateTimeZone('UTC');
$daytime = self::SCHOOL_UNITS[$unit];

return DateTimeImmutable::createFromFormat('Y-m-d G:i', $date->format('Y-m-d ').$daytime, $utctz);
return DateTimeImmutable::createFromFormat('Y-m-d G:i', $date->format('Y-m-d ') . $daytime, $utctz);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions lbplanner/classes/helpers/user_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
use dml_exception;
use stdClass;
use core_user;

use local_lbplanner\enums\NOTIF_TRIGGER;
use local_lbplanner\enums\PLAN_ACCESS_TYPE;
use local_lbplanner\enums\{NOTIF_TRIGGER, PLAN_ACCESS_TYPE};
use local_lbplanner\model\user;

/**
Expand All @@ -33,7 +31,6 @@
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class user_helper {

/**
* Name of the user database
*/
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/classes/model/kanbanentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static function api_structure(): external_single_structure {
'id' => new external_value(PARAM_INT, 'kanban board ID'),
'userid' => new external_value(PARAM_INT, 'ID of the owner of this entry'),
'cmid' => new external_value(PARAM_INT, 'ID of the course-module'),
'column' => new external_value(PARAM_TEXT, 'which column this module is in '.KANBANCOL_TYPE::format()),
'column' => new external_value(PARAM_TEXT, 'which column this module is in ' . KANBANCOL_TYPE::format()),
]
);
}
Expand Down
7 changes: 3 additions & 4 deletions lbplanner/classes/model/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ public function get_grade(int $userid): ?int {
$mdlgrade = end($mdlgrades);

if ($mdlgrade->grade > 0) {

$grade = modules_helper::determine_uinified_grade(
$mdlgrade->grade,
$moduleboundaries->grademax,
Expand Down Expand Up @@ -349,9 +348,9 @@ public static function api_structure_personal(): external_single_structure {
'cmid' => new external_value(PARAM_INT, 'Course module ID'),
'name' => new external_value(PARAM_TEXT, 'Shortened module name (max. 5 chars)'),
'courseid' => new external_value(PARAM_INT, 'Course ID'),
'status' => new external_value(PARAM_INT, 'Module status '.MODULE_STATUS::format()),
'type' => new external_value(PARAM_INT, 'Module type '.MODULE_TYPE::format()),
'grade' => new external_value(PARAM_INT, 'The grade of the module '.MODULE_GRADE::format()),
'status' => new external_value(PARAM_INT, 'Module status ' . MODULE_STATUS::format()),
'type' => new external_value(PARAM_INT, 'Module type ' . MODULE_TYPE::format()),
'grade' => new external_value(PARAM_INT, 'The grade of the module ' . MODULE_GRADE::format()),
'duedate' => new external_value(PARAM_INT, 'The deadline of the module set by the teacher'),
]
);
Expand Down
3 changes: 1 addition & 2 deletions lbplanner/classes/model/reservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
namespace local_lbplanner\model;

use DateTimeImmutable;

use core_external\{external_single_structure, external_value};
use DateTimeZone;
use core_external\{external_single_structure, external_value};
use local_lbplanner\model\slot;
use local_lbplanner\helpers\slot_helper;

Expand Down
20 changes: 14 additions & 6 deletions lbplanner/classes/model/slot.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

use local_lbplanner\enums\WEEKDAY;
use local_lbplanner\helpers\slot_helper;

use core_external\{external_multiple_structure, external_single_structure, external_value};
use moodle_exception;

Expand Down Expand Up @@ -90,19 +89,28 @@ class slot {
public function __construct(int $id, int $startunit, int $duration, int $weekday, string $room, int $size) {
$this->id = $id;
if ($startunit <= 0 || $startunit > slot_helper::SCHOOL_UNIT_MAX) {
throw new \moodle_exception("slot's startunit must be >0 and <=".slot_helper::SCHOOL_UNIT_MAX.", but is {$startunit}");
throw new \moodle_exception(
"slot's startunit must be >0 and <="
. slot_helper::SCHOOL_UNIT_MAX
. ", but is {$startunit}"
);
}
if ($duration <= 0 || ($startunit + $duration - 1) > slot_helper::SCHOOL_UNIT_MAX) {
throw new \moodle_exception(
"slot's duration must be >0 and can't exceed ".slot_helper::SCHOOL_UNIT_MAX." with startunit, but is {$duration}"
"slot's duration must be >0 and can't exceed "
. slot_helper::SCHOOL_UNIT_MAX
. " with startunit, but is {$duration}"
);
}
$this->startunit = $startunit;
$this->duration = $duration;
$this->weekday = WEEKDAY::from($weekday);
if (strlen($room) <= 0 && strlen($room) > slot_helper::ROOM_MAXLENGTH) {
throw new \moodle_exception(
"room name's length must be >0 and <=".slot_helper::ROOM_MAXLENGTH.", but is ".strlen($room)
"room name's length must be >0 and <="
. slot_helper::ROOM_MAXLENGTH
. ", but is "
. strlen($room)
);
}
$this->room = $room;
Expand Down Expand Up @@ -169,7 +177,7 @@ public function validate(): void {
if (strlen($this->room) <= 1) {
throw new moodle_exception('room name has to be at least 2 characters long');
} else if (strlen($this->room) > slot_helper::ROOM_MAXLENGTH) {
throw new moodle_exception('room name has a maximum of '.slot_helper::ROOM_MAXLENGTH.' characters');
throw new moodle_exception('room name has a maximum of ' . slot_helper::ROOM_MAXLENGTH . ' characters');
}
// Validating size.
if ($this->size < 0) {
Expand Down Expand Up @@ -313,7 +321,7 @@ public static function api_structure(): external_single_structure {
'id' => new external_value(PARAM_INT, 'slot ID'),
'startunit' => new external_value(PARAM_INT, 'unit this slot starts in (8:00 is unit 1)'),
'duration' => new external_value(PARAM_INT, 'duration of the slot in units'),
'weekday' => new external_value(PARAM_INT, 'The day this unit repeats weekly: '.WEEKDAY::format()),
'weekday' => new external_value(PARAM_INT, 'The day this unit repeats weekly: ' . WEEKDAY::format()),
'room' => new external_value(PARAM_TEXT, 'The room this slot is for'),
'size' => new external_value(PARAM_INT, 'total capacity of the slot'),
'fullness' => new external_value(PARAM_INT, 'how many people have already reserved this slot'),
Expand Down
12 changes: 5 additions & 7 deletions lbplanner/classes/model/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
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, KANBANCOL_TYPE_ORNONE};
use local_lbplanner\helpers\plan_helper;
use local_lbplanner\helpers\user_helper;
use local_lbplanner\enums\{CAPABILITY, CAPABILITY_FLAG, KANBANCOL_TYPE_ORNONE};
use local_lbplanner\helpers\{plan_helper, user_helper};

/**
* Model class for model
Expand Down Expand Up @@ -419,15 +417,15 @@ public static function api_structure(): external_single_structure {
'showcolumncolors' => new external_value(PARAM_BOOL, 'Whether column colors should show in kanban board'),
'automovecompletedtasks' => new external_value(
PARAM_TEXT,
'The kanban column to move a task to if completed '.KANBANCOL_TYPE_ORNONE::format()
'The kanban column to move a task to if completed ' . KANBANCOL_TYPE_ORNONE::format()
),
'automovesubmittedtasks' => new external_value(
PARAM_TEXT,
'The kanban column to move a task to if submitted '.KANBANCOL_TYPE_ORNONE::format()
'The kanban column to move a task to if submitted ' . KANBANCOL_TYPE_ORNONE::format()
),
'automoveoverduetasks' => new external_value(
PARAM_TEXT,
'The kanban column to move a task to if overdue '.KANBANCOL_TYPE_ORNONE::format()
'The kanban column to move a task to if overdue ' . KANBANCOL_TYPE_ORNONE::format()
),
'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),
Expand Down
4 changes: 2 additions & 2 deletions lbplanner/classes/polyfill/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static function find($value, bool $try): ?EnumCase {
if ($try) {
return null;
} else {
throw new \moodle_exception("value {$value} cannot be represented as a value in enum ".static::class);
throw new \moodle_exception("value {$value} cannot be represented as a value in enum " . static::class);
}
}
/**
Expand All @@ -70,7 +70,7 @@ private static function find_from_name(string $name, bool $try): ?EnumCase {
if ($try) {
return null;
} else {
throw new \moodle_exception("name {$name} doesn't exist in ".static::class);
throw new \moodle_exception("name {$name} doesn't exist in " . static::class);
}
}
/**
Expand Down
4 changes: 1 addition & 3 deletions lbplanner/classes/polyfill/EnumCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

namespace local_lbplanner\polyfill;

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

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

/**
Expand All @@ -47,4 +45,4 @@ public function __construct(string $name, $value) {
$this->name = $name;
$this->value = $value;
}
};
}
1 change: 0 additions & 1 deletion lbplanner/db/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ function xmldb_local_lbplanner_uninstall() {
$tag = core_tag_tag::get_by_name(core_tag_collection::get_default(), course_helper::EDUPLANNER_TAG, strictness:MUST_EXIST);
core_tag_tag::delete_tags($tag->id);
}

1 change: 0 additions & 1 deletion lbplanner/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/

use core\context\course as context_course;

use local_lbplanner\helpers\{config_helper, course_helper};

/**
Expand Down
1 change: 0 additions & 1 deletion lbplanner/services/courses/get_all_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later
*/
class courses_get_all_courses extends \core_external\external_api {

/**
* Has no Parameters
* @return external_function_parameters
Expand Down
Loading
Loading