ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
class.DashboardNewsManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
32{
34 protected \ilFavouritesManager $fav_manager;
35
36 public function __construct(
37 protected InternalDataService $data,
38 protected InternalRepoService $repo,
39 protected InternalDomainService $domain
40 ) {
41 $this->session_repo = $repo->dashboard();
42 $this->fav_manager = new \ilFavouritesManager();
43 }
44
45 public function getDashboardNewsPeriod(): int
46 {
47 $user = $this->domain->user();
48 $period = $this->session_repo->getDashboardNewsPeriod();
49 if ($period === 0) {
50 $period = \ilNewsItem::_lookupUserPDPeriod($user->getId());
51 }
52 return $period;
53 }
54
55 public function getDashboardSelectedRefId(): int
56 {
57 $user = $this->domain->user();
58 return (int) $user->getPref("news_sel_ref_id");
59 }
60
61 public function saveFilterData(?array $data): void
62 {
63 $user = $this->domain->user();
64 if (!is_null($data) && !is_null($data["news_ref_id"])) {
65 $user->writePref("news_sel_ref_id", (string) (int) $data["news_ref_id"]);
66 } else {
67 $user->writePref("news_sel_ref_id", "0");
68 }
69 $this->session_repo->setDashboardNewsPeriod((int) ($data["news_per"] ?? 0));
70 }
71
75 public function getPeriodOptions(): array
76 {
77 $lng = $this->domain->lng();
78 $news_set = new \ilSetting("news");
79 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
80 $allow_longer_periods = $news_set->get("allow_longer_periods");
82
83 $options = [
84 "7" => $lng->txt("news_period_1_week"),
85 "30" => $lng->txt("news_period_1_month"),
86 "366" => $lng->txt("news_period_1_year")
87 ];
88
89 return $options;
90
91 /*
92 $unset = [];
93 foreach ($options as $k => $opt) {
94 if (!$allow_shorter_periods && ($k < $default_per)) {
95 $unset[$k] = $k;
96 }
97 if (!$allow_longer_periods && ($k > $default_per)) {
98 $unset[$k] = $k;
99 }
100 }
101 foreach ($unset as $k) {
102 unset($options[$k]);
103 }
104
105 return $options;*/
106 }
107
111 public function getContextOptions(): array
112 {
113 $context_count = $this->repo->news()->countByContextsBatch(
114 $this->domain->resolver()->getAccessibleContexts(
115 $this->domain->user(),
116 new NewsCriteria(period: $this->getDashboardNewsPeriod(), only_public: false)
117 )
118 );
119
120 $options = [];
121 foreach ($context_count as [$context, $count]) {
122 $options[$context->getRefId()] = \ilObject::_lookupTitle($context->getObjId()) . " ({$count})";
123 }
124 asort($options);
125
126 return [0 => $this->domain->lng()->txt('news_all_items')] + $options;
127 }
128}
__construct(protected InternalDataService $data, protected InternalRepoService $repo, protected InternalDomainService $domain)
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.
Repository internal data service.
static _lookupUserPDPeriod(int $a_user_id)
static _lookupDefaultPDPeriod()
static _lookupTitle(int $obj_id)
global $lng
Definition: privfeed.php:31