diff --git a/lbplanner/classes/enums/CAPABILITY_FLAG_ORNONE.php b/lbplanner/classes/enums/CAPABILITY_FLAG_ORNONE.php index 9a9f45cb..2e4a8f7c 100644 --- a/lbplanner/classes/enums/CAPABILITY_FLAG_ORNONE.php +++ b/lbplanner/classes/enums/CAPABILITY_FLAG_ORNONE.php @@ -47,8 +47,8 @@ class CAPABILITY_FLAG_ORNONE extends CAPABILITY_FLAG { * @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'); + if ($num === 0) { + throw new \coding_exception(get_string('err_enum_capability_none', 'local_lbplanner')); } return parent::to_capability($num); } diff --git a/lbplanner/classes/helpers/config_helper.php b/lbplanner/classes/helpers/config_helper.php index b2b63343..9980f49a 100644 --- a/lbplanner/classes/helpers/config_helper.php +++ b/lbplanner/classes/helpers/config_helper.php @@ -53,8 +53,8 @@ public static function add_customfield(): void { $fieldcontroller = field_controller::create(0, $record, $categorycontroller); // Added the default attributes for the custom field. - $fieldcontroller->set('name', 'LB Planer Task Type'); - $fieldcontroller->set('description', 'Tracks whether the task is GK/EK/TEST/M'); + $fieldcontroller->set('name', get_string('cf_name', 'local_lbplanner')); + $fieldcontroller->set('description', get_string('cf_description', 'local_lbplanner')); $fieldcontroller->set('type', 'select'); // Because moodle wants me to save the configdata as a json string, I have to do this. // I don't know why moodle does this, but it does. I don't like it. but I have to do it. so I do it. diff --git a/lbplanner/classes/helpers/invite_helper.php b/lbplanner/classes/helpers/invite_helper.php index 919f5819..288e9939 100644 --- a/lbplanner/classes/helpers/invite_helper.php +++ b/lbplanner/classes/helpers/invite_helper.php @@ -54,7 +54,8 @@ 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}"); + $translatedname = get_string('invite_state_' . strtolower($name), 'local_lbplanner'); + throw new \moodle_exception(get_string('err_invite_alr', 'local_lbplanner', $translatedname)); } } } diff --git a/lbplanner/classes/helpers/modules_helper.php b/lbplanner/classes/helpers/modules_helper.php index 6660d6e6..3b01d33f 100644 --- a/lbplanner/classes/helpers/modules_helper.php +++ b/lbplanner/classes/helpers/modules_helper.php @@ -125,16 +125,17 @@ public static function determine_uinified_grade(int $grade, int $maxgrade, int $ * @throws \moodle_exception */ public static function determine_type(int $cmid): int { + // TODO: cache category controller. $catid = config_helper::get_category_id(); if ($catid === -1) { - throw new \moodle_exception('couldn\'t find custom fields category ID'); + throw new \moodle_exception(get_string('err_cf_nocatid', 'local_lbplanner')); } $categorycontroller = category_controller::create($catid); $instancedata = $categorycontroller->get_handler()->get_instance_data($cmid); if (count($instancedata) === 0) { - throw new \moodle_exception("couldn't find any instance data for module ID {$cmid} in category ID {$catid}"); + throw new \moodle_exception(get_string('err_cf_nodata', 'local_lbplanner', ['cmid' => $cmid, 'catid' => $catid])); } else if (count($instancedata) > 1) { - throw new \moodle_exception("found multiple data for module ID {$cmid} in category ID {$catid}"); + throw new \moodle_exception(get_string('err_cf_multidata', 'local_lbplanner', ['cmid' => $cmid, 'catid' => $catid])); } $type = intval($instancedata[array_key_last($instancedata)]->get_value()) - 1; if ($type === -1) { diff --git a/lbplanner/classes/helpers/plan_helper.php b/lbplanner/classes/helpers/plan_helper.php index fa82bb1f..e47036be 100644 --- a/lbplanner/classes/helpers/plan_helper.php +++ b/lbplanner/classes/helpers/plan_helper.php @@ -261,19 +261,19 @@ public static function copy_plan(int $planid, string $username): int { public static function remove_user(int $planid, int $userid, int $removeuserid): int { global $DB; // TODO: use global user object. if (self::get_owner($planid) != $userid) { - throw new \moodle_exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } if (self::get_plan_id($removeuserid) != $planid) { - throw new \moodle_exception('Cannot remove user from other plan'); + throw new \moodle_exception(get_string('err_plan_cantremove_userfromother', 'local_lbplanner')); } if ($userid == $removeuserid) { - throw new \moodle_exception('Cannot remove yourself'); + throw new \moodle_exception(get_string('err_plan_cantremove_yourself', 'local_lbplanner')); } if (self::get_access_type($removeuserid, $planid) === PLAN_ACCESS_TYPE::OWNER) { - throw new \moodle_exception('Cannot remove owner'); + throw new \moodle_exception(get_string('err_plan_cantremove_owner', 'local_lbplanner')); } $newplanid = self::copy_plan($planid, user_helper::get_mdluser($removeuserid)->username); diff --git a/lbplanner/classes/helpers/sentry_helper.php b/lbplanner/classes/helpers/sentry_helper.php index a796b407..75a95aec 100644 --- a/lbplanner/classes/helpers/sentry_helper.php +++ b/lbplanner/classes/helpers/sentry_helper.php @@ -89,7 +89,7 @@ public static function init(): void { public static function transaction_start(string $name, string $op, ?array $data = null): ?Transaction { if (self::enabled()) { if (SentrySdk::getCurrentHub()->getSpan() !== null) { - throw new \coding_exception('tried to start a new sentry transaction when there\'s already a span set'); + throw new \coding_exception(get_string('err_sentry_transactcoll', 'local_lbplanner')); } $ctx = TransactionContext::make() ->setName($name) diff --git a/lbplanner/classes/helpers/slot_helper.php b/lbplanner/classes/helpers/slot_helper.php index 8d77d0bc..70a52e98 100644 --- a/lbplanner/classes/helpers/slot_helper.php +++ b/lbplanner/classes/helpers/slot_helper.php @@ -219,7 +219,7 @@ public static function get_reservation(int $reservationid): reservation { $reservation = $DB->get_record(self::TABLE_RESERVATIONS, ['id' => $reservationid]); if ($reservation === false) { - throw new \moodle_exception('requested reservation does not exist'); + throw new \moodle_exception(get_string('err_slot_reservnoexist', 'local_lbplanner', $reservationid)); } return reservation::from_obj($reservation); @@ -395,7 +395,7 @@ public static function calculate_slot_datetime(slot $slot, DateTimeImmutable $no // 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}"); if ($slotdatetime === false) { - throw new \coding_exception('error while calculating slot datetime'); + throw new \coding_exception(get_string('err_slot_calcdatetime', 'local_lbplanner')); } // Check if slot is before now (because time of day and such) and move it a week into the future if so. @@ -449,7 +449,7 @@ public static function check_slot_supervisor(int $supervisorid, int $slotid): bo */ public static function assert_slot_supervisor(int $supervisorid, int $slotid): void { if (!self::check_slot_supervisor($supervisorid, $slotid)) { - throw new \moodle_exception('Insufficient Permission: you\'re not supervisor of this slot'); + throw new \moodle_exception(get_string('err_slot_urnotsupervisor', 'local_lbplanner')); } } } diff --git a/lbplanner/classes/helpers/user_helper.php b/lbplanner/classes/helpers/user_helper.php index abd3fb20..18838ab7 100644 --- a/lbplanner/classes/helpers/user_helper.php +++ b/lbplanner/classes/helpers/user_helper.php @@ -79,7 +79,7 @@ public static function get_user(int $userid): user { // Create empty plan for newly registered user. $plan = new \stdClass(); - $plan->name = 'Plan for ' . ($eduplanneruser->get_mdluser()->username); + $plan->name = get_string('plan_defaultname', 'local_lbplanner', $eduplanneruser->get_mdluser()->username); $planid = $DB->insert_record(plan_helper::TABLE, $plan); $eduplanneruser->set_planid($planid); diff --git a/lbplanner/classes/model/course.php b/lbplanner/classes/model/course.php index b0c09d61..da3a8f32 100644 --- a/lbplanner/classes/model/course.php +++ b/lbplanner/classes/model/course.php @@ -71,6 +71,7 @@ class course { * @param bool $enabled whether the course is enabled */ public function __construct(int $id, int $courseid, int $userid, string $shortname, string $color, bool $enabled) { + // TODO: private constructor, remove checks, separate public function with checks. $this->id = $id; $this->courseid = $courseid; $this->userid = $userid; @@ -110,7 +111,7 @@ public function set_fresh(int $id) { */ public function set_color(string $color) { if ($color[0] !== '#') { - throw new \coding_exception("incorrect color format - must be either #RGB or #RRGGBB, got \"{$color}\" instead"); + throw new \coding_exception(get_string('err_color_wrongformat', 'local_lbplanner', $color)); } $len = strlen($color); if ($len === 4) { @@ -122,11 +123,11 @@ public function set_color(string $color) { // Format #RRGGBB. $rrggbb = $color; } else { - throw new \coding_exception("incorrect color format - got incorrect length of {$len}"); + throw new \coding_exception(get_string('err_color_wronglength', 'local_lbplanner', $len)); } $rrggbb = strtoupper($rrggbb); if (preg_match('/^#[1-9A-F]{6}$/', $rrggbb) === false) { - throw new \coding_exception("incorrect color format - found non-hexadecimal character in color \"{$color}\""); + throw new \coding_exception(get_string('err_color_nonhexadecimal', 'local_lbplanner', $color)); } $this->color = $rrggbb; } @@ -139,7 +140,7 @@ public function set_color(string $color) { public function set_shortname(string $shortname) { $length = strlen($shortname); if ($length > 5 || $length < 0) { - throw new \moodle_exception("shortname length must be <=5 and >0, but is {$length} instead"); + throw new \moodle_exception(get_string('err_course_shortnamelength', 'local_lbplanner', $length)); } $this->shortname = $shortname; } @@ -173,7 +174,7 @@ public static function prepare_shortname(string $shortname): string { */ public function set_mdlcourse(\stdClass $mdlcourse): void { if ($this->mdlcourse !== null) { - throw new \coding_exception('tried to set cached mdluser twice'); + throw new \coding_exception(get_string('err_doublechacheset', 'local_lbplanner', 'mdlcourse')); } $this->mdlcourse = $mdlcourse; } diff --git a/lbplanner/classes/model/module.php b/lbplanner/classes/model/module.php index a6c6c62a..6384810e 100644 --- a/lbplanner/classes/model/module.php +++ b/lbplanner/classes/model/module.php @@ -139,7 +139,7 @@ public function get_assignid(): int { if ($this->cmid !== null) { $this->assignid = $this->get_cmobj()->instance; } else { - throw new \coding_exception('requested assignid, but no cmid'); + throw new \coding_exception(get_string('err_mod_assnocmid', 'local_lbplanner')); } } return $this->assignid; @@ -185,11 +185,11 @@ public function get_cmobj(): \stdClass { ['id' => $this->cmid, 'module' => modules_helper::get_assign_module_id()] ); if ($res === false) { - throw new \moodle_exception("couldn't get course module with cmid {$this->cmid}"); + throw new \moodle_exception(get_string('err_mod_cmidnocm', 'local_lbplanner', $this->cmid)); } } else { if ($this->assignid === null) { - throw new \coding_exception('tried to query cmid on a module object without assignid'); + throw new \coding_exception(get_string('err_mod_cmidnoass', 'local_lbplanner')); } $courseid = $this->get_courseid(); $res = $DB->get_record( @@ -201,9 +201,11 @@ public function get_cmobj(): \stdClass { ] ); if ($res === false) { - throw new \moodle_exception( - "couldn't get course module with assignid {$this->assignid} and courseid {$courseid}" - ); + throw new \moodle_exception(get_string( + 'err_mod_assnocm', + 'local_lbplanner', + ['assignid' => $this->assignid, 'courseid' => $courseid], + )); } } $this->cmobj = $res; @@ -243,7 +245,7 @@ public function get_courseid(): int { if ($this->cmid !== null) { $viacm = true; } else if ($this->cmid === null) { - throw new \coding_exception('invalid module model: neither cmid nor assignid defined'); + throw new \coding_exception(get_string('err_mod_nocmidnorass', 'local_lbplanner')); } } } diff --git a/lbplanner/classes/model/slot.php b/lbplanner/classes/model/slot.php index c2816a53..53f2b0de 100644 --- a/lbplanner/classes/model/slot.php +++ b/lbplanner/classes/model/slot.php @@ -88,40 +88,16 @@ 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}" - ); - } - 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}" - ); - } $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) - ); - } $this->room = $room; - if ($size < 0) { - throw new \moodle_exception('room size must be >0'); - } $this->size = $size; $this->fullness = null; $this->forcuruser = null; $this->supervisors = null; $this->filters = null; + $this->validate(); } /** @@ -161,27 +137,29 @@ public function validate(): void { static $maxunit = slot_helper::SCHOOL_UNIT_MAX; // Validating startunit. if ($this->startunit < 1) { - throw new moodle_exception('can\'t have a start unit smaller than 1'); + throw new moodle_exception(get_string('err_slot_startunittoosmall', 'local_lbplanner')); } else if ($this->startunit > $maxunit) { - throw new moodle_exception("can't have a start unit larger than {$maxunit}"); + throw new moodle_exception(get_string('err_slot_startunittoolarge', 'local_lbplanner')); } // Validating duration. if ($this->duration < 1) { - throw new moodle_exception('duration must be at least 1'); + throw new moodle_exception(get_string('err_slot_durationtoosmall', 'local_lbplanner')); } else if ($this->startunit + $this->duration > $maxunit) { - throw new moodle_exception("slot goes past the max unit {$maxunit}"); + throw new moodle_exception(get_string('err_slot_durationtoolarge', 'local_lbplanner', $maxunit)); } // Validating weekday. WEEKDAY::from($this->weekday); // Validating room. if (strlen($this->room) <= 1) { - throw new moodle_exception('room name has to be at least 2 characters long'); + throw new moodle_exception(get_string('err_slot_roomnametooshort', 'local_lbplanner')); } 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( + get_string('err_slot_roomnametoolong', 'local_lbplanner', slot_helper::ROOM_MAXLENGTH) + ); } // Validating size. if ($this->size < 0) { - throw new moodle_exception('can\'t have a negative size for a slot'); + throw new moodle_exception(get_string('err_slot_roomsizetoosmall', 'local_lbplanner')); } } diff --git a/lbplanner/classes/model/slot_filter.php b/lbplanner/classes/model/slot_filter.php index ca16b065..d9f17caf 100644 --- a/lbplanner/classes/model/slot_filter.php +++ b/lbplanner/classes/model/slot_filter.php @@ -58,6 +58,11 @@ class slot_filter { public function __construct(int $id, int $slotid, int $courseid, string $vintage) { assert(strlen($vintage) <= 7); + // Ensure that either $courseid or $vintage are non-null. + if (is_null($courseid) && is_null($vintage)) { + throw new \moodle_exception(get_string('err_slotfilter_bothnull', 'local_lbplanner')); + } + $this->id = $id; $this->slotid = $slotid; $this->courseid = $courseid; diff --git a/lbplanner/classes/model/user.php b/lbplanner/classes/model/user.php index 1b2157b4..80fc10fe 100644 --- a/lbplanner/classes/model/user.php +++ b/lbplanner/classes/model/user.php @@ -240,7 +240,7 @@ public function set_mdluser(\stdClass $mdluser): void { global $USER; if ($this->mdluser !== null) { if ($this->mdluser->id !== $USER->id) { - throw new \coding_exception('tried to set cached mdluser twice'); + throw new \coding_exception(get_string('err_doublechacheset', 'local_lbplanner', 'mdluser')); } } $this->mdluser = $mdluser; @@ -264,7 +264,7 @@ public function get_mdluser(): \stdClass { */ public function set_planid(int $planid): void { if ($this->planid !== null) { - throw new \coding_exception('tried to set cached planid twice'); + throw new \coding_exception(get_string('err_doublechacheset', 'local_lbplanner', 'planid')); } $this->planid = $planid; } diff --git a/lbplanner/classes/polyfill/Enum.php b/lbplanner/classes/polyfill/Enum.php index bdf49e46..ee84d45a 100644 --- a/lbplanner/classes/polyfill/Enum.php +++ b/lbplanner/classes/polyfill/Enum.php @@ -70,7 +70,9 @@ 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( + get_string('err_enum_namemissing', 'local_lbplanner', ['name' => $name, 'classname' => static::class]) + ); } } /** @@ -163,7 +165,7 @@ public static function format(): string { } else if (is_int($case->value)) { $formattedval = $case->value; } else { - throw new moodle_exception('unimplemented case value type for Enum::format()'); + throw new moodle_exception(get_string('err_enum_casevaluetype_unimp', 'local_lbplanner')); } $result .= "{$formattedval}=>{$case->name},"; } diff --git a/lbplanner/db/access.php b/lbplanner/db/access.php index 9de3ea5e..db76118c 100644 --- a/lbplanner/db/access.php +++ b/lbplanner/db/access.php @@ -45,9 +45,9 @@ $deprecatedcapabilities = [ 'local/lb_planner:admin' => [ - 'message' => 'this capability was removed because of internal changes making it unnecessary', + 'message' => get_string('capability_deprecated_unnecessary', 'local_lbplanner'), ], 'local/lb_planner:manager' => [ - 'message' => 'this capability was removed because of internal changes making it unnecessary', + 'message' => get_string('capability_deprecated_unnecessary', 'local_lbplanner'), ], ]; diff --git a/lbplanner/lang/de/local_lbplanner.php b/lbplanner/lang/de/local_lbplanner.php new file mode 100644 index 00000000..60e4b96e --- /dev/null +++ b/lbplanner/lang/de/local_lbplanner.php @@ -0,0 +1,109 @@ +. + +/** + * Defines some translation strings in german. + * + * @package local_lbplanner + * @copyright 2025 Pallasys + * @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC-BY-NC-SA 4.0 International or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$string['capability_deprecated_unnecessary'] = 'Diese Berechtigung wurde entfernt, da sie nicht mehr benötigt wird'; +$string['cf_description'] = 'Gibt an, ob die Aufgabe GK/EK/TEST/M ist'; +$string['cf_name'] = 'LB Planer Aufgabentyp'; +$string['err_accessdenied'] = 'Zugriff verweigert'; +$string['err_cf_multidata'] = 'Mehrere Einträge für Modul-ID {$a->cmid} in Kategorie-ID {$a->catid}'; +$string['err_cf_nocatid'] = 'Kategorie-ID für Custom Fields nicht gefunden'; +$string['err_cf_nodata'] = 'Keine Instanzdaten für Modul-ID {$a->cmid} in Kategorie-ID {$a->catid}'; +$string['err_color_nonhexadecimal'] = 'Ungültiges Farbformat - nicht-hexadezimalziffer in "{$a}"'; +$string['err_color_wrongformat'] = 'Ungültiges Farbformat - erwartet #RGB oder #RRGGBB, nicht "{$a}"'; +$string['err_color_wronglength'] = 'Ungültiges Farbformat - falsche Länge von {$a}'; +$string['err_course_shortnamelength'] = 'Länge des Kurznamens muss <=5 und >0 sein (aktuell: {$a})'; +$string['err_dateformat'] = 'Ungültiges Datumsformat: \'{$a}\' erhalten, erwartet YYYY-MM-DD'; +$string['err_doublechacheset'] = 'Versuchte {$a} doppelt im Cache zu speichern'; +$string['err_enum_capability_none'] = + '0 heißt die Abwesenheit von Berechtigungen, und kann daher nicht zur Berechtigung umgewandelt werden'; +$string['err_enum_casevaluetype_unimp'] = 'Nicht implementierter Case Value Typ für Enum::format()'; +$string['err_enum_namemissing'] = 'Name {$a->name} existiert nicht in {$a->classname}'; +$string['err_invite_alr'] = 'Einladung bereits {$a}'; +$string['err_invite_alrinvited'] = 'Kann keineN NutzerIn einladen dier bereits eingeladen wurde'; +$string['err_invite_alrmember'] = 'Kann keineN NutzerIn einladen dier bereits Mitglied ist'; +$string['err_invite_notfound'] = 'Einladung existiert nicht'; +$string['err_invite_yourself'] = 'Kann dich nicht selbst einladen'; +$string['err_mod_assnocm'] = 'Kursmodul mit assignid {$a->assignid} und courseid {$a->courseid} konnte nicht abgerufen werden'; +$string['err_mod_assnocmid'] = 'assignid angefordert, aber keine cmid gesetzt'; +$string['err_mod_cmidnoass'] = 'cmid angefordert, aber keine assignid gesetzt'; +$string['err_mod_cmidnocm'] = 'Kursmodul mit cmid {$a} konnte nicht abgerufen werden'; +$string['err_mod_nocmidnorass'] = 'Ungültiges Modulmodell: weder cmid noch assignid gesetzt'; +$string['err_notif_notfound'] = 'Benachrichtigung nicht gefunden'; +$string['err_panic'] = 'PANIK'; +$string['err_plan_cantleave_empty'] = 'Kann Plan nicht austreten: Plan muss mindestens ein weiteres Mitglied haben'; +$string['err_plan_cantremove_owner'] = 'Kann BesitzerIn nicht entfernen'; +$string['err_plan_cantremove_userfromother'] = 'Kann keineN NutzerIn von einem Plan entfernen in dem sier nicht ist'; +$string['err_plan_cantremove_yourself'] = 'Kann dich nicht selbst entfernen'; +$string['err_plan_changeaccess_inval'] = 'Ungültiger Zugriffstyp'; +$string['err_plan_changeaccess_ofowner'] = 'Kann Berechtigungen ders BesitzerIns nicht ändern'; +$string['err_plan_changeaccess_self'] = 'Kann eigene Berechtigungen nicht ändern'; +$string['err_plan_changeaccess_toowner'] = 'Kann Berechtigungen nicht auf BesitzerIn ändern'; +$string['err_reserv_past'] = 'Vergangene Termine können nicht reserviert werden'; +$string['err_reserv_slotfull'] = 'Slot ist schon voll'; +$string['err_reserv_studentalrin'] = 'SchülerIn hat bereits eine Reservierung für diesen Slot'; +$string['err_reserv_studentnoaccess'] = 'SchülerIn hat keinen Zugriff auf diesen Slot'; +$string['err_reserv_toofuture'] = 'Datum ist nach erlaubten Datum ({$a} Tage in der Zukunft)'; +$string['err_reserv_unreserv_alrended'] = 'Kann bereits vergangene Reservierung nicht stornieren'; +$string['err_reserv_unreserv_alrstarted'] = 'Kann bereits begonnene Reservierung nicht stornieren'; +$string['err_reserv_unreserv_alrstartedorforce'] = + 'Schüler können bereits begonnene Reservierungen nicht stornieren. Falls du trotzdem stornieren willst, bitte erzwingen.'; +$string['err_sentry_transactcoll'] = 'Versuchte neue Sentry-Transaktion zu starten obwohl ein Span schon existiert'; +$string['err_sentry_webservfalse'] = 'Webservice-Override: call_user_func_array gab bei {$a} false zurück'; +$string['err_slot_calcdatetime'] = 'Slot-Zeitpunkt konnte nicht berechnet werden'; +$string['err_slot_durationtoolarge'] = 'Slot-Starteinheit plus Dauer muss <={$a} sein'; +$string['err_slot_durationtoosmall'] = 'Slot-Dauer muss >=1 sein'; +$string['err_slot_overfull'] = 'Slot ist jetzt überfüllt'; +$string['err_slot_reservnoexist'] = 'Reservierung {$a} existiert nicht'; +$string['err_slot_roomnametoolong'] = 'Raumname darf maximal {$a} Zeichen haben'; +$string['err_slot_roomnametooshort'] = 'Raumname muss mindestens 2 Zeichen haben'; +$string['err_slot_roomsizetoosmall'] = 'Raumgröße muss >=0 sein'; +$string['err_slot_startunittoolarge'] = 'Slot-Starteinheit muss <={$a} sein'; +$string['err_slot_startunittoosmall'] = 'Slot-Starteinheit muss >=1 sein'; +$string['err_slot_urnotsupervisor'] = 'Du bist kein Betreuer dieses Slots'; +$string['err_slotfilter_bothnull'] = 'courseid und vintage können nicht beide null sein'; +$string['err_user_notfound'] = 'NutzerIn nicht in EduPlanner registriert'; +$string['invite_state_accepted'] = 'akzeptiert'; +$string['invite_state_declined'] = 'abgelehnt'; +$string['invite_state_expired'] = 'abgelaufen'; +$string['invite_state_pending'] = 'ausstehend'; +$string['lb_planner:admin'] = 'LB Planner Admin'; +$string['lb_planner:manager'] = 'LB Planner ManagerIn'; +$string['lb_planner:slotmaster'] = 'LB Planner Slotmeister'; +$string['lb_planner:student'] = 'LB Planner SchülerIn'; +$string['lb_planner:teacher'] = 'LB Planner Lehrkraft'; +$string['plan_defaultname'] = 'Plan für {$a}'; +$string['pluginname'] = 'LB Planner'; +$string['sett_futuresight_desc'] = 'Wie viele Tage im Voraus Schüler Termine/Slots buchen dürfen. (0 = nur selber Tag)'; +$string['sett_futuresight_title'] = 'Reservierungszeitraum der Schüler'; +$string['sett_outdaterange_desc'] = 'Die maximale Dauer, die ein Kurs nach seinem Ende im EduPlanner sichtbar bleibt.'; +$string['sett_outdaterange_title'] = 'Sichtbarkeitsdauer nach Kursende'; +$string['sett_panic_desc'] = + 'Schaltet API ab - nur im Notfall. Kein Datenverlust, aber totale Abschaltung der Dienste bis die box enthakt wird.'; +$string['sett_panic_title'] = 'PANIKSCHALTER'; +$string['sett_sentrydsn_desc'] = 'Wo Fehlermeldungen hingeschickt werden. (Bitte frag das Pallasys-Team um einen Code)'; +$string['sett_sentrydsn_title'] = 'Sentry DSN'; +$string['unit_day'] = 'Tag'; +$string['unit_day_pl'] = 'Tage'; diff --git a/lbplanner/lang/en/local_lbplanner.php b/lbplanner/lang/en/local_lbplanner.php index 07fceb43..d7173fcf 100644 --- a/lbplanner/lang/en/local_lbplanner.php +++ b/lbplanner/lang/en/local_lbplanner.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Defines some translation strings in english + * Defines some translation strings in english. * * @package local_lbplanner * @copyright 2025 Pallasys @@ -24,8 +24,86 @@ defined('MOODLE_INTERNAL') || die(); +$string['capability_deprecated_unnecessary'] = 'This capability was removed because of internal changes making it unnecessary'; +$string['cf_description'] = 'Tracks whether the task is GK/EK/TEST/M'; +$string['cf_name'] = 'LB Planer Task Type'; +$string['err_accessdenied'] = 'Access denied'; +$string['err_cf_multidata'] = 'Found multiple data for module ID {$a->cmid} in category ID {$a->catid}'; +$string['err_cf_nocatid'] = 'Couldn\'t find custom fields category ID'; +$string['err_cf_nodata'] = 'Couldn\'t find any instance data for module ID {$a->cmid} in category ID {$a->catid}'; +$string['err_color_nonhexadecimal'] = 'Incorrect color format - found non-hexadecimal character in color "{$a}"'; +$string['err_color_wrongformat'] = 'Incorrect color format - must be either #RGB or #RRGGBB, got "{$a}" instead'; +$string['err_color_wronglength'] = 'Incorrect color format - got incorrect length of {$a}'; +$string['err_course_shortnamelength'] = 'Shortname length must be <=5 and >0, but is {$a} instead'; +$string['err_dateformat'] = 'Invalid date formatting: got \'{$a}\', must be YYYY-MM-DD'; +$string['err_doublechacheset'] = 'Tried to set cached {$a} twice'; +$string['err_enum_capability_none'] = + '0 means the absence of capabilities, and thus cannot be converted to a capability'; +$string['err_enum_casevaluetype_unimp'] = 'Unimplemented case value type for Enum::format()'; +$string['err_enum_namemissing'] = 'Name {$a->name} doesn\'t exist in {$a->classname}'; +$string['err_invite_alr'] = 'Invite already {$a}'; +$string['err_invite_alrinvited'] = 'Cannot invite user who is already been invited'; +$string['err_invite_alrmember'] = 'Cannot invite user who is already a member'; +$string['err_invite_notfound'] = 'Invitation does not exist'; +$string['err_invite_yourself'] = 'Cannot invite yourself'; +$string['err_mod_assnocm'] = 'Couldn\'t get course module with assignid {$a->assignid} and courseid {$a->courseid}'; +$string['err_mod_assnocmid'] = 'Requested assignid, but no cmid is set'; +$string['err_mod_cmidnoass'] = 'Requested cmid, but no assignid is set'; +$string['err_mod_cmidnocm'] = 'Couldn\'t get course module with cmid {$a}'; +$string['err_mod_nocmidnorass'] = 'Invalid module model: neither cmid nor assignid defined'; +$string['err_notif_notfound'] = 'Notification does not exist'; +$string['err_panic'] = 'PANIC'; +$string['err_plan_cantleave_empty'] = 'Cannot Leave Plan: Plan must have at least one other member'; +$string['err_plan_cantremove_owner'] = 'Cannot remove owner'; +$string['err_plan_cantremove_userfromother'] = 'Cannot remove user from a plan they aren\'t in'; +$string['err_plan_cantremove_yourself'] = 'Cannot remove yourself'; +$string['err_plan_changeaccess_inval'] = 'Access type not valid'; +$string['err_plan_changeaccess_ofowner'] = 'Cannot change permissions for the plan owner'; +$string['err_plan_changeaccess_self'] = 'Cannot change own permissions'; +$string['err_plan_changeaccess_toowner'] = 'Cannot change permission to owner'; +$string['err_reserv_past'] = 'Can\'t reserve date in the past'; +$string['err_reserv_slotfull'] = 'Slot is already full'; +$string['err_reserv_studentalrin'] = 'Student already has a reservation for this slot'; +$string['err_reserv_studentnoaccess'] = 'Student does not have access to this slot'; +$string['err_reserv_toofuture'] = 'Date is past allowed date ({$a} days in the future)'; +$string['err_reserv_unreserv_alrended'] = 'You can\'t unbook this reservation because it has already ended'; +$string['err_reserv_unreserv_alrstarted'] = 'You can\'t unbook this reservation because it has already started'; +$string['err_reserv_unreserv_alrstartedorforce'] = + 'Students can\'t unbook reservations that have already started. If you want to unbook this reservation regardless, force it.'; +$string['err_sentry_transactcoll'] = 'Tried to start a new sentry transaction when there\'s already a span set'; +$string['err_sentry_webservfalse'] = 'Webservice override: call_user_func_array returned with false at {$a}'; +$string['err_slot_calcdatetime'] = 'Could not calculate slot datetime'; +$string['err_slot_durationtoolarge'] = 'Slot start unit plus duration must be <={$a}'; +$string['err_slot_durationtoosmall'] = 'Slot duration must be >=1'; +$string['err_slot_overfull'] = 'Slot is now overfull'; +$string['err_slot_reservnoexist'] = 'Reservation {$a} does not exist'; +$string['err_slot_roomnametoolong'] = 'Room name has to be {$a} characters long or shorter'; +$string['err_slot_roomnametooshort'] = 'Room name has to be at least 2 characters long'; +$string['err_slot_roomsizetoosmall'] = 'Room size must be >=0'; +$string['err_slot_startunittoolarge'] = 'Slot start unit must be <={$a}'; +$string['err_slot_startunittoosmall'] = 'Slot start unit must be >=1'; +$string['err_slot_urnotsupervisor'] = 'Insufficient Permission: you\'re not supervisor of this slot'; +$string['err_slotfilter_bothnull'] = 'Courseid and vintage can\'t both be null'; +$string['err_user_notfound'] = 'User is not registered in Eduplanner'; +$string['invite_state_accepted'] = 'accepted'; +$string['invite_state_declined'] = 'declined'; +$string['invite_state_expired'] = 'expired'; +$string['invite_state_pending'] = 'pending'; $string['lb_planner:admin'] = 'LB Planner Admin'; $string['lb_planner:manager'] = 'LB Planner Manager'; +$string['lb_planner:slotmaster'] = 'LB Planner Slotmaster'; $string['lb_planner:student'] = 'LB Planner Student'; $string['lb_planner:teacher'] = 'LB Planner Teacher'; +$string['plan_defaultname'] = 'Plan for {$a}'; $string['pluginname'] = 'LB Planner'; +$string['sett_futuresight_desc'] = 'Maximum number of days in advance students can reserve slots. (0 = same day only)'; +$string['sett_futuresight_title'] = 'Students\' reservation range'; +$string['sett_outdaterange_desc'] = 'The maximum duration a course remains visible in EduPlanner after it ends.'; +$string['sett_outdaterange_title'] = 'Courses\' outdated range'; +$string['sett_panic_desc'] = + 'Turns API off - only use in emergencies. No data loss, but total loss of EduPlanner services until box is unchecked.'; +$string['sett_panic_title'] = 'PANIC SWITCH'; +$string['sett_sentrydsn_desc'] = 'For where to send error debugging info to. (Please ask the Pallasys team for a key)'; +$string['sett_sentrydsn_title'] = 'Sentry DSN'; +$string['unit_day'] = 'Day'; +$string['unit_day_pl'] = 'Days'; diff --git a/lbplanner/lib.php b/lbplanner/lib.php index 59b097bd..c90809f8 100644 --- a/lbplanner/lib.php +++ b/lbplanner/lib.php @@ -36,7 +36,7 @@ function local_lbplanner_override_webservice_execution(stdClass $externalfunctio // Only override calling our own functions. if ($externalfunctioninfo->component === 'local_lbplanner') { if (get_config('local_lbplanner', SETTINGS::PANIC) === '1') { - throw new \moodle_exception('PANIC'); // TODO: add to translations. + throw new \moodle_exception(get_string('err_panic', 'local_lbplanner')); } sentry_helper::init(); // Actually calling the function (since we're overriding this part, duh). @@ -49,15 +49,8 @@ function local_lbplanner_override_webservice_execution(stdClass $externalfunctio // Report if call_user_func_array itself had some kind of issue. if ($result === false) { $paramsstring = var_export($params, true); - throw new \coding_exception( - "webservice override: call_user_func_array returned with false at " - . $externalfunctioninfo->classname - . "::" - . $externalfunctioninfo->methodname - . "(" - . $paramsstring - . ");" - ); + $fullname = "{$externalfunctioninfo->classname}::{$externalfunctioninfo->methodname}({$paramsstring})"; + throw new \coding_exception(get_string('err_sentry_webservfalse', 'local_lbplanner', $fullname)); } return $result; diff --git a/lbplanner/services/courses/get_all_courses.php b/lbplanner/services/courses/get_all_courses.php index 1d88192a..b17dbecc 100644 --- a/lbplanner/services/courses/get_all_courses.php +++ b/lbplanner/services/courses/get_all_courses.php @@ -46,7 +46,7 @@ public static function get_all_courses(): array { global $USER; $user = user::from_mdlobj($USER); if (!($user->get_capabilitybitmask() & (CAPABILITY_FLAG::SLOTMASTER | CAPABILITY_FLAG::TEACHER))) { - throw new \moodle_exception('access denied: must be slotmaster'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $courses = course_helper::get_eduplanner_courses(false); diff --git a/lbplanner/services/courses/update_course.php b/lbplanner/services/courses/update_course.php index 06cef154..a5e91f0c 100644 --- a/lbplanner/services/courses/update_course.php +++ b/lbplanner/services/courses/update_course.php @@ -69,10 +69,6 @@ public static function update_course(int $courseid, string $color, string $short ] ); - if (strlen($shortname) > 5) { - throw new moodle_exception('Shortname is too long'); - } - $course = course_helper::get_eduplanner_course($courseid, $USER->id); if ($color !== null) { diff --git a/lbplanner/services/notifications/update_notification.php b/lbplanner/services/notifications/update_notification.php index 44b34501..dba00ea2 100644 --- a/lbplanner/services/notifications/update_notification.php +++ b/lbplanner/services/notifications/update_notification.php @@ -65,7 +65,7 @@ public static function update_notification(int $status, int $notificationid) { ); if (!$DB->record_exists(notifications_helper::EDUPLANNER_NOTIFICATION_TABLE, ['id' => $notificationid])) { - throw new \moodle_exception('Notification does not exist'); + throw new \moodle_exception(get_string('err_notif_notfound', 'lb_plannerlocal_lbplanner')); } $notification = $DB->get_record( diff --git a/lbplanner/services/plan/accept_invite.php b/lbplanner/services/plan/accept_invite.php index 435a1fbf..39a40ab2 100644 --- a/lbplanner/services/plan/accept_invite.php +++ b/lbplanner/services/plan/accept_invite.php @@ -61,7 +61,7 @@ public static function accept_invite(int $inviteid) { ); if ($invite === false) { - throw new \moodle_exception('Invite not found'); + throw new \moodle_exception(get_string('err_invite_notfound', 'lb_plannerlocal_lbplanner')); } invite_helper::assert_invite_pending($invite->status); diff --git a/lbplanner/services/plan/clear_plan.php b/lbplanner/services/plan/clear_plan.php index 342897c5..905db79a 100644 --- a/lbplanner/services/plan/clear_plan.php +++ b/lbplanner/services/plan/clear_plan.php @@ -40,7 +40,7 @@ public static function clear_plan_parameters(): external_function_parameters { * Clears your current plan. * * @return void - * @throws Exception when access denied + * @throws \moodle_exception when access denied */ public static function clear_plan() { global $DB, $USER; @@ -48,7 +48,7 @@ public static function clear_plan() { $planid = plan_helper::get_plan_id($USER->id); if (!plan_helper::check_edit_permissions($planid, $USER->id)) { - throw new \Exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $DB->delete_records(plan_helper::DEADLINES_TABLE, ['planid' => $planid ]); diff --git a/lbplanner/services/plan/decline_invite.php b/lbplanner/services/plan/decline_invite.php index aa7ffd6d..791a777e 100644 --- a/lbplanner/services/plan/decline_invite.php +++ b/lbplanner/services/plan/decline_invite.php @@ -59,7 +59,7 @@ public static function decline_invite(int $inviteid) { ); if ($invite === false) { - throw new \moodle_exception('Invite not found'); + throw new \moodle_exception(get_string('err_invite_notfound', 'local_lbplanner')); } invite_helper::assert_invite_pending($invite->status); diff --git a/lbplanner/services/plan/delete_deadline.php b/lbplanner/services/plan/delete_deadline.php index 6803cadb..8a544174 100644 --- a/lbplanner/services/plan/delete_deadline.php +++ b/lbplanner/services/plan/delete_deadline.php @@ -49,7 +49,7 @@ public static function delete_deadline_parameters(): external_function_parameter * * @param int $moduleid ID of the Module * @return void - * @throws Exception when access denied + * @throws \moodle_exception when access denied */ public static function delete_deadline(int $moduleid) { global $DB, $USER; @@ -64,7 +64,7 @@ public static function delete_deadline(int $moduleid) { $planid = plan_helper::get_plan_id($USER->id); if (!plan_helper::check_edit_permissions($planid, $USER->id)) { - throw new \Exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $DB->delete_records( diff --git a/lbplanner/services/plan/invite_user.php b/lbplanner/services/plan/invite_user.php index 043e0876..2a744658 100644 --- a/lbplanner/services/plan/invite_user.php +++ b/lbplanner/services/plan/invite_user.php @@ -64,15 +64,15 @@ public static function invite_user(int $inviteeid): mixed { $planid = plan_helper::get_plan_id($USER->id); if (plan_helper::get_owner($planid) !== intval($USER->id)) { - throw new \moodle_exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } - if ($USER->id === $inviteeid) { - throw new \moodle_exception('Cannot invite yourself'); + if ((int)$USER->id === $inviteeid) { + throw new \moodle_exception(get_string('err_invite_yourself', 'local_lbplanner')); } if (plan_helper::get_plan_id($inviteeid) == $planid) { - throw new \moodle_exception('Cannot invite user who is already a member'); + throw new \moodle_exception(get_string('err_invite_alrmember', 'local_lbplanner')); } if ( @@ -81,7 +81,7 @@ public static function invite_user(int $inviteeid): mixed { ['inviteeid' => $inviteeid, 'planid' => $planid, 'status' => PLAN_INVITE_STATE::PENDING] ) ) { - throw new \moodle_exception('User is already invited'); + throw new \moodle_exception(get_string('err_invite_alrinvited', 'local_lbplanner')); } // Save the invite. diff --git a/lbplanner/services/plan/leave_plan.php b/lbplanner/services/plan/leave_plan.php index 095762bd..0d583ff8 100644 --- a/lbplanner/services/plan/leave_plan.php +++ b/lbplanner/services/plan/leave_plan.php @@ -53,14 +53,15 @@ public static function leave_plan() { // TODO: remove useless check. if (plan_helper::get_access_type($USER->id, $planid) === PLAN_ACCESS_TYPE::NONE) { - throw new \moodle_exception('User is not a member of this plan'); + throw new \moodle_exception(get_string('err_plan_cantremove_userfromother', 'local_lbplanner')); } + // TODO: factor this out into plan_helper. if (plan_helper::get_access_type($USER->id, $planid) === PLAN_ACCESS_TYPE::OWNER) { $members = plan_helper::get_plan_members($planid); if (count($members) == 1) { - throw new \moodle_exception('Cannot Leave Plan: Plan must have at least one other member'); + throw new \moodle_exception(get_string('err_plan_cantleave_empty', 'local_lbplanner')); } $writemembers = []; diff --git a/lbplanner/services/plan/set_deadline.php b/lbplanner/services/plan/set_deadline.php index b6639e9e..f149726b 100644 --- a/lbplanner/services/plan/set_deadline.php +++ b/lbplanner/services/plan/set_deadline.php @@ -82,7 +82,7 @@ public static function set_deadline(int $moduleid, int $deadlinestart, int $dead $planid = plan_helper::get_plan_id($USER->id); if (!plan_helper::check_edit_permissions($planid, $USER->id)) { - throw new \moodle_exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $deadline = $DB->get_record(plan_helper::DEADLINES_TABLE, ['moduleid' => $moduleid, 'planid' => $planid]); diff --git a/lbplanner/services/plan/update_access.php b/lbplanner/services/plan/update_access.php index 5219a1a1..c6e14061 100644 --- a/lbplanner/services/plan/update_access.php +++ b/lbplanner/services/plan/update_access.php @@ -72,25 +72,27 @@ public static function update_access(int $accesstype, int $memberid) { $planid = plan_helper::get_plan_id($USER->id); if (plan_helper::get_owner($planid) !== intval($USER->id)) { - throw new \moodle_exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } + // TODO: factor out into plan_helper. + $accesstypeobj = PLAN_ACCESS_TYPE::try_from($accesstype); if ($accesstypeobj === null) { - throw new \moodle_exception('Access type not valid'); + throw new \moodle_exception(get_string('err_plan_changeaccess_inval', 'local_lbplanner')); } if ($USER->id === $memberid) { - throw new \moodle_exception('Cannot change own permissions'); + throw new \moodle_exception(get_string('err_plan_changeaccess_self', 'local_lbplanner')); } if (plan_helper::get_owner($planid) == $memberid) { - throw new \moodle_exception('Cannot change permissions for the plan owner'); + throw new \moodle_exception(get_string('err_plan_changeaccess_ofowner', 'local_lbplanner')); } if ($accesstypeobj === PLAN_ACCESS_TYPE::OWNER) { - throw new \moodle_exception('Cannot change permission to owner'); + throw new \moodle_exception(get_string('err_plan_changeaccess_toowner', 'local_lbplanner')); } $access = $DB->get_record(plan_helper::ACCESS_TABLE, ['planid' => $planid, 'userid' => $memberid], '*', MUST_EXIST); diff --git a/lbplanner/services/plan/update_plan.php b/lbplanner/services/plan/update_plan.php index 1b2e00b5..4fa05ffd 100644 --- a/lbplanner/services/plan/update_plan.php +++ b/lbplanner/services/plan/update_plan.php @@ -49,7 +49,7 @@ public static function update_plan_parameters(): external_function_parameters { * * @param string $planname Name of the Plan * @return void - * @throws Exception when access denied + * @throws \moodle_exception when access denied */ public static function update_plan(string $planname) { global $DB, $USER; @@ -62,7 +62,7 @@ public static function update_plan(string $planname) { $planid = plan_helper::get_plan_id($USER->id); if (!plan_helper::check_edit_permissions($planid, $USER->id)) { - throw new \Exception('Access denied'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $plan = $DB->get_record(plan_helper::TABLE, ['id' => $planid], '*', MUST_EXIST); diff --git a/lbplanner/services/slots/add_slot_filter.php b/lbplanner/services/slots/add_slot_filter.php index cad122b7..c2074933 100644 --- a/lbplanner/services/slots/add_slot_filter.php +++ b/lbplanner/services/slots/add_slot_filter.php @@ -81,10 +81,6 @@ public static function add_slot_filter(int $slotid, ?int $courseid, ?string $vin // Check if user is supervisor for this slot, throw error if not. slot_helper::assert_slot_supervisor($USER->id, $slotid); - // Ensure that either $courseid or $vintage are non-null. - if (is_null($courseid) && is_null($vintage)) { - throw new \moodle_exception('courseid and vintage can\'t both be null'); - } $filter = new slot_filter(0, $slotid, $courseid, $vintage); diff --git a/lbplanner/services/slots/book_reservation.php b/lbplanner/services/slots/book_reservation.php index e31837a5..2e49839c 100644 --- a/lbplanner/services/slots/book_reservation.php +++ b/lbplanner/services/slots/book_reservation.php @@ -88,12 +88,12 @@ public static function book_reservation(int $slotid, string $date, int $userid): $now = new DateTimeImmutable('today', $utctz); $dateobj = DateTimeImmutable::createFromFormat("Y-m-d", $date, $utctz); if ($dateobj === false) { - throw new \moodle_exception("invalid date formatting: got '{$date}', must be YYYY-MM-DD"); + throw new \moodle_exception(get_string('err_dateformat', 'local_lbplanner', $date)); } $td = $now->diff($dateobj); if ($td->invert === 1) { - throw new \moodle_exception('Can\'t reserve date in the past'); + throw new \moodle_exception(get_string('err_reserv_past', 'local_lbplanner')); } $maxdays = null; @@ -115,26 +115,26 @@ public static function book_reservation(int $slotid, string $date, int $userid): } if ($td->days > $maxdays) { - throw new \moodle_exception("Date is past allowed date ({$maxdays} days in the future)"); + throw new \moodle_exception(get_string('err_reserv_toofuture', 'local_lbplanner', $maxdays)); } $slot = slot_helper::get_slot($slotid); // Check if user has access to slot. if (count(slot_helper::filter_slots_for_user([$slot], $student)) === 0) { - throw new \moodle_exception('Student does not have access to this slot'); + throw new \moodle_exception(get_string('err_reserv_studentnoaccess', 'local_lbplanner')); } // Check if user is already in slot. foreach (slot_helper::get_reservations_for_slot($slotid) as $tmpreservation) { if ($tmpreservation->userid === $userid) { - throw new \moodle_exception('Student is already in slot'); + throw new \moodle_exception(get_string('err_reserv_studentalrin', 'local_lbplanner')); } } // Check if slot is full. if ($slot->get_fullness() >= $slot->size) { - throw new \moodle_exception('Slot is already full'); + throw new \moodle_exception(get_string('err_reserv_slotfull', 'local_lbplanner')); } $reservation = new reservation(0, $slotid, $dateobj, $userid, $curuserid); diff --git a/lbplanner/services/slots/delete_slot_filter.php b/lbplanner/services/slots/delete_slot_filter.php index bab51257..6b6baa48 100644 --- a/lbplanner/services/slots/delete_slot_filter.php +++ b/lbplanner/services/slots/delete_slot_filter.php @@ -64,7 +64,7 @@ public static function delete_slot_filter(int $filterid): void { // Check if user is supervisor for this slot, throw error if not. if (!slot_helper::check_slot_supervisor($USER->id, $filter->slotid)) { - throw new \moodle_exception('Insufficient Permission: you\'re not supervisor of this filter\'s associated slot'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } // Delete filter. diff --git a/lbplanner/services/slots/get_all_slots.php b/lbplanner/services/slots/get_all_slots.php index f612370c..23f477a8 100644 --- a/lbplanner/services/slots/get_all_slots.php +++ b/lbplanner/services/slots/get_all_slots.php @@ -47,7 +47,7 @@ public static function get_all_slots(): array { $user = user::from_mdlobj($USER); if (!($user->get_capabilitybitmask() & CAPABILITY_FLAG::SLOTMASTER)) { - throw new \moodle_exception('current user is not slotmaster'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $slots = slot_helper::get_all_slots(); diff --git a/lbplanner/services/slots/unbook_reservation.php b/lbplanner/services/slots/unbook_reservation.php index 3fe80f11..d984797b 100644 --- a/lbplanner/services/slots/unbook_reservation.php +++ b/lbplanner/services/slots/unbook_reservation.php @@ -77,25 +77,24 @@ public static function unbook_reservation(int $reservationid, bool $nice): void $startpast = $endpast || ($now->diff($reservation->get_datetime())->invert === 1); if ($userid === $reservation->userid) { - if ($startpast) { - throw new \moodle_exception('You can\'t unbook this reservation because it has already started'); + if ($endpast) { + throw new \moodle_exception(get_string('err_reserv_unreserv_alrended', 'local_lbplanner')); + } else if ($startpast) { + throw new \moodle_exception(get_string('err_reserv_unreserv_alrstarted', 'local_lbplanner')); } } else if (slot_helper::check_slot_supervisor($userid, $reservation->slotid)) { if ($endpast) { - throw new \moodle_exception('You can\'t unbook this reservation because it has already ended'); + throw new \moodle_exception(get_string('err_reserv_unreserv_alrended', 'local_lbplanner')); } if ($nice) { if ($startpast) { - throw new \moodle_exception( - 'Students can\'t unbook reservations that have already started.' - . ' If you want to unbook this reservation regardless, force it.' - ); + throw new \moodle_exception(get_string('err_reserv_unreserv_alrstartedorforce', 'local_lbplanner')); } notifications_helper::notify_user($reservation->userid, $reservation->id, NOTIF_TRIGGER::UNBOOK_REQUESTED); return; } } else { - throw new \moodle_exception('insufficient permission to unbook this reservation'); + throw new \moodle_exception(get_string('err_accessdenied', 'local_lbplanner')); } $DB->delete_records( diff --git a/lbplanner/services/slots/update_slot.php b/lbplanner/services/slots/update_slot.php index 2b7a6761..716f4ef0 100644 --- a/lbplanner/services/slots/update_slot.php +++ b/lbplanner/services/slots/update_slot.php @@ -125,7 +125,7 @@ public static function update_slot(int $id, ?int $startunit, ?int $duration, ?in ); // Check if slot is now overfull, and notify frontend via exception if so. if ($slot->get_fullness() > $slot->size) { - throw new \moodle_exception('Slot is now overfull!'); + throw new \moodle_exception(get_string('err_slot_overfull', 'local_lbplanner')); } } diff --git a/lbplanner/services/user/delete_user.php b/lbplanner/services/user/delete_user.php index 8a60580c..8e7e042c 100644 --- a/lbplanner/services/user/delete_user.php +++ b/lbplanner/services/user/delete_user.php @@ -50,7 +50,7 @@ public static function delete_user() { // Check if User is in user table. if (!$DB->record_exists(user_helper::EDUPLANNER_USER_TABLE, ['userid' => $userid])) { - throw new moodle_exception('User is not registered in Eduplanner'); + throw new moodle_exception(get_string('err_user_notfound', 'local_lbplanner')); } $planid = plan_helper::get_plan_id($userid); @@ -61,6 +61,7 @@ public static function delete_user() { && !(plan_helper::get_access_type($planid, $userid) == PLAN_ACCESS_TYPE::OWNER) ) { + // TODO: replace with plan_helper function. self::call_external_function('local_lbplanner_plan_leave_plan', ['userid' => $userid, 'planid' => $planid]); } $DB->delete_records(plan_helper::DEADLINES_TABLE, ['planid' => $planid]); @@ -83,6 +84,7 @@ public static function delete_user() { // Deleting all Courses associated with the User. $DB->delete_records(course_helper::EDUPLANNER_COURSE_TABLE, ['userid' => $userid]); + // TODO: delete kanban, slot, slot_filter & reservation data // Deleting User from User table. $DB->delete_records(user_helper::EDUPLANNER_USER_TABLE, ['userid' => $userid]); } diff --git a/lbplanner/settings.php b/lbplanner/settings.php index e36e054a..fead9c72 100644 --- a/lbplanner/settings.php +++ b/lbplanner/settings.php @@ -30,28 +30,31 @@ $settings = new admin_settingpage('local_lbplanner', 'EduPlanner'); $ADMIN->add('localplugins', $settings); + $daysingular = get_string('unit_day', 'local_lbplanner'); + $dayplural = get_string('unit_day_pl', 'local_lbplanner'); + $futuresightsett = new admin_setting_configselect( 'local_lbplanner/' . SETTINGS::SLOT_FUTURESIGHT, - 'Advance reservation limit', - 'Maximum number of days in advance students can reserve slots (0 = same day only).', + get_string('sett_futuresight_title', 'local_lbplanner'), + get_string('sett_futuresight_desc', 'local_lbplanner'), 3, [ - 0 => "0 Days", - 1 => "1 Day", - 2 => "2 Days", - 3 => "3 Days", - 4 => "4 Days", - 5 => "5 Days", - 6 => "6 Days", - 7 => "7 Days", + 0 => "0 {$dayplural}", + 1 => "1 {$daysingular}", + 2 => "2 {$dayplural}", + 3 => "3 {$dayplural}", + 4 => "4 {$dayplural}", + 5 => "5 {$dayplural}", + 6 => "6 {$dayplural}", + 7 => "7 {$dayplural}", ], ); $settings->add($futuresightsett); $outdaterangesett = new admin_setting_configduration( 'local_lbplanner/' . SETTINGS::COURSE_OUTDATERANGE, - 'Mark courses as outdated after', - 'The maximum duration a course remains visible in EduPlanner after it ends.', + get_string('sett_outdaterange_title', 'local_lbplanner'), + get_string('sett_outdaterange_desc', 'local_lbplanner'), 31536000, // 1 non-leap year. 86400, // In days. ); @@ -60,8 +63,8 @@ $sentrydsnsett = new admin_setting_configtext( 'local_lbplanner/' . SETTINGS::SENTRY_DSN, - 'Sentry DSN', - 'for where to send error debugging info to.', + get_string('sett_sentrydsn_title', 'local_lbplanner'), + get_string('sett_sentrydsn_desc', 'local_lbplanner'), '', PARAM_TEXT ); @@ -69,8 +72,8 @@ $panicsett = new admin_setting_configcheckbox( 'local_lbplanner/' . SETTINGS::PANIC, - 'PANIC SWITCH', - 'Turns API off - only use in emergencies. No data loss, but total loss of EduPlanner services until box is unchecked.', + get_string('sett_panic_title', 'local_lbplanner'), + get_string('sett_panic_desc', 'local_lbplanner'), '0', ); $settings->add($panicsett);