ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.NewsManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
32{
33 protected \ILIAS\Blog\Posting\Service\GUIService $posting_gui;
34
35 public function __construct(
36 protected InternalDataService $data,
37 protected InternalRepoService $repo,
38 protected InternalDomainService $domain,
40 protected PageManagerInterface $page_manager
41 ) {
42 $this->posting_gui = $gui->posting();
43 }
44
48 public function handle(\ilBlogPosting $page, bool $update = false): void
49 {
50 $lng = $this->domain->lng();
51 $ilUser = $this->domain->user();
52
53 if (!$page->getActive()) {
54 return;
55 }
56
57 $news_item = null;
58
59 if ($update) {
61 $page->getBlogId(),
62 "blog",
63 $page->getId(),
64 $page->getParentType(),
65 true
66 );
67 if ($news_id > 0) {
68 $news_item = new \ilNewsItem($news_id);
69 }
70 }
71
72 if (!$news_item) {
73 $news_set = new \ilSetting("news");
74 $default_visibility = $news_set->get("default_visibility", "users");
75
76 $news_item = new \ilNewsItem();
77 $news_item->setContext(
78 $page->getBlogId(),
79 "blog",
80 $page->getId(),
81 $page->getParentType()
82 );
83 $news_item->setPriority(NEWS_NOTICE);
84 $news_item->setVisibility($default_visibility);
85 }
86
87 $news_item->setUserId($ilUser->getId());
88
89 $news_item->setTitle($page->getTitle());
90
91 $contentKey = $update
92 ? "blog_news_posting_updated"
93 : "blog_news_posting_published";
94 $content = sprintf(
95 $lng->txt($contentKey),
96 \ilUserUtil::getNamePresentation($ilUser->getId())
97 );
98
99 $contributors = [];
100 foreach ($this->page_manager->getPageContributors($page->getParentType(), $page->getId()) as $user) {
101 $contributors[] = $user["user_id"];
102 }
103 if (count($contributors) > 1 || !in_array($page->getAuthor(), $contributors, true)) {
104 $authors = [\ilUserUtil::getNamePresentation($page->getAuthor())];
105 foreach ($contributors as $user_id) {
106 if ($user_id !== $page->getAuthor()) {
108 }
109 }
110 $content .= "\n" . sprintf(
111 $lng->txt("blog_news_posting_authors"),
112 implode(", ", $authors)
113 );
114 }
115
116 $news_item->setContentTextIsLangVar(false);
117 $news_item->setContent($content);
118
119 $snippet = $this->posting_gui->getSnippet($page->getId());
120 $news_item->setContentLong($snippet);
121
122 if (!$news_item->getId()) {
123 $news_item->create();
124 } else {
125 $news_item->update(true);
126 }
127 }
128}
Domain class for handling news items of blog postings.
__construct(protected InternalDataService $data, protected InternalRepoService $repo, protected InternalDomainService $domain, \ILIAS\Blog\InternalGUIService $gui, protected PageManagerInterface $page_manager)
handle(\ilBlogPosting $page, bool $update=false)
Handle news item for a blog posting.
ILIAS Blog Posting Service GUIService $posting_gui
const NEWS_NOTICE
Class ilBlogPosting.
static getLastNewsIdForContext(int $a_context_obj_id, string $a_context_obj_type, int $a_context_sub_obj_id=0, string $a_context_sub_obj_type="", bool $a_only_today=false)
Get last news id of news set related to a certain context.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:26
$data
Definition: storeScorm.php:45