ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBlogExerciseGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
27 {
29  protected ilCtrl $ctrl;
30  protected ilObjUser $user;
31  protected ilLanguage $lng;
32  protected int $node_id;
33  protected int $ass_id;
34  protected string $file;
35  protected \ILIAS\DI\UIServices $ui;
36  private \ilGlobalTemplateInterface $main_tpl;
37 
38  public function __construct(int $a_node_id)
39  {
40  global $DIC;
41  $this->main_tpl = $DIC->ui()->mainTemplate();
42 
43  $this->ctrl = $DIC->ctrl();
44  $this->user = $DIC->user();
45  $this->lng = $DIC->language();
46  $this->node_id = $a_node_id;
47  $this->blog_request = $DIC->blog()
48  ->internal()
49  ->gui()
50  ->standardRequest();
51 
52  $this->ass_id = $this->blog_request->getAssId();
53  $this->file = $this->blog_request->getAssFile();
54  $this->ui = $DIC->ui();
55  }
56 
57  public function executeCommand(): void
58  {
59  $ilCtrl = $this->ctrl;
60 
61  if (!$this->ass_id) {
62  $this->ctrl->returnToParent($this);
63  }
64 
65  $next_class = $ilCtrl->getNextClass($this);
66  $cmd = $ilCtrl->getCmd();
67 
68  switch ($next_class) {
69  default:
70  $this->$cmd();
71  break;
72  }
73  }
74 
75  public static function checkExercise(
76  int $a_node_id
77  ): string {
78  $be = new ilBlogExercise($a_node_id);
79 
80  $info = [];
81 
82  foreach ($be->getAssignmentsOfBlog() as $ass) {
83  $part = self::getExerciseInfo($ass["ass_id"]);
84  if ($part) {
85  $info[] = $part;
86  }
87  }
88  if (count($info) > 0) {
89  return implode("<br />", $info);
90  }
91  return "";
92  }
93 
94  protected static function getExerciseInfo(
95  int $a_assignment_id
96  ): string {
97  global $DIC;
98 
99  $ui = $DIC->ui();
100 
101  $links = [];
102  $buttons = [];
103  $elements = [];
104  $items = [];
105 
106  $lng = $DIC->language();
107  $ilCtrl = $DIC->ctrl();
108  $ilUser = $DIC->user();
109 
110  $ass = new ilExAssignment($a_assignment_id);
111  $exercise_id = $ass->getExerciseId();
112  if (!$exercise_id) {
113  return "";
114  }
115 
116  // is the assignment still open?
117  $times_up = $ass->afterDeadlineStrict();
118 
119  // exercise goto
120  $exc_ref_id = current(ilObject::_getAllReferences($exercise_id));
121  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
122 
123  $text = sprintf(
124  $lng->txt("blog_exercise_info"),
125  $ass->getTitle(),
126  ilObject::_lookupTitle($exercise_id)
127  );
128  $links[] = $ui->factory()->link()->standard(ilObject::_lookupTitle($exercise_id), $exc_link);
129 
130  // submit button
131  if (!$times_up) {
132  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
133  $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
134  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
135 
136  $buttons[] = $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
137  }
138 
139  // submitted files
140  $submission = new ilExSubmission($ass, $ilUser->getId());
141  if ($submission->hasSubmitted()) {
142  // #16888
143  $submitted = $submission->getSelectedObject();
144 
145  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
146  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
147  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
148 
151 
152  $text .= "<br />" . sprintf(
153  $lng->txt("blog_exercise_submitted_info"),
155  ""
156  );
157 
159  $buttons[] = $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
160  }
161 
162 
163  // work instructions incl. files
164 
165  $tooltip = "";
166 
167  $inst = $ass->getInstruction();
168  if ($inst) {
169  $tooltip .= nl2br($inst);
170  }
171 
172  $ass_files = $ass->getFiles();
173  if (count($ass_files) > 0) {
174  $tooltip .= "<br /><br />";
175 
176  foreach ($ass_files as $file) {
177  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $a_assignment_id);
178  $ilCtrl->setParameterByClass("ilblogexercisegui", "file", urlencode($file["name"]));
179  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcAssFile");
180  $ilCtrl->setParameterByClass("ilblogexercisegui", "file", "");
181  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
182 
183  $items[] = $ui->renderer()->render($ui->factory()->button()->shy($file["name"], $dl_link));
184  }
185  $list = $ui->factory()->listing()->unordered($items);
186  $tooltip .= $ui->renderer()->render($list);
187  }
188 
189  if ($tooltip) {
190  $modal = $ui->factory()->modal()->roundtrip($lng->txt("exc_instruction"), $ui->factory()->legacy($tooltip))
191  ->withCancelButtonLabel("close");
192  $elements[] = $modal;
193  $buttons[] = $ui->factory()->button()->standard($lng->txt("exc_instruction"), '#')
194  ->withOnClick($modal->getShowSignal());
195  }
196 
197  $elements[] = $ui->factory()->messageBox()->info($text)
198  ->withLinks($links)
199  ->withButtons($buttons);
200 
201  return $ui->renderer()->render($elements);
202  }
203 
204  protected function downloadExcAssFile(): void
205  {
206  if ($this->file) {
207  $ass = new ilExAssignment($this->ass_id);
208  $ass_files = $ass->getFiles();
209  if (count($ass_files) > 0) {
210  foreach ($ass_files as $file) {
211  if ($file["name"] == $this->file) {
212  ilFileDelivery::deliverFileLegacy($file["fullpath"], $file["name"]);
213  }
214  }
215  }
216  }
217  }
218 
219  protected function downloadExcSubFile(): void
220  {
222 
223  $ass = new ilExAssignment($this->ass_id);
224  $submission = new ilExSubmission($ass, $ilUser->getId());
225  $submitted = $submission->getFiles();
226  if (count($submitted) > 0) {
227  $submitted = array_pop($submitted);
228 
229  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
230  $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
231  $ass->getTitle() . " - " .
232  $user_data["firstname"] . " " .
233  $user_data["lastname"] . " (" .
234  $user_data["login"] . ").zip";
235 
236  ilFileDelivery::deliverFileLegacy($submitted["filename"], $title);
237  }
238  }
239 
240  protected function finalize(): void
241  {
242  $ilCtrl = $this->ctrl;
243  $lng = $this->lng;
244 
245  $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
246  $exc_gui->submitBlog($this->node_id);
247 
248  $this->main_tpl->setOnScreenMessage('success', $lng->txt("blog_finalized"), true);
249  $ilCtrl->returnToParent($this);
250  }
251 
256  public function getSubmitButton(
257  int $ass_id
258  ): ?\ILIAS\UI\Component\Button\Primary {
259  $ilCtrl = $this->ctrl;
260  $ui = $this->ui;
261  $lng = $this->lng;
262 
263  $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user->getId());
264 
265  if ($state->isSubmissionAllowed()) {
266  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
267  $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
268  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
269  return $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
270  }
271  return null;
272  }
273 
279  int $ass_id
280  ): ?\ILIAS\UI\Component\Button\Standard {
281  $ilCtrl = $this->ctrl;
282  $lng = $this->lng;
283  $ui = $this->ui;
284 
285  // submitted files
286  $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user->getId());
287  if ($submission->hasSubmitted()) {
288  // #16888
289  $submitted = $submission->getSelectedObject();
290  if ($submitted["ts"] != "") {
291  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
292  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
293  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
294  return $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
295  }
296  }
297  return null;
298  }
299 
300 
301  public function getActionButtons(): array
302  {
303  $be = new ilBlogExercise($this->node_id);
304 
305  $buttons = [];
306  foreach ($be->getAssignmentsOfBlog() as $exercise) {
307  $ass_id = $exercise["ass_id"];
308  $buttons[$ass_id] = [];
309  $submit_button = $this->getSubmitButton($ass_id);
310  if ($submit_button) {
311  $buttons[$ass_id][] = $submit_button;
312  }
313  $download_button = $this->getDownloadSubmissionButton($ass_id);
314  if ($download_button) {
315  $buttons[$ass_id][] = $download_button;
316  }
317  }
318 
319  return $buttons;
320  }
321 }
getFiles(array $a_file_ids=null, bool $a_only_valid=false, string $a_min_timestamp=null, bool $print_versions=false)
Get submission items (not only files)
Exercise assignment.
Class Factory.
const IL_CAL_DATETIME
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...
Class ChatMainBarProvider .
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...
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
StandardGUIRequest $blog_request
Class ilBlogExerciseGUI.
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
global $DIC
Definition: feed.php:28
getDownloadSubmissionButton(int $ass_id)
static getExerciseInfo(int $a_assignment_id)
static _lookupTitle(int $obj_id)
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
ILIAS DI UIServices $ui
static checkExercise(int $a_node_id)
static initGUIForSubmit(int $a_ass_id, int $a_user_id=null)
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getSubmitButton(int $ass_id)
Get submit link.
ilGlobalTemplateInterface $main_tpl
static setUseRelativeDates(bool $a_status)
set use relative dates