ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBlogDraftsDerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 protected $taskService;
12
14 protected $accessHandler;
15
17 protected $lng;
18
25 public function __construct(
29 ) {
30 $this->taskService = $taskService;
31 $this->accessHandler = $accessHandler;
32 $this->lng = $lng;
33
34 $this->lng->loadLanguageModule('blog');
35 }
36
40 public function isActive() : bool
41 {
42 return true;
43 }
44
48 public function getTasks(int $user_id) : array
49 {
50 $tasks = [];
51
52 $blogs = ilBlogPosting::searchBlogsByAuthor($user_id);
53 foreach ($blogs as $blog_id) {
54 $posts = ilBlogPosting::getAllPostings($blog_id);
55 foreach ($posts as $post_id => $post) {
56 if ((int) $post['author'] !== $user_id) {
57 continue;
58 }
59
60 $active = ilBlogPosting::_lookupActive($post_id, "blp");
61 $withdrawn = $post['last_withdrawn']->get(IL_CAL_DATETIME);
62 if (!$active && $withdrawn === null) {
63 $refId = $this->getFirstRefIdWithPermission('read', $blog_id, $user_id);
64 $wspId = 0;
65
66 $url = ilLink::_getStaticLink($refId, 'blog', true, "_" . $post_id . "_edit");
67
68 if ($refId === 0) {
69 $wspId = $this->getWspId($blog_id, $user_id);
70 if ($wspId === 0) {
71 continue;
72 }
73 $url = ilLink::_getStaticLink($wspId, 'blog', true, "_" . $post_id . "_edit_wsp");
74 }
75
76 $title = sprintf(
77 $this->lng->txt('blog_task_publishing_draft_title'),
78 $post['title']
79 );
80
81 $task = $this->taskService->derived()->factory()->task(
82 $title,
83 $refId,
84 0,
85 0,
86 $wspId
87 );
88
89 $tasks[] = $task->withUrl($url);
90 }
91 }
92 }
93
94 return $tasks;
95 }
96
103 protected function getFirstRefIdWithPermission(string $operation, int $objId, int $userId) : int
104 {
106 if ($this->accessHandler->checkAccessOfUser($userId, $operation, '', $refId)) {
107 return $refId;
108 }
109 }
110
111 return 0;
112 }
113
119 protected function getWspId(int $objId, int $userId) : int
120 {
121 $wst = new ilWorkspaceTree($userId);
122 $nodeId = $wst->lookupNodeId($objId);
123 return $nodeId;
124 }
125}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Class ilBlogDraftsDerivedTaskProvider.
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
__construct(ilTaskService $taskService, \ilAccessHandler $accessHandler, \ilLanguage $lng)
ilBlogDraftsDerivedTaskProvider constructor.
static getAllPostings($a_blog_id, $a_limit=1000, $a_offset=0)
Get all postings of blog.
static searchBlogsByAuthor($a_user_id)
Get all blogs where user has postings.
language handling
static _getAllReferences($a_id)
get all reference ids of object
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
Tree handler for personal workspace.
Interface ilAccessHandler.
$url
$objId
Definition: xapitoken.php:41
$refId
Definition: xapitoken.php:42