ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ModeToggle.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
21 
25 
32 {
33  public const GS_MODE = 'gs_mode';
34  public const MODE1 = "all";
35  public const MODE2 = "none";
36 
40  protected $wrapper;
44  protected $refinery;
48  protected $ctrl;
52  protected $global_screen;
56  protected $http;
57 
58  public function __construct()
59  {
61  global $DIC;
62  $this->ctrl = $DIC->ctrl();
63  $this->wrapper = $DIC->http()->wrapper();
64  $this->http = $DIC->http();
65  $this->refinery = $DIC->refinery();
66  $this->global_screen = $DIC->globalScreen();
67  }
68 
69  public function getMode() : string
70  {
71  return $this->wrapper->cookie()->has(self::GS_MODE)
72  ? $this->wrapper->cookie()->retrieve(self::GS_MODE, $this->refinery->to()->string())
73  : self::MODE1;
74  }
75 
76  public function saveStateOfAll() : bool
77  {
78  return $this->getMode() == ItemState::LEVEL_OF_TOOL;
79  }
80 
81  public function toggle() : void
82  {
83  $current_mode = $this->getMode();
84  $new_mode = $current_mode == self::MODE1 ? self::MODE2 : self::MODE1;
85  $cookie_factory = new CookieFactoryImpl();
86  $cookie = $cookie_factory->create(self::GS_MODE, $new_mode)
87  ->withExpires(time() + 3600);
88  $this->http->cookieJar()->with($cookie);
89  header('Location: ' . $_SERVER['HTTP_REFERER']);
90  }
91 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: gs_content.php:1
static initILIAS()
ilias initialisation
static http()
Fetches the global http state from ILIAS.
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
global $DIC
Definition: goto.php:24
Class ModeToggle This is just for testing!!! And will be removed after.
Definition: ModeToggle.php:31