ILIAS  release_8 Revision v8.24
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.

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
ilGlobalTemplateInterface $main_tpl
global $DIC
Definition: feed.php:28

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

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilLikeGUI::executeCommand ( )

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

88 : string
89 {
90 $ilCtrl = $this->ctrl;
91
92 $next_class = $ilCtrl->getNextClass($this);
93 $cmd = $ilCtrl->getCmd("getHTML");
94
95 switch ($next_class) {
96 default:
97 if (in_array($cmd, array("getHTML", "renderEmoticons", "renderModal", "saveExpression"))) {
98 return $this->$cmd();
99 }
100 break;
101 }
102 return "";
103 }
getNextClass($a_gui_class=null)
@inheritDoc

◆ getExpressionText()

static ilLikeGUI::getExpressionText ( int  $a_const)
static

Get expression text for const.

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

350 : string {
351 global $DIC;
352
353 $lng = $DIC->language();
354
355 switch ($a_const) {
356 case ilLikeData::TYPE_LIKE: return $lng->txt("like");
357 case ilLikeData::TYPE_DISLIKE: return $lng->txt("dislike");
358 case ilLikeData::TYPE_LOVE: return $lng->txt("love");
359 case ilLikeData::TYPE_LAUGH: return $lng->txt("laugh");
360 case ilLikeData::TYPE_ASTOUNDED: return $lng->txt("astounded");
361 case ilLikeData::TYPE_SAD: return $lng->txt("sad");
362 case ilLikeData::TYPE_ANGRY: return $lng->txt("angry");
363 }
364 return "";
365 }
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
ilLanguage $lng

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

◆ getGlyphForConst()

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

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

191 $f = $this->ui->factory();
192 $like = null;
193 switch ($a_const) {
194 case ilLikeData::TYPE_LIKE: $like = $f->symbol()->glyph()->like(); break;
195 case ilLikeData::TYPE_DISLIKE: $like = $f->symbol()->glyph()->dislike(); break;
196 case ilLikeData::TYPE_LOVE: $like = $f->symbol()->glyph()->love(); break;
197 case ilLikeData::TYPE_LAUGH: $like = $f->symbol()->glyph()->laugh(); break;
198 case ilLikeData::TYPE_ASTOUNDED: $like = $f->symbol()->glyph()->astounded(); break;
199 case ilLikeData::TYPE_SAD: $like = $f->symbol()->glyph()->sad(); break;
200 case ilLikeData::TYPE_ANGRY: $like = $f->symbol()->glyph()->angry(); break;
201 }
202 if ($unavailable) {
203 $like = $like->withUnavailableAction();
204 }
205 return $like;
206 }
This describes how a glyph could be modified during construction of UI.
Definition: Glyph.php:31

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

◆ getHTML()

ilLikeGUI::getHTML ( )

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

105 : string
106 {
107 $f = $this->ui->factory();
108 $r = $this->ui->renderer();
111
112 $tpl = new ilTemplate("tpl.like.html", true, true, "Services/Like");
113
114 // modal
115 $modal_asyn_url = $ctrl->getLinkTarget($this, "renderModal", "", true, false);
116 $modal = $f->modal()->roundtrip('', $f->legacy(""))
117 ->withAsyncRenderUrl($modal_asyn_url);
118
119 $modal_show_sig_id = $modal->getShowSignal()->getId();
120 $this->ctrl->setParameter($this, "modal_show_sig_id", $modal_show_sig_id);
121 $emo_counters = $this->renderEmoCounters($modal->getShowSignal());
122 $tpl->setVariable("EMO_COUNTERS", $emo_counters . $r->render($modal));
123
124
125
126 // emoticon popover
127 $popover = $f->popover()->standard($f->legacy(''))->withTitle('');
128 $ctrl->setParameter($this, "repl_sig", $popover->getReplaceContentSignal()->getId());
129 $asyn_url = $ctrl->getLinkTarget($this, "renderEmoticons", "", true, false);
130 $popover = $popover->withAsyncContentUrl($asyn_url);
131 $button = $f->button()->shy($lng->txt("like"), '#')
132 ->withOnClick($popover->getShowSignal());
133
134 $tpl->setVariable("LIKE", $r->render([$popover, $button]));
135
136 return $tpl->get();
137 }
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
renderEmoCounters(ILIAS\UI\Component\Signal $modal_signal=null, bool $unavailable=false)
Render emo counters.
special template class to simplify handling of ITX/PEAR
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41

References Vendor\Package\$f, $lng, $tpl, ILIAS\Repository\ctrl(), ilCtrl\getLinkTarget(), ilCtrl\setParameter(), and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ initJavascript()

ilLikeGUI::initJavascript ( )
protected

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

67 : void
68 {
69 $this->main_tpl->addJavaScript("./Services/Like/js/Like.js");
70 }

Referenced by __construct().

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

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

◆ renderEmoticons()

ilLikeGUI::renderEmoticons ( )

Render emoticons (asynch)

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

211 : void
212 {
213 $ilCtrl = $this->ctrl;
214 $r = $this->ui->renderer();
215 $glyphs = [];
216
217 $ilCtrl->saveParameter($this, "modal_show_sig_id");
218
219 $tpl = new ilTemplate("tpl.emoticons.html", true, true, "Services/Like");
220 $tpl->setVariable("ID", $this->dom_id);
221
222 $url = $ilCtrl->getLinkTarget($this, "", "", true);
223 foreach ($this->data->getExpressionTypes() as $k => $txt) {
224 $g = $this->getGlyphForConst($k);
225
226 if ($this->data->isExpressionSet(
227 $this->user->getId(),
228 $k,
229 $this->obj_id,
230 $this->obj_type,
231 $this->sub_obj_id,
232 $this->sub_obj_type,
233 $this->news_id
234 )) {
235 $g = $g->withHighlight();
236 }
237
238 $g = $g->withAdditionalOnLoadCode(function ($id) use ($k, $url) {
239 return
240 "$('#" . $id . "').click(function() { il.Like.toggle('" . $url . "','" . $id . "','" . $this->dom_id . "'," . $k . ");});";
241 });
242 $glyphs[] = $g;
243 }
244
245 $tpl->setVariable("GLYPHS", $r->renderAsync($glyphs));
246
247 echo $tpl->get();
248 exit;
249 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
exit
Definition: login.php:28
$url

References $id, $tpl, $txt, $url, exit, and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ renderModal()

ilLikeGUI::renderModal ( )

Render modal (asynch)

Exceptions
ilDateTimeException
ilLikeDataException
ilWACException

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

294 : void
295 {
297
298 $f = $this->ui->factory();
299 $r = $this->ui->renderer();
300
301
302 $list_items = [];
303
304 $glyph_renderings = [];
305 foreach ($this->data->getExpressionEntries(
306 $this->obj_id,
307 $this->obj_type,
308 $this->sub_obj_id,
309 $this->sub_obj_type,
310 $this->news_id
311 ) as $exp) {
312 $name = ilUserUtil::getNamePresentation($exp["user_id"]);
313
314 $image = $f->image()->responsive(
315 ilObjUser::_getPersonalPicturePath($exp["user_id"]),
316 $name
317 );
318
319 $g = $this->getGlyphForConst($exp["expression"], true);
320 $placeholder = "###" . $exp["expression"] . "###";
321 $glyph_renderings[$placeholder] = $r->render($g);
322
323 $list_items[] = $f->item()->standard($name)
324 ->withDescription($placeholder . " " .
326 ->withLeadImage($image);
327 }
328
329 $std_list = $f->panel()->listing()->standard("", array(
330 $f->item()->group("", $list_items)
331 ));
332
333 $header = $f->legacy($this->renderEmoCounters(null, true));
334 //$header = $f->legacy("---");
335
336 $modal = $f->modal()->roundtrip('', [$header, $std_list]);
337 $html = $r->render($modal);
338 foreach ($glyph_renderings as $pl => $gl) {
339 $html = str_replace($pl, $gl, $html);
340 }
341 echo $html;
342 exit;
343 }
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
ilObjUser $user
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)
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:
if($format !==null) $name
Definition: metadata.php:247

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

+ Here is the call graph for this function:

◆ saveExpression()

ilLikeGUI::saveExpression ( )
protected

Save expression (asynch)

Exceptions
ilLikeDataException

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

255 : void
256 {
257 $exp_key = $this->request->getExpressionKey();
258 $exp_val = $this->request->getValue();
259 $modal_show_sig_id = $this->request->getModalSignalId();
260 $show_signal = new \ILIAS\UI\Implementation\Component\Signal($modal_show_sig_id);
261
262 if ($exp_val) {
263 $this->data->addExpression(
264 $this->user->getId(),
265 $exp_key,
266 $this->obj_id,
267 $this->obj_type,
268 $this->sub_obj_id,
269 $this->sub_obj_type,
270 $this->news_id
271 );
272 } else {
273 $this->data->removeExpression(
274 $this->user->getId(),
275 $exp_key,
276 $this->obj_id,
277 $this->obj_type,
278 $this->sub_obj_id,
279 $this->sub_obj_type,
280 $this->news_id
281 );
282 }
283 echo $this->renderEmoCounters($show_signal);
284 exit;
285 }

References exit, and ILIAS\Repository\user().

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

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

Field Documentation

◆ $ctrl

ilCtrl ilLikeGUI::$ctrl
protected

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

◆ $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.

◆ $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.

◆ $obj_id

int ilLikeGUI::$obj_id
protected

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

◆ $obj_type

string ilLikeGUI::$obj_type
protected

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

◆ $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.

◆ $sub_obj_type

string ilLikeGUI::$sub_obj_type
protected

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

◆ $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.


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