ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ModeToggle.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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 
39  protected WrapperFactory $wrapper;
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())
60  : self::MODE1;
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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static initILIAS()
ilias initialisation
ILIAS HTTP Services $http
Definition: ModeToggle.php:43
static http()
Fetches the global http state from ILIAS.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
global $DIC
Definition: shib_login.php:26
Class ModeToggle This is just for testing!!! And will be removed after.
Definition: ModeToggle.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
header()
expected output: > ILIAS shows the rendered Component.
Definition: header.php:29