ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilLikeGUI Class Reference

User interface for like feature. More...

+ Collaboration diagram for ilLikeGUI:

Public Member Functions

 __construct (\ilLikeData $data, ?\ilTemplate $main_tpl=null)
 
 setObject (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id=0, string $a_sub_obj_type="", int $a_news_id=0)
 
 executeCommand ()
 
 getHTML ()
 
 renderEmoticons ()
 Render emoticons (asynch) More...
 
 renderModal ()
 Render modal (asynch) More...
 

Static Public Member Functions

static getExpressionText (int $a_const)
 Get expression text for const. More...
 

Protected Member Functions

 initJavascript ()
 
 renderEmoCounters (?ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
 Render emo counters. More...
 
 getGlyphForConst (int $a_const, bool $unavailable=false)
 
 saveExpression ()
 Save expression (asynch) More...
 

Protected Attributes

ILIAS Like InternalGUIService $gui
 
ilLikeData $data
 
ILIAS DI UIServices $ui
 
ilGlobalTemplateInterface $main_tpl
 
StandardGUIRequest $request
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilObjUser $user
 
int $obj_id
 
string $obj_type
 
int $sub_obj_id
 
string $sub_obj_type
 
int $news_id
 
string $dom_id
 

Detailed Description

User interface for like feature.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

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

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

References $data, $DIC, $main_tpl, ILIAS\Repository\ctrl(), initJavascript(), ILIAS\Repository\lng(), null, ILIAS\Repository\ui(), and ILIAS\Repository\user().

45  {
46  global $DIC;
47 
48  $this->main_tpl = ($main_tpl == null)
49  ? $DIC->ui()->mainTemplate()
50  : $main_tpl;
51 
52  $this->gui = $DIC->like()->internal()->gui();
53 
54  $this->lng = $DIC->language();
55  $this->ctrl = $DIC->ctrl();
56  $this->user = $DIC->user();
57  $this->ui = $DIC->ui();
58 
59  $this->data = $data;
60 
61  $this->lng->loadLanguageModule("like");
62  $this->request = new StandardGUIRequest(
63  $DIC->http(),
64  $DIC->refinery()
65  );
66 
67  $this->initJavascript();
68  }
ilLikeData $data
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
ilGlobalTemplateInterface $main_tpl
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilLikeGUI::executeCommand ( )

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

References $ctrl, and ilCtrl\getNextClass().

97  : string
98  {
99  $ilCtrl = $this->ctrl;
100 
101  $next_class = $ilCtrl->getNextClass($this);
102  $cmd = $ilCtrl->getCmd("getHTML");
103 
104  switch ($next_class) {
105  default:
106  if (in_array($cmd, array("getHTML", "renderEmoticons", "renderModal", "saveExpression"))) {
107  return $this->$cmd();
108  }
109  break;
110  }
111  return "";
112  }
getNextClass($a_gui_class=null)
+ Here is the call graph for this function:

◆ getExpressionText()

static ilLikeGUI::getExpressionText ( int  $a_const)
static

Get expression text for const.

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

References $DIC, ilLanguage\txt(), 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\run().

366  : string {
367  global $DIC;
368 
369  $lng = $DIC->language();
370 
371  switch ($a_const) {
372  case ilLikeData::TYPE_LIKE: return $lng->txt("like");
373  case ilLikeData::TYPE_DISLIKE: return $lng->txt("dislike");
374  case ilLikeData::TYPE_LOVE: return $lng->txt("love");
375  case ilLikeData::TYPE_LAUGH: return $lng->txt("laugh");
376  case ilLikeData::TYPE_ASTOUNDED: return $lng->txt("astounded");
377  case ilLikeData::TYPE_SAD: return $lng->txt("sad");
378  case ilLikeData::TYPE_ANGRY: return $lng->txt("angry");
379  }
380  return "";
381  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
const TYPE_ASTOUNDED
global $DIC
Definition: shib_login.php:22
ilLanguage $lng
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGlyphForConst()

ilLikeGUI::getGlyphForConst ( int  $a_const,
bool  $unavailable = false 
)
protected

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

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

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

199  : ?\ILIAS\UI\Component\Symbol\Glyph\Glyph {
200  $f = $this->ui->factory();
201  $like = null;
202  switch ($a_const) {
203  case ilLikeData::TYPE_LIKE: $like = $f->symbol()->glyph()->like();
204  break;
205  case ilLikeData::TYPE_DISLIKE: $like = $f->symbol()->glyph()->dislike();
206  break;
207  case ilLikeData::TYPE_LOVE: $like = $f->symbol()->glyph()->love();
208  break;
209  case ilLikeData::TYPE_LAUGH: $like = $f->symbol()->glyph()->laugh();
210  break;
211  case ilLikeData::TYPE_ASTOUNDED: $like = $f->symbol()->glyph()->astounded();
212  break;
213  case ilLikeData::TYPE_SAD: $like = $f->symbol()->glyph()->sad();
214  break;
215  case ilLikeData::TYPE_ANGRY: $like = $f->symbol()->glyph()->angry();
216  break;
217  }
218  if ($unavailable) {
219  $like = $like->withUnavailableAction();
220  }
221  return $like;
222  }
const TYPE_ASTOUNDED
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHTML()

ilLikeGUI::getHTML ( )

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

References $ctrl, Vendor\Package\$f, $lng, $r, ILIAS\Repository\ctrl(), ilCtrl\getLinkTarget(), renderEmoCounters(), ilCtrl\setParameter(), ilLanguage\txt(), ILIAS\Repository\ui(), and ILIAS\GlobalScreen\Scope\Footer\Factory\withTitle().

114  : string
115  {
116  $f = $this->ui->factory();
117  $r = $this->ui->renderer();
118  $ctrl = $this->ctrl;
119  $lng = $this->lng;
120 
121  $tpl = new ilTemplate("tpl.like.html", true, true, "components/ILIAS/Like");
122 
123  // modal
124  $modal_asyn_url = $ctrl->getLinkTarget($this, "renderModal", "", true, false);
125  $modal = $f->modal()->roundtrip('', $f->legacy()->content(""))
126  ->withAsyncRenderUrl($modal_asyn_url);
127 
128  $modal_show_sig_id = $modal->getShowSignal()->getId();
129  $this->ctrl->setParameter($this, "modal_show_sig_id", $modal_show_sig_id);
130  $emo_counters = $this->renderEmoCounters($modal->getShowSignal());
131  $tpl->setVariable("EMO_COUNTERS", $emo_counters . $r->render($modal));
132 
133 
134 
135  // emoticon popover
136  $popover = $f->popover()->standard($f->legacy()->content(''))->withTitle('');
137  $ctrl->setParameter($this, "repl_sig", $popover->getReplaceContentSignal()->getId());
138  $asyn_url = $ctrl->getLinkTarget($this, "renderEmoticons", "", true, false);
139  $popover = $popover->withAsyncContentUrl($asyn_url);
140  $button = $f->button()->shy($lng->txt("like"), '#')
141  ->withOnClick($popover->getShowSignal());
142 
143  $tpl->setVariable("LIKE", $r->render([$popover, $button]));
144 
145  return $tpl->get();
146  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
renderEmoCounters(?ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
ilLanguage $lng
$r
+ Here is the call graph for this function:

◆ initJavascript()

ilLikeGUI::initJavascript ( )
protected

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

Referenced by __construct().

70  : void
71  {
72  $debug = false;
73  $this->gui->initFetch();
74  if ($debug) {
75  $this->main_tpl->addJavaScript("../components/ILIAS/Like/resources/Like.js");
76  } else {
77  $this->main_tpl->addJavaScript("assets/js/Like.js");
78  }
79  }
+ Here is the caller graph for this function:

◆ renderEmoCounters()

ilLikeGUI::renderEmoCounters ( ?ILIAS\UI\Component\Signal  $modal_signal = null,
bool  $unavailable = false 
)
protected

Render emo counters.

Exceptions
ilLikeDataException

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

References $ctrl, Vendor\Package\$f, $r, $txt, getGlyphForConst(), null, and ILIAS\Repository\ui().

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

155  : string {
156  $ilCtrl = $this->ctrl;
157 
158  $tpl = new ilTemplate("tpl.emo_counters.html", true, true, "components/ILIAS/Like");
159  $f = $this->ui->factory();
160  $r = $this->ui->renderer();
161 
162  $cnts = $this->data->getExpressionCounts(
163  $this->obj_id,
164  $this->obj_type,
165  $this->sub_obj_id,
166  $this->sub_obj_type,
167  $this->news_id
168  );
169  $comps = array();
170  foreach ($this->data->getExpressionTypes() as $k => $txt) {
171  if ($cnts[$k] > 0) {
172  $glyph = $this->getGlyphForConst($k, $unavailable);
173  if ($modal_signal !== null) {
174  $glyph = $glyph->withOnClick($modal_signal);
175  }
176  $comps[] = $glyph->withCounter($f->counter()->status($cnts[$k]));
177  }
178  }
179 
180  if ($ilCtrl->isAsynch()) {
181  $tpl->setVariable("MODAL_TRIGGER", $r->renderAsync($comps));
182  } else {
183  $tpl->setVariable("MODAL_TRIGGER", $r->render($comps));
184  }
185  if ($modal_signal !== null) {
186  $tpl->setVariable("ID", $this->dom_id);
187  }
188 
189  if (count($comps) > 0 && $modal_signal !== null) {
190  $tpl->setVariable("SEP", $r->render($f->divider()->vertical()));
191  }
192 
193  return $tpl->get();
194  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getGlyphForConst(int $a_const, bool $unavailable=false)
$txt
Definition: error.php:31
$r
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderEmoticons()

ilLikeGUI::renderEmoticons ( )

Render emoticons (asynch)

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

References $ctrl, $id, $news_id, $obj_id, $obj_type, $r, $sub_obj_id, $sub_obj_type, $txt, $url, exit, getGlyphForConst(), and ILIAS\Repository\ui().

227  : void
228  {
229  $ilCtrl = $this->ctrl;
230  $r = $this->ui->renderer();
231  $glyphs = [];
232 
233  $ilCtrl->saveParameter($this, "modal_show_sig_id");
234 
235  $tpl = new ilTemplate("tpl.emoticons.html", true, true, "components/ILIAS/Like");
236  $tpl->setVariable("ID", $this->dom_id);
237 
238  $url = $ilCtrl->getLinkTarget($this, "", "", true);
239  foreach ($this->data->getExpressionTypes() as $k => $txt) {
240  $g = $this->getGlyphForConst($k);
241 
242  if ($this->data->isExpressionSet(
243  $this->user->getId(),
244  $k,
250  )) {
251  $g = $g->withHighlight();
252  }
253 
254  $g = $g->withAdditionalOnLoadCode(function ($id) use ($k, $url) {
255  return
256  "$('#" . $id . "').click(function() { il.Like.toggle('" . $url . "','" . $id . "','" . $this->dom_id . "'," . $k . ");});";
257  });
258  $glyphs[] = $g;
259  }
260 
261  $tpl->setVariable("GLYPHS", $r->renderAsync($glyphs));
262 
263  echo $tpl->get();
264  exit;
265  }
$url
Definition: shib_logout.php:66
getGlyphForConst(int $a_const, bool $unavailable=false)
$txt
Definition: error.php:31
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
string $sub_obj_type
string $obj_type
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r
+ Here is the call graph for this function:

◆ renderModal()

ilLikeGUI::renderModal ( )

Render modal (asynch)

Exceptions
ilDateTimeException
ilLikeDataException
ilWACException

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

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

310  : void
311  {
312  $user = $this->user;
313 
314  $f = $this->ui->factory();
315  $r = $this->ui->renderer();
316 
317 
318  $list_items = [];
319 
320  $glyph_renderings = [];
321  foreach ($this->data->getExpressionEntries(
322  $this->obj_id,
323  $this->obj_type,
324  $this->sub_obj_id,
325  $this->sub_obj_type,
326  $this->news_id
327  ) as $exp) {
328  $name = ilUserUtil::getNamePresentation($exp["user_id"]);
329 
330  $image = $f->image()->responsive(
331  ilObjUser::_getPersonalPicturePath($exp["user_id"]),
332  $name
333  );
334 
335  $g = $this->getGlyphForConst($exp["expression"], true);
336  $placeholder = "###" . $exp["expression"] . "###";
337  $glyph_renderings[$placeholder] = $r->render($g);
338 
339  $list_items[] = $f->item()->standard($name)
340  ->withDescription($placeholder . " " .
342  ->withLeadImage($image);
343  }
344 
345  $std_list = $f->panel()->listing()->standard("", array(
346  $f->item()->group("", $list_items)
347  ));
348 
349  $header = $f->legacy()->content($this->renderEmoCounters(null, true));
350  //$header = $f->legacy("---");
351 
352  $modal = $f->modal()->roundtrip('', [$header, $std_list]);
353  $html = $r->render($modal);
354  foreach ($glyph_renderings as $pl => $gl) {
355  $html = str_replace($pl, $gl, $html);
356  }
357  echo $html;
358  exit;
359  }
const IL_CAL_DATETIME
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getGlyphForConst(int $a_const, bool $unavailable=false)
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path='ilpublicuserprofilegui')
Default behaviour is:
renderEmoCounters(?ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
static _getPersonalPicturePath(int $a_usr_id, string $a_size='small', bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
ilObjUser $user
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$r
+ Here is the call graph for this function:

◆ saveExpression()

ilLikeGUI::saveExpression ( )
protected

Save expression (asynch)

Exceptions
ilLikeDataException

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

References $news_id, $obj_id, $obj_type, $sub_obj_id, $sub_obj_type, exit, renderEmoCounters(), and ILIAS\Repository\user().

271  : void
272  {
273  $exp_key = $this->request->getExpressionKey();
274  $exp_val = $this->request->getValue();
275  $modal_show_sig_id = $this->request->getModalSignalId();
276  $show_signal = new \ILIAS\UI\Implementation\Component\Signal($modal_show_sig_id);
277 
278  if ($exp_val) {
279  $this->data->addExpression(
280  $this->user->getId(),
281  $exp_key,
287  );
288  } else {
289  $this->data->removeExpression(
290  $this->user->getId(),
291  $exp_key,
297  );
298  }
299  echo $this->renderEmoCounters($show_signal);
300  exit;
301  }
renderEmoCounters(?ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
string $sub_obj_type
string $obj_type
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ setObject()

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

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

References $news_id.

87  : void {
88  $this->obj_id = $a_obj_id;
89  $this->obj_type = $a_obj_type;
90  $this->sub_obj_id = $a_sub_obj_id;
91  $this->sub_obj_type = $a_sub_obj_type;
92  $this->news_id = $a_news_id;
93  $this->dom_id = "like_" . $this->obj_id . "_" . $this->obj_type . "_" . $this->sub_obj_id . "_" .
94  $this->sub_obj_type . "_" . $this->news_id;
95  }

Field Documentation

◆ $ctrl

ilCtrl ilLikeGUI::$ctrl
protected

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

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

◆ $data

ilLikeData ilLikeGUI::$data
protected

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

Referenced by __construct().

◆ $dom_id

string ilLikeGUI::$dom_id
protected

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

◆ $gui

ILIAS Like InternalGUIService ilLikeGUI::$gui
protected

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

◆ $lng

ilLanguage ilLikeGUI::$lng
protected

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

Referenced by getHTML().

◆ $main_tpl

ilGlobalTemplateInterface ilLikeGUI::$main_tpl
protected

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

Referenced by __construct().

◆ $news_id

int ilLikeGUI::$news_id
protected

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

Referenced by renderEmoticons(), saveExpression(), and setObject().

◆ $obj_id

int ilLikeGUI::$obj_id
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $obj_type

string ilLikeGUI::$obj_type
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $request

StandardGUIRequest ilLikeGUI::$request
protected

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

◆ $sub_obj_id

int ilLikeGUI::$sub_obj_id
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $sub_obj_type

string ilLikeGUI::$sub_obj_type
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $ui

ILIAS DI UIServices ilLikeGUI::$ui
protected

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

◆ $user

ilObjUser ilLikeGUI::$user
protected

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

Referenced by renderModal().


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