ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
KeywordManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
27 protected \ILIAS\Blog\Posting\PostingManager $posting_manager;
28
29 public function __construct(
30 protected InternalDomainService $domain
31 ) {
32 $this->posting_manager = $this->domain->posting();
33 }
34
35 public function getKeywords(
36 int $blog_id,
37 bool $a_show_inactive,
38 ?int $a_posting_id = null
39 ): array {
40
41 $posting_list = $this->domain->postingList($blog_id);
42 $month_items = $posting_list->getPostingsGroupedByMonth();
43
44 $keywords = array();
45 if ($a_posting_id) {
46 foreach ($this->posting_manager->getKeywords($blog_id, $a_posting_id) as $keyword) {
47 if (isset($keywords[$keyword])) {
48 $keywords[$keyword]++;
49 } else {
50 $keywords[$keyword] = 1;
51 }
52 }
53 } else {
54 foreach ($month_items as $month => $items) {
55 foreach ($items as $item) {
57 $item_id = $item->getId();
58 if ($a_show_inactive || $this->domain->pageManager()->lookupActive($item_id, "blp")) {
59 foreach ($this->posting_manager->getKeywords($blog_id, $item_id) as $keyword) {
60 if (isset($keywords[$keyword])) {
61 $keywords[$keyword]++;
62 } else {
63 $keywords[$keyword] = 1;
64 }
65 }
66 }
67 }
68 }
69 }
70
71 // #15881
72 $tmp = array();
73 foreach ($keywords as $keyword => $counter) {
74 $tmp[] = array("keyword" => $keyword, "counter" => $counter);
75 }
76 $tmp = \ilArrayUtil::sortArray($tmp, "keyword", "ASC");
77
78 $keywords = array();
79 foreach ($tmp as $item) {
80 $keywords[(string) $item["keyword"]] = $item["counter"];
81 }
82 return $keywords;
83 }
84
85}
__construct(protected InternalDomainService $domain)
ILIAS Blog Posting PostingManager $posting_manager
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)