ILIAS  release_7 Revision v7.30-3-g800a261c036
ItemState.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
21
23use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
24use ILIAS\HTTP\Wrapper\WrapperFactory;
26
33{
34 use Hasher;
35
36 public const LEVEL_OF_TOOL = 1;
37 public const COOKIE_NS_GS = 'gs_active_items';
45 private $storage;
46
50 protected $wrapper;
54 protected $refinery;
55
62 {
63 $this->identification = $identification;
64 $this->storage = $this->getStorage();
66 global $DIC;
67 $this->wrapper = $DIC->http()->wrapper();
68 $this->refinery = $DIC->refinery();
69 }
70
71 public function isItemActive() : bool
72 {
73 $hash = $this->hash($this->identification->serialize());
74 $b = isset($this->storage[$hash]) && $this->storage[$hash] == true;
75
76 return $b;
77 }
78
82 public function getStorage() : array
83 {
84 static $json_decode;
85 if (!isset($json_decode)) {
86 $cookie_value = $this->wrapper->cookie()->has(self::COOKIE_NS_GS)
87 ? $this->wrapper->cookie()->retrieve(self::COOKIE_NS_GS, $this->refinery->to()->string())
88 : '{}';
89
90 $json_decode = json_decode($cookie_value, true, 512);
91 $json_decode = is_array($json_decode) ? $json_decode : [];
92 }
93
94 return $json_decode;
95 }
96}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
__construct(IdentificationInterface $identification)
ItemState constructor.
Definition: ItemState.php:61
static initILIAS()
ilias initialisation
global $DIC
Definition: goto.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: gs_content.php:1