33 protected \ILIAS\News\InternalGUIService
$gui;
35 protected \ILIAS\News\Timeline\TimelineManager
$manager;
36 protected \ILIAS\DI\UIServices
$ui;
37 protected \ILIAS\Notes\Service
$notes;
38 protected \ILIAS\HTTP\Services
$http;
56 bool $a_include_auto_entries
60 $this->
ctrl = $DIC->ctrl();
61 $this->tpl =
$DIC[
"tpl"];
62 $this->ref_id = $a_ref_id;
63 $this->
lng = $DIC->language();
64 $this->
toolbar = $DIC->toolbar();
65 $this->
user = $DIC->user();
66 $this->include_auto_entries = $a_include_auto_entries;
67 $this->
access = $DIC->access();
68 $this->
http = $DIC->http();
69 $this->notes =
$DIC->notes();
71 $this->std_request =
$DIC->news()
76 $this->news_id = $this->std_request->getNewsId();
78 $this->
lng->loadLanguageModule(
"news");
79 $this->
lng->loadLanguageModule(
"cont");
80 $this->
ui = $DIC->ui();
81 $this->manager =
$DIC->news()->internal()->domain()->timeline();
82 $this->gui =
$DIC->news()->internal()->gui();
87 $this->enable_add_news = $a_val;
97 $this->period = $a_val;
111 $this->user_edit_all = $a_val;
124 bool $a_include_auto_entries
126 return new self($a_ref_id, $a_include_auto_entries);
136 $next_class = $this->
ctrl->getNextClass($this);
137 $cmd = $this->
ctrl->getCmd(
"show");
139 switch ($next_class) {
141 $item = $this->manager->getNewsItem($this->news_id);
143 $like_gui = $likef->widget([$item->getContextObjId()]);
145 $like_gui->setObject(
146 $item->getContextObjId(),
147 $item->getContextObjType(),
148 $item->getContextSubObjId(),
149 (
string) $item->getContextSubObjType(),
155 case strtolower(ilCommentGUI::class):
156 $item = $this->manager->getNewsItem($this->news_id);
158 $notes_obj_type = ($item->getContextSubObjType() ===
null)
159 ? $item->getContextObjType()
160 : $item->getContextSubObjType();
161 $comment_gui = $this->notes->gui()->getCommentsGUI(
162 $item->getContextObjId(),
163 $item->getContextSubObjId(),
167 $comment_gui->setShowHeader(
false);
172 if (in_array($cmd, [
"show",
"save",
"update",
"loadMore",
"remove",
"updateNewsItem",
"downloadMob"])) {
180 $this->tpl->setContent($this->getHTML($form));
185 $this->news_collection = $this->manager->getNewsData(
187 $this->
ctrl->getContextObjId(),
188 $this->ctrl->getContextObjType(),
190 $this->include_auto_entries,
191 self::$items_per_load,
199 if ($this->getEnableAddNews() &&
200 $this->
access->checkAccess(
"news_add_news",
"", $this->ref_id)) {
202 $this->
lng->txt(
"news_add_news"),
204 )->onClick(
"return il.News.create();")->primary()->toToolbar(
true, $this->
toolbar);
207 $this->readNewsData();
212 $obj_ids = array_unique($this->news_collection->pluck(
'context_obj_id'));
214 $like_gui = $likef->widget($obj_ids);
219 foreach ($this->news_collection as $news_item) {
221 $item->setUserEditAll($this->getUserEditAll());
222 $timeline->addItem($item);
223 $js_items[$news_item->getId()] = [
224 "id" => $news_item->getId(),
225 "user_id" => $news_item->getUserId(),
226 "title" => $news_item->getTitle(),
227 "content" => $news_item->getContent() . $news_item->getContentLong(),
228 "content_long" =>
'',
229 "priority" => $news_item->getPriority(),
230 "visibility" => $news_item->getVisibility(),
231 "content_type" => $news_item->getContentType(),
232 "mob_id" => $news_item->getMobId()
236 $this->tpl->addOnLoadCode(
"il.News.setItems(" . json_encode($js_items, JSON_THROW_ON_ERROR) .
");");
237 $this->tpl->addOnLoadCode(
"il.News.setAjaxUrl('" . $this->
ctrl->getLinkTarget($this,
"",
"",
true) .
"');");
239 if (!$this->news_collection->isEmpty()) {
240 $ttpl =
new ilTemplate(
"tpl.news_timeline.html",
true,
true,
"components/ILIAS/News");
241 $ttpl->setVariable(
"NEWS", $timeline->render());
242 $this->renderDeleteModal($ttpl);
243 $this->renderEditModal($form, $ttpl);
245 $this->tpl->setContent($ttpl->get());
246 $html = $ttpl->get();
248 if ($this->getEnableAddNews()) {
249 $ttpl =
new ilTemplate(
"tpl.news_timeline.html",
true,
true,
"components/ILIAS/News");
250 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"news_timline_add_entries_info"));
251 $this->renderEditModal($form, $ttpl);
252 $this->tpl->setContent($ttpl->get());
253 $html = $ttpl->get();
255 $mess = $this->
ui->factory()->messageBox()->info(
256 $this->
lng->txt(
"news_timline_no_entries")
258 $html = $this->
ui->renderer()->render($mess);
262 $this->
lng->toJS(
"create");
263 $this->
lng->toJS(
"edit");
264 $this->
lng->toJS(
"update");
265 $this->
lng->toJS(
"save");
269 $this->tpl->addJavaScript(
"../components/ILIAS/News/resources/News.js");
271 $this->tpl->addJavaScript(
"assets/js/News.js");
273 $this->notes->gui()->initJavascript();
277 public function loadMore(): void
280 $news_item->setContextObjId($this->
ctrl->getContextObjId());
281 $news_item->setContextObjType($this->
ctrl->getContextObjType());
283 $excluded = $this->std_request->getRenderedNews();
285 $this->readNewsData($excluded);
290 $obj_ids = array_unique($this->news_collection->pluck(
'context_obj_id'));
292 $like_gui = $likef->widget($obj_ids);
297 foreach ($this->news_collection as $news_item) {
299 $item->setUserEditAll($this->getUserEditAll());
300 $timeline->addItem($item);
301 $js_items[$news_item->getId()] = [
302 "id" => $news_item->getId(),
303 "user_id" => $news_item->getUserId(),
304 "title" => $news_item->getTitle(),
305 "content" => $news_item->getContent() . $news_item->getContentLong(),
306 "content_long" =>
'',
307 "priority" => $news_item->getPriority(),
308 "visibility" => $news_item->getVisibility(),
309 "content_type" => $news_item->getContentType(),
310 "mob_id" => $news_item->getMobId()
314 $obj =
new stdClass();
315 $obj->data = $js_items;
316 $obj->html = $timeline->render(
true);
318 $this->
send(json_encode($obj, JSON_THROW_ON_ERROR));
324 protected function send(
string $output): void
326 $this->
http->saveResponse($this->
http->response()->withBody(
327 Streams::ofString($output)
329 $this->
http->sendResponse();
330 $this->
http->close();
335 if ($this->std_request->getNewsAction() ===
"save") {
338 if ($this->std_request->getNewsAction() ===
"update") {
348 if ($form->checkInput()) {
350 $news_item->setTitle($form->getInput(
"news_title"));
351 $news_item->setContent($form->getInput(
"news_content"));
352 $news_item->setVisibility($form->getInput(
"news_visibility"));
354 $news_item->setContentHtml(
true);
357 $news_item->setContentLong(
"");
361 $news_item->setContextObjId($obj_id);
362 $news_item->setContextObjType($obj_type);
363 $news_item->setUserId($this->
user->getId());
365 $media = $_FILES[
"media"];
366 if ($media[
"name"] !=
"") {
368 $news_item->setMobId($mob->getId());
372 if (!$news_set->get(
"enable_rss_for_internal")) {
373 $news_item->setVisibility(
"users");
375 $news_item->create();
376 $this->
ctrl->redirect($this,
"show");
378 $form->setValuesByPost();
380 $this->tpl->addOnLoadCode(
"il.News.create(true);");
390 if ($form->checkInput()) {
391 $news_item =
new ilNewsItem($this->std_request->getId());
392 $news_item->setTitle($form->getInput(
"news_title"));
393 $news_item->setContent($form->getInput(
"news_content"));
394 $news_item->setVisibility($form->getInput(
"news_visibility"));
397 $news_item->setContentHtml(
true);
399 $news_item->setContentLong(
"");
401 $media = $_FILES[
"media"];
405 if ($media[
"name"] !=
"" || $this->std_request->getDeleteMedia() > 0) {
407 $old_mob_id = $news_item->getMobId();
409 $news_item->setMobId(0);
412 if ($media[
"name"] !=
"") {
414 $news_item->setMobId($mob->getId());
419 if ($news_item->getContextObjId() === $obj_id) {
420 $news_item->setUpdateUserId($this->
user->getId());
421 $news_item->update();
423 if ($old_mob_id > 0) {
428 $this->
ctrl->redirect($this,
"show");
430 $form->setValuesByPost();
432 $this->tpl->addOnLoadCode(
"il.News.edit(" . $this->std_request->getNewsId() .
", true);");
437 public function remove():
void
439 $news_item =
new ilNewsItem($this->std_request->getNewsId());
440 if ($this->getUserEditAll() || $this->
user->getId() === $news_item->getUserId()) {
441 $news_item->delete();
448 if (is_null($form)) {
451 $form->setShowTopButtons(
false);
452 $form->setFormAction($this->
ctrl->getFormAction($this));
459 $form->addItem($act);
460 $form->setId(
"news_edit_form");
462 $modal = $this->gui->ui()->factory()->modal()->roundtrip(
463 $this->
lng->txt(
"edit"),
464 $this->ui->factory()->legacy()->content($form->getHTML())
472 $mbox = $this->gui->ui()->factory()->messageBox()->confirmation(
473 $this->
lng->txt(
"news_really_delete_news")
475 $title = $this->gui->ui()->factory()->legacy()->content(
"<p id='news_delete_news_title'></p>");
476 $modal = $this->gui->modal($this->
lng->txt(
"delete"))
477 ->content([$title, $mbox])
478 ->button($this->
lng->txt(
"delete"),
"#",
false,
"il.News.remove(); return false;");
479 $c = $modal->getTriggerButtonComponents(
"");
480 $tpl->
setVariable(
"DELETE_MODAL", $this->gui->ui()->renderer()->render(
$c[
"modal"]));
486 $edit_modal = $this->getEditModal($form);
487 $signal = $edit_modal->getShowSignal()->getId();
488 $close_signal = $edit_modal->getCloseSignal()->getId();
490 $tpl->
setVariable(
"CLOSE_EDIT_SIGNAL", $close_signal);
491 $tpl->
setVariable(
"EDIT_MODAL", $this->
ui->renderer()->render($edit_modal));
496 $news_id = $this->std_request->getNewsId();
498 $news->deliverMobFile(
"Standard",
true);
setVariable($variable, $value='')
Sets a variable value.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Optimized News Collection with memory-efficient data structures to support large news feeds.
News Item DTO for transfer of news items.
show()
returns the content of IniFile
Class ilCtrl provides processing control methods.
saveParameter(object $a_gui_obj, $a_parameter)
@inheritDoc
forwardCommand(object $a_gui_object)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getEditForm(int $a_mode, int $a_ref_id)
A news item can be created by different sources.
ilGlobalTemplateInterface $tpl
show(?ilPropertyFormGUI $form=null)
ILIAS HTTP Services $http
renderDeleteModal(ilTemplate $tpl)
ILIAS News InternalGUIService $gui
ILIAS News Timeline TimelineManager $manager
static getInstance(int $a_ref_id, bool $a_include_auto_entries)
ILIAS Notes Service $notes
bool $include_auto_entries
setEnableAddNews(bool $a_val)
setUserEditAll(bool $a_val)
Set user can edit other users postings.
static int $items_per_load
NewsCollection $news_collection
getUserEditAll()
Get user can edit other users postings.
renderEditModal(?ilPropertyFormGUI $form, ilTemplate $tpl)
StandardGUIRequest $std_request
__construct(int $a_ref_id, bool $a_include_auto_entries)
readNewsData($excluded=[])
static getInstance(NewsItem $news_item, ilLikeGUI $like_gui)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
special template class to simplify handling of ITX/PEAR
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
catch(ilCmiXapiException $e) send($response)