Handle news item for a blog posting.
42 : void
43 {
44 $lng = $this->domain->lng();
45 $ilUser = $this->domain->user();
46
47 if (!$page->getActive()) {
48 return;
49 }
50
51 $news_item = null;
52
53 if ($update) {
55 $page->getBlogId(),
56 "blog",
57 $page->getId(),
58 $page->getParentType(),
59 true
60 );
61 if ($news_id > 0) {
62 $news_item = new \ilNewsItem($news_id);
63 }
64 }
65
66 if (!$news_item) {
67 $news_set = new \ilSetting("news");
68 $default_visibility = $news_set->get("default_visibility", "users");
69
70 $news_item = new \ilNewsItem();
71 $news_item->setContext(
72 $page->getBlogId(),
73 "blog",
74 $page->getId(),
75 $page->getParentType()
76 );
78 $news_item->setVisibility($default_visibility);
79 }
80
81 $news_item->setUserId($ilUser->getId());
82
83 $news_item->setTitle($page->getTitle());
84
85 $contentKey = $update
86 ? "blog_news_posting_updated"
87 : "blog_news_posting_published";
88 $content = sprintf(
89 $lng->txt($contentKey),
91 );
92
93 $contributors = [];
95 $contributors[] = $user["user_id"];
96 }
97 if (count($contributors) > 1 || !in_array($page->getAuthor(), $contributors, true)) {
99 foreach ($contributors as
$user_id) {
100 if (
$user_id !== $page->getAuthor()) {
102 }
103 }
104 $content .= "\n" . sprintf(
105 $lng->txt(
"blog_news_posting_authors"),
106 implode(", ", $authors)
107 );
108 }
109
110 $news_item->setContentTextIsLangVar(false);
111 $news_item->setContent($content);
112
114 $news_item->setContentLong($snippet);
115
116 if (!$news_item->getId()) {
117 $news_item->create();
118 } else {
119 $news_item->update(true);
120 }
121 }
static getSnippet(int $a_id, bool $a_truncate=false, int $a_truncate_length=500, string $a_truncate_sign="...", bool $a_include_picture=false, int $a_picture_width=144, int $a_picture_height=144, ?string $a_export_directory=null)
Get first text paragraph of page.
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 getPageContributors(string $a_parent_type, int $a_page_id, string $a_lang="-")
Get all contributors for parent object.
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: