ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ctrl;
18
22 protected $ui;
23
27 function __construct()
28 {
29 global $DIC;
30 $this->ui = $DIC->ui();
31
32 $this->ref_id = (int) $_GET["ref_id"];
33 $this->ctrl = $DIC->ctrl();
34 }
35
39 function executeCommand()
40 {
41 $cmd = $this->ctrl->getCmd();
42
43 if (in_array($cmd, array("getAwarenessList")))
44 {
45 $this->$cmd();
46 }
47 }
48
49
55 static function getInstance()
56 {
57 return new ilAwarenessGUI();
58 }
59
63 function getMainMenuHTML()
64 {
65 global $ilUser;
66
67 $awrn_set = new ilSetting("awrn");
68 if (!$awrn_set->get("awrn_enabled", false) || ANONYMOUS_USER_ID == $ilUser->getId())
69 {
70 return "";
71 }
72
73 $cache_period = (int) $awrn_set->get("caching_period");
74 $last_update = ilSession::get("awrn_last_update");
75 $now = time();
76
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($this,
81 "", "", true, false)."');");
82 $GLOBALS["tpl"]->addOnloadCode("il.Awareness.setLoaderSrc('".ilUtil::getImagePath("loader.svg")."');");
83 $GLOBALS["tpl"]->addOnloadCode("il.Awareness.init();");
84
85 $tpl = new ilTemplate("tpl.awareness.html", true, true, "Services/Awareness");
86
87 include_once("./Services/Awareness/classes/class.ilAwarenessAct.php");
88 $act = ilAwarenessAct::getInstance($ilUser->getId());
89 $act->setRefId($this->ref_id);
90
91 if ($last_update == "" || ($now - $last_update) >= $cache_period)
92 {
93 $cnt = explode(":", $act->getAwarenessUserCounter());
94 $hcnt = $cnt[1];
95 $cnt = $cnt[0];
96 $act->notifyOnNewOnlineContacts();
97 ilSession::set("awrn_last_update", $now);
98 ilSession::set("awrn_nr_users", $cnt);
99 ilSession::set("awrn_nr_husers", $hcnt);
100 }
101 else
102 {
103 $cnt = (int) ilSession::get("awrn_nr_users");
104 $hcnt = (int) ilSession::get("awrn_nr_husers");
105 }
106
107 if ($hcnt > 0 || $cnt > 0)
108 {
109 /*
110 $tpl->setCurrentBlock("status_text");
111 $tpl->setVariable("STATUS_TXT", $cnt);
112 if ($cnt == 0)
113 {
114 $tpl->setVariable("HIDDEN", "ilAwrnBadgeHidden");
115 }
116 $tpl->parseCurrentBlock();
117 $tpl->setCurrentBlock("h_status_text");
118 $tpl->setVariable("H_STATUS_TXT", $hcnt);
119 if ($hcnt == 0)
120 {
121 $tpl->setVariable("H_HIDDEN", "ilAwrnBadgeHidden");
122 }
123 $tpl->parseCurrentBlock();
124 $tpl->setVariable("HSP", "&nbsp;");*/
125
126 $f = $this->ui->factory();
127 $renderer = $this->ui->renderer();
128
129 $glyph = $f->glyph()->user("#");
130 if ($cnt > 0)
131 {
132 $glyph = $glyph->withCounter($f->counter()->status((int) $cnt));
133 }
134 if ($hcnt > 0)
135 {
136 $glyph =$glyph->withCounter($f->counter()->novelty((int) $hcnt));
137 }
138 $glyph_html = $renderer->render($glyph);
139 $tpl->setVariable("GLYPH", $glyph_html);
140
141
142
143 $tpl->setVariable("LOADER", ilUtil::getImagePath("loader.svg"));
144
145 return $tpl->get();
146 }
147
148 return "";
149 }
150
155 {
156 global $ilUser;
157
158 $filter = $_GET["filter"];
159
160 $tpl = new ilTemplate("tpl.awareness_list.html", true, true, "Services/Awareness");
161
162 include_once("./Services/Awareness/classes/class.ilAwarenessAct.php");
163 $act = ilAwarenessAct::getInstance($ilUser->getId());
164 $act->setRefId($this->ref_id);
165
166 $ad = $act->getAwarenessData($filter);
167
168 // update counter
169 $now = time();
170 $cnt = explode(":",$ad["cnt"]);
171 $hcnt = $cnt[1];
172 $cnt = $cnt[0];
173 ilSession::set("awrn_last_update", $now);
174 ilSession::set("awrn_nr_users", $cnt);
175 ilSession::set("awrn_nr_husers", $hcnt);
176
177
178 $users = $ad["data"];
179
180 $ucnt = 0;
181 $last_uc_title = "";
182 foreach ($users as $u)
183 {
184 if ($u->collector != $last_uc_title)
185 {
186 if ($u->highlighted)
187 {
188 $tpl->touchBlock("highlighted");
189 }
190 $tpl->setCurrentBlock("uc_title");
191 $tpl->setVariable("UC_TITLE", $u->collector);
192 $tpl->parseCurrentBlock();
193 $tpl->setCurrentBlock("item");
194 $tpl->parseCurrentBlock();
195 }
196 $last_uc_title = $u->collector;
197
198 $ucnt++;
199
200 $fcnt = 0;
201 foreach ($u->actions as $act)
202 {
203 $fcnt++;
204 if ($fcnt == 1)
205 {
206 $tpl->touchBlock("arrow");
207 //$tpl->setCurrentBlock("arrow");
208 //$tpl->parseCurrentBlock();
209 }
210 if (is_array($act->data) && count($act->data) > 0)
211 {
212 foreach ($act->data as $k => $v)
213 {
214 $tpl->setCurrentBlock("f_data");
215 $tpl->setVariable("DATA_KEY", $k);
216 $tpl->setVariable("DATA_VAL", ilUtil::prepareFormOutput($v));
217 $tpl->parseCurrentBlock();
218 }
219 }
220 $tpl->setCurrentBlock("feature");
221 $tpl->setVariable("FEATURE_HREF", $act->href);
222 $tpl->setVariable("FEATURE_TEXT", $act->text);
223 $tpl->parseCurrentBlock();
224 }
225
226 if ($u->online)
227 {
228 $tpl->touchBlock("uonline");
229 }
230
231 $tpl->setCurrentBlock("user");
232 if ($u->public_profile)
233 {
234 $tpl->setVariable("UNAME", $u->lastname.", ".$u->firstname);
235 }
236 else
237 {
238 $tpl->setVariable("UNAME", "&nbsp;");
239 }
240 $tpl->setVariable("UACCOUNT", $u->login);
241
242 $tpl->setVariable("USERIMAGE", $u->img);
243 $tpl->setVariable("CNT", $ucnt);
244 $tpl->parseCurrentBlock();
245 $tpl->setCurrentBlock("item");
246 $tpl->parseCurrentBlock();
247 }
248
249 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
250 $tpl->setCurrentBlock("filter");
251 $tpl->setVariable("GL_FILTER", ilGlyphGUI::get(ilGlyphGUI::FILTER));
252 $tpl->setVariable("VAL_FILTER", ilUtil::prepareFormOutput($filter));
253 $tpl->parseCurrentBlock();
254
255 echo json_encode(array("html" => $tpl->get(),
256 "cnt" => $ad["cnt"]));
257 exit;
258 }
259
260}
261?>
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static getInstance($a_user_id)
Get instance (for a user)
Awareness GUI class.
static getInstance()
Get instance.
executeCommand()
Execute command.
getMainMenuHTML()
Get main menu html.
__construct()
Constructor.
getAwarenessList()
Get awareness list (ajax)
static get($a_glyph, $a_text="")
Get glyph html.
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$cmd
Definition: sahs_server.php:35
global $DIC
$ilUser
Definition: imgupload.php:18