ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBlogExerciseGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
29 {
30  protected \ILIAS\Blog\Exercise\BlogExercise $blog_exercise;
32  protected ilCtrl $ctrl;
33  protected ilObjUser $user;
34  protected ilLanguage $lng;
35  protected int $node_id;
36  protected int $ass_id;
37  protected string $file;
38  protected \ILIAS\DI\UIServices $ui;
39  private \ilGlobalTemplateInterface $main_tpl;
40 
41  public function __construct(
42  int $a_node_id,
43  \ILIAS\Blog\Exercise\BlogExercise $blog_exercise,
44  ilLanguage $lng,
45  ilObjUser $user,
46  \ILIAS\Blog\InternalGUIService $gui
47  ) {
48  $this->main_tpl = $gui->ui()->mainTemplate();
49  $this->ctrl = $gui->ctrl();
50  $this->user = $user;
51  $this->lng = $lng;
52  $this->node_id = $a_node_id;
53  $this->blog_request = $gui->standardRequest();
54 
55  $this->ass_id = $this->blog_request->getAssId();
56  $this->file = $this->blog_request->getAssFile();
57  $this->ui = $gui->ui();
58  $this->blog_exercise = $blog_exercise;
59  }
60 
61  public function executeCommand(): void
62  {
63  $ilCtrl = $this->ctrl;
64 
65  if (!$this->ass_id) {
66  $this->ctrl->returnToParent($this);
67  }
68 
69  $next_class = $ilCtrl->getNextClass($this);
70  $cmd = $ilCtrl->getCmd();
71 
72  switch ($next_class) {
73  default:
74  $this->$cmd();
75  break;
76  }
77  }
78 
79  protected function downloadExcAssFile(): void
80  {
81  if ($this->file) {
82  $ass = new ilExAssignment($this->ass_id);
83  $ass_files = $ass->getFiles();
84  if (count($ass_files) > 0) {
85  foreach ($ass_files as $file) {
86  if ($file["name"] == $this->file) {
87  ilFileDelivery::deliverFileLegacy($file["fullpath"], $file["name"]);
88  }
89  }
90  }
91  }
92  }
93 
94  protected function downloadExcSubFile(): void
95  {
96  $ilUser = $this->user;
97 
98  $ass = new ilExAssignment($this->ass_id);
99  $submission = new ilExSubmission($ass, $ilUser->getId());
100  $submitted = $submission->getFiles();
101  if (count($submitted) > 0) {
102  $submitted = array_pop($submitted);
103 
104  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
105  $title = ilObject::_lookupTitle($submitted["obj_id"]) . " - " .
106  $ass->getTitle() . " - " .
107  $user_data["firstname"] . " " .
108  $user_data["lastname"] . " (" .
109  $user_data["login"] . ").zip";
110 
111  ilFileDelivery::deliverFileLegacy($submitted["filename"], $title);
112  }
113  }
114 
115  protected function finalize(): void
116  {
117  $ilCtrl = $this->ctrl;
118  $lng = $this->lng;
119 
120  $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
121  $exc_gui->submitBlog($this->node_id);
122 
123  $this->main_tpl->setOnScreenMessage('success', $lng->txt("blog_finalized"), true);
124  $ilCtrl->returnToParent($this);
125  }
126 
131  public function getSubmitButton(
132  int $ass_id
133  ): ?\ILIAS\UI\Component\Button\Primary {
134  $ilCtrl = $this->ctrl;
135  $ui = $this->ui;
136  $lng = $this->lng;
137 
138  $state = ilExcAssMemberState::getInstanceByIds($ass_id, $this->user->getId());
139 
140  if ($state->isSubmissionAllowed()) {
141  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
142  $submit_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "finalize");
143  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
144  return $ui->factory()->button()->primary($lng->txt("blog_finalize_blog"), $submit_link);
145  }
146  return null;
147  }
148 
154  int $ass_id
155  ): ?\ILIAS\UI\Component\Button\Standard {
156  $ilCtrl = $this->ctrl;
157  $lng = $this->lng;
158  $ui = $this->ui;
159 
160  // submitted files
161  $submission = new ilExSubmission(new ilExAssignment($ass_id), $this->user->getId());
162  if ($submission->hasSubmitted()) {
163  // #16888
164  $submitted = $submission->getSelectedObject();
165  if ($submitted["ts"] != "") {
166  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", $ass_id);
167  $dl_link = $ilCtrl->getLinkTargetByClass("ilblogexercisegui", "downloadExcSubFile");
168  $ilCtrl->setParameterByClass("ilblogexercisegui", "ass", "");
169  return $ui->factory()->button()->standard($lng->txt("blog_download_submission"), $dl_link);
170  }
171  }
172  return null;
173  }
174 
175 
176  public function getActionButtons(): array
177  {
178  $be = $this->blog_exercise;
179 
180  $buttons = [];
181  foreach ($be->getAssignmentsOfBlog() as $exercise) {
182  $ass_id = $exercise["ass_id"];
183  $buttons[$ass_id] = [];
184  $submit_button = $this->getSubmitButton($ass_id);
185  if ($submit_button) {
186  $buttons[$ass_id][] = $submit_button;
187  }
188  $download_button = $this->getDownloadSubmissionButton($ass_id);
189  if ($download_button) {
190  $buttons[$ass_id][] = $download_button;
191  }
192  }
193 
194  return $buttons;
195  }
196 }
ILIAS Blog Exercise BlogExercise $blog_exercise
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.
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 .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupName(int $a_user_id)
lookup user name
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)
getDownloadSubmissionButton(int $ass_id)
static _lookupTitle(int $obj_id)
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
__construct(int $a_node_id, \ILIAS\Blog\Exercise\BlogExercise $blog_exercise, ilLanguage $lng, ilObjUser $user, \ILIAS\Blog\InternalGUIService $gui)
ILIAS DI UIServices $ui
static initGUIForSubmit(int $a_ass_id, int $a_user_id=null)
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