ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ItemState.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
27
34{
35 use Hasher;
36
37 public const LEVEL_OF_TOOL = 1;
38 public const COOKIE_NS_GS = 'gs_active_items';
39 private array $storage;
40
42 protected Factory $refinery;
43
49 public function __construct(private IdentificationInterface $identification)
50 {
51 $this->storage = $this->getStorage();
53 global $DIC;
54 $this->wrapper = $DIC->http()->wrapper();
55 $this->refinery = $DIC->refinery();
56 }
57
58 public function isItemActive(): bool
59 {
60 $hash = $this->hash($this->identification->serialize());
61 $b = isset($this->storage[$hash]) && $this->storage[$hash] == true;
62
63 return $b;
64 }
65
69 public function getStorage(): array
70 {
71 static $json_decode;
72 if (!isset($json_decode)) {
73 $cookie_value = $this->wrapper->cookie()->has(self::COOKIE_NS_GS)
74 ? $this->wrapper->cookie()->retrieve(self::COOKIE_NS_GS, $this->refinery->to()->string())
75 : '{}';
76
77 $json_decode = json_decode((string) $cookie_value, true);
78 $json_decode = is_array($json_decode) ? $json_decode : [];
79 }
80
81 return $json_decode;
82 }
83}
Builds data types.
Definition: Factory.php:36
__construct(private IdentificationInterface $identification)
ItemState constructor.
Definition: ItemState.php:49
static initILIAS()
ilias initialisation
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26