From f1b2dce1a89e2d53492375f5f2847a5c498caa07 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Mon, 14 Nov 2022 13:42:56 +0000
Subject: [PATCH] apply chdate filter first (and fix the filter so it actually
 works), fixes #1779

Closes #1779

Merge request studip/studip!1156
---
 app/controllers/course/admission.php      | 6 +++---
 lib/classes/admission/CourseSet.class.php | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/app/controllers/course/admission.php b/app/controllers/course/admission.php
index 78f1c1d6bdc..8b91dca46e2 100644
--- a/app/controllers/course/admission.php
+++ b/app/controllers/course/admission.php
@@ -70,7 +70,8 @@ class Course_AdmissionController extends AuthenticatedController
         $this->activated_admission_rules = AdmissionRule::getAvailableAdmissionRules();
         if (!$this->current_courseset) {
             $available_coursesets = new SimpleCollection();
-            foreach (CourseSet::getCoursesetsByInstituteId($this->course->institut_id) as $cs) {
+            $filter = ['course_set_chdate' => strtotime('-1 year')];
+            foreach (CourseSet::getCoursesetsByInstituteId($this->course->institut_id, $filter) as $cs) {
                 $cs = new CourseSet($cs['set_id']);
                 if ($cs->isUserAllowedToAssignCourse($this->user_id, $this->course_id)) {
                     $available_coursesets[] = [
@@ -81,7 +82,7 @@ class Course_AdmissionController extends AuthenticatedController
                     ];
                 }
             }
-            foreach (CourseSet::getglobalCoursesets() as $cs) {
+            foreach (CourseSet::getglobalCoursesets($filter) as $cs) {
                 $cs = new CourseSet($cs['set_id']);
                 if ($cs->isUserAllowedToAssignCourse($this->user_id, $this->course_id)) {
                     $available_coursesets[] = [
@@ -92,7 +93,6 @@ class Course_AdmissionController extends AuthenticatedController
                     ];
                 }
             }
-            $available_coursesets = $available_coursesets->findBy('chdate', strtotime('-1 year'), '>');
             $available_coursesets->orderBy('name');
             $this->available_coursesets = $available_coursesets;
 
diff --git a/lib/classes/admission/CourseSet.class.php b/lib/classes/admission/CourseSet.class.php
index e3a7e9246cb..a2ac383d297 100644
--- a/lib/classes/admission/CourseSet.class.php
+++ b/lib/classes/admission/CourseSet.class.php
@@ -394,8 +394,8 @@ class CourseSet
             $parameters[] = Semester::find($filter['semester_id'])->beginn;
         }
         if (!empty($filter['course_set_chdate'])) {
-            $query .= " AND c.chdate < ?";
-            $parameters[] = $filter['chdate'];
+            $query .= " AND c.chdate > ?";
+            $parameters[] = $filter['course_set_chdate'];
         }
         $query .= " ORDER BY c.name";
         $stmt = DBManager::get()->prepare($query);
@@ -433,8 +433,8 @@ class CourseSet
             $parameters[] = Semester::find($filter['semester_id'])->beginn;
         }
         if (!empty($filter['course_set_chdate'])) {
-            $query .= " AND c.chdate < ?";
-            $parameters[] = $filter['chdate'];
+            $query .= " AND c.chdate > ?";
+            $parameters[] = $filter['course_set_chdate'];
         }
         $query .= " ORDER BY c.name";
         $stmt = DBManager::get()->prepare($query);
-- 
GitLab