ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\Blog\News\NewsManager Class Reference

Domain class for handling news items of blog postings. More...

+ Collaboration diagram for ILIAS\Blog\News\NewsManager:

Public Member Functions

 __construct (protected InternalDataService $data, protected InternalRepoService $repo, protected InternalDomainService $domain)
 
 handle (\ilBlogPosting $page, bool $update=false)
 Handle news item for a blog posting. More...
 

Detailed Description

Domain class for handling news items of blog postings.

Definition at line 30 of file class.NewsManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Blog\News\NewsManager::__construct ( protected InternalDataService  $data,
protected InternalRepoService  $repo,
protected InternalDomainService  $domain 
)

Definition at line 32 of file class.NewsManager.php.

36  {
37  }

Member Function Documentation

◆ handle()

ILIAS\Blog\News\NewsManager::handle ( \ilBlogPosting  $page,
bool  $update = false 
)

Handle news item for a blog posting.

Definition at line 42 of file class.NewsManager.php.

References $lng, $user_id, ilPageObject\getActive(), ilBlogPosting\getAuthor(), ilBlogPosting\getBlogId(), ilPageObject\getId(), ilNewsItem\getLastNewsIdForContext(), ilUserUtil\getNamePresentation(), ilPageObject\getPageContributors(), ilBlogPosting\getParentType(), ilBlogPostingGUI\getSnippet(), ilBlogPosting\getTitle(), NEWS_NOTICE, and null.

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  );
77  $news_item->setPriority(NEWS_NOTICE);
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),
90  \ilUserUtil::getNamePresentation($ilUser->getId())
91  );
92 
93  $contributors = [];
94  foreach (\ilBlogPosting::getPageContributors($page->getParentType(), $page->getId()) as $user) {
95  $contributors[] = $user["user_id"];
96  }
97  if (count($contributors) > 1 || !in_array($page->getAuthor(), $contributors, true)) {
98  $authors = [\ilUserUtil::getNamePresentation($page->getAuthor())];
99  foreach ($contributors as $user_id) {
100  if ($user_id !== $page->getAuthor()) {
101  $authors[] = \ilUserUtil::getNamePresentation($user_id);
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 
113  $snippet = \ilBlogPostingGUI::getSnippet($page->getId());
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 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 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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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='ilpublicuserprofilegui')
Default behaviour is:
const NEWS_NOTICE
global $lng
Definition: privfeed.php:31
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: