commit c3a5b6d031a3e7407c98d76ce772a7c24b7e26e6 Author: Atanas Georgiev Date: Thu Sep 28 12:34:05 2023 +0300 Alternative to UNION clause diff --git a/category.php b/category.php index 72538c8..8d51a36 100644 --- a/category.php +++ b/category.php @@ -3213,24 +3213,26 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr SELECT cc.". join(',cc.', $fields). ", $ctxselect FROM {course_categories} cc JOIN {context} ctx ON cc.id = ctx.instanceid AND ctx.contextlevel = :contextcoursecat1 - JOIN {role_assignments} ra ON ra.contextid = ctx.id WHERE ctx.path LIKE :parentpath1 - AND ra.userid = :userid1 - UNION - SELECT cc.". join(',cc.', $fields). ", $ctxselect - FROM {course_categories} cc - JOIN {context} ctx ON cc.id = ctx.instanceid AND ctx.contextlevel = :contextcoursecat2 - JOIN {role_capabilities} rc ON rc.contextid = ctx.id - JOIN {role_assignments} rc_ra ON rc_ra.roleid = rc.roleid - JOIN {context} rc_ra_ctx ON rc_ra_ctx.id = rc_ra.contextid - WHERE ctx.path LIKE :parentpath2 - AND rc_ra.userid = :userid2 - AND (ctx.path = rc_ra_ctx.path OR ctx.path LIKE " . $DB->sql_concat("rc_ra_ctx.path", "'/%'") . ") + AND ( + (ctx.id IN ( + SELECT ra.contextid + FROM {role_assignments} ra + WHERE ra.userid = :userid1 + )) + OR + (ctx.id IN ( + SELECT rc.contextid + FROM {role_capabilities} rc + JOIN {role_assignments} rc_ra ON rc.roleid = rc_ra.roleid + JOIN {context} rc_ra_ctx ON rc_ra_ctx.id = rc_ra.contextid + WHERE rc_ra.userid = :userid2 + AND (ctx.path = rc_ra_ctx.path OR ctx.path LIKE " . $DB->sql_concat("rc_ra_ctx.path", "'/%'") . ") + )) + ) ", [ 'contextcoursecat1' => CONTEXT_COURSECAT, - 'contextcoursecat2' => CONTEXT_COURSECAT, 'parentpath1' => $parentcat->get_context()->path . '/%', - 'parentpath2' => $parentcat->get_context()->path . '/%', 'userid1' => $USER->id, 'userid2' => $USER->id ]);