ILIAS  release_8 Revision v8.24
class.ilPDTasksBlockGUI.php
Go to the documentation of this file.
1<?php
2
20
29{
30 public static string $block_type = "pdtasks";
31
32 protected array $tasks = [];
33
37 public function __construct()
38 {
39 global $DIC;
40
41 $this->ctrl = $DIC->ctrl();
42 $this->lng = $DIC->language();
43 $this->user = $DIC->user();
44 $lng = $DIC->language();
45
47
48 $this->setLimit(5);
49 $lng->loadLanguageModule("task");
50 $this->setTitle($lng->txt("task_derived_tasks"));
51
52 $this->setPresentation(self::PRES_SEC_LIST);
53 }
54
58 public function getBlockType(): string
59 {
60 return self::$block_type;
61 }
62
66 protected function isRepositoryObject(): bool
67 {
68 return false;
69 }
70
74 public static function getScreenMode(): string
75 {
76 return IL_SCREEN_SIDE;
77 }
78
82 public function executeCommand()
83 {
84 $ilCtrl = $this->ctrl;
85
86 $cmd = $ilCtrl->getCmd("getHTML");
87
88 return $this->$cmd();
89 }
90
94 public function fillDataSection(): void
95 {
96 global $DIC;
97 $collector = $DIC->task()->derived()->factory()->collector();
98
99 $this->tasks = $collector->getEntries($this->user->getId());
100
101 if (count($this->tasks) > 0) {
102 $this->setRowTemplate("tpl.pd_tasks.html", "Services/Tasks");
103 $this->getListRowData();
104 parent::fillDataSection();
105 } else {
106 $this->setEnableNumInfo(false);
107 $this->setDataSection($this->getOverview());
108 }
109 }
110
111
115 public function getListRowData(): void
116 {
117 $data = [];
118
120 foreach ($this->tasks as $task) {
121 $data[] = array(
122 "title" => $task->getTitle(),
123 "url" => $task->getUrl(),
124 "ref_id" => $task->getRefId(),
125 "wsp_id" => $task->getWspId(),
126 "deadline" => $task->getDeadline(),
127 "starting_time" => $task->getStartingTime()
128 );
129 }
130
131 $this->setData($data);
132 }
133
137 public function fillRow(array $a_set): void
138 {
139 global $DIC;
140
141 $factory = $DIC->ui()->factory();
142 $renderer = $DIC->ui()->renderer();
144
145 $info_screen = new ilInfoScreenGUI($this);
146 $info_screen->setFormAction("#");
147 $info_screen->addSection($lng->txt(""));
148 //$toolbar = new ilToolbarGUI();
149
150 $info_screen->addProperty(
151 $lng->txt("task_task"),
152 $a_set["title"]
153 );
154
155 if ($a_set["ref_id"] > 0) {
156 $obj_id = ilObject::_lookupObjId($a_set["ref_id"]);
157 $obj_type = ilObject::_lookupType($obj_id);
158
159 $url = 0 === $a_set['url'] ? ilLink::_getStaticLink($a_set["ref_id"]) : $a_set['url'];
160 $link = $factory->button()->shy(ilObject::_lookupTitle($obj_id), $url);
161
162 $info_screen->addProperty(
163 $lng->txt("obj_" . $obj_type),
164 $renderer->render($link)
165 );
166 }
167
168 if ($a_set["wsp_id"] > 0) {
169 $wst = new ilWorkspaceTree($this->user->getId());
170 $obj_id = $wst->lookupObjectId($a_set["wsp_id"]);
171 $obj_type = ilObject::_lookupType($obj_id);
172
173 $url = 0 === $a_set['url'] ? ilLink::_getStaticLink($a_set["wsp_id"]) : $a_set['url'];
174 $link = $factory->button()->shy(ilObject::_lookupTitle($obj_id), $url);
175
176 $info_screen->addProperty(
177 $lng->txt("obj_" . $obj_type),
178 $renderer->render($link)
179 );
180 }
181
182 if ($a_set["starting_time"] > 0) {
183 $start = new ilDateTime($a_set["starting_time"], IL_CAL_UNIX);
184 $info_screen->addProperty(
185 $lng->txt("task_start"),
187 );
188 }
189
190 if ($a_set["deadline"] > 0) {
191 $end = new ilDateTime($a_set["deadline"], IL_CAL_UNIX);
192 $info_screen->addProperty(
193 $lng->txt("task_deadline"),
195 );
196 }
197
198 $modal = $factory->modal()->roundtrip(
199 $lng->txt("task_details"),
200 $factory->legacy($info_screen->getHTML())
201 )
202 ->withCancelButtonLabel("close");
203 $button1 = $factory->button()->shy($a_set["title"], '#')
204 ->withOnClick($modal->getShowSignal());
205
206 $this->tpl->setVariable("TITLE", $renderer->render([$button1, $modal]));
207 }
208
212 public function getOverview(): string
213 {
215
216 return '<div class="small">' . (count($this->tasks)) . " " . $lng->txt("task_derived_tasks") . "</div>";
217 }
218
219 //
220 // New rendering
221 //
222
223 protected bool $new_rendering = true;
224
228 public function getHTMLNew(): string
229 {
230 global $DIC;
231 $collector = $DIC->task()->derived()->factory()->collector();
232
233 $this->tasks = $collector->getEntries($this->user->getId());
234
235 $this->getListRowData();
236
237 return parent::getHTMLNew();
238 }
239
243 protected function getListItemForData(array $data): ?Item
244 {
245 $factory = $this->ui->factory();
247
248 $title = $data["title"];
249 $props = [];
250
251 if ($data["ref_id"] > 0) {
252 $obj_id = ilObject::_lookupObjId($data["ref_id"]);
253 $obj_type = ilObject::_lookupType($obj_id);
254 $url = $data['url'] == "" ? ilLink::_getStaticLink($data["ref_id"]) : $data['url'];
255 $link = $url;
256 $title = $factory->link()->standard($data["title"], $link);
257 $props[$lng->txt("obj_" . $obj_type)] = ilObject::_lookupTitle($obj_id);
258 }
259
260 if ($data["wsp_id"] > 0) {
261 $wst = new ilWorkspaceTree($this->user->getId());
262 $obj_id = $wst->lookupObjectId($data["wsp_id"]);
263 $obj_type = ilObject::_lookupType($obj_id);
264 $url = $data['url'] == "" ? ilLink::_getStaticLink($data["wsp_id"]) : $data['url'];
265 $link = $url;
266 $title = $factory->link()->standard($data["title"], $link);
267 $props[$lng->txt("obj_" . $obj_type)] = ilObject::_lookupTitle($obj_id);
268 }
269
270 if ($data["starting_time"] > 0) {
271 $start = new ilDateTime($data["starting_time"], IL_CAL_UNIX);
272 $props[$lng->txt("task_start")] = ilDatePresentation::formatDate($start);
273 }
274
275 $factory = $this->ui->factory();
276 $item = $factory->item()->standard($title)
277 ->withProperties($props);
278
279 if ($data["deadline"] > 0) {
280 $end = new ilDateTime($data["deadline"], IL_CAL_UNIX);
281 //$props[$lng->txt("task_deadline")] =
282 // ilDatePresentation::formatDate($end);
283 $item = $item->withDescription(ilDatePresentation::formatDate($end));
284 }
285
286
287 return $item;
288 }
289
293 public function getNoItemFoundContent(): string
294 {
295 return $this->lng->txt("task_no_task_items");
296 }
297}
const IL_SCREEN_SIDE
const IL_CAL_UNIX
This class represents a block method of a block.
setData(array $a_data)
ilLanguage $lng
setDataSection(string $a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setTitle(string $a_title)
setPresentation(int $type)
setLimit(int $a_limit)
setEnableNumInfo(bool $a_enablenuminfo)
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
getCmd(string $fallback_command=null)
@inheritDoc
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class ilInfoScreenGUI.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
BlockGUI class for Tasks on PD.
isRepositoryObject()
Returns whether block has a corresponding repository object.
executeCommand()
execute command
static getScreenMode()
Get Screen Mode for current command.
getNoItemFoundContent()
No item entry.
fillRow(array $a_set)
get flat list for personal desktop
fillDataSection()
Fill data section.
getListItemForData(array $data)
Get list item for data array.null|\ILIAS\UI\Component\Item\Item
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Common interface to all items.
Definition: Item.php:32
$factory
Definition: metadata.php:75
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url