ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.PostingManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Blog\Posting;
22
27
29{
30 public function __construct(
31 protected InternalDataService $data,
32 protected InternalRepoService $repo,
33 protected InternalDomainService $domain
34 ) {
35 }
36
37 public function create(Posting $posting): int
38 {
39 return $this->repo->posting()->create($posting);
40 }
41
42 public function update(Posting $posting): void
43 {
44 $this->repo->posting()->update($posting);
45 }
46
47 public function delete(int $posting_id): void
48 {
49 $this->repo->posting()->delete($posting_id);
50 }
51
52 public function getById(int $id): ?Posting
53 {
54 $posting = $this->repo->posting()->getById($id);
55 return $posting === null ? null : $this->withPageActivation($posting);
56 }
57
61 public function getAllByBlog(int $blog_id, int $limit = 1000, int $offset = 0): array
62 {
63 return array_map(
64 fn(Posting $posting): Posting => $this->withPageActivation($posting),
65 $this->repo->posting()->getAllByBlog($blog_id, $limit, $offset)
66 );
67 }
68
72 public function getAllPostingIds(int $blog_id, int $limit = 1000, int $offset = 0): array
73 {
74 $pages = \ilPageObject::getAllPages("blp", $blog_id);
75 $ids = [];
76 foreach ($this->repo->posting()->getAllByBlog($blog_id, $limit, $offset) as $posting) {
77 $id = $posting->getId();
78 if (isset($pages[$id])) {
79 $ids[] = $id;
80 }
81 }
82
83 return $ids;
84 }
85
92 public function getAllPostings(int $a_blog_id, int $a_limit = 1000, int $a_offset = 0): array
93 {
94 $pages = \ilPageObject::getAllPages("blp", $a_blog_id);
95 $posts = [];
96 foreach ($this->getAllByBlog(
97 $a_blog_id,
98 $a_limit,
99 $a_offset
100 ) as $posting) {
101 $id = $posting->getId();
102 if (isset($pages[$id])) {
103 $posts[] = $posting;
104 }
105 }
106
107 return $posts;
108 }
109
110 public function exists(int $blog_id, int $posting_id): bool
111 {
112 return $this->repo->posting()->exists($blog_id, $posting_id);
113 }
114
115 public function lookupBlogId(int $posting_id): ?int
116 {
117 return $this->repo->posting()->lookupBlogId($posting_id);
118 }
119
120 public function deleteAllByBlog(int $blog_id): void
121 {
122 $lom = $this->domain->lom();
123 foreach ($this->getAllPostingIds($blog_id) as $posting_id) {
124 $lom->deleteAll($blog_id, $posting_id, "blp");
125 }
126 $this->repo->posting()->deleteAllBlogPostings($blog_id);
127 }
128
129 public function getLastPost(int $blog_id): int
130 {
131 return $this->repo->posting()->getLastPost($blog_id);
132 }
133
134 public function searchBlogsByAuthor(int $user_id): array
135 {
136 return $this->repo->posting()->searchBlogsByAuthor($user_id);
137 }
138
139 public function getKeywords(int $blog_id, int $posting_id): array
140 {
141 $lom_services = $this->domain->lom();
142
143 $result = [];
144 $keywords = $lom_services->read($blog_id, $posting_id, "blp")
145 ->allData($lom_services->paths()->keywords());
146 foreach ($keywords as $keyword) {
147 if ($keyword->value() !== "") {
148 $result[] = $keyword->value();
149 }
150 }
151
152 return $result;
153 }
154
155 protected function withPageActivation(Posting $posting): Posting
156 {
157 return $posting->withActive(
158 $this->domain->pageManager()->lookupActive($posting->getId(), "blp")
159 );
160 }
161}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Domain class for handling news items of blog postings.
getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Return all postings of a blog as data objects (Posting[]), filtered to those that have an associated ...
__construct(protected InternalDataService $data, protected InternalRepoService $repo, protected InternalDomainService $domain)
getAllPostingIds(int $blog_id, int $limit=1000, int $offset=0)
getAllByBlog(int $blog_id, int $limit=1000, int $offset=0)
getKeywords(int $blog_id, int $posting_id)
exists(int $blog_id, int $posting_id)
static getAllPages(string $a_parent_type, int $a_parent_id, string $a_lang="-")
Get all pages for parent object.
$data
Definition: storeScorm.php:45