From f684f77e01c30a38c8d8fff887ac87353dd8470c Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Wed, 23 Oct 2024 16:05:24 +0200
Subject: [PATCH] Revert "remove unused RangeTreeIndex route, fixes #4397"

This reverts commit b4c1d253b302e2d5244ce607d54b5325372f0d65.
---
 .../Routes/RangeTree/RangeTreeIndex.php       | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 lib/classes/JsonApi/Routes/RangeTree/RangeTreeIndex.php

diff --git a/lib/classes/JsonApi/Routes/RangeTree/RangeTreeIndex.php b/lib/classes/JsonApi/Routes/RangeTree/RangeTreeIndex.php
new file mode 100644
index 00000000000..c706c482204
--- /dev/null
+++ b/lib/classes/JsonApi/Routes/RangeTree/RangeTreeIndex.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace JsonApi\Routes\RangeTree;
+
+use Psr\Http\Message\ServerRequestInterface as Request;
+use Psr\Http\Message\ResponseInterface as Response;
+use JsonApi\Errors\AuthorizationFailedException;
+use JsonApi\Errors\RecordNotFoundException;
+use JsonApi\JsonApiController;
+
+/**
+ * Zeigt eine bestimmte Veranstaltung an.
+ */
+class RangeTreeIndex extends JsonApiController
+{
+
+    protected $allowedIncludePaths = [
+        'children',
+        'courses',
+        'institute',
+        'parent',
+    ];
+    protected $allowedPagingParameters = ['offset', 'limit'];
+
+    /**
+     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+     */
+    public function __invoke(Request $request, Response $response, $args)
+    {
+        $tree = \TreeAbstract::getInstance('StudipSemTree', ['visible_only' => 1]);
+        $studyAreas = self::mapTree('root', $tree);
+        list($offset, $limit) = $this->getOffsetAndLimit();
+
+        return $this->getPaginatedContentResponse(
+            array_slice($studyAreas, $offset, $limit),
+            count($studyAreas)
+        );
+    }
+
+    private function mapTree($parentId, &$tree)
+    {
+        $level = [];
+        $kids = $tree->getKids($parentId);
+        if (is_array($kids) && count($kids) > 0) {
+            foreach ($kids as $kid) {
+                $level[] = \StudipStudyArea::find($kid);
+                $level = array_merge($level, self::mapTree($kid, $tree));
+            }
+        }
+
+        return $level;
+    }
+}
-- 
GitLab