ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAwarenessGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
17  protected $user;
18 
22  protected $ctrl;
23 
27  protected $ui;
28 
32  protected $lng;
33 
37  public function __construct()
38  {
39  global $DIC;
40 
41  $this->user = $DIC->user();
42  global $DIC;
43  $this->ui = $DIC->ui();
44 
45  $this->ref_id = (int) $_GET["ref_id"];
46  $this->ctrl = $DIC->ctrl();
47  $this->lng = $DIC->language();
48  $this->lng->loadLanguageModule("awrn");
49  }
50 
54  public function executeCommand()
55  {
56  $cmd = $this->ctrl->getCmd();
57 
58  if (in_array($cmd, array("getAwarenessList"))) {
59  $this->$cmd();
60  }
61  }
62 
63 
69  public static function getInstance()
70  {
71  return new ilAwarenessGUI();
72  }
73 
77  public function getMainMenuHTML()
78  {
80 
81  $awrn_set = new ilSetting("awrn");
82  if (!$awrn_set->get("awrn_enabled", false) || ANONYMOUS_USER_ID == $ilUser->getId()) {
83  return "";
84  }
85 
86  $cache_period = (int) $awrn_set->get("caching_period");
87  $last_update = ilSession::get("awrn_last_update");
88  $now = time();
89 
90  // init js
91  $GLOBALS["tpl"]->addJavascript("./Services/Awareness/js/Awareness.js");
92  $this->ctrl->setParameter($this, "ref_id", $this->ref_id);
93  $GLOBALS["tpl"]->addOnloadCode("il.Awareness.setBaseUrl('" . $this->ctrl->getLinkTarget(
94  $this,
95  "",
96  "",
97  true,
98  false
99  ) . "');");
100  $GLOBALS["tpl"]->addOnloadCode("il.Awareness.setLoaderSrc('" . ilUtil::getImagePath("loader.svg") . "');");
101  $GLOBALS["tpl"]->addOnloadCode("il.Awareness.init();");
102 
103  // include user action js
104  include_once("./Services/User/Actions/classes/class.ilUserActionGUI.php");
105  include_once("./Services/Awareness/classes/class.ilAwarenessUserActionContext.php");
107  $ua_gui->init();
108 
109  $tpl = new ilTemplate("tpl.awareness.html", true, true, "Services/Awareness");
110 
111  include_once("./Services/Awareness/classes/class.ilAwarenessAct.php");
112  $act = ilAwarenessAct::getInstance($ilUser->getId());
113  $act->setRefId($this->ref_id);
114 
115  if ($last_update == "" || ($now - $last_update) >= $cache_period) {
116  $cnt = explode(":", $act->getAwarenessUserCounter());
117  $hcnt = $cnt[1];
118  $cnt = $cnt[0];
119  $act->notifyOnNewOnlineContacts();
120  ilSession::set("awrn_last_update", $now);
121  ilSession::set("awrn_nr_users", $cnt);
122  ilSession::set("awrn_nr_husers", $hcnt);
123  } else {
124  $cnt = (int) ilSession::get("awrn_nr_users");
125  $hcnt = (int) ilSession::get("awrn_nr_husers");
126  }
127 
128  if ($hcnt > 0 || $cnt > 0) {
129  /*
130  $tpl->setCurrentBlock("status_text");
131  $tpl->setVariable("STATUS_TXT", $cnt);
132  if ($cnt == 0)
133  {
134  $tpl->setVariable("HIDDEN", "ilAwrnBadgeHidden");
135  }
136  $tpl->parseCurrentBlock();
137  $tpl->setCurrentBlock("h_status_text");
138  $tpl->setVariable("H_STATUS_TXT", $hcnt);
139  if ($hcnt == 0)
140  {
141  $tpl->setVariable("H_HIDDEN", "ilAwrnBadgeHidden");
142  }
143  $tpl->parseCurrentBlock();
144  $tpl->setVariable("HSP", "&nbsp;");*/
145 
146  $f = $this->ui->factory();
147  $renderer = $this->ui->renderer();
148 
149  $glyph = $f->glyph()->user("#");
150  if ($cnt > 0) {
151  $glyph = $glyph->withCounter($f->counter()->status((int) $cnt));
152  }
153  if ($hcnt > 0) {
154  $glyph =$glyph->withCounter($f->counter()->novelty((int) $hcnt));
155  }
156  $glyph_html = $renderer->render($glyph);
157  $tpl->setVariable("GLYPH", $glyph_html);
158 
159 
160 
161  $tpl->setVariable("LOADER", ilUtil::getImagePath("loader.svg"));
162 
163  return $tpl->get();
164  }
165 
166  return "";
167  }
168 
172  public function getAwarenessList()
173  {
175 
176  $filter = $_GET["filter"];
177 
178  $tpl = new ilTemplate("tpl.awareness_list.html", true, true, "Services/Awareness");
179 
180  include_once("./Services/Awareness/classes/class.ilAwarenessAct.php");
181  $act = ilAwarenessAct::getInstance($ilUser->getId());
182  $act->setRefId($this->ref_id);
183 
184  $ad = $act->getAwarenessData($filter);
185 
186  // update counter
187  $now = time();
188  $cnt = explode(":", $ad["cnt"]);
189  $hcnt = $cnt[1];
190  $cnt = $cnt[0];
191  ilSession::set("awrn_last_update", $now);
192  ilSession::set("awrn_nr_users", $cnt);
193  ilSession::set("awrn_nr_husers", $hcnt);
194 
195 
196  $users = $ad["data"];
197 
198  $ucnt = 0;
199  $last_uc_title = "";
200  foreach ($users as $u) {
201  if ($u->collector != $last_uc_title) {
202  if ($u->highlighted) {
203  $tpl->touchBlock("highlighted");
204  }
205  $tpl->setCurrentBlock("uc_title");
206  $tpl->setVariable("UC_TITLE", $u->collector);
207  $tpl->parseCurrentBlock();
208  $tpl->setCurrentBlock("item");
209  $tpl->parseCurrentBlock();
210  }
211  $last_uc_title = $u->collector;
212 
213  $ucnt++;
214 
215  $fcnt = 0;
216  foreach ($u->actions as $act) {
217  $fcnt++;
218  if ($fcnt == 1) {
219  $tpl->touchBlock("arrow");
220  //$tpl->setCurrentBlock("arrow");
221  //$tpl->parseCurrentBlock();
222  }
223  if (is_array($act->data) && count($act->data) > 0) {
224  foreach ($act->data as $k => $v) {
225  $tpl->setCurrentBlock("f_data");
226  $tpl->setVariable("DATA_KEY", $k);
227  $tpl->setVariable("DATA_VAL", ilUtil::prepareFormOutput($v));
228  $tpl->parseCurrentBlock();
229  }
230  }
231  $tpl->setCurrentBlock("feature");
232  $tpl->setVariable("FEATURE_HREF", $act->href);
233  $tpl->setVariable("FEATURE_TEXT", $act->text);
234  $tpl->parseCurrentBlock();
235  }
236 
237  if ($u->online) {
238  $tpl->touchBlock("uonline");
239  $tpl->setCurrentBlock("uonline_text");
240  $tpl->setVariable("TXT_ONLINE", $this->lng->txt("awrn_online"));
241  $tpl->parseCurrentBlock();
242  }
243 
244  $tpl->setCurrentBlock("user");
245  if ($u->public_profile) {
246  $tpl->setVariable("UNAME", $u->lastname . ", " . $u->firstname);
247  } else {
248  $tpl->setVariable("UNAME", "&nbsp;");
249  }
250  $tpl->setVariable("UACCOUNT", $u->login);
251 
252  $tpl->setVariable("USERIMAGE", $u->img);
253  $tpl->setVariable("CNT", $ucnt);
254  $tpl->parseCurrentBlock();
255  $tpl->setCurrentBlock("item");
256  $tpl->parseCurrentBlock();
257  }
258 
259  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
260  $tpl->setCurrentBlock("filter");
261  $tpl->setVariable("GL_FILTER", ilGlyphGUI::get(ilGlyphGUI::FILTER));
262  $tpl->parseCurrentBlock();
263 
264  echo json_encode(array("html" => $tpl->get(),
265  "filter_val" => ilUtil::prepareFormOutput($filter),
266  "cnt" => $ad["cnt"]));
267  exit;
268  }
269 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
__construct()
Constructor.
static getInstance($a_user_id)
Get instance (for a user)
getAwarenessList()
Get awareness list (ajax)
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tpl
Definition: ilias.php:10
static getInstance()
Get instance.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static get($a_var)
Get a value.
static get($a_glyph, $a_text="")
Get glyph html.
static getInstance(ilUserActionContext $a_user_action_context, ilTemplate $a_global_tpl, $a_current_user_id)
Get instance.
static set($a_var, $a_val)
Set a value.
user()
Definition: user.php:4
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
$ilUser
Definition: imgupload.php:18
getMainMenuHTML()
Get main menu html.
Awareness context for user actions.
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
executeCommand()
Execute command.
Awareness GUI class.