ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ItemState.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
21 
26 
32 class ItemState
33 {
34  use Hasher;
35 
36  public const LEVEL_OF_TOOL = 1;
37  public const COOKIE_NS_GS = 'gs_active_items';
39  private array $storage;
40 
42  protected Factory $refinery;
43 
49  public function __construct(IdentificationInterface $identification)
50  {
51  $this->identification = $identification;
52  $this->storage = $this->getStorage();
54  global $DIC;
55  $this->wrapper = $DIC->http()->wrapper();
56  $this->refinery = $DIC->refinery();
57  }
58 
59  public function isItemActive(): bool
60  {
61  $hash = $this->hash($this->identification->serialize());
62  $b = isset($this->storage[$hash]) && $this->storage[$hash] == true;
63 
64  return $b;
65  }
66 
70  public function getStorage(): array
71  {
72  static $json_decode;
73  if (!isset($json_decode)) {
74  $cookie_value = $this->wrapper->cookie()->has(self::COOKIE_NS_GS)
75  ? $this->wrapper->cookie()->retrieve(self::COOKIE_NS_GS, $this->refinery->to()->string())
76  : '{}';
77 
78  $json_decode = json_decode($cookie_value, true);
79  $json_decode = is_array($json_decode) ? $json_decode : [];
80  }
81 
82  return $json_decode;
83  }
84 }
IdentificationInterface $identification
Definition: ItemState.php:38
__construct(IdentificationInterface $identification)
ItemState constructor.
Definition: ItemState.php:49
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: gs_content.php:1
global $DIC
Definition: feed.php:28
static initILIAS()
ilias initialisation
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...