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