/** * Prioritize courses. */ function claim_action() { CSRFProtection::verifyUnsafeRequest(); $user_id = $GLOBALS['user']->id; $courseset = CourseSet::getSetForCourse($this->course_id); if ($courseset->isSeatDistributionEnabled() && !count($courseset->checkAdmission($user_id, $this->course_id))) { if ($limit = $courseset->getAdmissionRule('LimitedAdmission')) { $admission_user_limit = Request::int('admission_user_limit'); if ($admission_user_limit && $admission_user_limit <= $limit->getMaxNumber()) { $limit->setCustomMaxNumber($user_id, $admission_user_limit); } $admission_prio = Request::getArray('admission_prio'); $max_prio = max($admission_prio); $admission_prio = array_map(function ($a) use(&$max_prio) { return $a > 0 ? $a : ++$max_prio; }, $admission_prio); if (count(array_unique($admission_prio)) != count(Request::getArray('admission_prio'))) { PageLayout::postMessage(MessageBox::info(_("Sie dürfen jede Priorität nur einmal auswählen. Überprüfen Sie bitte Ihre Auswahl!"))); } $old_prio_count = AdmissionPriority::unsetAllPrioritiesForUser($courseset->getId(), $user_id); if ($order_up = key(Request::getArray('admission_prio_order_up'))) { $prio_to_move = $admission_prio[$order_up]; $change_with = array_search($prio_to_move - 1, $admission_prio); $admission_prio[$order_up] = $prio_to_move - 1; $admission_prio[$change_with] = $prio_to_move; } if ($order_down = key(Request::getArray('admission_prio_order_down'))) { $prio_to_move = $admission_prio[$order_down]; $change_with = array_search($prio_to_move + 1, $admission_prio); $admission_prio[$order_down] = $prio_to_move + 1; $admission_prio[$change_with] = $prio_to_move; } if ($delete = key(Request::getArray('admission_prio_delete'))) { unset($admission_prio[$delete]); $changed = 1; $admission_prio = array_map(function ($a) { static $c = 1; return $c++; }, $admission_prio); } foreach ($admission_prio as $course_id => $p) { $changed += AdmissionPriority::setPriority($courseset->getId(), $user_id, $course_id, $p); } if ($changed || $old_prio_count && !count($admission_prio)) { if (count(AdmissionPriority::getPrioritiesByUser($courseset->getId(), $user_id))) { PageLayout::postMessage(MessageBox::success(_("Ihre Priorisierung wurde gespeichert."))); } else { PageLayout::postMessage(MessageBox::success(_("Ihre Anmeldung zur Platzvergabe wurde zurückgezogen."))); } } } else { if (Request::int('courseset_claimed')) { if (AdmissionPriority::setPriority($courseset->getId(), $user_id, $this->course_id, 1)) { PageLayout::postMessage(MessageBox::success(_("Ihre Anmeldung zur Platzvergabe wurde gespeichert."))); } } else { if (AdmissionPriority::unsetPriority($courseset->getId(), $user_id, $this->course_id)) { PageLayout::postMessage(MessageBox::success(_("Ihre Anmeldung zur Platzvergabe wurde zurückgezogen."))); } } } } $this->redirect($this->url_for('/apply/' . $this->course_id)); }