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

Tag classification provider. More...

+ Inheritance diagram for ilTaggingClassificationProvider:
+ Collaboration diagram for ilTaggingClassificationProvider:

Public Member Functions

 __construct (int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
 
 render (array &$a_html, object $a_parent_gui)
 @inheritDoc More...
 
 importPostData (?array $a_saved=null)
 @inheritDoc More...
 
 setSelection (array $a_value)
 @inheritDoc More...
 
 getFilteredObjects ()
 @inheritDoc More...
 
 initListGUI (ilObjectListGUI $a_list_gui)
 Init list gui properties. More...
 
 __construct (int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
 
 render (array &$a_html, object $a_parent_gui)
 Render HTML chunks. More...
 
 importPostData (?array $a_saved=null)
 Import post data. More...
 
 setSelection (array $a_value)
 Set selection. More...
 
 getFilteredObjects ()
 Get filtered object ref ids. More...
 
 initListGUI (ilObjectListGUI $a_list_gui)
 Init list gui properties. More...
 

Static Public Member Functions

static isActive (int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
 @inheritDoc More...
 
- Static Public Member Functions inherited from ilClassificationProvider
static getValidProviders (int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
 Get all valid providers (for parent container) More...
 
static isActive (int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
 Is provider currently active? More...
 

Protected Member Functions

 init ()
 
 getSubTreeTags ()
 
 init ()
 

Protected Attributes

ilLanguage $lng
 
ilObjUser $user
 
ilTree $tree
 
ilObjectDefinition $obj_definition
 
ilCtrl $ctrl
 
RequestInterface $request
 
string $requested_type
 
string $requested_tag_code
 
bool $enable_all_users = false
 
array $selection
 
- Protected Attributes inherited from ilClassificationProvider
int $parent_ref_id
 
int $parent_obj_id
 
string $parent_type
 
RequestInterface $request
 

Detailed Description

Tag classification provider.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

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

Constructor & Destructor Documentation

◆ __construct()

ilTaggingClassificationProvider::__construct ( int  $a_parent_ref_id,
int  $a_parent_obj_id,
string  $a_parent_obj_type 
)

Reimplemented from ilClassificationProvider.

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

45 {
46 global $DIC;
47 parent::__construct($a_parent_ref_id, $a_parent_obj_id, $a_parent_obj_type);
48
49 $this->lng = $DIC->language();
50 $this->user = $DIC->user();
51 $this->tree = $DIC->repositoryTree();
52 $this->obj_definition = $DIC["objDefinition"];
53 $this->ctrl = $DIC->ctrl();
54 $this->request = $DIC->http()->request();
55
56 $params = $this->request->getQueryParams();
57 $body = $this->request->getParsedBody();
58 $this->requested_type = trim($body["tag_type"] ?? ($params["tag_type"] ?? ""));
59 $this->requested_tag_code = trim($body["tag"] ?? ($params["tag"] ?? ""));
60 }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References $DIC, $params, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ getFilteredObjects()

ilTaggingClassificationProvider::getFilteredObjects ( )

@inheritDoc

Reimplemented from ilClassificationProvider.

Definition at line 206 of file class.ilTaggingClassificationProvider.php.

206 : array
207 {
208 $ilUser = $this->user;
209
210 if (!$this->selection) {
211 return[];
212 }
213
214 $types = array("personal");
215 if ($this->enable_all_users) {
216 $types[] = "other";
217 }
218
219 $found = array();
220 foreach ($types as $type) {
221 if (isset($this->selection[$type])) {
222 $invert = ($type == "personal")
223 ? false
224 : true;
225
226 foreach ($this->selection[$type] as $tag) {
227 $found[$tag] = array_keys(ilTagging::_findObjectsByTag((string) $tag, $ilUser->getId(), $invert));
228 }
229 }
230 }
231
232 /* OR
233 $res = array();
234 foreach($found as $tag => $ids)
235 {
236 $res = array_merge($res, $ids);
237 }
238 */
239
240 // AND
241 $res = null;
242 foreach ($found as $tag => $ids) {
243 if ($res === null) {
244 $res = $ids;
245 } else {
246 $res = array_intersect($res, $ids);
247 }
248 }
249
250 if (!is_null($res) && count($res) > 0) {
251 return array_unique($res);
252 }
253 return [];
254 }
static _findObjectsByTag(string $a_tag, ?int $a_user_id=null, bool $a_invert=false)
Find all objects with given tag.
$res
Definition: ltiservices.php:69

References $res, and ilTagging\_findObjectsByTag().

+ Here is the call graph for this function:

◆ getSubTreeTags()

ilTaggingClassificationProvider::getSubTreeTags ( )
protected

Definition at line 256 of file class.ilTaggingClassificationProvider.php.

256 : array
257 {
259 $ilUser = $this->user;
260 $sub_ids = array();
261
262 // categories show only direct children and their tags
263 if (ilObject::_lookupType($this->parent_ref_id, true) == "cat") {
264 foreach ($tree->getChilds($this->parent_ref_id) as $sub_item) {
265 if ($sub_item["ref_id"] != $this->parent_ref_id &&
266 $sub_item["type"] != "rolf" &&
267 !$tree->isDeleted((int) $sub_item["ref_id"])) {
268 $sub_ids[$sub_item["obj_id"]] = $sub_item["type"];
269 }
270 }
271 } else {
272 foreach ($tree->getSubTree($tree->getNodeData($this->parent_ref_id)) as $sub_item) {
273 if ($sub_item["ref_id"] != $this->parent_ref_id &&
274 $sub_item["type"] != "rolf" &&
275 !$tree->isDeleted((int) $sub_item["ref_id"])) {
276 $sub_ids[$sub_item["obj_id"]] = $sub_item["type"];
277 }
278 }
279 }
280
281 if ($sub_ids) {
282 $only_user = $this->enable_all_users
283 ? null
284 : $ilUser->getId();
285
286 return ilTagging::_getTagCloudForObjects($sub_ids, $only_user, $ilUser->getId());
287 }
288 return [];
289 }
static _lookupType(int $id, bool $reference=false)
static _getTagCloudForObjects(array $a_obj_ids, ?int $a_user_id=null, int $a_divide=0)
Count tags for given object ids.
isDeleted(int $a_node_id)
This is a wrapper for isSaved() with a more useful name.
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node

References ilTagging\_getTagCloudForObjects(), ilObject\_lookupType(), ilTree\getChilds(), ilTree\getNodeData(), ilTree\getSubTree(), and ilTree\isDeleted().

+ Here is the call graph for this function:

◆ importPostData()

ilTaggingClassificationProvider::importPostData ( ?array  $a_saved = null)

@inheritDoc

Reimplemented from ilClassificationProvider.

Definition at line 162 of file class.ilTaggingClassificationProvider.php.

162 : array
163 {
164 $type = $this->requested_type;
165 $tag_code = $this->requested_tag_code;
166 if ($type && $tag_code) {
167 // code to tag
168 $found = null;
169 foreach ($this->getSubTreeTags() as $tags) {
170 foreach (array_keys($tags) as $tag) {
171 if (md5((string) $tag) === $tag_code) {
172 $found = $tag;
173 break(2);
174 }
175 }
176 }
177 if ($found) {
178 // multi select
179 if (isset($a_saved[$type]) &&
180 in_array($found, $a_saved[$type])) {
181 $key = array_search($found, $a_saved[$type]);
182 unset($a_saved[$type][$key]);
183 if (!sizeof($a_saved[$type])) {
184 unset($a_saved[$type]);
185 }
186 } else {
187 $a_saved[$type][] = $found;
188 }
189 }
190 return $a_saved ?? [];
191 }
192 return [];
193 }

◆ init()

ilTaggingClassificationProvider::init ( )
protected

Reimplemented from ilClassificationProvider.

Definition at line 62 of file class.ilTaggingClassificationProvider.php.

62 : void
63 {
64 $tags_set = new ilSetting("tags");
65 $this->enable_all_users = (bool) $tags_set->get("enable_all_users", '0');
66 }
ILIAS Setting Class.

◆ initListGUI()

ilTaggingClassificationProvider::initListGUI ( ilObjectListGUI  $a_list_gui)

Init list gui properties.

Reimplemented from ilClassificationProvider.

Definition at line 291 of file class.ilTaggingClassificationProvider.php.

291 : void
292 {
293 $a_list_gui->enableTags(true);
294 }

References ilObjectListGUI\enableTags().

+ Here is the call graph for this function:

◆ isActive()

static ilTaggingClassificationProvider::isActive ( int  $a_parent_ref_id,
int  $a_parent_obj_id,
string  $a_parent_obj_type 
)
static

@inheritDoc

Reimplemented from ilClassificationProvider.

Definition at line 71 of file class.ilTaggingClassificationProvider.php.

75 : bool {
76 global $DIC;
77
78 $ilUser = $DIC->user();
79
80 // we currently only check for the parent object setting
81 // might change later on (parent containers)
83 $a_parent_obj_id,
85 '0'
86 );
87
88 if ($valid) {
89 $tags_set = new ilSetting("tags");
90 if (!$tags_set->get("enable_all_users", '0') &&
91 $ilUser->getId() === ANONYMOUS_USER_ID) {
92 $valid = false;
93 }
94 }
95
96 return $valid;
97 }
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$valid

References $valid, and ANONYMOUS_USER_ID.

◆ render()

ilTaggingClassificationProvider::render ( array &  $a_html,
object  $a_parent_gui 
)

@inheritDoc

Reimplemented from ilClassificationProvider.

Definition at line 102 of file class.ilTaggingClassificationProvider.php.

105 : void {
108
109 $lng->loadLanguageModule("tagging");
110 $all_tags = $this->getSubTreeTags();
111 if ($all_tags) {
112 $map = array(
113 "personal" => $lng->txt("tagging_my_tags"),
114 "other" => $lng->txt("tagging_other_users")
115 );
116 foreach ($map as $type => $title) {
117 $tags = $all_tags[$type] ?? null;
118 if ($tags) {
119 $max = 1;
120 foreach ($tags as $tag => $counter) {
121 $max = max($counter, $max);
122 }
123 reset($tags);
124
125 $tpl = new ilTemplate("tpl.tag_cloud_block.html", true, true, "components/ILIAS/Tagging");
126
127 $tpl->setCurrentBlock("tag_bl");
128 foreach ($tags as $tag => $counter) {
129 $ctrl->setParameter($a_parent_gui, "tag_type", $type);
130 $ctrl->setParameter($a_parent_gui, "tag", md5((string) $tag));
131 $tpl->setVariable("HREF", $ctrl->getLinkTarget($a_parent_gui, "toggle"));
132
133 $tpl->setVariable("TAG_TYPE", $type);
134 $tpl->setVariable("TAG_TITLE", $tag);
135 $tpl->setVariable("TAG_CODE", md5((string) $tag));
136 $tpl->setVariable(
137 "REL_CLASS",
139 );
140 if (isset($this->selection[$type]) &&
141 in_array($tag, $this->selection[$type])) {
142 $tpl->setVariable("HIGHL_CLASS", ' ilHighlighted');
143 }
144
145 $tpl->parseCurrentBlock();
146 $ctrl->setParameter($a_parent_gui, "tag_type", "");
147 $ctrl->setParameter($a_parent_gui, "tag", "");
148 }
149
150 $a_html[] = array(
151 "title" => $title,
152 "html" => $tpl->get()
153 );
154 }
155 }
156 }
157 }
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
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 getRelevanceClass(int $cnt, int $max)
special template class to simplify handling of ITX/PEAR
$counter

◆ setSelection()

ilTaggingClassificationProvider::setSelection ( array  $a_value)

@inheritDoc

Reimplemented from ilClassificationProvider.

Definition at line 198 of file class.ilTaggingClassificationProvider.php.

198 : void
199 {
200 $this->selection = $a_value;
201 }

Field Documentation

◆ $ctrl

ilCtrl ilTaggingClassificationProvider::$ctrl
protected

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

◆ $enable_all_users

bool ilTaggingClassificationProvider::$enable_all_users = false
protected

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

◆ $lng

ilLanguage ilTaggingClassificationProvider::$lng
protected

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

◆ $obj_definition

ilObjectDefinition ilTaggingClassificationProvider::$obj_definition
protected

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

◆ $request

RequestInterface ilTaggingClassificationProvider::$request
protected

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

◆ $requested_tag_code

string ilTaggingClassificationProvider::$requested_tag_code
protected

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

◆ $requested_type

string ilTaggingClassificationProvider::$requested_type
protected

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

◆ $selection

array ilTaggingClassificationProvider::$selection
protected

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

◆ $tree

ilTree ilTaggingClassificationProvider::$tree
protected

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

◆ $user

ilObjUser ilTaggingClassificationProvider::$user
protected

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


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