ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilBlogExerciseGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
29{
31 protected \ILIAS\Blog\Exercise\BlogExercise $blog_exercise;
33 protected ilCtrl $ctrl;
34 protected ilObjUser $user;
35 protected ilLanguage $lng;
36 protected int $node_id;
37 protected int $ass_id;
38 protected string $file;
39 protected \ILIAS\DI\UIServices $ui;
40 private \ilGlobalTemplateInterface $main_tpl;
41
42 public function __construct(
43 int $a_node_id,
44 \ILIAS\Blog\Exercise\BlogExercise $blog_exercise,
47 \ILIAS\Blog\InternalGUIService $gui
48 ) {
49 global $DIC;
50
51 $this->main_tpl = $gui->ui()->mainTemplate();
52 $this->ctrl = $gui->ctrl();
53 $this->user = $user;
54 $this->lng = $lng;
55 $this->node_id = $a_node_id;
56 $this->blog_request = $gui->standardRequest();
57
58 $this->ass_id = $this->blog_request->getAssId();
59 $this->file = $this->blog_request->getAssFile();
60 $this->ui = $gui->ui();
61 $this->blog_exercise = $blog_exercise;
62 $this->submission = $DIC->exercise()->internal()->domain()->submission(
63 $this->ass_id
64 );
65 }
66
67 public function executeCommand(): void
68 {
69 $ilCtrl = $this->ctrl;
70
71 if (!$this->ass_id) {
72 $this->ctrl->returnToParent($this);
73 }
74
75 $next_class = $ilCtrl->getNextClass($this);
76 $cmd = $ilCtrl->getCmd();
77
78 switch ($next_class) {
79 default:
80 $this->$cmd();
81 break;
82 }
83 }
84
85 protected function downloadExcAssFile(): void
86 {
87 if ($this->file) {
88 $ass = new ilExAssignment($this->ass_id);
89 $ass_files = $ass->getFiles();
90 if (count($ass_files) > 0) {
91 foreach ($ass_files as $file) {
92 if ($file["name"] == $this->file) {
93 ilFileDelivery::deliverFileLegacy($file["fullpath"], $file["name"]);
94 }
95 }
96 }
97 }
98 }
99
100 protected function downloadExcSubFile(): void
101 {
102 $ass = new ilExAssignment($this->ass_id);
103 $submissions = $this->submission->getSubmissionsOfUser(
104 $this->user->getId()
105 );
107 if ($submitted = $submissions->current()) {
108 $user_data = ilObjUser::_lookupName($submitted->getUserId());
109 $title = ilObject::_lookupTitle($ass->getExerciseId()) . " - " .
110 $ass->getTitle() . " - " .
111 $user_data["firstname"] . " " .
112 $user_data["lastname"] . " (" .
113 $user_data["login"] . ").zip";
114 $this->submission->deliverFile(
115 $submitted->getUserId(),
116 $submitted->getRid(),
117 $title
118 );
119 }
120 }
121
122 protected function finalize(): void
123 {
124 $ilCtrl = $this->ctrl;
126
127 $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
128 $exc_gui->submitBlog($this->node_id);
129
130 $this->main_tpl->setOnScreenMessage('success', $lng->txt("blog_finalized"), true);
131 $ilCtrl->returnToParent($this);
132 }
133
138 public function getSubmitButton(
139 int $ass_id
140 ): ?\ILIAS\UI\Component\Button\Primary {
141 $ilCtrl = $this->ctrl;
142 $ui = $this->ui;
144
145 $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user->getId());
146
147 if ($state->isSubmissionAllowed()) {
148 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
149 $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
150 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
151 return $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
152 }
153 return null;
154 }
155
161 int $ass_id
162 ): ?\ILIAS\UI\Component\Button\Standard {
163 $ilCtrl = $this->ctrl;
165 $ui = $this->ui;
166
167 // submitted files
168 $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user->getId());
169 if ($submission->hasSubmitted()) {
170 // #16888
171 $submitted = $submission->getSelectedObject();
172 if ($submitted?->getTimestamp() !== "") {
173 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
174 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
175 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
176 return $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
177 }
178 }
179 return null;
180 }
181
182
183 public function getActionButtons(): array
184 {
185 $be = $this->blog_exercise;
186
187 $buttons = [];
188 foreach ($be->getAssignmentsOfBlog() as $exercise) {
189 $ass_id = $exercise["ass_id"];
190 $buttons[$ass_id] = [];
191 $submit_button = $this->getSubmitButton($ass_id);
192 if ($submit_button) {
193 $buttons[$ass_id][] = $submit_button;
194 }
195 $download_button = $this->getDownloadSubmissionButton($ass_id);
196 if ($download_button) {
197 $buttons[$ass_id][] = $download_button;
198 }
199 }
200
201 return $buttons;
202 }
203}
@ilCtrl_Calls ilBlogExerciseGUI:
getDownloadSubmissionButton(int $ass_id)
SubmissionManager $submission
ILIAS DI UIServices $ui
__construct(int $a_node_id, \ILIAS\Blog\Exercise\BlogExercise $blog_exercise, ilLanguage $lng, ilObjUser $user, \ILIAS\Blog\InternalGUIService $gui)
ilGlobalTemplateInterface $main_tpl
ILIAS Blog Exercise BlogExercise $blog_exercise
StandardGUIRequest $blog_request
getSubmitButton(int $ass_id)
Get submit link.
Class ilCtrl provides processing control methods.
Exercise assignment.
static initGUIForSubmit(int $a_ass_id, ?int $a_user_id=null)
Exercise submission //TODO: This class has many static methods related to delivered "files".
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
language handling
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...
User class.
static _lookupName(int $a_user_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26