ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ItemState.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
33 class ItemState
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 
41  protected WrapperFactory $wrapper;
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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ItemState.
Definition: ItemState.php:33
WrapperFactory $wrapper
Definition: ItemState.php:41
__construct(private IdentificationInterface $identification)
ItemState constructor.
Definition: ItemState.php:49
static initILIAS()
ilias initialisation
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...