ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAwarenessMetaBarProvider.php
Go to the documentation of this file.
1 <?php
2 
3 
10 
17 {
18 
22  private function getId() : IdentificationInterface
23  {
24  return $this->if->identifier('awareness');
25  }
26 
27 
31  public function getAllIdentifications() : array
32  {
33  return [$this->getId()];
34  }
35 
36 
40  public function getMetaBarItems() : array
41  {
42  global $DIC;
43 
44  $ilUser = $DIC->user();
45 
46  $awrn_set = new ilSetting("awrn");
47  if (!$awrn_set->get("awrn_enabled", false) || ANONYMOUS_USER_ID == $ilUser->getId() || $ilUser->getId() == 0) {
48  return [];
49  }
50 
51  $cache_period = (int) $awrn_set->get("caching_period");
52  $last_update = ilSession::get("awrn_last_update");
53  $now = time();
54 
55  $act = ilAwarenessAct::getInstance($ilUser->getId());
56  $act->setRefId((int) $_GET["ref_id"]);
57  if ($last_update == "" || ($now - $last_update) >= $cache_period) {
58  $cnt = explode(":", $act->getAwarenessUserCounter());
59  $hcnt = $cnt[1];
60  $cnt = $cnt[0];
61  $act->notifyOnNewOnlineContacts();
62  ilSession::set("awrn_last_update", $now);
63  ilSession::set("awrn_nr_users", $cnt);
64  ilSession::set("awrn_nr_husers", $hcnt);
65  } else {
66  $cnt = (int) ilSession::get("awrn_nr_users");
67  $hcnt = (int) ilSession::get("awrn_nr_husers");
68  }
69 
70 
71  $gui = new ilAwarenessGUI();
72  $result = $gui->getAwarenessList(true);
73 
74  $content = function () use ($result) {
75  //return $this->dic->ui()->factory()->legacy("<div id='awareness-content'></div>");
76  return $this->dic->ui()->factory()->legacy($result["html"]);
77  };
78 
79  $mb = $this->globalScreen()->metaBar();
80 
81  $f = $DIC->ui()->factory();
82 
83  $online = explode(":", $result["cnt"]);
84  $online = $online[0];
85 
86  $item = $mb
87  ->topLegacyItem($this->getId())
88  ->addComponentDecorator(static function (ILIAS\UI\Component\Component $c) : ILIAS\UI\Component\Component {
89  if ($c instanceof BulkyButton || $c instanceof BulkyLink) {
90  return $c->withAdditionalOnLoadCode(static function (string $id) : string {
91  return "$('#$id').on('click', function() {
92  console.log('trigger awareness slate');
93  })";
94  });
95  }
96  return $c;
97  })
98  ->withLegacyContent($content())
99  ->withSymbol(
100  $this->dic->ui()->factory()
101  ->symbol()
102  ->glyph()
103  ->user()
104  ->withCounter($f->counter()->status((int) $cnt))
105  ->withCounter($f->counter()->novelty((int) $hcnt))
106  )
107  ->withTitle($this->dic->language()->txt("awra"))
108  ->withPosition(2)
109  ->withAvailableCallable(
110  function () use ($DIC, $online) {
111  $ilUser = $DIC->user();
112 
113  $awrn_set = new ilSetting("awrn");
114  if ($online <= 0 || !$awrn_set->get("awrn_enabled", false) || ANONYMOUS_USER_ID == $ilUser->getId()) {
115  return false;
116  }
117  return true;
118  }
119  );
120 
121  return [$item];
122  }
123 }
Class Factory.
static getInstance($a_user_id)
Get instance (for a user)
$c
Definition: cli.php:37
const ANONYMOUS_USER_ID
Definition: constants.php:25
$result
$_GET["client_id"]
Class ChatMainBarProvider .
static get($a_var)
Get a value.
static set($a_var, $a_val)
Set a value.
Who-Is-Online meta bar provider.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
Awareness GUI class.