From b4f508cfda9d8233912059a72a51217c438f8e0e Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Mon, 15 Apr 2024 12:12:44 +0000
Subject: [PATCH] add room request actions to action menu on times rooms for
 irregular dates, fixes #4003

Closes #4003

Merge request studip/studip!2861
---
 app/controllers/course/timesrooms.php     |  5 ----
 app/views/course/timesrooms/_cycleRow.php | 30 ++++++++++++++++++++---
 app/views/course/timesrooms/editDate.php  | 20 ---------------
 3 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/app/controllers/course/timesrooms.php b/app/controllers/course/timesrooms.php
index c2b51cd671a..41a78a819bf 100644
--- a/app/controllers/course/timesrooms.php
+++ b/app/controllers/course/timesrooms.php
@@ -331,11 +331,6 @@ class Course_TimesroomsController extends AuthenticatedController
         $this->date       = CourseDate::find($termin_id) ?: CourseExDate::find($termin_id);
         $this->attributes = [];
 
-        if ($request = RoomRequest::findByDate($this->date->id)) {
-            $this->params = ['request_id' => $request->getId()];
-        } else {
-            $this->params = ['new_room_request_type' => 'date_' . $this->date->id];
-        }
         $this->only_bookable_rooms = Request::submitted('only_bookable_rooms');
 
         if (Config::get()->RESOURCES_ENABLE) {
diff --git a/app/views/course/timesrooms/_cycleRow.php b/app/views/course/timesrooms/_cycleRow.php
index 71a5085e1bf..5a5f60b15dc 100644
--- a/app/views/course/timesrooms/_cycleRow.php
+++ b/app/views/course/timesrooms/_cycleRow.php
@@ -82,8 +82,8 @@ $is_exTermin = $termin instanceof CourseExDate;
         <?= $room_holiday ?: '' ?>
     <? endif ?>
 
-    <? $room_request_exists = RoomRequest::existsByDate($termin->id, true) ?>
-    <? if ($room_request_exists): ?>
+    <? $room_request = RoomRequest::findByDate($termin->id) ?>
+    <? if ($room_request && $room_request->closed == ResourceRequest::STATE_OPEN): ?>
         <? $msg_info = _('Für diesen Termin existiert eine Raumanfrage.') ?>
         <?= tooltipIcon($msg_info) ?>
     <? endif ?>
@@ -123,9 +123,33 @@ $is_exTermin = $termin instanceof CourseExDate;
         <? $actionMenu->addLink(
             $controller->url_for('course/timesrooms/editDate/' . $termin->id, $linkAttributes),
             _('Termin bearbeiten'),
-            Icon::create('edit', Icon::ROLE_CLICKABLE, ['title' => _('Diesen Termin bearbeiten')]),
+            Icon::create('edit'),
             ['data-dialog' => '']
         ) ?>
+        <? $actionMenu
+                ->conditionAll(Config::get()->RESOURCES_ENABLE && Config::get()->RESOURCES_ALLOW_ROOM_REQUESTS)
+                ->condition((bool) $room_request)
+                ->addLink(
+                    $controller->url_for(
+                        'course/room_requests/request_show_summary',
+                        $room_request
+                    ),
+                    _('Raumanfrage bearbeiten'),
+                    Icon::create('room-occupied'),
+                    ['data-dialog' => 'size=big']
+                )
+                ->condition(!$room_request)
+                ->addLink(
+                    $controller->url_for(
+                        'course/room_requests/new_request',
+                        ['range_str' => 'date', 'range_id' => $termin->id]
+                    ),
+                    _('Neue Raumanfrage'),
+                    Icon::create('room-request'),
+                    ['data-dialog' => 'size=big']
+                )
+                ->conditionAll(true)
+        ?>
 
         <? $actionMenu->addLink(
             $controller->url_for(
diff --git a/app/views/course/timesrooms/editDate.php b/app/views/course/timesrooms/editDate.php
index e3bde2c2bcc..c4c1495a6d7 100644
--- a/app/views/course/timesrooms/editDate.php
+++ b/app/views/course/timesrooms/editDate.php
@@ -223,25 +223,5 @@
                 ),
               ['data-dialog' => 'size=big']) ?>
         <? endif ?>
-        <? if (Request::isXhr() && !$locked && Config::get()->RESOURCES_ENABLE && Config::get()->RESOURCES_ALLOW_ROOM_REQUESTS): ?>
-            <? if (isset($request_id)) : ?>
-                <?= Studip\LinkButton::create(
-                    _('Zur Raumanfrage wechseln'),
-                    $controller->url_for(
-                        'course/room_requests/request_show_summary/' . $request_id
-                    ),
-                    ['data-dialog' => 'size=big']
-                ) ?>
-            <? else : ?>
-                <?= Studip\LinkButton::create(
-                    _('Raumanfrage erstellen'),
-                    $controller->url_for(
-                        'course/room_requests/new_request',
-                        array_merge($params, ['range_str' => 'date', 'range_id' => $date->id])
-                    ),
-                    ['data-dialog' => 'size=big']
-                ) ?>
-            <? endif ?>
-        <? endif ?>
     </footer>
 </form>
-- 
GitLab