ILIAS  release_8 Revision v8.24
class.ilForumDraftsDerivedTaskProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
29 protected ilLanguage $lng;
32
33 public function __construct(
39 ) {
40 $this->taskService = $taskService;
41 $this->accessHandler = $accessHandler;
42 $this->lng = $lng;
43 $this->settings = $settings;
44 $this->ctrl = $ctrl;
45
46 $this->lng->loadLanguageModule('forum');
47 }
48
49 public function getTasks(int $user_id): array
50 {
51 $tasks = [];
52
54 foreach ($drafts as $draft) {
55 $objId = ilForum::_lookupObjIdForForumId($draft->getForumId());
56 $refId = $this->getFirstRefIdWithPermission('read', $objId, $user_id);
57
58 if (0 === $refId) {
59 continue;
60 }
61
62 $title = sprintf(
63 $this->lng->txt('frm_task_publishing_draft_title'),
64 $draft->getPostSubject()
65 );
66
67 $task = $this->taskService->derived()->factory()->task(
68 $title,
69 $refId,
70 0,
71 0
72 );
73
74 $isThread = false;
75 if (0 === $draft->getThreadId()) {
76 $isThread = true;
77 }
78
79 $anchor = '';
80 $params = ['ref_id' => $refId];
81 if ($isThread) {
82 $params['draft_id'] = $draft->getDraftId();
83 $cmd = 'editThreadDraft';
84 } else {
85 $params['thr_pk'] = $draft->getThreadId();
86 $params['pos_pk'] = $draft->getPostId();
87 $cmd = 'viewThread';
88 $anchor = 'draft_' . $draft->getDraftId();
89 }
90
91 foreach ($params as $name => $value) {
92 $this->ctrl->setParameterByClass(ilObjForumGUI::class, $name, $value);
93 }
94 $url = $this->ctrl->getLinkTargetByClass(
95 [
96 ilRepositoryGUI::class,
97 ilObjForumGUI::class
98 ],
99 $cmd,
100 $anchor
101 );
102 foreach (array_keys($params) as $name) {
103 $this->ctrl->setParameterByClass(ilObjForumGUI::class, $name, null);
104 }
105
106 $tasks[] = $task->withUrl($url);
107 }
108
109 return $tasks;
110 }
111
112 protected function getFirstRefIdWithPermission(string $operation, int $objId, int $userId): int
113 {
115 if ($this->accessHandler->checkAccessOfUser($userId, $operation, '', $refId)) {
116 return $refId;
117 }
118 }
119
120 return 0;
121 }
122
123 public function isActive(): bool
124 {
125 return (bool) $this->settings->get('save_post_drafts', '0');
126 }
127}
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
__construct(ilTaskService $taskService, ilAccessHandler $accessHandler, ilLanguage $lng, ilSetting $settings, 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
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...
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:33
if($format !==null) $name
Definition: metadata.php:247
$url
$objId
Definition: xapitoken.php:57
$refId
Definition: xapitoken.php:58