Skip to content

Commit

Permalink
lifecycletrigger_categories: A bit of general refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Feb 21, 2024
1 parent b8fbf35 commit 433ee39
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions trigger/categories/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function check_course($course, $triggerid) {
public function get_course_recordset_where($triggerid) {
global $DB, $CFG;
$categories = settings_manager::get_settings($triggerid, settings_type::TRIGGER)['categories'];
$exclude = settings_manager::get_settings($triggerid, settings_type::TRIGGER)['exclude'] && true;
$exclude = settings_manager::get_settings($triggerid, settings_type::TRIGGER)['exclude'];

$categories = explode(',', $categories);
// Use core_course_category for moodle 3.6 and higher.
Expand All @@ -75,17 +75,14 @@ public function get_course_recordset_where($triggerid) {
}
$allcategories = [];
foreach ($categories as $category) {
array_push($allcategories , $category);
array_push($allcategories, $category);
$children = $categoryobjects[$category]->get_all_children_ids();
$allcategories = array_merge($allcategories , $children);
$allcategories = array_merge($allcategories, $children);
}

list($insql, $inparams) = $DB->get_in_or_equal($allcategories, SQL_PARAMS_NAMED);
list($insql, $inparams) = $DB->get_in_or_equal($allcategories, SQL_PARAMS_NAMED, 'param', !$exclude);

$where = "{course}.category {$insql}";
if ($exclude) {
$where = "NOT " . $where;
}

return [$where, $inparams];
}
Expand Down Expand Up @@ -142,7 +139,7 @@ public function ensure_validity(array $settings): array {
// Use core_course_category for moodle 3.6 and higher.
$categoryobjects = \core_course_category::get_many($categories);
foreach ($categories as $category) {
if (!$categoryobjects[$category]) {
if (!isset($categoryobjects[$category])) {
$errors[] = get_string('category_does_not_exist', 'lifecycletrigger_categories', $category);
}
}
Expand Down

0 comments on commit 433ee39

Please sign in to comment.