ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
SlateSessionStateCode.php
Go to the documentation of this file.
1 <?php
2 
4 
10 
17 {
18  use Hasher;
19 
20 
26  public function addOnloadCode(Slate $slate, isItem $item) : Slate
27  {
28  return $slate;
29  if ($item instanceof Tool) {
30  $signal = $slate->getEngageSignal();
31  } else {
32  $signal = $slate->getToggleSignal();
33  }
34 
35  $signal_generator = new \ILIAS\UI\Implementation\Component\SignalGenerator();
36  $in_view_signal = $signal_generator->create();
37 
38  $slate = $slate->appendOnInView($in_view_signal);
39 
40  $identification = $item->getProviderIdentification()->serialize();
41  $item_state = new ItemState($item->getProviderIdentification());
42 
43  // if ($item_state->isItemActive()) {
44  // $slate = $slate->withEngaged(true);
45  // }
46 
47  $level = $this->getLevel($item);
48 
49  $slate = $slate->withAdditionalOnLoadCode(
50  function ($id) use ($in_view_signal, $identification, $level) {
51  $identification = addslashes($identification);
52 
53  return "
54  il.GS.Client.register(il.GS.Identification.getFromServerSideString('{$identification}'), '{$id}', {$level});
55  $(document).on('{$in_view_signal}', function(event, signalData) {
56  console.log('SlateSessionStateCode');
57  });
58  $(document).on('{$in_view_signal}', function(event, signalData) {
59  il.GS.Client.trigger('$id');
60  });";
61  }
62  );
63 
65  return $slate;
66  }
67 
68 
74  private function getLevel(isItem $item) : int
75  {
76  switch (true) {
77  case ($item instanceof Tool):
78  $level = ItemState::LEVEL_OF_TOOL;
79  break;
80  case ($item instanceof isTopItem):
82  break;
83  default:
85  }
86 
87  return $level;
88  }
89 }
getToggleSignal()
Signal that toggles the slate when triggered.
withAdditionalOnLoadCode(\Closure $binder)
Add some onload-code to the component instead of replacing the existing one.
appendOnInView(Signal $signal)
A Signal that is triggered when the slate "comes into view", i.e.
getEngageSignal()
Signal that engages the slate when triggered.