ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilTaggingGUI Class Reference

Class ilTaggingGUI. More...

+ Collaboration diagram for ilTaggingGUI:

Public Member Functions

 __construct ()
 Constructor. More...
 
 executeCommand ()
 Execute command. More...
 
 setObject (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id=0, string $a_sub_obj_type="")
 Set Object. More...
 
 setUserId (int $a_userid)
 
 getUserId ()
 
 setSaveCmd (string $a_savecmd)
 
 getSaveCmd ()
 
 setInputFieldName (string $a_inputfieldname)
 
 getInputFieldName ()
 
 getTaggingInputHTML ()
 
 saveInput ()
 
 isForbidden (string $a_tag)
 
 getAllUserTagsForObjectHTML ()
 
 getHTML ()
 Get HTML. More...
 
 saveJS ()
 Save JS. More...
 

Static Public Member Functions

static initJavascript (string $a_ajax_url, ?ilGlobalTemplateInterface $a_main_tpl=null)
 
static getModalTemplate ()
 
static getListTagsJSCall (string $a_hash, ?string $a_update_code=null)
 

Protected Member Functions

 getTagsFromInput (string $input)
 

Protected Attributes

ilCtrl $ctrl
 
ilObjUser $user
 
ilLanguage $lng
 
ILIAS DI UIServices $ui
 
int $obj_id = 0
 
string $obj_type = ""
 
int $sub_obj_id = 0
 
string $sub_obj_type
 
array $forbidden = []
 
int $userid = 0
 
string $savecmd = ""
 
string $inputfieldname = ""
 
RequestInterface $request
 
string $mess = ""
 
string $requested_mess = ""
 

Private Attributes

ilGlobalTemplateInterface $main_tpl
 

Detailed Description

Class ilTaggingGUI.

User interface class for tagging engine.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilTaggingGUI::__construct ( )

Constructor.

Definition at line 50 of file class.ilTaggingGUI.php.

51 {
52 global $DIC;
53 $this->main_tpl = $DIC->ui()->mainTemplate();
54
55 $this->ctrl = $DIC->ctrl();
56 $this->user = $DIC->user();
57 $this->lng = $DIC->language();
58 $this->ui = $DIC->ui();
59 $this->request = $DIC->http()->request();
60
61 $params = $this->request->getQueryParams();
62 $this->requested_mess = ($params["mess"] ?? "");
63 }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
global $DIC
Definition: shib_login.php:26

References $DIC, $params, ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\ui(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilTaggingGUI::executeCommand ( )

Execute command.

Definition at line 69 of file class.ilTaggingGUI.php.

69 : void
70 {
71 $ilCtrl = $this->ctrl;
72
73 $next_class = $ilCtrl->getNextClass();
74 // PHP8 Review: 'switch' with single 'case'
75 switch ($next_class) {
76 default:
77 $cmd = $ilCtrl->getCmd();
78 $this->$cmd();
79 break;
80 }
81 }
getNextClass($a_gui_class=null)
@inheritDoc

References $ctrl, and ilCtrl\getNextClass().

+ Here is the call graph for this function:

◆ getAllUserTagsForObjectHTML()

ilTaggingGUI::getAllUserTagsForObjectHTML ( )

Definition at line 225 of file class.ilTaggingGUI.php.

225 : string
226 {
227 $ttpl = new ilTemplate("tpl.tag_cloud.html", true, true, "components/ILIAS/Tagging");
229 $this->obj_id,
230 $this->obj_type,
231 $this->sub_obj_id,
232 $this->sub_obj_type
233 );
234
235 $max = 1;
236 foreach ($tags as $tag) {
237 $max = max($max, $tag["cnt"]);
238 }
239 reset($tags);
240 foreach ($tags as $tag) {
241 if (!$this->isForbidden($tag["tag"])) {
242 $ttpl->setCurrentBlock("unlinked_tag");
243 $ttpl->setVariable(
244 "REL_CLASS",
245 ilTagging::getRelevanceClass((int) $tag["cnt"], (int) $max)
246 );
247 $ttpl->setVariable("TAG_TITLE", $tag["tag"]);
248 $ttpl->parseCurrentBlock();
249 }
250 }
251
252 return $ttpl->get();
253 }
isForbidden(string $a_tag)
static getTagsForObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, bool $a_only_online=true)
static getRelevanceClass(int $cnt, int $max)
special template class to simplify handling of ITX/PEAR

References ilTagging\getRelevanceClass(), and ilTagging\getTagsForObject().

+ Here is the call graph for this function:

◆ getHTML()

ilTaggingGUI::getHTML ( )

Get HTML.

Definition at line 319 of file class.ilTaggingGUI.php.

319 : string
320 {
322 $ilCtrl = $this->ctrl;
323 $ui = $this->ui;
324
325 $lng->loadLanguageModule("tagging");
326 $tpl = new ilTemplate("tpl.edit_tags.html", true, true, "components/ILIAS/Tagging");
327 $tpl->setVariable("TXT_TAGS", $lng->txt("tagging_tags"));
328
329 $mtxt = "";
330 $mtype = "";
331 $mess = $this->requested_mess != ""
332 ? $this->requested_mess
333 : $this->mess;
334 // PHP8 Review: 'switch' with single 'case'
335 switch ($mess) {
336 case "mod":
337 $mtype = "success";
338 $mtxt = $lng->txt("msg_obj_modified");
339 break;
340 }
341 if ($mtxt != "") {
342 $tpl->setVariable("MESS", ilUtil::getSystemMessageHTML($mtxt, $mtype));
343 } else {
344 $tpl->setVariable("MESS", "");
345 }
346
347 $title = ilObject::_lookupTitle($this->obj_id);
348 $icon = $ui->factory()->symbol()->icon()->custom(
349 ilObject::_getIcon($this->obj_id),
350 $title,
351 "medium"
352 );
353 $tpl->setVariable("ICON", $ui->renderer()->render($icon));
354 $tpl->setVariable("TXT_OBJ_TITLE", ilObject::_lookupTitle($this->obj_id));
356 $this->obj_id,
357 $this->obj_type,
358 $this->sub_obj_id,
359 $this->sub_obj_type,
360 $this->getUserId()
361 );
362 $tpl->setVariable(
363 "VAL_TAGS",
365 );
366 $tpl->setVariable("TXT_SAVE", $lng->txt("save"));
367 $tpl->setVariable("TXT_COMMA_SEPARATED", $lng->txt("comma_separated"));
368 $tpl->setVariable("CMD_SAVE", "saveJS");
369
370 $os = "ilTagging.cmdAjaxForm(event, '" .
371 $ilCtrl->getFormActionByClass("iltagginggui", "", "", true) .
372 "');";
373 $tpl->setVariable("ON_SUBMIT", $os);
374
375 $tags_set = new ilSetting("tags");
376 if ($tags_set->get("enable_all_users")) {
377 $tpl->setVariable("TAGS_TITLE", $lng->txt("tagging_my_tags"));
378
379 $all_obj_tags = ilTagging::_getListTagsForObjects(array($this->obj_id));
380 $all_obj_tags = $all_obj_tags[$this->obj_id] ?? null;
381 if (is_array($all_obj_tags) &&
382 sizeof($all_obj_tags) != sizeof($tags)) {
383 $tpl->setVariable("TITLE_OTHER", $lng->txt("tagging_other_users"));
384 $tpl->setCurrentBlock("tag_other_bl");
385 foreach ($all_obj_tags as $tag => $is_owner) {
386 if (!$is_owner) {
387 $tpl->setVariable("OTHER_TAG", $tag);
388 $tpl->parseCurrentBlock();
389 }
390 }
391 }
392 }
393
394 echo $tpl->get();
395 exit;
396 }
loadLanguageModule(string $a_module)
Load language module.
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...
static prepareFormOutput($a_str, bool $a_strip=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupTitle(int $obj_id)
ILIAS Setting Class.
ILIAS DI UIServices $ui
static getTagsForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id)
static _getListTagsForObjects(array $a_obj_ids, ?int $a_user_id=null)
Get tags for given object ids.
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
exit

References $lng, ilObject\_getIcon(), ilTagging\_getListTagsForObjects(), ilObject\_lookupTitle(), exit, ilUtil\getSystemMessageHTML(), ilTagging\getTagsForUserAndObject(), and ilLegacyFormElementsUtil\prepareFormOutput().

+ Here is the call graph for this function:

◆ getInputFieldName()

ilTaggingGUI::getInputFieldName ( )

Definition at line 142 of file class.ilTaggingGUI.php.

142 : string
143 {
145 }

◆ getListTagsJSCall()

static ilTaggingGUI::getListTagsJSCall ( string  $a_hash,
?string  $a_update_code = null 
)
static

Definition at line 304 of file class.ilTaggingGUI.php.

307 : string {
308 if ($a_update_code === null) {
309 $a_update_code = "null";
310 } else {
311 $a_update_code = "'" . $a_update_code . "'";
312 }
313 return "ilTagging.listTags(event, '" . $a_hash . "', " . $a_update_code . ");";
314 }

Referenced by ilObjectListGUI\determineProperties(), ilObjectListGUI\getHeaderAction(), and ilObjectListGUI\insertCommonSocialCommands().

+ Here is the caller graph for this function:

◆ getModalTemplate()

static ilTaggingGUI::getModalTemplate ( )
static

Definition at line 290 of file class.ilTaggingGUI.php.

290 : array
291 {
292 global $DIC;
293
294 $ui = $DIC->ui();
295 $modal = $ui->factory()->modal()->roundtrip('#tag_title#', $ui->factory()->legacy()->content(''));
296 $modalt["show"] = $modal->getShowSignal()->getId();
297 $modalt["close"] = $modal->getCloseSignal()->getId();
298 $modalt["template"] = $ui->renderer()->renderAsync($modal);
299
300 return $modalt;
301 }

References $DIC.

◆ getSaveCmd()

ilTaggingGUI::getSaveCmd ( )

Definition at line 132 of file class.ilTaggingGUI.php.

132 : string
133 {
134 return $this->savecmd;
135 }

◆ getTaggingInputHTML()

ilTaggingGUI::getTaggingInputHTML ( )

Definition at line 147 of file class.ilTaggingGUI.php.

147 : string
148 {
150
151 $ttpl = new ilTemplate("tpl.tags_input.html", true, true, "components/ILIAS/Tagging");
153 $this->obj_id,
154 $this->obj_type,
155 $this->sub_obj_id,
156 $this->sub_obj_type,
157 $this->getUserId()
158 );
159 $ttpl->setVariable(
160 "VAL_TAGS",
162 );
163 $ttpl->setVariable("TAG_LABEL", $lng->txt("tagging_my_tags"));
164 $ttpl->setVariable("TXT_SAVE", $lng->txt("save"));
165 $ttpl->setVariable("TXT_COMMA_SEPARATED", $lng->txt("comma_separated"));
166 $ttpl->setVariable("CMD_SAVE", $this->savecmd);
167 $ttpl->setVariable("NAME_TAGS", $this->getInputFieldName());
168
169 return $ttpl->get();
170 }

References $lng, ilTagging\getTagsForUserAndObject(), and ilLegacyFormElementsUtil\prepareFormOutput().

+ Here is the call graph for this function:

◆ getTagsFromInput()

ilTaggingGUI::getTagsFromInput ( string  $input)
protected

Definition at line 172 of file class.ilTaggingGUI.php.

172 : array
173 {
174 $input = ilUtil::stripSlashes($input);
175 $input = str_replace("\r", "\n", $input);
176 $input = str_replace("\n\n", "\n", $input);
177 $input = str_replace("\n", ",", $input);
178 $itags = explode(",", $input);
179 return $itags;
180 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ getUserId()

ilTaggingGUI::getUserId ( )

Definition at line 122 of file class.ilTaggingGUI.php.

122 : int
123 {
124 return $this->userid;
125 }

◆ initJavascript()

static ilTaggingGUI::initJavascript ( string  $a_ajax_url,
?ilGlobalTemplateInterface  $a_main_tpl = null 
)
static

Definition at line 260 of file class.ilTaggingGUI.php.

263 : void {
264 global $DIC;
265
266 if ($a_main_tpl != null) {
267 $tpl = $a_main_tpl;
268 } else {
269 $tpl = $DIC["tpl"];
270 }
271
272 $lng = $DIC->language();
273
274 $lng->loadLanguageModule("tagging");
275 $lng->toJS("tagging_tags", $tpl);
276
279 $tpl->addJavaScript("assets/js/ilTagging.js");
280 //$tpl->addJavaScript("../components/ILIAS/Tagging/resources/ilTagging.js");
281
282 $modal_template = self::getModalTemplate();
283
284 $tpl->addOnLoadCode("ilTagging.setAjaxUrl('" . $a_ajax_url . "');");
285 $tpl->addOnLoadCode('ilTagging.setModalTemplate("' . addslashes(json_encode($modal_template["template"])) . '");');
286 $tpl->addOnLoadCode("ilTagging.setShowSignal('" . $modal_template["show"] . "');");
287 $tpl->addOnLoadCode("ilTagging.setHideSignal('" . $modal_template["close"] . "');");
288 }
toJS($a_lang_key, ?ilGlobalTemplateInterface $a_tpl=null)
Transfer text to Javascript.
static getModalTemplate()
static initConnection(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Connection module.
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template

◆ isForbidden()

ilTaggingGUI::isForbidden ( string  $a_tag)

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

211 : bool
212 {
213 foreach ($this->forbidden as $f) {
214 if (is_int(strpos(strtolower(
215 str_replace(array("+", "§", '"', "'", "*", "%", "&", "/", "\\", "(", ")", "=", ":", ";", ":", "-", "_", "\$",
216 "£" . "!" . "¨", "^", "`", "@", "<", ">"), "", $a_tag)
217 ), $f))) {
218 return true;
219 }
220 }
221 return false;
222 }

References Vendor\Package\$f.

◆ saveInput()

ilTaggingGUI::saveInput ( )

Definition at line 182 of file class.ilTaggingGUI.php.

182 : void
183 {
186 $body = $request->getParsedBody();
187
188 $itags = $this->getTagsFromInput($body[$this->getInputFieldName()]);
189 $tags = array();
190 foreach ($itags as $itag) {
191 $itag = trim($itag);
192 if (!in_array($itag, $tags) && $itag != "") {
193 if (!$this->isForbidden($itag)) {
194 $tags[] = $itag;
195 }
196 }
197 }
198
200 $this->obj_id,
201 $this->obj_type,
202 $this->sub_obj_id,
203 $this->sub_obj_type,
204 $this->getUserId(),
205 $tags
206 );
207 $this->main_tpl->setOnScreenMessage('success', $lng->txt('msg_obj_modified'));
208 }
RequestInterface $request
getTagsFromInput(string $input)
static writeTagsForUserAndObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id, array $a_tags)

References $lng, and ilTagging\writeTagsForUserAndObject().

+ Here is the call graph for this function:

◆ saveJS()

ilTaggingGUI::saveJS ( )

Save JS.

Definition at line 401 of file class.ilTaggingGUI.php.

401 : void
402 {
404 $body = $request->getParsedBody();
405 $itags = $this->getTagsFromInput($body["tags"]);
406 $tags = array();
407 foreach ($itags as $itag) {
408 $itag = trim($itag);
409 if (!in_array($itag, $tags) && $itag != "") {
410 if (!$this->isForbidden($itag)) {
411 $tags[] = $itag;
412 }
413 }
414 }
415
417 $this->obj_id,
418 $this->obj_type,
419 $this->sub_obj_id,
420 $this->sub_obj_type,
421 $this->getUserId(),
422 $tags
423 );
424
425 $this->mess = "mod";
426
427 $this->getHTML();
428 }

References ilTagging\writeTagsForUserAndObject().

+ Here is the call graph for this function:

◆ setInputFieldName()

ilTaggingGUI::setInputFieldName ( string  $a_inputfieldname)

Definition at line 137 of file class.ilTaggingGUI.php.

137 : void
138 {
139 $this->inputfieldname = $a_inputfieldname;
140 }

◆ setObject()

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

Set Object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSub-object ID
string$a_sub_obj_typeSub-object Type

Definition at line 91 of file class.ilTaggingGUI.php.

96 : void {
97 $ilUser = $this->user;
98
99 $this->obj_id = $a_obj_id;
100 $this->obj_type = $a_obj_type;
101 $this->sub_obj_id = $a_sub_obj_id;
102 $this->sub_obj_type = $a_sub_obj_type;
103
104 $this->setSaveCmd("saveTags");
105 $this->setUserId($ilUser->getId());
106 $this->setInputFieldName("il_tags");
107
108 $tags_set = new ilSetting("tags");
109 $forbidden = $tags_set->get("forbidden_tags");
110 if ($forbidden != "") {
111 $this->forbidden = unserialize((string) $forbidden, ['allowed_classes' => false]);
112 } else {
113 $this->forbidden = array();
114 }
115 }
setSaveCmd(string $a_savecmd)
setInputFieldName(string $a_inputfieldname)
setUserId(int $a_userid)

◆ setSaveCmd()

ilTaggingGUI::setSaveCmd ( string  $a_savecmd)

Definition at line 127 of file class.ilTaggingGUI.php.

127 : void
128 {
129 $this->savecmd = $a_savecmd;
130 }

◆ setUserId()

ilTaggingGUI::setUserId ( int  $a_userid)

Definition at line 117 of file class.ilTaggingGUI.php.

117 : void
118 {
119 $this->userid = $a_userid;
120 }

Field Documentation

◆ $ctrl

ilCtrl ilTaggingGUI::$ctrl
protected

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

Referenced by executeCommand().

◆ $forbidden

array ilTaggingGUI::$forbidden = []
protected

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

◆ $inputfieldname

string ilTaggingGUI::$inputfieldname = ""
protected

Definition at line 41 of file class.ilTaggingGUI.php.

◆ $lng

ilLanguage ilTaggingGUI::$lng
protected

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

◆ $main_tpl

ilGlobalTemplateInterface ilTaggingGUI::$main_tpl
private

Definition at line 45 of file class.ilTaggingGUI.php.

◆ $mess

string ilTaggingGUI::$mess = ""
protected

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

◆ $obj_id

int ilTaggingGUI::$obj_id = 0
protected

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

◆ $obj_type

string ilTaggingGUI::$obj_type = ""
protected

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

◆ $request

RequestInterface ilTaggingGUI::$request
protected

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

◆ $requested_mess

string ilTaggingGUI::$requested_mess = ""
protected

Definition at line 44 of file class.ilTaggingGUI.php.

◆ $savecmd

string ilTaggingGUI::$savecmd = ""
protected

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

◆ $sub_obj_id

int ilTaggingGUI::$sub_obj_id = 0
protected

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

◆ $sub_obj_type

string ilTaggingGUI::$sub_obj_type
protected

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

◆ $ui

ILIAS DI UIServices ilTaggingGUI::$ui
protected

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

◆ $user

ilObjUser ilTaggingGUI::$user
protected

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

◆ $userid

int ilTaggingGUI::$userid = 0
protected

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


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