From 99be6af8ce8a01257c8af28d4c22e9090f9bf1f7 Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Mon, 16 Jun 2025 14:08:57 +0000
Subject: [PATCH] GS-1843
---
php/alex.php | 86 ++++++++++++++++++++++++++++++++++++++----
1 files changed, 77 insertions(+), 9 deletions(-)
diff --git a/php/alex.php b/php/alex.php
index 7334cf6..82a2306 100644
--- a/php/alex.php
+++ b/php/alex.php
@@ -1,21 +1,89 @@
<?php
declare(strict_types=1);
-# Testdatei für globus-ilias-rest
-
try {
-
+ # Init ILIAS
require_once("Services/Init/classes/class.ilInitialisation.php");
ilInitialisation::initILIAS();
- $usr = ilObjectFactory::getInstanceByObjId(316);
- //echo $usr; aa
- echo json_encode($usr);
+ include_once 'Services/Context/classes/class.ilContext.php';
+ ilContext::init(ilContext::CONTEXT_REST);
- echo "jojojo";
-}
-catch(Exception $ex) {
+ header("Content-Type: application/json; charset=UTF-8");
+
+ $method = $_SERVER['REQUEST_METHOD'];
+ $command = $_GET["command"];
+ $obj_id = (int) $_GET["obj_id"];
+ $dry = $_GET["dry"]; # "0" = false, "1" = true
+
+ $res = array(
+ "method" => $method,
+ "command" => $command,
+ "obj_id" => $obj_id,
+ "status" => null,
+ "msg" => null
+ );
+
+ try {
+ switch ($command) {
+ case "deleteUser":
+ if ($method == "DELETE") {
+ $res["msg"] = deleteUser($obj_id, $dry);
+ $res["status"] = "ok";
+ break;
+ }
+ case "deleteTeilnahme":
+ if ($method == "DELETE") {
+ $usr_id = (int) $_GET["usr_id"];
+ $res["usr_id"] = $usr_id;
+ $res["msg"] = deleteTeilnahme($obj_id, $usr_id, $dry);
+ $res["status"] = "ok";
+ break;
+ }
+ default:
+ http_response_code(500);
+ $res = array("status" => "error", "msg" => "unknown command or method");
+ }
+ } catch (Exception $err) {
+ http_response_code(500);
+ $res["status"] = "error";
+ $res["msg"] = $err->__tostring();
+ }
+
+ $json = json_encode($res, JSON_PRETTY_PRINT);
+ echo $json;
+} catch (Exception $ex) {
echo $ex;
}
+
+###############################
+
+function deleteUser($obj_id, $dry)
+{
+ $usr = ilObjectFactory::getInstanceByObjId($obj_id);
+ $msg = "deleted user {$usr->firstname} {$usr->lastname} ({$obj_id})";
+ if ($dry == "0") {
+ $usr->delete();
+ return $msg;
+ } else {
+ $msg = "DRY:: ".$msg;
+ return $msg;
+ }
+}
+
+function deleteTeilnahme($obj_id, $usr_id, $dry) {
+ $course = ilObjectFactory::getInstanceByObjId($obj_id);
+ #$members = $course->getMembersObject(); # ilCourseParticipants # sackgasse
+ $msg = "deleted user({$usr_id}) teilnahme for course '{$course->getTitle()}' ({$obj_id})";
+ #return json_encode($members, JSON_PRETTY_PRINT);
+ if ($dry == "0") {
+ $course->_deleteUser($usr_id);
+ return $msg;
+ } else {
+ $msg = "DRY:: ".$msg;
+ return $msg;
+ }
+}
+
?>
--
Gitblit v1.8.0