ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilBlogDraftsDerivedTaskProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 {
27  protected \ILIAS\Blog\InternalGUIService $gui;
29  protected \ilAccess $accessHandler;
30  protected \ilLanguage $lng;
31 
32  public function __construct(
33  ilTaskService $taskService,
34  \ilAccessHandler $accessHandler,
35  \ilLanguage $lng
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 }
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...
const IL_CAL_DATETIME
static _getAllReferences(int $id)
get all reference ids for object ID
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
__construct(ilTaskService $taskService, \ilAccessHandler $accessHandler, \ilLanguage $lng)
Class ilBlogDraftsDerivedTaskProvider.
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58
$url
Definition: shib_logout.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
Task service.
$post
Definition: ltitoken.php:46