ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
PostingListGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Blog\Posting;
22
26use ilObjBlogGUI;
28use ilTemplate;
32
34{
35 protected string $approve_cmd_class;
36 protected array $approve_cmd_path;
37 protected string $admin_cmd_class;
38 protected array $admin_cmd_path;
39 protected \ILIAS\Blog\Keywords\KeywordManager $keyword_manager;
40 protected \ILIAS\Blog\Export\ExportManager $exp_manager;
41 protected int $author;
42 protected string $keyword;
43 protected \ILIAS\Blog\Settings\Settings $blog_settings;
44 protected \ILIAS\Blog\ReadingTime\ReadingTimeManager $reading_time_manager;
46 protected \ILIAS\Notes\Service $notes;
47
48 public function __construct(
49 protected InternalDataService $data,
50 protected InternalDomainService $domain,
51 protected InternalGUIService $gui,
52 protected PageManagerInterface $page_manager,
53 protected int $blog_id,
54 protected PermissionManager $perm,
55 protected ?string $current_month = null,
56 protected ?int $node_id = null,
57 protected int $id_type = \ilObjBlogGUI::REPOSITORY_NODE_ID
58 ) {
59 global $DIC;
60 $this->notes = $DIC->notes();
61 $this->approve_cmd_path = [
62 \ilObjBlogGUI::class,
63 \ILIAS\Blog\Editing\EditingGUI::class
64 ];
65 $this->approve_cmd_class = end($this->approve_cmd_path);
66 $this->admin_cmd_path = [
67 \ilObjBlogGUI::class,
68 \ILIAS\Blog\Editing\EditingGUI::class
69 ];
70 $this->admin_cmd_class = end($this->admin_cmd_path);
71
72
73 $this->posting_manager = $domain->posting();
74 $this->reading_time_manager = $domain->readingTime();
75 $this->blog_settings =
76 $domain->blogSettings()->getByObjId($this->blog_id);
77 $req = $gui->standardRequest();
78 $this->keyword = $req->getKeyword();
79 $this->author = $req->getAuthor();
80 $this->exp_manager = $domain->export()->manager();
81 $this->keyword_manager = $domain->keywords();
82 }
83
84 public function render(
85 array $items,
86 string $a_cmd = "preview",
87 string $a_link_template = "",
88 bool $a_show_inactive = false,
89 string $a_export_directory = ""
90 ): string {
91 $lng = $this->domain->lng();
92 $ilCtrl = $this->gui->ctrl();
93 $ui_factory = $this->gui->ui()->factory();
94 $ui_renderer = $this->gui->ui()->renderer();
95
96 $wtpl = new ilTemplate("tpl.blog_list.html", true, true, "components/ILIAS/Blog");
97
98 $is_admin = $this->perm->canManage();
99
100 $last_month = null;
101 $is_empty = true;
102 foreach ($items as $item) {
104 $item_id = $item->getId();
105 $author = $item->getAuthor();
106 $created = $item->getCreated();
107 $approved = $item->isApproved();
108 // only published items
109 $is_active = $this->page_manager->lookupActive($item_id, "blp");
110 if (!$is_active && !$a_show_inactive) {
111 continue;
112 }
113
114 $is_empty = false;
115
116 $month = "";
117 if (!$this->keyword && !$this->author) {
118 $month = substr($created->get(IL_CAL_DATE), 0, 7);
119 }
120
121 if (!$last_month || $last_month != $month) {
122 if ($last_month) {
123 $wtpl->setCurrentBlock("month_bl");
124 $wtpl->parseCurrentBlock();
125 }
126
127 // title according to current "filter"/navigation
128 if ($this->keyword) {
129 $title = $lng->txt("blog_keyword") . ": " . $this->keyword;
130 } elseif ($this->author) {
131 $title = $lng->txt("blog_author") . ": " . \ilUserUtil::getNamePresentation($this->author);
132 } else {
133 $title = $this->gui->presentation()->util()->getMonthPresentation($month);
134 $last_month = $month;
135 }
136
137 $wtpl->setVariable("TXT_CURRENT_MONTH", $title);
138 }
139
140 if (!$a_link_template) {
141 $ilCtrl->setParameterByClass("ilblogpostinggui", "bmn", $this->current_month);
142 $ilCtrl->setParameterByClass("ilblogpostinggui", "blpg", $item_id);
143 $preview = $ilCtrl->getLinkTargetByClass("ilblogpostinggui", $a_cmd);
144 } else {
145 $preview = $this->exp_manager->buildExportLink(
146 $a_link_template,
147 "posting",
148 (string) $item_id,
149 $this->keyword_manager->getKeywords($this->blog_id, false)
150 );
151 }
152 $more_link = $preview;
153
154 // actions
155 $posting_edit = $this->perm->mayEditPosting($item_id, $author);
156 if (($posting_edit || $is_admin) && !$a_link_template && $a_cmd === "preview") {
157 $actions = [];
158
159 if ($is_active && $this->blog_settings->getApproval() && !$approved) {
160 if ($is_admin) {
161 $ilCtrl->setParameterByClass($this->approve_cmd_class, "apid", $item_id);
162 $actions[] = $ui_factory->link()->standard(
163 $lng->txt("blog_approve"),
164 $ilCtrl->getLinkTargetByClass($this->approve_cmd_path, "approve")
165 );
166 $ilCtrl->setParameterByClass($this->approve_cmd_class, "apid", "");
167 }
168
169 $wtpl->setVariable("APPROVAL", $lng->txt("blog_needs_approval"));
170 }
171
172 if ($posting_edit) {
173 $actions[] = $ui_factory->link()->standard(
174 $lng->txt("edit_content"),
175 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "edit")
176 );
177 $more_link = $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "edit");
178
179 // #11858
180 if ($is_active) {
181 $actions[] = $ui_factory->link()->standard(
182 $lng->txt("blog_toggle_draft"),
183 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "deactivatePageToList")
184 );
185 } else {
186 $actions[] = $ui_factory->link()->standard(
187 $lng->txt("blog_toggle_final"),
188 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "activatePageToList")
189 );
190 }
191
192 $actions[] = $ui_factory->link()->standard(
193 $lng->txt("rename"),
194 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "edittitle")
195 );
196
197 if ($this->blog_settings->getKeywords()) { // #13616
198 $actions[] = $ui_factory->link()->standard(
199 $lng->txt("blog_edit_keywords"),
200 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "editKeywords")
201 );
202 }
203
204 $actions[] = $ui_factory->link()->standard(
205 $lng->txt("blog_edit_date"),
206 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "editdate")
207 );
208
209 $actions[] = $ui_factory->link()->standard(
210 $lng->txt("delete"),
211 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "deleteBlogPostingConfirmationScreen")
212 );
213 } elseif ($is_admin) {
214 // #10513
215 if ($is_active) {
216 $ilCtrl->setParameterByClass($this->admin_cmd_class, "apid", $item_id);
217 $actions[] = $ui_factory->link()->standard(
218 $lng->txt("blog_toggle_draft_admin"),
219 $ilCtrl->getLinkTargetByClass($this->admin_cmd_path, "deactivateAdmin")
220 );
221 $ilCtrl->setParameterByClass($this->admin_cmd_class, "apid", "");
222 }
223
224 $actions[] = $ui_factory->link()->standard(
225 $lng->txt("delete"),
226 $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "deleteBlogPostingConfirmationScreen")
227 );
228 }
229
230 $dd = $ui_factory->dropdown()->standard($actions)->withLabel($lng->txt("actions"));
231
232 $wtpl->setCurrentBlock("actions");
233 $wtpl->setVariable("ACTION_SELECTOR", $ui_renderer->render($dd));
234 $wtpl->parseCurrentBlock();
235 }
236
237 // comments
238 $notes_status = $this->notes->domain()->commentsActive($this->blog_id);
239 if ($notes_status && !$a_link_template) {
240 // count (public) notes
241 $notes_context = $this->notes
242 ->data()
243 ->context(
244 $this->blog_id,
245 (int) $item_id,
246 "blp"
247 );
248 $count = $this->notes
249 ->domain()
250 ->getNrOfCommentsForContext($notes_context);
251
252 if ($a_cmd !== "preview") {
253 $wtpl->setCurrentBlock("comments");
254 $wtpl->setVariable("TEXT_COMMENTS", $lng->txt("blog_comments"));
255 $wtpl->setVariable("URL_COMMENTS", $preview);
256 $wtpl->setVariable("COUNT_COMMENTS", $count);
257 $wtpl->parseCurrentBlock();
258 }
259 }
260
261 // permanent link
262 if ($this->node_id !== null &&
263 $a_cmd !== "preview") {
264 if ($this->id_type === ilObjBlogGUI::WORKSPACE_NODE_ID) {
265 $goto = $this->gui->permanentLink(0, (int) $this->node_id)->getPermanentLink((int) $item_id);
266 } else {
267 $goto = $this->gui->permanentLink((int) $this->node_id)->getPermanentLink((int) $item_id);
268 }
269 $wtpl->setCurrentBlock("permalink");
270 $wtpl->setVariable("URL_PERMALINK", $goto);
271 $wtpl->setVariable("TEXT_PERMALINK", $lng->txt("blog_link"));
272 $wtpl->parseCurrentBlock();
273 }
274
275 $snippet = $this->gui->posting()->getSnippet(
276 $item_id,
277 $this->blog_settings->getAbstractShorten(),
278 $this->blog_settings->getAbstractShortenLength(),
279 "&hellip;",
280 $this->blog_settings->getAbstractImage(),
281 $this->blog_settings->getAbstractImageWidth(),
282 $this->blog_settings->getAbstractImageHeight(),
283 $a_export_directory
284 );
285
286 if ($snippet) {
287 $wtpl->setCurrentBlock("more");
288 $wtpl->setVariable("URL_MORE", $more_link);
289 $wtpl->setVariable("TEXT_MORE", $lng->txt("blog_list_more"));
290 $wtpl->parseCurrentBlock();
291 }
292
293 if (!$is_active) {
294 $wtpl->setCurrentBlock("draft_text");
295 $wtpl->setVariable("DRAFT_TEXT", $lng->txt("blog_draft_text"));
296 $wtpl->parseCurrentBlock();
297 $wtpl->setVariable("DRAFT_CLASS", " ilBlogListItemDraft");
298 }
299
300 // reading time
301 $reading_time = $this->reading_time_manager->getReadingTime(
302 $this->blog_id,
303 $item_id
304 );
305 if (!is_null($reading_time)) {
306 $lng->loadLanguageModule("copg");
307 $wtpl->setCurrentBlock("reading_time");
308 $wtpl->setVariable(
309 "READING_TIME",
310 $lng->txt("copg_est_reading_time") . ": " .
311 sprintf($lng->txt("copg_x_minutes"), $reading_time)
312 );
313 $wtpl->parseCurrentBlock();
314 }
315
316 $wtpl->setCurrentBlock("posting");
317
318 $author_str = "";
319 if ($this->id_type === ilObjBlogGUI::REPOSITORY_NODE_ID) {
320 $authors = array();
321
322 // primary author
323 if ($author) {
325 }
326
327 // additional editors
328 foreach ($this->page_manager->getPageContributors("blp", $item_id) as $editor) {
329 $editor_id = (int) $editor["user_id"];
330 if ($editor_id !== $author) {
331 $authors[] = \ilUserUtil::getNamePresentation($editor_id);
332 }
333 }
334
335 if ($authors) {
336 $author_str = implode(", ", $authors) . " - ";
337 }
338 }
339
340 // title
341 $wtpl->setVariable("URL_TITLE", $preview);
342 $wtpl->setVariable("TITLE", $item->getTitle());
343
344 $kw = $this->posting_manager->getKeywords($this->blog_id, $item_id);
345 natcasesort($kw);
346 $keywords = (count($kw) > 0)
347 ? "<br>" . $lng->txt("keywords") . ": " . implode(", ", $kw)
348 : "";
349
350 $wtpl->setVariable("DATETIME", $author_str .
351 ilDatePresentation::formatDate($created) . $keywords);
352
353 // content
354 $wtpl->setVariable("CONTENT", $snippet);
355
356 $wtpl->parseCurrentBlock();
357 }
358
359 // permalink
360 if ($a_cmd === "previewFullscreen") {
361 $ref_id = ($this->id_type === ilObjBlogGUI::WORKSPACE_NODE_ID)
362 ? 0
363 : $this->node_id;
364 $wsp_id = ($this->id_type === ilObjBlogGUI::WORKSPACE_NODE_ID)
365 ? $this->node_id
366 : 0;
367 $this->gui->permanentLink($ref_id, $wsp_id)->setPermanentLink();
368 }
369
370 if (!$is_empty || $a_show_inactive) {
371 return $wtpl->get();
372 }
373 return "";
374 }
375}
ILIAS Blog Settings Settings $blog_settings
ILIAS Blog Export ExportManager $exp_manager
ILIAS Blog Keywords KeywordManager $keyword_manager
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected PageManagerInterface $page_manager, protected int $blog_id, protected PermissionManager $perm, protected ?string $current_month=null, protected ?int $node_id=null, protected int $id_type=\ilObjBlogGUI::REPOSITORY_NODE_ID)
ILIAS Blog ReadingTime ReadingTimeManager $reading_time_manager
const IL_CAL_DATE
Class ilBlogPosting.
Class for date presentation.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@ilCtrl_Calls ilObjBlogGUI: ilWorkspaceAccessGUI @ilCtrl_Calls ilObjBlogGUI: ilInfoScreenGUI,...
special template class to simplify handling of ITX/PEAR
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:
catch(\Exception $e) $req
Definition: xapiproxy.php:81
global $lng
Definition: privfeed.php:26
global $DIC
Definition: shib_login.php:26
$data
Definition: storeScorm.php:45