From db4ca7bcb4329b7fc4d3a16d4be38c5ed889ac96 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <hackl@data-quest.de>
Date: Thu, 17 Feb 2022 15:50:55 +0100
Subject: [PATCH] allow optional use of semester index in SemesterSelector,
 fixes #685

---
 app/views/admin/autoinsert/_search.php | 3 ++-
 lib/models/Semester.class.php          | 6 +++++-
 templates/shared/semester-selector.php | 2 +-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/app/views/admin/autoinsert/_search.php b/app/views/admin/autoinsert/_search.php
index 10890f6feb1..c457d7466b0 100644
--- a/app/views/admin/autoinsert/_search.php
+++ b/app/views/admin/autoinsert/_search.php
@@ -7,7 +7,8 @@
         <?= Semester::getSemesterSelector(
             ['name' => 'sem_select', 'id' => 'sem_select', 'class' => 'user_form'],
             $sem_select, 'semester_id',
-            true
+            true,
+            false
         )?>
     </label>
     <label>
diff --git a/lib/models/Semester.class.php b/lib/models/Semester.class.php
index 022a59a0e62..b2b7f31a864 100644
--- a/lib/models/Semester.class.php
+++ b/lib/models/Semester.class.php
@@ -233,13 +233,16 @@ class Semester extends SimpleORMap
      * @param integer $default
      * @param string $option_value
      * @param boolean $include_all
+     * @param boolean $use_semester_id
      * @return string
      */
     public static function getSemesterSelector(
         $select_attributes = null,
         $default = 0,
         $option_value = 'semester_id',
-        $include_all = true)
+        $include_all = true,
+        $use_semester_id = true
+    )
     {
         $semester = Semester::findAllVisible();
 
@@ -262,6 +265,7 @@ class Semester extends SimpleORMap
         $template->select_attributes = $select_attributes;
         $template->default = $default;
         $template->option_value = $option_value;
+        $template->use_semester_id = $use_semester_id;
         return $template->render();
     }
 
diff --git a/templates/shared/semester-selector.php b/templates/shared/semester-selector.php
index 4d5ab8eb62a..74761bf8027 100644
--- a/templates/shared/semester-selector.php
+++ b/templates/shared/semester-selector.php
@@ -4,7 +4,7 @@
 <select <?= $attributes ?>>
     <? foreach ($semesters as $sem_key => $one_sem) : ?>
         <? $one_sem['key'] = $sem_key; ?>
-        <option value="<?= $one_sem[$option_value] ?>" <?= ($one_sem[$option_value] == $default ? "selected" : "") ?>>
+        <option value="<?= $use_semester_id ? $one_sem[$option_value] : $sem_key ?>" <?= ($one_sem[$option_value] == $default ? "selected" : "") ?>>
             <?= htmlReady($one_sem['name']) ?>
         </option>
     <? endforeach ?>
-- 
GitLab