ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilPortfolioExerciseGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "Modules/Exercise/classes/class.ilExAssignment.php";
6 include_once "Modules/Exercise/classes/class.ilExSubmission.php";
7 
17 {
18  protected $user_id; // [int]
19  protected $obj_id; // [int]
20  protected $ass_id; // [int]
21  protected $file; // [string]
22 
23  public function __construct($a_user_id, $a_obj_id)
24  {
25  $this->user_id = $a_user_id;
26  $this->obj_id = $a_obj_id;
27  $this->ass_id = (int)$_GET["ass"];
28  $this->file = trim($_GET["file"]);
29  }
30 
31  function executeCommand()
32  {
33  global $ilCtrl;
34 
35  if(!$this->ass_id ||
36  !$this->user_id)
37  {
38  $this->ctrl->returnToParent($this);
39  }
40 
41  $next_class = $ilCtrl->getNextClass($this);
42  $cmd = $ilCtrl->getCmd();
43 
44  switch($next_class)
45  {
46  default:
47  $this->$cmd();
48  break;
49  }
50 
51  return true;
52  }
53 
54  public static function checkExercise($a_user_id, $a_obj_id, $a_add_submit = false)
55  {
56  global $tree;
57 
58  $info = array();
59 
60  $exercises = ilExSubmission::findUserFiles($a_user_id, $a_obj_id);
61  // #0022794
62  if (!$exercises)
63  {
64  $exercises = ilExSubmission::findUserFiles($a_user_id, $a_obj_id.".sec");
65  }
66  if($exercises)
67  {
68  foreach($exercises as $exercise)
69  {
70  // #9988
71  $active_ref = false;
72  foreach(ilObject::_getAllReferences($exercise["obj_id"]) as $ref_id)
73  {
74  if(!$tree->isSaved($ref_id))
75  {
76  $active_ref = true;
77  break;
78  }
79  }
80  if($active_ref)
81  {
82  $part = self::getExerciseInfo($a_user_id, $exercise["ass_id"], $a_add_submit);
83  if($part)
84  {
85  $info[] = $part;
86  }
87  }
88  }
89  if(sizeof($info))
90  {
91  return implode("<br />", $info);
92  }
93  }
94  }
95 
96  protected static function getExerciseInfo($a_user_id, $a_assignment_id, $a_add_submit = false)
97  {
98  global $lng, $ilCtrl;
99 
100  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
101  $ass = new ilExAssignment($a_assignment_id);
102  $exercise_id = $ass->getExerciseId();
103  if(!$exercise_id)
104  {
105  return;
106  }
107 
108  // is the assignment still open?
109  $times_up = $ass->afterDeadlineStrict();
110 
111  // exercise goto
112  include_once "./Services/Link/classes/class.ilLink.php";
113  $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
114  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
115 
116  $info = sprintf($lng->txt("prtf_exercise_info"),
117  $ass->getTitle(),
118  "<a href=\"".$exc_link."\">".
119  ilObject::_lookupTitle($exercise_id)."</a>");
120 
121  // submit button
122  if($a_add_submit && !$times_up)
123  {
124  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
125  $submit_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "finalize");
126  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
127 
128  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
129  $button = ilLinkButton::getInstance();
130  $button->setCaption("prtf_finalize_portfolio");
131  $button->setPrimary(true);
132  $button->setUrl($submit_link);
133  $info .= " ".$button->render();
134  }
135 
136  // submitted files
137  include_once "Modules/Exercise/classes/class.ilExSubmission.php";
138  $submission = new ilExSubmission($ass, $a_user_id);
139  if($submission->hasSubmitted())
140  {
141  // #16888
142  $submitted = $submission->getSelectedObject();
143 
144  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
145  $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcSubFile");
146  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
147 
150 
151  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
152  $button = ilLinkButton::getInstance();
153  $button->setCaption("download");
154  $button->setUrl($dl_link);
155 
156  $info .= "<br />".sprintf($lng->txt("prtf_exercise_submitted_info"),
158  $button->render());
159 
161  }
162 
163 
164  // work instructions incl. files
165 
166  $tooltip = "";
167 
168  $inst = $ass->getInstruction();
169  if($inst)
170  {
171  $tooltip .= nl2br($inst);
172  }
173 
174  $ass_files = $ass->getFiles();
175  if (count($ass_files) > 0)
176  {
177  if($tooltip)
178  {
179  $tooltip .= "<br /><br />";
180  }
181 
182  foreach($ass_files as $file)
183  {
184  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", $a_assignment_id);
185  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", urlencode($file["name"]));
186  $dl_link = $ilCtrl->getLinkTargetByClass("ilportfolioexercisegui", "downloadExcAssFile");
187  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "file", "");
188  $ilCtrl->setParameterByClass("ilportfolioexercisegui", "ass", "");
189 
190  $tooltip .= $file["name"].": <a href=\"".$dl_link."\">".
191  $lng->txt("download")."</a>";
192  }
193  }
194 
195  if($tooltip)
196  {
197  $ol_id = "exc_ass_".$a_assignment_id;
198 
199  include_once "Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
200  $overlay = new ilOverlayGUI($ol_id);
201 
202  // overlay
203  $overlay->setAnchor($ol_id."_tr");
204  $overlay->setTrigger($ol_id."_tr", "click", $ol_id."_tr");
205  $overlay->setAutoHide(false);
206  // $overlay->setCloseElementId($cl_id);
207  $overlay->add();
208 
209  // trigger
210  $overlay->addTrigger($ol_id."_tr", "click", $ol_id."_tr");
211 
212  $info .= "<div id=\"".$ol_id."_tr\"><a href=\"#\">".$lng->txt("exc_instruction")."</a></div>".
213  "<div id=\"".$ol_id."\" style=\"display:none; background-color:white; border: 1px solid #bbb; padding: 10px;\">".$tooltip."</div>";
214  }
215 
216  return $info;
217  }
218 
220  {
221  if($this->file)
222  {
223  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
224  $ass = new ilExAssignment($this->ass_id);
225  $ass_files = $ass->getFiles();
226  if (count($ass_files) > 0)
227  {
228  foreach($ass_files as $file)
229  {
230  if($file["name"] == $this->file)
231  {
232  ilUtil::deliverFile($file["fullpath"], $file["name"]);
233  }
234  }
235  }
236  }
237  }
238 
240  {
241  $ass = new ilExAssignment($this->ass_id);
242  $submission = new ilExSubmission($ass, $this->user_id);
243  $submitted = $submission->getFiles();
244  if (count($submitted) > 0)
245  {
246  $submitted = array_pop($submitted);
247 
248  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
249  $title = ilObject::_lookupTitle($submitted["obj_id"])." - ".
250  $ass->getTitle()." - ".
251  $user_data["firstname"]." ".
252  $user_data["lastname"]." (".
253  $user_data["login"].").zip";
254 
255  ilUtil::deliverFile($submitted["filename"], $title);
256  }
257  }
258 
262  protected function finalize()
263  {
264  global $lng, $ilCtrl;
265 
266  include_once "Modules/Exercise/classes/class.ilExSubmissionBaseGUI.php";
267  include_once "Modules/Exercise/classes/class.ilExSubmissionObjectGUI.php";
268  $exc_gui = ilExSubmissionObjectGUI::initGUIForSubmit($this->ass_id);
269  $exc_gui->submitPortfolio($this->obj_id);
270 
271  ilUtil::sendSuccess($lng->txt("prtf_finalized"), true);
272  $ilCtrl->returnToParent($this);
273  }
274 }
275 
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupName($a_user_id)
lookup user name
Exercise assignment.
const IL_CAL_DATETIME
$_GET["client_id"]
static getExerciseInfo($a_user_id, $a_assignment_id, $a_add_submit=false)
$cmd
Definition: sahs_server.php:35
static setUseRelativeDates($a_status)
set use relative dates
static _lookupTitle($a_id)
lookup object title
Class ilPortfolioExerciseGUI.
static _getAllReferences($a_id)
get all reference ids of object
static useRelativeDates()
check if relative dates are used
global $ilCtrl
Definition: ilias.php:18
static initGUIForSubmit($a_ass_id, $a_user_id=null)
$info
Definition: example_052.php:80
This is a utility class for the yui overlays.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
Reload workbook from saved file
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Create styles array
The data for the language used.
static findUserFiles($a_user_id, $a_filetitle)
Check if given file was assigned.
static checkExercise($a_user_id, $a_obj_id, $a_add_submit=false)
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
finalize()
Finalize and submit portfolio to exercise.
Exercise submission.
__construct($a_user_id, $a_obj_id)