ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumDraftsDerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 public function __construct(
28 protected ilTaskService $taskService,
29 protected ilAccessHandler $accessHandler,
30 protected ilLanguage $lng,
31 protected ilSetting $settings,
32 protected ilCtrlInterface $ctrl
33 ) {
34 $this->lng->loadLanguageModule('forum');
35 }
36
37 public function getTasks(int $user_id): array
38 {
39 $tasks = [];
40
42 foreach ($drafts as $draft) {
43 $objId = ilForum::_lookupObjIdForForumId($draft->getForumId());
44 $refId = $this->getFirstRefIdWithPermission('read', $objId, $user_id);
45
46 if (0 === $refId) {
47 continue;
48 }
49
50 $title = sprintf(
51 $this->lng->txt('frm_task_publishing_draft_title'),
52 $draft->getPostSubject()
53 );
54
55 $task = $this->taskService->derived()->factory()->task(
56 $title,
57 $refId,
58 0,
59 0
60 );
61
62 $isThread = false;
63 if (0 === $draft->getThreadId()) {
64 $isThread = true;
65 }
66
67 $anchor = '';
68 $params = ['ref_id' => $refId];
69 if ($isThread) {
70 $params['draft_id'] = $draft->getDraftId();
71 $cmd = 'editThreadDraft';
72 } else {
73 $params['thr_pk'] = $draft->getThreadId();
74 $params['pos_pk'] = $draft->getPostId();
75 $cmd = 'viewThread';
76 $anchor = 'draft_' . $draft->getDraftId();
77 }
78
79 foreach ($params as $name => $value) {
80 $this->ctrl->setParameterByClass(ilObjForumGUI::class, $name, $value);
81 }
82 $url = $this->ctrl->getLinkTargetByClass(
83 [
84 ilRepositoryGUI::class,
85 ilObjForumGUI::class
86 ],
87 $cmd,
88 $anchor
89 );
90 foreach (array_keys($params) as $name) {
91 $this->ctrl->setParameterByClass(ilObjForumGUI::class, $name, null);
92 }
93
94 $tasks[] = $task->withUrl($url);
95 }
96
97 return $tasks;
98 }
99
100 protected function getFirstRefIdWithPermission(string $operation, int $objId, int $userId): int
101 {
103 if ($this->accessHandler->checkAccessOfUser($userId, $operation, '', $refId)) {
104 return $refId;
105 }
106 }
107
108 return 0;
109 }
110
111 public function isActive(): bool
112 {
113 return (bool) $this->settings->get('save_post_drafts', '0');
114 }
115}
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
__construct(protected ilTaskService $taskService, protected ilAccessHandler $accessHandler, protected ilLanguage $lng, protected ilSetting $settings, protected ilCtrlInterface $ctrl)
static getDraftInstancesByUserId(int $user_id)
static _lookupObjIdForForumId(int $a_for_id)
language handling
static _getAllReferences(int $id)
get all reference ids for object ID
ILIAS Setting Class.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
global $lng
Definition: privfeed.php:31
$url
Definition: shib_logout.php:68
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58