ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Blog\Posting\PostingList Class Reference
+ Collaboration diagram for ILIAS\Blog\Posting\PostingList:

Public Member Functions

 __construct (protected int $obj_id, protected PostingManager $posting_manager, protected \ILIAS\Blog\Settings\Settings $settings, protected PageManagerInterface $page_manager, protected bool $include_inactive=true)
 
 getPostingsForView (int $author_id=0, string $keyword="", string $month="")
 
 getByMonth (string $month)
 
 getByAuthor (int $author_id)
 
 getByKeyword (string $keyword)
 
 getPostingsGroupedByMonth ()
 
 prepareViewState (string $month, ?int $author)
 
 getMonthsWithPostings ()
 
 getAuthors ()
 
 hasAuthorPostings (int $user_id)
 

Protected Member Functions

 getPostings ()
 

Protected Attributes

array $postings = null
 

Detailed Description

Definition at line 25 of file PostingList.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Blog\Posting\PostingList::__construct ( protected int  $obj_id,
protected PostingManager  $posting_manager,
protected \ILIAS\Blog\Settings\Settings  $settings,
protected PageManagerInterface  $page_manager,
protected bool  $include_inactive = true 
)

Definition at line 30 of file PostingList.php.

36 {
37 }

Member Function Documentation

◆ getAuthors()

ILIAS\Blog\Posting\PostingList::getAuthors ( )
Returns
int[] user ids

Definition at line 189 of file PostingList.php.

189 : array
190 {
191 $authors = [];
192 foreach ($this->getPostings() as $posting) {
193 $author_id = $posting->getAuthor();
194 if ($author_id > 0 && !in_array($author_id, $authors, true)) {
195 $authors[] = $author_id;
196 }
197
198 foreach ($this->page_manager->getPageContributors("blp", $posting->getId()) as $editor) {
199 $editor_id = (int) $editor["user_id"];
200 if ($editor_id > 0 && !in_array($editor_id, $authors, true)) {
201 $authors[] = $editor_id;
202 }
203 }
204 }
205 return $authors;
206 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getByAuthor()

ILIAS\Blog\Posting\PostingList::getByAuthor ( int  $author_id)
Returns
Posting[]

Definition at line 105 of file PostingList.php.

105 : array
106 {
107 $res = [];
108 foreach ($this->getPostings() as $posting) {
109 if ($posting->getAuthor() === $author_id) {
110 $res[$posting->getId()] = $posting;
111 continue;
112 }
113 foreach ($this->page_manager->getPageContributors("blp", $posting->getId()) as $editor) {
114 if ((int) $editor["user_id"] === $author_id) {
115 $res[$posting->getId()] = $posting;
116 break;
117 }
118 }
119 }
120 return $res;
121 }
foreach($_POST as $key=> $value) $res

References $res.

Referenced by ILIAS\Blog\Posting\PostingList\getPostingsForView().

+ Here is the caller graph for this function:

◆ getByKeyword()

ILIAS\Blog\Posting\PostingList::getByKeyword ( string  $keyword)
Returns
Posting[]

Definition at line 126 of file PostingList.php.

126 : array
127 {
128 $res = [];
129 foreach ($this->getPostings() as $posting) {
130 if (in_array(
131 $keyword,
132 $this->posting_manager->getKeywords($this->obj_id, $posting->getId()),
133 true
134 )) {
135 $res[$posting->getId()] = $posting;
136 }
137 }
138 return $res;
139 }

References $res.

◆ getByMonth()

ILIAS\Blog\Posting\PostingList::getByMonth ( string  $month)
Returns
Posting[]

Definition at line 91 of file PostingList.php.

91 : array
92 {
93 $res = [];
94 foreach ($this->getPostings() as $posting) {
95 if (substr($posting->getCreated()->get(IL_CAL_DATE), 0, 7) === $month) {
96 $res[$posting->getId()] = $posting;
97 }
98 }
99 return $res;
100 }
const IL_CAL_DATE

References $res, and IL_CAL_DATE.

◆ getMonthsWithPostings()

ILIAS\Blog\Posting\PostingList::getMonthsWithPostings ( )
Returns
string[] months (YYYY-MM)

Definition at line 173 of file PostingList.php.

173 : array
174 {
175 $months = [];
176 foreach ($this->getPostings() as $posting) {
177 $month = substr($posting->getCreated()->get(IL_CAL_DATE), 0, 7);
178 if (!in_array($month, $months, true)) {
179 $months[] = $month;
180 }
181 }
182 rsort($months);
183 return $months;
184 }

References IL_CAL_DATE.

◆ getPostings()

ILIAS\Blog\Posting\PostingList::getPostings ( )
protected
Returns
Posting[]

Definition at line 75 of file PostingList.php.

75 : array
76 {
77 if ($this->postings === null) {
78 $this->postings = $this->posting_manager->getAllPostings($this->obj_id);
79 if (!$this->include_inactive) {
80 $this->postings = array_filter($this->postings, function (Posting $posting) {
81 return $posting->isActive();
82 });
83 }
84 }
85 return $this->postings;
86 }

References ILIAS\Blog\Posting\Posting\isActive().

+ Here is the call graph for this function:

◆ getPostingsForView()

ILIAS\Blog\Posting\PostingList::getPostingsForView ( int  $author_id = 0,
string  $keyword = "",
string  $month = "" 
)
Returns
Posting[]

Definition at line 42 of file PostingList.php.

46 : array {
47 if ($author_id > 0) {
48 return $this->getByAuthor($author_id);
49 }
50 if ($keyword !== "") {
51 return $this->getByKeyword($keyword);
52 }
53
54 $max = $this->settings->getOverviewPostings();
55 if ($month === "" && $max > 0) {
56 $list_items = [];
57 $all_items = $this->getPostingsGroupedByMonth();
58 foreach ($all_items as $postings) {
59 foreach ($postings as $id => $item) {
60 $list_items[$id] = $item;
61 if (count($list_items) >= $max) {
62 break(2);
63 }
64 }
65 }
66 return $list_items;
67 }
68
69 return $this->getByMonth($month);
70 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References ILIAS\Blog\Posting\PostingList\getByAuthor().

+ Here is the call graph for this function:

◆ getPostingsGroupedByMonth()

ILIAS\Blog\Posting\PostingList::getPostingsGroupedByMonth ( )
Returns
array<string, array<int, Posting>> [month => [posting_id => Posting]]

Definition at line 144 of file PostingList.php.

144 : array
145 {
146 $items = [];
147 foreach ($this->getPostings() as $posting) {
148 $month = substr($posting->getCreated()->get(IL_CAL_DATE), 0, 7);
149 $items[$month][$posting->getId()] = $posting;
150 }
151 return $items;
152 }

References IL_CAL_DATE.

◆ hasAuthorPostings()

ILIAS\Blog\Posting\PostingList::hasAuthorPostings ( int  $user_id)

Definition at line 208 of file PostingList.php.

208 : bool
209 {
210 foreach ($this->getPostings() as $posting) {
211 if ($posting->getAuthor() === $user_id) {
212 return true;
213 }
214 foreach ($this->page_manager->getPageContributors("blp", $posting->getId()) as $editor) {
215 if ((int) $editor["user_id"] === $user_id) {
216 return true;
217 }
218 }
219 }
220 return false;
221 }

References $user_id.

◆ prepareViewState()

ILIAS\Blog\Posting\PostingList::prepareViewState ( string  $month,
?int  $author 
)

Definition at line 154 of file PostingList.php.

157 : PostingViewState {
158 if ($author && !$this->hasAuthorPostings($author)) {
159 $author = null;
160 }
161
162 $items = $this->getPostingsGroupedByMonth();
163 if ($items && (!$month || !isset($items[$month]) || $items[$month] === [])) {
164 $month = (string) array_key_first($items);
165 }
166
167 return new PostingViewState($month, $author);
168 }

Field Documentation

◆ $postings

array ILIAS\Blog\Posting\PostingList::$postings = null
protected

Definition at line 28 of file PostingList.php.


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