ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.DashboardNewsManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
31{
36 protected \ilFavouritesManager $fav_manager;
40 protected static ?array $user_object_ref_ids = null;
41
42 public function __construct(
46 ) {
47 $this->session_repo = $repo->dashboard();
48 $this->data = $data;
49 $this->domain = $domain;
50 $this->fav_manager = new \ilFavouritesManager();
51 }
52
53 public function getDashboardNewsPeriod(): int
54 {
55 $user = $this->domain->user();
56 $period = $this->session_repo->getDashboardNewsPeriod();
57 if ($period === 0) {
58 $period = \ilNewsItem::_lookupUserPDPeriod($user->getId());
59 }
60 return $period;
61 }
62
63 public function getDashboardSelectedRefId(): int
64 {
65 $user = $this->domain->user();
66 return (int) $user->getPref("news_sel_ref_id");
67 }
68
69 public function saveFilterData(?array $data): void
70 {
71 $user = $this->domain->user();
72 if (!is_null($data) && !is_null($data["news_ref_id"])) {
73 $user->writePref("news_sel_ref_id", (string) (int) $data["news_ref_id"]);
74 } else {
75 $user->writePref("news_sel_ref_id", "0");
76 }
77 $this->session_repo->setDashboardNewsPeriod((int) ($data["news_per"] ?? 0));
78 }
79
83 public function getPeriodOptions(): array
84 {
85 $lng = $this->domain->lng();
86 $news_set = new \ilSetting("news");
87 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
88 $allow_longer_periods = $news_set->get("allow_longer_periods");
90
91 $options = [
92 "7" => $lng->txt("news_period_1_week"),
93 "30" => $lng->txt("news_period_1_month"),
94 "366" => $lng->txt("news_period_1_year")
95 ];
96
97 return $options;
98
99 /*
100 $unset = [];
101 foreach ($options as $k => $opt) {
102 if (!$allow_shorter_periods && ($k < $default_per)) {
103 $unset[$k] = $k;
104 }
105 if (!$allow_longer_periods && ($k > $default_per)) {
106 $unset[$k] = $k;
107 }
108 }
109 foreach ($unset as $k) {
110 unset($options[$k]);
111 }
112
113 return $options;*/
114 }
115
119 public function getContextOptions(): array
120 {
121 $lng = $this->domain->lng();
122 $user = $this->domain->user();
123 $period = $this->getDashboardNewsPeriod();
124
125 $cnt = [];
127 $user->getId(),
128 false,
129 true,
130 $period,
131 $cnt
132 );
133
134 $ref_ids = $this->getUserNewsObjectRefIds();
135
136 // related objects (contexts) of news
137 $contexts[0] = $lng->txt("news_all_items");
138
139 $conts = [];
140 foreach ($ref_ids as $ref_id) {
142 $title = \ilObject::_lookupTitle($obj_id);
143 $conts[$ref_id] = $title;
144 }
145
146 asort($conts);
147 foreach ($conts as $ref_id => $title) {
148 $contexts[$ref_id] = $title . " (" . (int) ($cnt[$ref_id] ?? 0) . ")";
149 }
150
151 return $contexts;
152 }
153
159 protected function getUserNewsObjectRefIds(): array
160 {
161 if (is_null(self::$user_object_ref_ids)) {
162 $ref_ids = [];
163 $user = $this->domain->user();
164 $user_id = $user->getId();
165
166 // get all items of the personal desktop
167 $fav_items = $this->fav_manager->getFavouritesOfUser($user_id);
168 foreach ($fav_items as $item) {
169 if (!in_array($item["ref_id"], $ref_ids)) {
170 $ref_ids[] = (int) $item["ref_id"];
171 }
172 }
173
174 // get all memberships
177 $items = array_merge($crs_mbs, $grp_mbs);
178 foreach ($items as $i) {
179 $item_references = \ilObject::_getAllReferences($i);
180 $ref_ids = array_unique(array_merge($ref_ids, $item_references));
181 }
182 self::$user_object_ref_ids = $ref_ids;
183 }
185 }
186
187 protected function getNewsForOverview(
188 int $ref_id,
189 int $period,
190 bool $include_auto_entries,
191 int $items_per_load
192 ): array {
193 $user = $this->domain->user();
194 $news_item = new \ilNewsItem();
195 //$news_item->setContextObjId($this->ctrl->getContextObjId());
196 //$news_item->setContextObjType($this->ctrl->getContextObjType());
197
198 if ($ref_id > 0) {
199 $news_data = $news_item->getNewsForRefId(
200 $ref_id,
201 false,
202 false,
203 $period,
204 true,
205 false,
206 !$include_auto_entries,
207 false,
208 null,
209 $items_per_load
210 );
211 } else {
212 $cnt = [];
214 $user->getId(),
215 false,
216 true,
217 $period,
218 $cnt,
219 !$include_auto_entries
220 );
221 }
222 return $news_data;
223 }
224}
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain)
getUserNewsObjectRefIds()
User news on the daashboard/news overview are presented for all favourites and all memberships of the...
getNewsForOverview(int $ref_id, int $period, bool $include_auto_entries, int $items_per_load)
Repository internal data service.
static _lookupUserPDPeriod(int $a_user_id)
static _getNewsItemsOfUser(int $a_user_id, bool $a_only_public=false, bool $a_prevent_aggregation=false, int $a_per=0, array &$a_cnt=[], bool $no_auto_generated=false, array $excluded=[], int $a_limit=0)
Get all news items for a user.
static _lookupDefaultPDPeriod()
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
$ref_id
Definition: ltiauth.php:66
global $lng
Definition: privfeed.php:31