ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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

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

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

44  {
45  global $DIC;
46 
47  $this->main_tpl = ($main_tpl == null)
48  ? $DIC->ui()->mainTemplate()
49  : $main_tpl;
50 
51  $this->lng = $DIC->language();
52  $this->ctrl = $DIC->ctrl();
53  $this->user = $DIC->user();
54  $this->ui = $DIC->ui();
55 
56  $this->data = $data;
57 
58  $this->lng->loadLanguageModule("like");
59  $this->request = new StandardGUIRequest(
60  $DIC->http(),
61  $DIC->refinery()
62  );
63 
64  $this->initJavascript();
65  }
ilLikeData $data
global $DIC
Definition: feed.php:28
ilGlobalTemplateInterface $main_tpl
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilLikeGUI::executeCommand ( )

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

References $ctrl, and ilCtrl\getNextClass().

89  : string
90  {
91  $ilCtrl = $this->ctrl;
92 
93  $next_class = $ilCtrl->getNextClass($this);
94  $cmd = $ilCtrl->getCmd("getHTML");
95 
96  switch ($next_class) {
97  default:
98  if (in_array($cmd, array("getHTML", "renderEmoticons", "renderModal", "saveExpression"))) {
99  return $this->$cmd();
100  }
101  break;
102  }
103  return "";
104  }
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 356 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().

358  : string {
359  global $DIC;
360 
361  $lng = $DIC->language();
362 
363  switch ($a_const) {
364  case ilLikeData::TYPE_LIKE: return $lng->txt("like");
365  case ilLikeData::TYPE_DISLIKE: return $lng->txt("dislike");
366  case ilLikeData::TYPE_LOVE: return $lng->txt("love");
367  case ilLikeData::TYPE_LAUGH: return $lng->txt("laugh");
368  case ilLikeData::TYPE_ASTOUNDED: return $lng->txt("astounded");
369  case ilLikeData::TYPE_SAD: return $lng->txt("sad");
370  case ilLikeData::TYPE_ANGRY: return $lng->txt("angry");
371  }
372  return "";
373  }
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: feed.php:28
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 188 of file class.ilLikeGUI.php.

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 ILIAS\Repository\ui().

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

192  $f = $this->ui->factory();
193  $like = null;
194  switch ($a_const) {
195  case ilLikeData::TYPE_LIKE: $like = $f->symbol()->glyph()->like();
196  break;
197  case ilLikeData::TYPE_DISLIKE: $like = $f->symbol()->glyph()->dislike();
198  break;
199  case ilLikeData::TYPE_LOVE: $like = $f->symbol()->glyph()->love();
200  break;
201  case ilLikeData::TYPE_LAUGH: $like = $f->symbol()->glyph()->laugh();
202  break;
203  case ilLikeData::TYPE_ASTOUNDED: $like = $f->symbol()->glyph()->astounded();
204  break;
205  case ilLikeData::TYPE_SAD: $like = $f->symbol()->glyph()->sad();
206  break;
207  case ilLikeData::TYPE_ANGRY: $like = $f->symbol()->glyph()->angry();
208  break;
209  }
210  if ($unavailable) {
211  $like = $like->withUnavailableAction();
212  }
213  return $like;
214  }
const TYPE_ASTOUNDED
This describes how a glyph could be modified during construction of UI.
Definition: Glyph.php:30
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHTML()

ilLikeGUI::getHTML ( )

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

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

106  : string
107  {
108  $f = $this->ui->factory();
109  $r = $this->ui->renderer();
110  $ctrl = $this->ctrl;
111  $lng = $this->lng;
112 
113  $tpl = new ilTemplate("tpl.like.html", true, true, "Services/Like");
114 
115  // modal
116  $modal_asyn_url = $ctrl->getLinkTarget($this, "renderModal", "", true, false);
117  $modal = $f->modal()->roundtrip('', $f->legacy(""))
118  ->withAsyncRenderUrl($modal_asyn_url);
119 
120  $modal_show_sig_id = $modal->getShowSignal()->getId();
121  $this->ctrl->setParameter($this, "modal_show_sig_id", $modal_show_sig_id);
122  $emo_counters = $this->renderEmoCounters($modal->getShowSignal());
123  $tpl->setVariable("EMO_COUNTERS", $emo_counters . $r->render($modal));
124 
125 
126 
127  // emoticon popover
128  $popover = $f->popover()->standard($f->legacy(''))->withTitle('');
129  $ctrl->setParameter($this, "repl_sig", $popover->getReplaceContentSignal()->getId());
130  $asyn_url = $ctrl->getLinkTarget($this, "renderEmoticons", "", true, false);
131  $popover = $popover->withAsyncContentUrl($asyn_url);
132  $button = $f->button()->shy($lng->txt("like"), '#')
133  ->withOnClick($popover->getShowSignal());
134 
135  $tpl->setVariable("LIKE", $r->render([$popover, $button]));
136 
137  return $tpl->get();
138  }
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...
renderEmoCounters(ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
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 67 of file class.ilLikeGUI.php.

References ilYuiUtil\initConnection().

Referenced by __construct().

67  : void
68  {
70  $this->main_tpl->addJavaScript("./Services/Like/js/Like.js");
71  }
static initConnection(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
+ Here is the call graph for this function:
+ 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 144 of file class.ilLikeGUI.php.

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

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

147  : string {
148  $ilCtrl = $this->ctrl;
149 
150  $tpl = new ilTemplate("tpl.emo_counters.html", true, true, "Services/Like");
151  $f = $this->ui->factory();
152  $r = $this->ui->renderer();
153 
154  $cnts = $this->data->getExpressionCounts(
155  $this->obj_id,
156  $this->obj_type,
157  $this->sub_obj_id,
158  $this->sub_obj_type,
159  $this->news_id
160  );
161  $comps = array();
162  foreach ($this->data->getExpressionTypes() as $k => $txt) {
163  if ($cnts[$k] > 0) {
164  $glyph = $this->getGlyphForConst($k, $unavailable);
165  if ($modal_signal !== null) {
166  $glyph = $glyph->withOnClick($modal_signal);
167  }
168  $comps[] = $glyph->withCounter($f->counter()->status($cnts[$k]));
169  }
170  }
171 
172  if ($ilCtrl->isAsynch()) {
173  $tpl->setVariable("MODAL_TRIGGER", $r->renderAsync($comps));
174  } else {
175  $tpl->setVariable("MODAL_TRIGGER", $r->render($comps));
176  }
177  if ($modal_signal !== null) {
178  $tpl->setVariable("ID", $this->dom_id);
179  }
180 
181  if (count($comps) > 0 && $modal_signal !== null) {
182  $tpl->setVariable("SEP", $r->render($f->divider()->vertical()));
183  }
184 
185  return $tpl->get();
186  }
getGlyphForConst(int $a_const, bool $unavailable=false)
$txt
Definition: error.php:14
$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 219 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().

219  : void
220  {
221  $ilCtrl = $this->ctrl;
222  $r = $this->ui->renderer();
223  $glyphs = [];
224 
225  $ilCtrl->saveParameter($this, "modal_show_sig_id");
226 
227  $tpl = new ilTemplate("tpl.emoticons.html", true, true, "Services/Like");
228  $tpl->setVariable("ID", $this->dom_id);
229 
230  $url = $ilCtrl->getLinkTarget($this, "", "", true);
231  foreach ($this->data->getExpressionTypes() as $k => $txt) {
232  $g = $this->getGlyphForConst($k);
233 
234  if ($this->data->isExpressionSet(
235  $this->user->getId(),
236  $k,
242  )) {
243  $g = $g->withHighlight();
244  }
245 
246  $g = $g->withAdditionalOnLoadCode(function ($id) use ($k, $url) {
247  return
248  "$('#" . $id . "').click(function() { il.Like.toggle('" . $url . "','" . $id . "','" . $this->dom_id . "'," . $k . ");});";
249  });
250  $glyphs[] = $g;
251  }
252 
253  $tpl->setVariable("GLYPHS", $r->renderAsync($glyphs));
254 
255  echo $tpl->get();
256  exit;
257  }
exit
Definition: login.php:29
getGlyphForConst(int $a_const, bool $unavailable=false)
$url
Definition: ltiregstart.php:35
$txt
Definition: error.php:14
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
string $sub_obj_type
string $obj_type
$r
+ Here is the call graph for this function:

◆ renderModal()

ilLikeGUI::renderModal ( )

Render modal (asynch)

Exceptions
ilDateTimeException
ilLikeDataException
ilWACException

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

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

302  : void
303  {
304  $user = $this->user;
305 
306  $f = $this->ui->factory();
307  $r = $this->ui->renderer();
308 
309 
310  $list_items = [];
311 
312  $glyph_renderings = [];
313  foreach ($this->data->getExpressionEntries(
314  $this->obj_id,
315  $this->obj_type,
316  $this->sub_obj_id,
317  $this->sub_obj_type,
318  $this->news_id
319  ) as $exp) {
320  $name = ilUserUtil::getNamePresentation($exp["user_id"]);
321 
322  $image = $f->image()->responsive(
323  ilObjUser::_getPersonalPicturePath($exp["user_id"]),
324  $name
325  );
326 
327  $g = $this->getGlyphForConst($exp["expression"], true);
328  $placeholder = "###" . $exp["expression"] . "###";
329  $glyph_renderings[$placeholder] = $r->render($g);
330 
331  $list_items[] = $f->item()->standard($name)
332  ->withDescription($placeholder . " " .
334  ->withLeadImage($image);
335  }
336 
337  $std_list = $f->panel()->listing()->standard("", array(
338  $f->item()->group("", $list_items)
339  ));
340 
341  $header = $f->legacy($this->renderEmoCounters(null, true));
342  //$header = $f->legacy("---");
343 
344  $modal = $f->modal()->roundtrip('', [$header, $std_list]);
345  $html = $r->render($modal);
346  foreach ($glyph_renderings as $pl => $gl) {
347  $html = str_replace($pl, $gl, $html);
348  }
349  echo $html;
350  exit;
351  }
exit
Definition: login.php:29
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
renderEmoCounters(ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
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:
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
$r
+ Here is the call graph for this function:

◆ saveExpression()

ilLikeGUI::saveExpression ( )
protected

Save expression (asynch)

Exceptions
ilLikeDataException

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

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

263  : void
264  {
265  $exp_key = $this->request->getExpressionKey();
266  $exp_val = $this->request->getValue();
267  $modal_show_sig_id = $this->request->getModalSignalId();
268  $show_signal = new \ILIAS\UI\Implementation\Component\Signal($modal_show_sig_id);
269 
270  if ($exp_val) {
271  $this->data->addExpression(
272  $this->user->getId(),
273  $exp_key,
279  );
280  } else {
281  $this->data->removeExpression(
282  $this->user->getId(),
283  $exp_key,
289  );
290  }
291  echo $this->renderEmoCounters($show_signal);
292  exit;
293  }
exit
Definition: login.php:29
renderEmoCounters(ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
string $sub_obj_type
string $obj_type
+ 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 73 of file class.ilLikeGUI.php.

References $news_id.

79  : void {
80  $this->obj_id = $a_obj_id;
81  $this->obj_type = $a_obj_type;
82  $this->sub_obj_id = $a_sub_obj_id;
83  $this->sub_obj_type = $a_sub_obj_type;
84  $this->news_id = $a_news_id;
85  $this->dom_id = "like_" . $this->obj_id . "_" . $this->obj_type . "_" . $this->sub_obj_id . "_" .
86  $this->sub_obj_type . "_" . $this->news_id;
87  }

Field Documentation

◆ $ctrl

ilCtrl ilLikeGUI::$ctrl
protected

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

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

◆ $data

ilLikeData ilLikeGUI::$data
protected

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

Referenced by __construct().

◆ $dom_id

string ilLikeGUI::$dom_id
protected

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

◆ $lng

ilLanguage ilLikeGUI::$lng
protected

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

Referenced by getHTML().

◆ $main_tpl

ilGlobalTemplateInterface ilLikeGUI::$main_tpl
protected

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

Referenced by __construct().

◆ $news_id

int ilLikeGUI::$news_id
protected

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

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

◆ $obj_id

int ilLikeGUI::$obj_id
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $obj_type

string ilLikeGUI::$obj_type
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $request

StandardGUIRequest ilLikeGUI::$request
protected

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

◆ $sub_obj_id

int ilLikeGUI::$sub_obj_id
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $sub_obj_type

string ilLikeGUI::$sub_obj_type
protected

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

Referenced by renderEmoticons(), and saveExpression().

◆ $ui

ILIAS DI UIServices ilLikeGUI::$ui
protected

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

◆ $user

ilObjUser ilLikeGUI::$user
protected

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

Referenced by renderModal().


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