ILIAS  release_8 Revision v8.25
class.ilBlogDraftsDerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2
24{
26 protected \ilAccess $accessHandler;
27 protected \ilLanguage $lng;
28
29 public function __construct(
33 ) {
34 $this->taskService = $taskService;
35 $this->accessHandler = $accessHandler;
36 $this->lng = $lng;
37
38 $this->lng->loadLanguageModule('blog');
39 }
40
41 public function isActive(): bool
42 {
43 return true;
44 }
45
46 public function getTasks(int $user_id): array
47 {
48 $tasks = [];
49
50 $blogs = ilBlogPosting::searchBlogsByAuthor($user_id);
51 foreach ($blogs as $blog_id) {
52 $posts = ilBlogPosting::getAllPostings($blog_id);
53 foreach ($posts as $post_id => $post) {
54 if ((int) $post['author'] !== $user_id) {
55 continue;
56 }
57
58 $active = ilBlogPosting::_lookupActive($post_id, "blp");
59 $withdrawn = $post['last_withdrawn']->get(IL_CAL_DATETIME);
60 if (!$active && $withdrawn === null) {
61 $refId = $this->getFirstRefIdWithPermission('read', $blog_id, $user_id);
62 $wspId = 0;
63
64 $url = ilLink::_getStaticLink($refId, 'blog', true, "_" . $post_id . "_edit");
65
66 if ($refId === 0) {
67 $wspId = $this->getWspId($blog_id, $user_id);
68 if ($wspId === 0) {
69 continue;
70 }
71 $url = ilLink::_getStaticLink($wspId, 'blog', true, "_" . $post_id . "_edit_wsp");
72 }
73
74 $title = sprintf(
75 $this->lng->txt('blog_task_publishing_draft_title'),
76 $post['title']
77 );
78
79 $task = $this->taskService->derived()->factory()->task(
80 $title,
81 $refId,
82 0,
83 0,
84 $wspId
85 );
86
87 $tasks[] = $task->withUrl($url);
88 }
89 }
90 }
91
92 return $tasks;
93 }
94
95 protected function getFirstRefIdWithPermission(
96 string $operation,
97 int $objId,
98 int $userId
99 ): int {
100 foreach (\ilObject::_getAllReferences($objId) as $refId) {
101 if ($this->accessHandler->checkAccessOfUser($userId, $operation, '', $refId)) {
102 return $refId;
103 }
104 }
105
106 return 0;
107 }
108
109 protected function getWspId(int $objId, int $userId): int
110 {
111 $wst = new ilWorkspaceTree($userId);
112 return $wst->lookupNodeId($objId);
113 }
114}
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
__construct(ilTaskService $taskService, \ilAccessHandler $accessHandler, \ilLanguage $lng)
static searchBlogsByAuthor(int $a_user_id)
Get all blogs where user has postings.
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$post
Definition: ltitoken.php:49
$url
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58