ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBlogDraftsDerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 protected \ILIAS\Blog\InternalDomainService $domain;
28 protected \ILIAS\Blog\InternalGUIService $gui;
30 protected \ilAccess $accessHandler;
31 protected \ilLanguage $lng;
32
33 public function __construct(
37 ) {
38 global $DIC;
39
40 $service = $DIC->blog()->internal();
41 $this->gui = $service->gui();
42 $this->domain = $service->domain();
43 $this->taskService = $taskService;
44 $this->accessHandler = $accessHandler;
45 $this->lng = $lng;
46
47 $this->lng->loadLanguageModule('blog');
48 }
49
50 public function isActive(): bool
51 {
52 return true;
53 }
54
55 public function getTasks(int $user_id): array
56 {
57 $tasks = [];
58
59 $mgr = $this->domain->posting();
60 $blogs = $mgr->searchBlogsByAuthor($user_id);
61 foreach ($blogs as $blog_id) {
62 $posts = $mgr->getAllByBlog($blog_id);
63 foreach ($posts as $post) {
64 $post_id = $post->getId();
65 if ($post->getAuthor() !== $user_id) {
66 continue;
67 }
68
69 $active = $this->domain->pageManager()->lookupActive($post->getId(), "blp");
70 $withdrawn = $post->getLastWithdrawn()?->get(IL_CAL_DATETIME);
71 if (!$active && $withdrawn === null) {
72 $refId = $this->getFirstRefIdWithPermission('read', $blog_id, $user_id);
73 $wspId = 0;
74 $url = $this->gui->permanentLink($refId)->getPermanentLink($post->getId(), true);
75
76 if ($refId === 0) {
77 $wspId = $this->getWspId($blog_id, $user_id);
78 if ($wspId === 0) {
79 continue;
80 }
81 $url = $this->gui->permanentLink(0, $wspId)->getPermanentLink($post_id, true);
82 }
83
84 $title = sprintf(
85 $this->lng->txt('blog_task_publishing_draft_title'),
86 $post->getTitle(),
87 );
88
89 $task = $this->taskService->derived()->factory()->task(
90 $title,
91 $refId,
92 0,
93 0,
94 $wspId
95 );
96
97 $tasks[] = $task->withUrl($url);
98 }
99 }
100 }
101
102 return $tasks;
103 }
104
105 protected function getFirstRefIdWithPermission(
106 string $operation,
107 int $objId,
108 int $userId
109 ): int {
110 foreach (\ilObject::_getAllReferences($objId) as $refId) {
111 if ($this->accessHandler->checkAccessOfUser($userId, $operation, '', $refId)) {
112 return $refId;
113 }
114 }
115
116 return 0;
117 }
118
119 protected function getWspId(int $objId, int $userId): int
120 {
121 $wst = new ilWorkspaceTree($userId);
122 return $wst->lookupNodeId($objId);
123 }
124}
const IL_CAL_DATETIME
Class ilBlogDraftsDerivedTaskProvider.
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
__construct(ilTaskService $taskService, \ilAccessHandler $accessHandler, \ilLanguage $lng)
language handling
Class ilObject Basic functions for all objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach( $report as $row)
Combines all available interfaces which can be called via global $ilAccess.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$service
Definition: ltiresult.php:44
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58