ILIAS  release_8 Revision v8.24
ModeToggle.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
21
25
32{
33 public const GS_MODE = 'gs_mode';
34 public const MODE1 = "all";
35 public const MODE2 = "none";
36
38 protected Factory $refinery;
39 protected \ilCtrlInterface $ctrl;
40 protected \ILIAS\GlobalScreen\Services $global_screen;
41 protected \ILIAS\HTTP\Services $http;
42
43 public function __construct()
44 {
46 global $DIC;
47 $this->ctrl = $DIC->ctrl();
48 $this->wrapper = $DIC->http()->wrapper();
49 $this->http = $DIC->http();
50 $this->refinery = $DIC->refinery();
51 $this->global_screen = $DIC->globalScreen();
52 }
53
54 public function getMode(): string
55 {
56 return $this->wrapper->cookie()->has(self::GS_MODE)
57 ? $this->wrapper->cookie()->retrieve(self::GS_MODE, $this->refinery->to()->string())
59 }
60
61 public function saveStateOfAll(): bool
62 {
63 return $this->getMode() == ItemState::LEVEL_OF_TOOL;
64 }
65
66 public function toggle(): void
67 {
68 $current_mode = $this->getMode();
69 $new_mode = $current_mode == self::MODE1 ? self::MODE2 : self::MODE1;
70 $cookie_factory = new CookieFactoryImpl();
71 $cookie = $cookie_factory->create(self::GS_MODE, $new_mode)
72 ->withExpires(time() + 3600);
73 $this->http->cookieJar()->with($cookie);
74 header('Location: ' . $_SERVER['HTTP_REFERER']);
75 }
76}
Builds data types.
Definition: Factory.php:21
Class ModeToggle This is just for testing!!! And will be removed after.
Definition: ModeToggle.php:32
ILIAS GlobalScreen Services $global_screen
Definition: ModeToggle.php:40
static initILIAS()
ilias initialisation
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: gs_content.php:1
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10