ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilForumDraftsDerivedTaskProvider.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 
20  protected $settings;
21 
23  protected $ctrl;
24 
33  public function __construct(
38  \ilCtrl $ctrl
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 
52  public function getTasks(int $user_id) : array
53  {
54  $tasks = [];
55 
57  foreach ($drafts as $draft) {
58  $objId = ilForum::_lookupObjIdForForumId($draft->getForumId());
59  $refId = $this->getFirstRefIdWithPermission('read', $objId, $user_id);
60 
61  if (0 === $refId) {
62  continue;
63  }
64 
65  $title = sprintf(
66  $this->lng->txt('frm_task_publishing_draft_title'),
67  $draft->getPostSubject()
68  );
69 
70  $task = $this->taskService->derived()->factory()->task(
71  $title,
72  $refId,
73  0,
74  0
75  );
76 
77  $isThread = false;
78  if (0 === (int) $draft->getThreadId()) {
79  $isThread = true;
80  }
81 
82  $anchor = '';
83  if ($isThread) {
84  $params['draft_id'] = $draft->getDraftId();
85  $params['cmd'] = 'editThreadDraft';
86  } else {
87  $params['thr_pk'] = $draft->getThreadId();
88  $params['pos_pk'] = $draft->getPostId();
89  $params['cmd'] = 'viewThread';
90  $anchor = '#draft_' . $draft->getDraftId();
91  }
92 
93  $url = \ilLink::_getLink($refId, 'frm', $params) . $anchor;
94 
95  $tasks[] = $task->withUrl($url);
96  }
97 
98  return $tasks;
99  }
100 
107  protected function getFirstRefIdWithPermission(string $operation, int $objId, int $userId) : int
108  {
109  foreach (\ilObject::_getAllReferences($objId) as $refId) {
110  if ($this->accessHandler->checkAccessOfUser($userId, $operation, '', $refId)) {
111  return $refId;
112  }
113  }
114 
115  return 0;
116  }
117 
121  public function isActive() : bool
122  {
123  return (bool) $this->settings->get('save_post_drafts', false);
124  }
125 }
static getDraftInstancesByUserId($user_id)
This class provides processing control methods.
static _lookupObjIdForForumId($a_for_id)
settings()
Definition: settings.php:2
$objId
Definition: xapitoken.php:39
$refId
Definition: xapitoken.php:40
static _getAllReferences($a_id)
get all reference ids of object
__construct(ilTaskService $taskService, \ilAccessHandler $accessHandler, \ilLanguage $lng, \ilSetting $settings, \ilCtrl $ctrl)
ilForumDraftsDerivedTaskProvider constructor.
getFirstRefIdWithPermission(string $operation, int $objId, int $userId)
$url
Task service.
Class ilForumDraftsDerivedTaskProvider.