ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
KeywordBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Blog\Navigation;
22
27
29{
30 public function __construct(
31 protected InternalDomainService $domain,
32 protected InternalGUIService $gui,
33 protected LinkBuilder $link_builder,
34 protected bool $is_repository
35 ) {
36 }
37
38 public function render(
39 bool $show_inactive = false,
40 int $blpg = 0
41 ): string {
42 $keywords = $this->getKeywords($show_inactive, $blpg);
43 if ($keywords) {
44 $wtpl = new \ilTemplate("tpl.blog_list_navigation_keywords.html", true, true, "components/ILIAS/Blog");
45
46 $max = max($keywords);
47
48 $wtpl->setCurrentBlock("keyword");
49 foreach ($keywords as $keyword => $counter) {
50 $url = $this->link_builder->forKeyword($keyword);
51
52 $wtpl->setVariable("TXT_KEYWORD", (string) $keyword);
53 $wtpl->setVariable("CLASS_KEYWORD", \ilTagging::getRelevanceClass((int) $counter, (int) $max));
54 $wtpl->setVariable("URL_KEYWORD", $url);
55 $wtpl->parseCurrentBlock();
56 }
57
58 return $wtpl->get();
59 }
60 return "";
61 }
62
63 protected function getKeywords(
64 bool $show_inactive,
65 ?int $posting_id = null
66 ): array {
67 $keywords = array();
68 $posting_manager = $this->domain->posting();
69 if ($this->is_repository) {
70 $obj_id = \ilObject::_lookupObjId($this->gui->standardRequest()->getRefId());
71 } else {
72 $obj_id = $this->domain->getObjectIdForWspId($this->gui->standardRequest()->getWspId());
73 }
74
75 if ($posting_id) {
76 foreach ($posting_manager->getKeywords($obj_id, $posting_id) as $keyword) {
77 if (isset($keywords[$keyword])) {
78 $keywords[$keyword]++;
79 } else {
80 $keywords[$keyword] = 1;
81 }
82 }
83 } else {
84 $posting_list = $this->domain->postingList(
85 $obj_id,
86 $show_inactive
87 );
88 $all_items = $posting_list->getPostingsGroupedByMonth();
89 foreach ($all_items as $month => $month_items) {
90 foreach ($month_items as $item) {
91 $item_id = $item->getId();
92 foreach ($posting_manager->getKeywords($obj_id, $item_id) as $keyword) {
93 if (isset($keywords[$keyword])) {
94 $keywords[$keyword]++;
95 } else {
96 $keywords[$keyword] = 1;
97 }
98 }
99 }
100 }
101 }
102
103 $tmp = array();
104 foreach ($keywords as $keyword => $counter) {
105 $tmp[] = array("keyword" => $keyword, "counter" => $counter);
106 }
107 $tmp = \ilArrayUtil::sortArray($tmp, "keyword", "ASC");
108
109 $keywords = array();
110 foreach ($tmp as $item) {
111 $keywords[(string) $item["keyword"]] = $item["counter"];
112 }
113 return $keywords;
114 }
115}
getKeywords(bool $show_inactive, ?int $posting_id=null)
render(bool $show_inactive=false, int $blpg=0)
__construct(protected InternalDomainService $domain, protected InternalGUIService $gui, protected LinkBuilder $link_builder, protected bool $is_repository)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _lookupObjId(int $ref_id)
static getRelevanceClass(int $cnt, int $max)