ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilLikeGUI Class Reference

User interface for like feature. More...

+ Collaboration diagram for ilLikeGUI:

Public Member Functions

 __construct (\ilLikeData $data, \ilTemplate $main_tpl=null)
 ilLikeGUI constructor. More...
 
 setObject ($a_obj_id, $a_obj_type, $a_sub_obj_id=0, $a_sub_obj_type="", $a_news_id=0)
 Set Object. More...
 
 executeCommand ()
 Execute command. More...
 
 getHTML ()
 Get HTML. More...
 
 renderEmoticons ()
 Render emoticons. More...
 
 renderModal ()
 Render modal. More...
 

Static Public Member Functions

static getExpressionText ($a_const)
 Get unicode for const. More...
 

Protected Member Functions

 initJavascript ()
 Init javascript. More...
 
 renderEmoCounters ($modal_signal=null)
 Render emo counters. More...
 
 getGlyphForConst ($a_const)
 Get glyph for const. More...
 
 saveExpression ()
 Save expresseion. More...
 

Protected Attributes

 $lng
 
 $ctrl
 
 $user
 
 $obj_id
 
 $obj_type
 
 $sub_obj_id
 
 $sub_obj_type
 
 $news_id
 
 $dom_id
 
 $language
 

Detailed Description

User interface for like feature.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 13 of file class.ilLikeGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilLikeGUI::__construct ( \ilLikeData  $data,
\ilTemplate  $main_tpl = null 
)

ilLikeGUI constructor.

Parameters
ilLikeData$data
ilTemplate | null$main_tpl

Definition at line 70 of file class.ilLikeGUI.php.

71 {
72 global $DIC;
73
74 $this->main_tpl = ($main_tpl == null)
75 ? $DIC->ui()->mainTemplate()
76 : $main_tpl;
77
78 $this->lng = $DIC->language();
79 $this->ctrl = $DIC->ctrl();
80 $this->user = $DIC->user();
81 $this->ui = $DIC->ui();
82 $this->lng = $DIC->language();
83
84 $this->data = $data;
85
86 $this->lng->loadLanguageModule("like");
87
88 $this->initJavascript();
89 }
user()
Definition: user.php:4
initJavascript()
Init javascript.
global $DIC
Definition: saml.php:7
$this data['403_header']
$data
Definition: bench.php:6

References $data, $DIC, data, initJavascript(), and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilLikeGUI::executeCommand ( )

Execute command.

Returns
string

Definition at line 123 of file class.ilLikeGUI.php.

124 {
126
127 $next_class = $ilCtrl->getNextClass($this);
128 $cmd = $ilCtrl->getCmd("getHTML");
129
130 switch ($next_class) {
131 default:
132 if (in_array($cmd, array("getHTML", "renderEmoticons", "renderModal", "saveExpression"))) {
133 return $this->$cmd();
134 }
135 break;
136 }
137 return "";
138 }
global $ilCtrl
Definition: ilias.php:18

References $ctrl, and $ilCtrl.

◆ getExpressionText()

static ilLikeGUI::getExpressionText (   $a_const)
static

Get unicode for const.

Parameters
int$a_const
Returns
string Get expresseion text for const
Parameters
int$a_const
Returns
string

Definition at line 407 of file class.ilLikeGUI.php.

408 {
409 global $DIC;
410
411 $lng = $DIC->language();
412
413 switch ($a_const) {
414 case ilLikeData::TYPE_LIKE: return $lng->txt("like"); break;
415 case ilLikeData::TYPE_DISLIKE: return $lng->txt("dislike"); break;
416 case ilLikeData::TYPE_LOVE: return $lng->txt("love"); break;
417 case ilLikeData::TYPE_LAUGH: return $lng->txt("laugh"); break;
418 case ilLikeData::TYPE_ASTOUNDED: return $lng->txt("astounded"); break;
419 case ilLikeData::TYPE_SAD: return $lng->txt("sad"); break;
420 case ilLikeData::TYPE_ANGRY: return $lng->txt("angry"); break;
421 }
422 return "";
423 }
const TYPE_ASTOUNDED

References $DIC, $lng, ilLikeData\TYPE_ANGRY, ilLikeData\TYPE_ASTOUNDED, ilLikeData\TYPE_DISLIKE, ilLikeData\TYPE_LAUGH, ilLikeData\TYPE_LIKE, ilLikeData\TYPE_LOVE, and ilLikeData\TYPE_SAD.

Referenced by ilMembershipCronNotifications\parseNewsItem().

+ Here is the caller graph for this function:

◆ getGlyphForConst()

ilLikeGUI::getGlyphForConst (   $a_const)
protected

Get glyph for const.

Parameters
int$a_const
Returns
\ILIAS\UI\Component\Glyph\Glyph|null

Definition at line 241 of file class.ilLikeGUI.php.

242 {
243 $f = $this->ui->factory();
244 $like = null;
245 switch ($a_const) {
246 case ilLikeData::TYPE_LIKE: $like = $f->glyph()->like(); break;
247 case ilLikeData::TYPE_DISLIKE: $like = $f->glyph()->dislike(); break;
248 case ilLikeData::TYPE_LOVE: $like = $f->glyph()->love(); break;
249 case ilLikeData::TYPE_LAUGH: $like = $f->glyph()->laugh(); break;
250 case ilLikeData::TYPE_ASTOUNDED: $like = $f->glyph()->astounded(); break;
251 case ilLikeData::TYPE_SAD: $like = $f->glyph()->sad(); break;
252 case ilLikeData::TYPE_ANGRY: $like = $f->glyph()->angry(); break;
253 }
254 return $like;
255 }

References $f, ilLikeData\TYPE_ANGRY, ilLikeData\TYPE_ASTOUNDED, ilLikeData\TYPE_DISLIKE, ilLikeData\TYPE_LAUGH, ilLikeData\TYPE_LIKE, ilLikeData\TYPE_LOVE, and ilLikeData\TYPE_SAD.

Referenced by renderEmoCounters(), renderEmoticons(), and renderModal().

+ Here is the caller graph for this function:

◆ getHTML()

ilLikeGUI::getHTML ( )

Get HTML.

Parameters
$a_obj_id
$a_obj_type
int$a_sub_obj_id
string$a_sub_obj_type
int$a_news_id
Returns
string
Exceptions
ilLikeDataException

Definition at line 151 of file class.ilLikeGUI.php.

152 {
153 $f = $this->ui->factory();
154 $r = $this->ui->renderer();
157
158 $tpl = new ilTemplate("tpl.like.html", true, true, "Services/Like");
159
160 // modal
161 $modal_asyn_url = $ctrl->getLinkTarget($this, "renderModal", "", true, false);
162 $modal = $f->modal()->roundtrip('', $f->legacy(""))
163 ->withAsyncRenderUrl($modal_asyn_url);
164
165 $modal_show_sig_id = $modal->getShowSignal()->getId();
166 $this->ctrl->setParameter($this, "modal_show_sig_id", $modal_show_sig_id);
167 $emo_counters = $this->renderEmoCounters($modal->getShowSignal());
168 $tpl->setVariable("EMO_COUNTERS", $emo_counters . $r->render($modal));
169
170
171
172 // emoticon popover
173 $popover = $f->popover()->standard($f->legacy(''))->withTitle('');
174 $ctrl->setParameter($this, "repl_sig", $popover->getReplaceContentSignal()->getId());
175 $asyn_url = $ctrl->getLinkTarget($this, "renderEmoticons", "", true, false);
176 $popover = $popover->withAsyncContentUrl($asyn_url);
177 $button = $f->button()->shy($lng->txt("like"), '#')
178 ->withOnClick($popover->getShowSignal());
179
180 $tpl->setVariable("LIKE", $r->render([$popover, $button]));
181
182 return $tpl->get();
183 }
$tpl
Definition: ilias.php:10
renderEmoCounters($modal_signal=null)
Render emo counters.
special template class to simplify handling of ITX/PEAR
$r
Definition: example_031.php:79

References $ctrl, $f, $lng, $r, $tpl, and renderEmoCounters().

+ Here is the call graph for this function:

◆ initJavascript()

ilLikeGUI::initJavascript ( )
protected

Init javascript.

Definition at line 94 of file class.ilLikeGUI.php.

95 {
96 $this->main_tpl->addJavaScript("./Services/Like/js/Like.js");
97 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ renderEmoCounters()

ilLikeGUI::renderEmoCounters (   $modal_signal = null)
protected

Render emo counters.

Parameters
$modal_signal
Returns
string
Exceptions
ilLikeDataException

Definition at line 192 of file class.ilLikeGUI.php.

193 {
195
196 $tpl = new ilTemplate("tpl.emo_counters.html", true, true, "Services/Like");
197 $f = $this->ui->factory();
198 $r = $this->ui->renderer();
199
200 $cnts = $this->data->getExpressionCounts(
201 $this->obj_id,
202 $this->obj_type,
203 $this->sub_obj_id,
204 $this->sub_obj_type,
205 $this->news_id
206 );
207 $comps = array();
208 foreach ($this->data->getExpressionTypes() as $k => $txt) {
209 if ($cnts[$k] > 0) {
210 $glyph = $this->getGlyphForConst($k);
211 if ($modal_signal !== null) {
212 $glyph = $glyph->withOnClick($modal_signal);
213 }
214 $comps[] = $glyph->withCounter($f->counter()->status($cnts[$k]));
215 }
216 }
217
218 if ($ilCtrl->isAsynch()) {
219 $tpl->setVariable("MODAL_TRIGGER", $r->renderAsync($comps));
220 } else {
221 $tpl->setVariable("MODAL_TRIGGER", $r->render($comps));
222 }
223 if ($modal_signal !== null) {
224 $tpl->setVariable("ID", $this->dom_id);
225 }
226
227 if (count($comps) > 0 && $modal_signal !== null) {
228 $tpl->setVariable("SEP", $r->render($f->divider()->vertical()));
229 }
230
231 return $tpl->get();
232 }
getGlyphForConst($a_const)
Get glyph for const.
$txt
Definition: error.php:11

References $ctrl, $f, $ilCtrl, $r, $tpl, $txt, data, and getGlyphForConst().

Referenced by getHTML(), renderModal(), and saveExpression().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderEmoticons()

ilLikeGUI::renderEmoticons ( )

Render emoticons.

Definition at line 262 of file class.ilLikeGUI.php.

263 {
265 $r = $this->ui->renderer();
266
267 $ilCtrl->saveParameter($this, "modal_show_sig_id");
268
269 $tpl = new ilTemplate("tpl.emoticons.html", true, true, "Services/Like");
270 $tpl->setVariable("ID", $this->dom_id);
271
272 $url = $ilCtrl->getLinkTarget($this, "", "", true);
273 foreach ($this->data->getExpressionTypes() as $k => $txt) {
274 $g = $this->getGlyphForConst($k);
275
276 if ($this->data->isExpressionSet(
277 $this->user->getId(),
278 $k,
279 $this->obj_id,
280 $this->obj_type,
281 $this->sub_obj_id,
282 $this->sub_obj_type,
283 $this->news_id
284 )) {
285 $g = $g->withHighlight();
286 }
287
288 $g = $g->withAdditionalOnLoadCode(function ($id) use ($k, $url) {
289 return
290 "$('#" . $id . "').click(function() { il.Like.toggle('" . $url . "','" . $id . "','" . $this->dom_id . "'," . $k . ");});";
291 });
292 $glyphs[] = $g;
293 }
294
295 $tpl->setVariable("GLYPHS", $r->renderAsync($glyphs));
296
297 echo $tpl->get();
298 exit;
299 }
exit
Definition: backend.php:16
if(!array_key_exists('StateId', $_REQUEST)) $id
$url

References $ctrl, $id, $ilCtrl, $r, $tpl, $txt, $url, data, exit, and getGlyphForConst().

+ Here is the call graph for this function:

◆ renderModal()

ilLikeGUI::renderModal ( )

Render modal.

Exceptions
ilLikeDataException

Definition at line 343 of file class.ilLikeGUI.php.

344 {
346
347 $f = $this->ui->factory();
348 $r = $this->ui->renderer();
349
350
351 $list_items = [];
352 foreach ($this->data->getExpressionEntries(
353 $this->obj_id,
354 $this->obj_type,
355 $this->sub_obj_id,
356 $this->sub_obj_type,
357 $this->news_id
358 ) as $exp) {
359 $name = ilUserUtil::getNamePresentation($exp["user_id"]);
360
361 $image = $f->image()->responsive(
362 ilObjUser::_getPersonalPicturePath($exp["user_id"]),
363 $name
364 );
365
366 $g = $this->getGlyphForConst($exp["expression"]);
367
368 $list_items[] = $f->item()->standard($name)
369 ->withDescription($r->render($g) . " " .
371 ->withLeadImage($image);
372 }
373
374 $std_list = $f->panel()->listing()->standard("", array(
375 $f->item()->group("", $list_items)
376 ));
377
378 $header = $f->legacy($this->renderEmoCounters());
379 //$header = $f->legacy("---");
380
381 $modal = $f->modal()->roundtrip('', [$header, $std_list]);
382 echo $r->render($modal);
383 exit;
384 }
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:

References $f, $header, $name, $r, $user, data, exit, ilDatePresentation\formatDate(), getGlyphForConst(), ilUserUtil\getNamePresentation(), IL_CAL_DATETIME, and renderEmoCounters().

+ Here is the call graph for this function:

◆ saveExpression()

ilLikeGUI::saveExpression ( )
protected

Save expresseion.

Exceptions
ilLikeDataException

Definition at line 306 of file class.ilLikeGUI.php.

307 {
308 $exp_key = (int) $_GET["exp"];
309 $exp_val = (int) $_GET["val"];
310 $modal_show_sig_id = ilUtil::stripSlashes($_GET["modal_show_sig_id"]);
311 $show_signal = new \ILIAS\UI\Implementation\Component\Signal($modal_show_sig_id);
312
313 if ($exp_val) {
314 $this->data->addExpression(
315 $this->user->getId(),
316 $exp_key,
317 $this->obj_id,
318 $this->obj_type,
319 $this->sub_obj_id,
320 $this->sub_obj_type,
321 $this->news_id
322 );
323 } else {
324 $this->data->removeExpression(
325 $this->user->getId(),
326 $exp_key,
327 $this->obj_id,
328 $this->obj_type,
329 $this->sub_obj_id,
330 $this->sub_obj_type,
331 $this->news_id
332 );
333 }
334 echo $this->renderEmoCounters($show_signal);
335 exit;
336 }
$_GET["client_id"]
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled

References $_GET, data, exit, renderEmoCounters(), ilUtil\stripSlashes(), and user().

+ Here is the call graph for this function:

◆ setObject()

ilLikeGUI::setObject (   $a_obj_id,
  $a_obj_type,
  $a_sub_obj_id = 0,
  $a_sub_obj_type = "",
  $a_news_id = 0 
)

Set Object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type

Definition at line 108 of file class.ilLikeGUI.php.

109 {
110 $this->obj_id = $a_obj_id;
111 $this->obj_type = $a_obj_type;
112 $this->sub_obj_id = $a_sub_obj_id;
113 $this->sub_obj_type = $a_sub_obj_type;
114 $this->news_id = $a_news_id;
115 $this->dom_id = "like_" . $this->obj_id . "_" . $this->obj_type . "_" . $this->sub_obj_id . "_" .
116 $this->sub_obj_type . "_" . $this->news_id;
117 }

References $news_id.

Field Documentation

◆ $ctrl

ilLikeGUI::$ctrl
protected

Definition at line 23 of file class.ilLikeGUI.php.

Referenced by executeCommand(), getHTML(), renderEmoCounters(), and renderEmoticons().

◆ $dom_id

ilLikeGUI::$dom_id
protected

Definition at line 58 of file class.ilLikeGUI.php.

◆ $language

ilLikeGUI::$language
protected

Definition at line 63 of file class.ilLikeGUI.php.

◆ $lng

ilLikeGUI::$lng
protected

Definition at line 18 of file class.ilLikeGUI.php.

Referenced by getExpressionText(), and getHTML().

◆ $news_id

ilLikeGUI::$news_id
protected

Definition at line 53 of file class.ilLikeGUI.php.

Referenced by setObject().

◆ $obj_id

ilLikeGUI::$obj_id
protected

Definition at line 33 of file class.ilLikeGUI.php.

◆ $obj_type

ilLikeGUI::$obj_type
protected

Definition at line 38 of file class.ilLikeGUI.php.

◆ $sub_obj_id

ilLikeGUI::$sub_obj_id
protected

Definition at line 43 of file class.ilLikeGUI.php.

◆ $sub_obj_type

ilLikeGUI::$sub_obj_type
protected

Definition at line 48 of file class.ilLikeGUI.php.

◆ $user

ilLikeGUI::$user
protected

Definition at line 28 of file class.ilLikeGUI.php.

Referenced by renderModal().


The documentation for this class was generated from the following file: