ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilBlogExerciseGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
30{
32 protected \ILIAS\Blog\Exercise\BlogExercise $blog_exercise;
34 protected ilCtrl $ctrl;
35 protected ilObjUser $user;
36 protected ilLanguage $lng;
37 protected int $node_id;
38 protected int $ass_id;
39 protected string $file;
40 protected \ILIAS\DI\UIServices $ui;
41 private \ilGlobalTemplateInterface $main_tpl;
42
43 public function __construct(
44 int $a_node_id,
45 \ILIAS\Blog\Exercise\BlogExercise $blog_exercise,
46 protected BlogCmdPermission $cmd_perm,
49 \ILIAS\Blog\InternalGUIService $gui
50 ) {
51 global $DIC;
52
53 $this->main_tpl = $gui->ui()->mainTemplate();
54 $this->ctrl = $gui->ctrl();
55 $this->user = $user;
56 $this->lng = $lng;
57 $this->node_id = $a_node_id;
58 $this->blog_request = $gui->standardRequest();
59
60 $this->ass_id = $this->blog_request->getAssId();
61 $this->file = $this->blog_request->getAssFile();
62 $this->ui = $gui->ui();
63 $this->blog_exercise = $blog_exercise;
64 $this->submission = $DIC->exercise()->internal()->domain()->submission(
65 $this->ass_id
66 );
67 }
68
69 public function executeCommand(): void
70 {
71 $ilCtrl = $this->ctrl;
72
73 if (!$this->ass_id) {
74 $this->ctrl->returnToParent($this);
75 return;
76 }
77
78 $next_class = $ilCtrl->getNextClass($this);
79 $cmd = $this->cmd_perm->getPermittedCommand();
80
81 switch ($next_class) {
82 default:
83 if ($cmd !== "") {
84 $this->$cmd();
85 }
86 break;
87 }
88 }
89
90 protected function downloadExcAssFile(): void
91 {
92 if ($this->file) {
93 $ass = new ilExAssignment($this->ass_id);
94 $ass_files = $ass->getFiles();
95 if (count($ass_files) > 0) {
96 foreach ($ass_files as $file) {
97 if ($file["name"] == $this->file) {
98 ilFileDelivery::deliverFileLegacy($file["fullpath"], $file["name"]);
99 }
100 }
101 }
102 }
103 }
104
105 protected function downloadExcSubFile(): void
106 {
107 $ass = new ilExAssignment($this->ass_id);
108 $submissions = $this->submission->getSubmissionsOfUser(
109 $this->user->getId()
110 );
112 if ($submitted = $submissions->current()) {
113 $user_data = ilObjUser::_lookupName($submitted->getUserId());
114 $title = ilObject::_lookupTitle($ass->getExerciseId()) . " - " .
115 $ass->getTitle() . " - " .
116 $user_data["firstname"] . " " .
117 $user_data["lastname"] . " (" .
118 $user_data["login"] . ").zip";
119 $this->submission->deliverFile(
120 $submitted->getUserId(),
121 $submitted->getRid(),
122 $title
123 );
124 }
125 }
126
127 protected function finalize(): void
128 {
129 $ilCtrl = $this->ctrl;
131
132 $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
133 $exc_gui->submitBlog($this->node_id, $this->user->getId());
134
135 $this->main_tpl->setOnScreenMessage('success', $lng->txt("blog_finalized"), true);
136 $ilCtrl->redirectByClass(
137 [
138 ilDashboardGUI::class,
139 ilPersonalWorkspaceGUI::class,
140 ilObjBlogGUI::class,
141 \ILIAS\Blog\Editing\EditingGUI::class,
142 ],
143 ""
144 );
145 }
146
151 public function getSubmitButton(
152 int $ass_id
153 ): ?\ILIAS\UI\Component\Button\Primary {
154 $ilCtrl = $this->ctrl;
155 $ui = $this->ui;
157
158 $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user->getId());
159
160 if ($state->isSubmissionAllowed()) {
161 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
162 $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
163 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
164 return $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
165 }
166 return null;
167 }
168
174 int $ass_id
175 ): ?\ILIAS\UI\Component\Button\Standard {
176 $ilCtrl = $this->ctrl;
178 $ui = $this->ui;
179
180 // submitted files
181 $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user->getId());
182 if ($submission->hasSubmitted()) {
183 // #16888
184 $submitted = $submission->getSelectedObject();
185 if ($submitted?->getTimestamp() !== "") {
186 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
187 $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
188 $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
189 return $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
190 }
191 }
192 return null;
193 }
194
195
196 public function getActionButtons(): array
197 {
198 $be = $this->blog_exercise;
199
200 $buttons = [];
201 foreach ($be->getAssignmentsOfBlog() as $exercise) {
202 $ass_id = $exercise["ass_id"];
203 $buttons[$ass_id] = [];
204 $submit_button = $this->getSubmitButton($ass_id);
205 if ($submit_button) {
206 $buttons[$ass_id][] = $submit_button;
207 }
208 $download_button = $this->getDownloadSubmissionButton($ass_id);
209 if ($download_button) {
210 $buttons[$ass_id][] = $download_button;
211 }
212 }
213
214 return $buttons;
215 }
216}
@ilCtrl_Calls ilBlogExerciseGUI:
getDownloadSubmissionButton(int $ass_id)
SubmissionManager $submission
__construct(int $a_node_id, \ILIAS\Blog\Exercise\BlogExercise $blog_exercise, protected BlogCmdPermission $cmd_perm, ilLanguage $lng, ilObjUser $user, \ILIAS\Blog\InternalGUIService $gui)
ILIAS DI UIServices $ui
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|LanguageIdentifier $a_topic, ?int $n=null)
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:26
global $DIC
Definition: shib_login.php:26
ilObjExercise $exercise