From a629426a92c0907821ffd20ad991b23c87bc3d66 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Tue, 25 Jun 2024 12:12:17 +0000
Subject: [PATCH] add column to mark resources as requestable via the booking
 plan, fixes #2715

Closes #2715

Merge request studip/studip!2172
---
 app/controllers/resources/room.php          |  2 ++
 app/views/resources/room/_add_edit_form.php |  5 +++++
 db/migrations/6.0.12_tic_2715.php           | 21 +++++++++++++++++++++
 lib/models/resources/Resource.php           |  2 +-
 4 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 db/migrations/6.0.12_tic_2715.php

diff --git a/app/controllers/resources/room.php b/app/controllers/resources/room.php
index b3a77a1a4f6..a5448c06a31 100644
--- a/app/controllers/resources/room.php
+++ b/app/controllers/resources/room.php
@@ -293,6 +293,7 @@ class Resources_RoomController extends AuthenticatedController
                 $this->room_type              = Request::get('room_type');
                 $this->seats                  = Request::int('seats');
                 $this->booking_plan_is_public = Request::get('booking_plan_is_public');
+                $this->booking_plan_request   = Request::int('booking_plan_request', 0);
                 $this->sort_position          = Request::get('sort_position');
                 $this->property_data          = Request::getArray('properties');
 
@@ -365,6 +366,7 @@ class Resources_RoomController extends AuthenticatedController
                 $this->room->description = $this->description;
                 $this->room->requestable = strval($this->requestable);
                 $this->room->lockable    = $this->lockable;
+                $this->room->booking_plan_request = $this->booking_plan_request;
                 if ($GLOBALS['perm']->have_perm('root')) {
                     $this->room->sort_position = $this->sort_position;
                 }
diff --git a/app/views/resources/room/_add_edit_form.php b/app/views/resources/room/_add_edit_form.php
index 320996ccc26..77e45699725 100644
--- a/app/views/resources/room/_add_edit_form.php
+++ b/app/views/resources/room/_add_edit_form.php
@@ -37,6 +37,11 @@
                        <?= $room->lockable ? 'checked' : '' ?>>
                 <?= _('Globale Buchungssperren gelten fÞr diesen Raum') ?>
             </label>
+            <label>
+                <input type="checkbox" name="booking_plan_request" value="1"
+                       <?= $room->booking_plan_request ? 'checked' : '' ?>>
+                <?= _('Raumanfragen Þber den Belegungsplan mÃķglich') ?>
+            </label>
             <label>
                 <?= _('Raumtyp') ?>
                 <input type="text" name="room_type" value="<?= htmlReady($room_type ?? '') ?>">
diff --git a/db/migrations/6.0.12_tic_2715.php b/db/migrations/6.0.12_tic_2715.php
new file mode 100644
index 00000000000..f6cfa597dc5
--- /dev/null
+++ b/db/migrations/6.0.12_tic_2715.php
@@ -0,0 +1,21 @@
+<?php
+class Tic2715 extends Migration
+{
+    public function description ()
+    {
+        return 'Add a column to mark resources as requestable via the booking plan, default is 1';
+    }
+
+    public function up()
+    {
+        $query = 'ALTER TABLE `resources`
+                  ADD `booking_plan_request` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 AFTER `lockable`';
+        DBManager::get()->exec($query);
+    }
+
+    public function down()
+    {
+        $query = 'ALTER TABLE `resources` DROP `booking_plan_request`';
+        DBManager::get()->exec($query);
+    }
+}
diff --git a/lib/models/resources/Resource.php b/lib/models/resources/Resource.php
index 32fce2b5926..7c870d93262 100644
--- a/lib/models/resources/Resource.php
+++ b/lib/models/resources/Resource.php
@@ -2479,7 +2479,7 @@ class Resource extends SimpleORMap implements StudipItem
      */
     public function userHasRequestRights(User $user)
     {
-        if (!Config::get()->RESOURCES_ALLOW_ROOM_REQUESTS) {
+        if (!Config::get()->RESOURCES_ALLOW_ROOM_REQUESTS || !$this->booking_plan_request) {
             return false;
         }
         $min_perm = Config::get()->RESOURCES_MIN_REQUEST_PERMISSION;
-- 
GitLab