ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPDNewsGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
30  protected ilLanguage $lng;
31  protected ilCtrl $ctrl;
32  protected ilHelpGUI $help;
33  protected ilObjUser $user;
36 
37  public function __construct()
38  {
39  global $DIC;
40 
41  $this->help = $DIC["ilHelp"];
42  $this->user = $DIC->user();
43  $tpl = $DIC->ui()->mainTemplate();
44  $lng = $DIC->language();
45  $ilCtrl = $DIC->ctrl();
46  $ilHelp = $DIC["ilHelp"];
47 
48  $ilHelp->setScreenIdComponent("news");
49 
50  $this->std_request = new StandardGUIRequest(
51  $DIC->http(),
52  $DIC->refinery()
53  );
54 
55  // initiate variables
56  $this->tpl = $tpl;
57  $this->lng = $lng;
58  $this->ctrl = $ilCtrl;
59 
60  $lng->loadLanguageModule("news");
61 
62  $this->ctrl->saveParameter($this, "news_ref_id");
63  $this->fav_manager = new ilFavouritesManager();
64  }
65 
66  public function executeCommand(): bool
67  {
68  $next_class = $this->ctrl->getNextClass();
69 
70  switch ($next_class) {
71 
72  default:
73  $cmd = $this->ctrl->getCmd("view");
74  $this->displayHeader();
75  $this->$cmd();
76  break;
77  }
78  $this->tpl->printToStdout();
79  return true;
80  }
81 
82  public function displayHeader(): void
83  {
84  $this->tpl->setTitle($this->lng->txt("news"));
85  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_nwss.svg"));
86  }
87 
88  public function view(): void
89  {
91  $lng = $this->lng;
92  $tpl = $this->tpl;
93 
94  $ref_ids = [];
95  $obj_ids = [];
96  $pd_items = $this->fav_manager->getFavouritesOfUser($ilUser->getId());
97  foreach ($pd_items as $item) {
98  $ref_ids[] = (int) $item["ref_id"];
99  $obj_ids[] = (int) $item["obj_id"];
100  }
101 
102  $sel_ref_id = ($this->std_request->getNewsRefId() > 0)
103  ? $this->std_request->getNewsRefId()
104  : $ilUser->getPref("news_sel_ref_id");
105 
106  $per = (ilSession::get("news_pd_news_per") != "")
107  ? ilSession::get("news_pd_news_per")
109  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
110 
111  // related objects (contexts) of news
112  $contexts[0] = $lng->txt("news_all_items");
113 
114  $conts = [];
115  $sel_has_news = false;
116  foreach ($ref_ids as $ref_id) {
117  $obj_id = ilObject::_lookupObjId($ref_id);
118  $title = ilObject::_lookupTitle($obj_id);
119 
120  $conts[$ref_id] = $title;
121  if ((int) $sel_ref_id === $ref_id) {
122  $sel_has_news = true;
123  }
124  }
125 
126  $cnt = [];
127  $nitem = new ilNewsItem();
128  $news_items = ilNewsItem::_getNewsItemsOfUser(
129  $ilUser->getId(),
130  false,
131  true,
132  $per,
133  $cnt
134  );
135 
136  // reset selected news ref id, if no news are given for id
137  if (!$sel_has_news) {
138  $sel_ref_id = "";
139  }
140  asort($conts);
141  foreach ($conts as $ref_id => $title) {
142  $contexts[$ref_id] = $title . " (" . (int) ($cnt[$ref_id] ?? 0) . ")";
143  }
144 
145 
146  if ($sel_ref_id > 0) {
147  $obj_id = ilObject::_lookupObjId((int) $sel_ref_id);
148  $obj_type = ilObject::_lookupType($obj_id);
149  $nitem->setContextObjId($obj_id);
150  $nitem->setContextObjType($obj_type);
151  $news_items = $nitem->getNewsForRefId(
152  $sel_ref_id,
153  false,
154  false,
155  $per,
156  true
157  );
158  }
159 
160  $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
161  $pd_news_table->setData($news_items);
162  $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
163 
164  $tpl->setContent($pd_news_table->getHTML());
165  }
166 
167  public function applyFilter(): void
168  {
170 
171  $news_ref_id = $this->std_request->getNewsRefId();
172  $news_per = $this->std_request->getNewsPer();
173 
174  $this->ctrl->setParameter($this, "news_ref_id", $news_ref_id);
175  $ilUser->writePref("news_sel_ref_id", (string) $news_ref_id);
176  if ($news_per > 0) {
177  ilSession::set("news_pd_news_per", $news_per);
178  }
179  $this->ctrl->redirect($this, "view");
180  }
181 
182  public function resetFilter(): void
183  {
185  $this->ctrl->setParameter($this, "news_ref_id", 0);
186  $ilUser->writePref("news_sel_ref_id", '0');
187  ilSession::clear("news_pd_news_per");
188  $this->ctrl->redirect($this, "view");
189  }
190 }
static get(string $a_var)
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=[])
Get all news items for a user.
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 filterObjIdsPerNews(array $a_obj_ids, $a_time_period=0, string $a_starting_date="", string $a_ending_date='', bool $ignore_period=false)
Checks whether news are available for.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Help GUI class.
loadLanguageModule(string $a_module)
Load language module.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Personal desktop news table.
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
ilFavouritesManager $fav_manager
ilGlobalTemplateInterface $tpl
$ref_id
Definition: ltiauth.php:67
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A news item can be created by different sources.
$ilUser
Definition: imgupload.php:34
StandardGUIRequest $std_request
News on PD.
static _lookupType(int $id, bool $reference=false)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.