ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ModeToggle.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
34{
35 public const GS_MODE = 'gs_mode';
36 public const MODE1 = "all";
37 public const MODE2 = "none";
38
40 protected Factory $refinery;
41 protected \ilCtrlInterface $ctrl;
43 protected \ILIAS\HTTP\Services $http;
44
45 public function __construct()
46 {
48 global $DIC;
49 $this->ctrl = $DIC->ctrl();
50 $this->wrapper = $DIC->http()->wrapper();
51 $this->http = $DIC->http();
52 $this->refinery = $DIC->refinery();
53 $this->global_screen = $DIC->globalScreen();
54 }
55
56 public function getMode(): string
57 {
58 return $this->wrapper->cookie()->has(self::GS_MODE)
59 ? $this->wrapper->cookie()->retrieve(self::GS_MODE, $this->refinery->to()->string())
61 }
62
63 public function saveStateOfAll(): bool
64 {
65 return $this->getMode() == ItemState::LEVEL_OF_TOOL;
66 }
67
68 public function toggle(): void
69 {
70 $current_mode = $this->getMode();
71 $new_mode = $current_mode === self::MODE1 ? self::MODE2 : self::MODE1;
72 $cookie_factory = new CookieFactoryImpl();
73 $cookie = $cookie_factory->create(self::GS_MODE, $new_mode)
74 ->withExpires(time() + 3600);
75 $this->http->cookieJar()->with($cookie);
76 header('Location: ' . $_SERVER['HTTP_REFERER']);
77 }
78}
Builds data types.
Definition: Factory.php:36
Class ModeToggle This is just for testing!!! And will be removed after.
Definition: ModeToggle.php:34
static initILIAS()
ilias initialisation
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...
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26