ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
74  public function initJS()
75  {
77  // init js
78  $GLOBALS["tpl"]->addJavascript("./Services/Awareness/js/Awareness.js");
79  $this->ctrl->setParameter($this, "ref_id", $this->ref_id);
80  $GLOBALS["tpl"]->addOnloadCode("il.Awareness.setBaseUrl('" . $this->ctrl->getLinkTarget(
81  $this,
82  "",
83  "",
84  true,
85  false
86  ) . "');");
87  $GLOBALS["tpl"]->addOnloadCode("il.Awareness.setLoaderSrc('" . ilUtil::getImagePath("loader.svg") . "');");
88  $GLOBALS["tpl"]->addOnloadCode("il.Awareness.init();");
89 
90  // include user action js
91  include_once("./Services/User/Actions/classes/class.ilUserActionGUI.php");
92  include_once("./Services/Awareness/classes/class.ilAwarenessUserActionContext.php");
94  $ua_gui->init();
95  }
96 
100  public function getMainMenuHTML()
101  {
103 
104  $awrn_set = new ilSetting("awrn");
105  if (!$awrn_set->get("awrn_enabled", false) || ANONYMOUS_USER_ID == $ilUser->getId()) {
106  return "";
107  }
108 
109  $cache_period = (int) $awrn_set->get("caching_period");
110  $last_update = ilSession::get("awrn_last_update");
111  $now = time();
112 
113  $this->initJS();
114 
115  $tpl = new ilTemplate("tpl.awareness.html", true, true, "Services/Awareness");
116 
117  include_once("./Services/Awareness/classes/class.ilAwarenessAct.php");
118  $act = ilAwarenessAct::getInstance($ilUser->getId());
119  $act->setRefId($this->ref_id);
120  var_dump("1");
121  exit;
122  if ($last_update == "" || ($now - $last_update) >= $cache_period) {
123  $cnt = explode(":", $act->getAwarenessUserCounter());
124  $hcnt = $cnt[1];
125  $cnt = $cnt[0];
126  $act->notifyOnNewOnlineContacts();
127  ilSession::set("awrn_last_update", $now);
128  ilSession::set("awrn_nr_users", $cnt);
129  ilSession::set("awrn_nr_husers", $hcnt);
130  } else {
131  $cnt = (int) ilSession::get("awrn_nr_users");
132  $hcnt = (int) ilSession::get("awrn_nr_husers");
133  }
134 
135  if ($hcnt > 0 || $cnt > 0) {
136  /*
137  $tpl->setCurrentBlock("status_text");
138  $tpl->setVariable("STATUS_TXT", $cnt);
139  if ($cnt == 0)
140  {
141  $tpl->setVariable("HIDDEN", "ilAwrnBadgeHidden");
142  }
143  $tpl->parseCurrentBlock();
144  $tpl->setCurrentBlock("h_status_text");
145  $tpl->setVariable("H_STATUS_TXT", $hcnt);
146  if ($hcnt == 0)
147  {
148  $tpl->setVariable("H_HIDDEN", "ilAwrnBadgeHidden");
149  }
150  $tpl->parseCurrentBlock();
151  $tpl->setVariable("HSP", "&nbsp;");*/
152 
153  $f = $this->ui->factory();
154  $renderer = $this->ui->renderer();
155 
156  $glyph = $f->symbol()->glyph()->user("#");
157  if ($cnt > 0) {
158  $glyph = $glyph->withCounter($f->counter()->status((int) $cnt));
159  }
160  if ($hcnt > 0) {
161  $glyph = $glyph->withCounter($f->counter()->novelty((int) $hcnt));
162  }
163  $glyph_html = $renderer->render($glyph);
164  $tpl->setVariable("GLYPH", $glyph_html);
165 
166 
167 
168  $tpl->setVariable("LOADER", ilUtil::getImagePath("loader.svg"));
169 
170  return $tpl->get();
171  }
172 
173  return "";
174  }
175 
179  public function getAwarenessList($return = false)
180  {
182 
183  $filter = $_GET["filter"];
184 
185  $tpl = new ilTemplate("tpl.awareness_list.html", true, true, "Services/Awareness");
186 
187  include_once("./Services/Awareness/classes/class.ilAwarenessAct.php");
188  $act = ilAwarenessAct::getInstance($ilUser->getId());
189  $act->setRefId($this->ref_id);
190 
191  $ad = $act->getAwarenessData($filter);
192 
193  // update counter
194  $now = time();
195  $cnt = explode(":", $ad["cnt"]);
196  $hcnt = $cnt[1];
197  $cnt = $cnt[0];
198  ilSession::set("awrn_last_update", $now);
199  ilSession::set("awrn_nr_users", $cnt);
200  ilSession::set("awrn_nr_husers", $hcnt);
201 
202 
203  $users = $ad["data"];
204 
205  $ucnt = 0;
206  $last_uc_title = "";
207  foreach ($users as $u) {
208  if ($u->collector != $last_uc_title) {
209  if ($u->highlighted) {
210  $tpl->touchBlock("highlighted");
211  }
212  $tpl->setCurrentBlock("uc_title");
213  $tpl->setVariable("UC_TITLE", $u->collector);
214  $tpl->parseCurrentBlock();
215  $tpl->setCurrentBlock("item");
216  $tpl->parseCurrentBlock();
217  }
218  $last_uc_title = $u->collector;
219 
220  $ucnt++;
221 
222  $fcnt = 0;
223  foreach ($u->actions as $act) {
224  $fcnt++;
225  if ($fcnt == 1) {
226  $tpl->touchBlock("arrow");
227  //$tpl->setCurrentBlock("arrow");
228  //$tpl->parseCurrentBlock();
229  }
230  if (is_array($act->data) && count($act->data) > 0) {
231  foreach ($act->data as $k => $v) {
232  $tpl->setCurrentBlock("f_data");
233  $tpl->setVariable("DATA_KEY", $k);
234  $tpl->setVariable("DATA_VAL", ilUtil::prepareFormOutput($v));
235  $tpl->parseCurrentBlock();
236  }
237  }
238  $tpl->setCurrentBlock("feature");
239  $tpl->setVariable("FEATURE_HREF", $act->href);
240  $tpl->setVariable("FEATURE_TEXT", $act->text);
241  $tpl->parseCurrentBlock();
242  }
243 
244  if ($u->online) {
245  $tpl->touchBlock("uonline");
246  $tpl->setCurrentBlock("uonline_text");
247  $tpl->setVariable("TXT_ONLINE", $this->lng->txt("awrn_online"));
248  $tpl->parseCurrentBlock();
249  }
250 
251  $tpl->setCurrentBlock("user");
252  if ($u->public_profile) {
253  $tpl->setVariable("UNAME", $u->lastname . ", " . $u->firstname);
254  } else {
255  $tpl->setVariable("UNAME", "-");
256  }
257  $tpl->setVariable("UACCOUNT", $u->login);
258 
259  $tpl->setVariable("USERIMAGE", $u->img);
260  $tpl->setVariable("CNT", $ucnt);
261  $tpl->parseCurrentBlock();
262  $tpl->setCurrentBlock("item");
263  $tpl->parseCurrentBlock();
264  }
265 
266  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
267  $tpl->setCurrentBlock("filter");
268  $tpl->setVariable("GL_FILTER", ilGlyphGUI::get(ilGlyphGUI::FILTER));
269  $tpl->setVariable("FILTER_INPUT_LABEL", $this->lng->txt("awrn_filter"));
270  $tpl->parseCurrentBlock();
271 
272 
273  $result = ["html" => $tpl->get(),
274  "filter_val" => ilUtil::prepareFormOutput($filter),
275  "cnt" => $ad["cnt"]];
276 
277  if ($return) {
278  $this->initJS();
279  return $result;
280  }
281 
282  echo json_encode($result);
283  exit;
284  }
285 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
__construct()
Constructor.
exit
Definition: login.php:29
static getInstance($a_user_id)
Get instance (for a user)
const ANONYMOUS_USER_ID
Definition: constants.php:25
$result
$_GET["client_id"]
static getInstance()
Get instance.
getAwarenessList($return=false)
Get awareness list (ajax)
static get($a_var)
Get a value.
static get($a_glyph, $a_text="")
Get glyph html.
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)
global $DIC
Definition: goto.php:24
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
ui()
Definition: ui.php:5
static getInstance(ilUserActionContext $a_user_action_context, ilGlobalTemplateInterface $a_global_tpl, $a_current_user_id)
Get instance.
getMainMenuHTML()
Get main menu html.
Awareness context for user actions.
$ilUser
Definition: imgupload.php:18
executeCommand()
Execute command.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
Awareness GUI class.