ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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, $unavailable=false)
 Render emo counters. More...
 
 getGlyphForConst ($a_const, $unavailable=false)
 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.
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46

References $data, $DIC, initJavascript(), ui(), 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 410 of file class.ilLikeGUI.php.

411 {
412 global $DIC;
413
414 $lng = $DIC->language();
415
416 switch ($a_const) {
417 case ilLikeData::TYPE_LIKE: return $lng->txt("like"); break;
418 case ilLikeData::TYPE_DISLIKE: return $lng->txt("dislike"); break;
419 case ilLikeData::TYPE_LOVE: return $lng->txt("love"); break;
420 case ilLikeData::TYPE_LAUGH: return $lng->txt("laugh"); break;
421 case ilLikeData::TYPE_ASTOUNDED: return $lng->txt("astounded"); break;
422 case ilLikeData::TYPE_SAD: return $lng->txt("sad"); break;
423 case ilLikeData::TYPE_ANGRY: return $lng->txt("angry"); break;
424 }
425 return "";
426 }
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,
  $unavailable = false 
)
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->symbol()->glyph()->like(); break;
247 case ilLikeData::TYPE_DISLIKE: $like = $f->symbol()->glyph()->dislike(); break;
248 case ilLikeData::TYPE_LOVE: $like = $f->symbol()->glyph()->love(); break;
249 case ilLikeData::TYPE_LAUGH: $like = $f->symbol()->glyph()->laugh(); break;
250 case ilLikeData::TYPE_ASTOUNDED: $like = $f->symbol()->glyph()->astounded(); break;
251 case ilLikeData::TYPE_SAD: $like = $f->symbol()->glyph()->sad(); break;
252 case ilLikeData::TYPE_ANGRY: $like = $f->symbol()->glyph()->angry(); break;
253 }
254 if ($unavailable) {
255 $like = $like->withUnavailableAction();
256 }
257 return $like;
258 }

References Vendor\Package\$f, ilLikeData\TYPE_ANGRY, ilLikeData\TYPE_ASTOUNDED, ilLikeData\TYPE_DISLIKE, ilLikeData\TYPE_LAUGH, ilLikeData\TYPE_LIKE, ilLikeData\TYPE_LOVE, ilLikeData\TYPE_SAD, and ui().

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

+ Here is the call graph for this function:
+ 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 }
renderEmoCounters($modal_signal=null, $unavailable=false)
Render emo counters.
special template class to simplify handling of ITX/PEAR
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl

References $ctrl, Vendor\Package\$f, $lng, $tpl, renderEmoCounters(), and ui().

+ 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,
  $unavailable = false 
)
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, $unavailable);
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, $unavailable=false)
Get glyph for const.
$txt
Definition: error.php:13

References $ctrl, Vendor\Package\$f, $ilCtrl, $tpl, $txt, getGlyphForConst(), and ui().

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 265 of file class.ilLikeGUI.php.

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

References $ctrl, $ilCtrl, $tpl, $txt, $url, exit, getGlyphForConst(), and ui().

+ Here is the call graph for this function:

◆ renderModal()

ilLikeGUI::renderModal ( )

Render modal.

Exceptions
ilLikeDataException

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

347 {
349
350 $f = $this->ui->factory();
351 $r = $this->ui->renderer();
352
353
354 $list_items = [];
355 foreach ($this->data->getExpressionEntries(
356 $this->obj_id,
357 $this->obj_type,
358 $this->sub_obj_id,
359 $this->sub_obj_type,
360 $this->news_id
361 ) as $exp) {
362 $name = ilUserUtil::getNamePresentation($exp["user_id"]);
363
364 $image = $f->image()->responsive(
365 ilObjUser::_getPersonalPicturePath($exp["user_id"]),
366 $name
367 );
368
369 $g = $this->getGlyphForConst($exp["expression"], true);
370
371 $list_items[] = $f->item()->standard($name)
372 ->withDescription($r->render($g) . " " .
374 ->withLeadImage($image);
375 }
376
377 $std_list = $f->panel()->listing()->standard("", array(
378 $f->item()->group("", $list_items)
379 ));
380
381 $header = $f->legacy($this->renderEmoCounters(null, true));
382 //$header = $f->legacy("---");
383
384 $modal = $f->modal()->roundtrip('', [$header, $std_list]);
385 echo $r->render($modal);
386 exit;
387 }
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 _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
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:
if($format !==null) $name
Definition: metadata.php:230

References Vendor\Package\$f, $name, $user, ilObjUser\_getPersonalPicturePath(), exit, ilDatePresentation\formatDate(), getGlyphForConst(), ilUserUtil\getNamePresentation(), IL_CAL_DATETIME, renderEmoCounters(), and ui().

+ Here is the call graph for this function:

◆ saveExpression()

ilLikeGUI::saveExpression ( )
protected

Save expresseion.

Exceptions
ilLikeDataException

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

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

References $_GET, 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: