ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExcAssMemberState.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
33 {
37  protected $ass_id;
38 
42  protected $user_id;
43 
47  protected $assignment;
48 
52  protected $member_id;
53 
57  protected $team_id = 0;
58 
62  protected $is_team = false;
63 
69  protected function __construct(ilExAssignment $a_ass, ilObjUser $a_user, ilExcIndividualDeadline $a_idl, $a_time, ilLanguage $lng, ilExAssignmentTeam $a_team = null)
70  {
71  $this->time = $a_time;
72  $this->ass_id = $a_ass->getId();
73  $this->user_id = $a_user->getId();
74  $this->member_id = $a_user->getId();
75  $this->lng = $lng;
76 
77  $this->assignment = $a_ass;
78 
79  // check team status
80  $this->is_team = false;
81  if ($this->assignment->getType() == ilExAssignment::TYPE_UPLOAD_TEAM) {
82  if ($a_team->getId()) {
83  $this->member_id = $a_team->getId();
84  $this->team_id = $a_team->getId();
85  $this->is_team = true;
86  }
87  }
88 
89  $this->idl = $a_idl;
90  }
91 
99  public static function getInstanceByIds($a_ass_id, $a_user_id = 0)
100  {
101  global $DIC;
102 
103  $lng = $DIC->language();
104  $user = ($a_user_id > 0)
105  ? new ilObjUser($a_user_id)
106  : $DIC->user();
107 
108  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
109  $ass = new ilExAssignment($a_ass_id);
110 
111  $member_id = $user->getId();
112  $is_team = false;
113  $team = null;
114  if ($ass->getType() == ilExAssignment::TYPE_UPLOAD_TEAM) { // better move this to ilExcIndividualDeadline
115  include_once("./Modules/Exercise/classes/class.ilExAssignmentTeam.php");
116  $team = ilExAssignmentTeam::getInstanceByUserId($a_ass_id, $user->getId());
117  if ($team->getId()) {
118  $member_id = $team->getId();
119  $is_team = true;
120  }
121  }
122 
123  // note: team may be not null, but is_team still false
124  include_once("./Modules/Exercise/classes/class.ilExcIndividualDeadline.php");
126 
127  return self::getInstance($ass, $user, $idl, time(), $lng, $team);
128  }
129 
135  public static function getInstance(ilExAssignment $a_ass, ilObjUser $a_user, ilExcIndividualDeadline $a_idl, $a_time, ilLanguage $lng, ilExAssignmentTeam $a_team = null)
136  {
137  return new self($a_ass, $a_user, $a_idl, $a_time, $lng, $a_team);
138  }
139 
145  public function getIndividualDeadlineObject()
146  {
147  return $this->idl;
148  }
149 
150 
157  public function getGeneralStart()
158  {
159  return $this->assignment->getStartTime();
160  }
161 
167  public function getGeneralStartPresentation()
168  {
169  if ($this->getGeneralStart()) {
170  return $this->getTimePresentation($this->getGeneralStart());
171  }
172  return "";
173  }
174 
180  public function getIndividualStart()
181  {
182  if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
183  return $this->idl->getStartingTimestamp();
184  }
185  return 0;
186  }
187 
188 
194  public function hasGenerallyStarted()
195  {
196  return !$this->assignment->notStartedYet();
197  }
198 
204  public function getCalculatedDeadline()
205  {
206  $calculated_deadline = 0;
207  if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
208  if ($this->idl->getStartingTimestamp() && $this->assignment->getRelativeDeadline()) {
209  $calculated_deadline = $this->idl->getStartingTimestamp() + ($this->assignment->getRelativeDeadline() * 24 * 60 * 60);
210  }
211  }
212  return $calculated_deadline;
213  }
214 
220  public function getRelativeDeadline()
221  {
222  if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
223  return $this->assignment->getRelativeDeadline();
224  }
225  return 0;
226  }
227 
234  {
235  if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_RELATIVE) {
236  return $this->getRelativeDeadline() . " " . $this->lng->txt("days");
237  }
238  return "";
239  }
240 
248  public function getOfficialDeadline()
249  {
250  $dl = $this->idl->getIndividualDeadline(); // team or user individual deadline
251 
252  if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_ABSOLUTE) { // absolute deadline
253  return max($this->assignment->getDeadline(), $dl); // take what's greater: idl or abs deadline
254  }
255 
256  // relative deadline: take max idl or calculated deadline
257  return max($this->getCalculatedDeadline(), $dl);
258  }
259 
260 
267  {
268  if ($this->getOfficialDeadline() > 0) {
269  return $this->getTimePresentation($this->getOfficialDeadline());
270  }
271 
272  return "";
273  }
274 
280  public function exceededOfficialDeadline()
281  {
282  $od = $this->getOfficialDeadline();
283  if ($od && $od < time()) {
284  return true;
285  }
286  return false;
287  }
288 
296  {
297  $lng = $this->lng;
298  $official_deadline = $this->getOfficialDeadline();
299  if ($official_deadline == 0) {
300  return $lng->txt("exc_no_deadline_specified");
301  }
302  if ($official_deadline - $this->time <= 0) {
303  $time_str = $lng->txt("exc_time_over_short");
304  } else {
305  $time_str = ilUtil::period2String(new ilDateTime($official_deadline, IL_CAL_UNIX));
306  }
307 
308  return $time_str;
309  }
310 
316  public function getIndividualDeadline()
317  {
318  if ($this->idl->getIndividualDeadline() > $this->getCommonDeadline()) {
319  return $this->idl->getIndividualDeadline();
320  }
321  return 0;
322  }
323 
324 
331  {
332  if ($this->getIndividualDeadline() > 0) {
333  return $this->getTimePresentation($this->getIndividualDeadline());
334  }
335 
336  return "";
337  }
338 
344  public function getCommonDeadline()
345  {
346  if ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_ABSOLUTE) { // absolute deadline
347  return $this->assignment->getDeadline();
348  }
349 
350  return $this->getCalculatedDeadline();
351  }
352 
359  {
360  if ($this->getCommonDeadline() > 0) {
361  return $this->getTimePresentation($this->getCommonDeadline());
362  }
363 
364  return "no deadline";
365  }
366 
372  public function getEffectiveDeadline()
373  {
374  return max($this->getOfficialDeadline(), $this->assignment->getExtendedDeadline());
375  }
376 
382  public function getPeerReviewDeadline()
383  {
384  if ($this->assignment->getPeerReview() &&
385  $this->assignment->getPeerReviewDeadline()) {
386  return $this->assignment->getPeerReviewDeadline();
387  }
388  return 0;
389  }
390 
397  {
398  if ($this->getPeerReviewDeadline() > 0) {
399  return $this->getTimePresentation($this->getPeerReviewDeadline());
400  }
401 
402  return "no peer review deadline";
403  }
404 
410  public function isPeerReviewAllowed()
411  {
412  if ($this->assignment->getPeerReview() && $this->hasSubmissionEndedForAllUsers()
413  && ($this->getPeerReviewDeadline() == 0 || $this->getPeerReviewDeadline() > $this->time)) {
414  return true;
415  }
416 
417  return false;
418  }
419 
425  protected function getTimePresentation($a_timestamp)
426  {
427  if ($a_timestamp > 0) {
428  return ilDatePresentation::formatDate(new ilDateTime($a_timestamp, IL_CAL_UNIX));
429  }
430 
431  return "";
432  }
433 
439  public function areInstructionsVisible()
440  {
441  return $this->hasSubmissionStarted();
442  }
443 
450  /*
451  function getLateSubmissionWarning()
452  {
453  $lng = $this->lng;
454  $late_dl = "";
455 
456  // official deadline is done, but submission still allowed
457  if ($this->inLateSubmissionPhase())
458  {
459  // extended deadline date should not be presented anywhere
460  $late_dl = $this->getTimePresentation($this->getOfficialDeadline());
461  $late_dl = "<br />".sprintf($lng->txt("exc_late_submission_warning"), $late_dl);
462  $late_dl = '<span class="warning">'.$late_dl.'</span>';
463  }
464 
465  return $late_dl;
466  }*/
467 
474  public function inLateSubmissionPhase()
475  {
476  // official deadline is done, but submission still allowed
477  if ($this->getOfficialDeadline() &&
478  $this->getOfficialDeadline() < $this->time &&
479  $this->isSubmissionAllowed()) {
480  return true;
481  }
482  return false;
483  }
484 
485 
493  public function hasSubmissionStarted()
494  {
495  if ($this->hasGenerallyStarted() && ($this->assignment->getDeadlineMode() == ilExAssignment::DEADLINE_ABSOLUTE ||
496  $this->getIndividualStart() > 0)) {
497  return true;
498  }
499  return false;
500  }
501 
507  public function hasSubmissionEnded()
508  {
509  if ($this->getEffectiveDeadline() == 0) {
510  return false;
511  }
512 
513  if ($this->time > $this->getEffectiveDeadline()) {
514  return true;
515  }
516  return false;
517  }
518 
526  {
527  $global_subm_end = max($this->getEffectiveDeadline(), $this->assignment->getLastPersonalDeadline());
528 
529  if ($global_subm_end == 0) {
530  return false;
531  }
532 
533  if ($this->time > $global_subm_end) {
534  return true;
535  }
536  return false;
537  }
538 
539 
540 
547  public function isSubmissionAllowed()
548  {
549  if ($this->hasSubmissionStarted() && !$this->hasSubmissionEnded()) {
550  return true;
551  }
552  return false;
553  }
554 
560  public function isGlobalFeedbackFileAccessible(ilExSubmission $submission)
561  {
562  $access = false;
563 
564  if (!$this->assignment->getFeedbackFile()) {
565  return false;
566  }
567 
568  // global feedback / sample solution
569  if ($this->assignment->getFeedbackDate() == ilExAssignment::FEEDBACK_DATE_DEADLINE) {
570  $access = $this->hasSubmissionEndedForAllUsers();
571  } elseif ($this->assignment->getFeedbackDate() == ilExAssignment::FEEDBACK_DATE_CUSTOM) {
572  $access = $this->assignment->afterCustomDate();
573  } else {
574  $access = $submission->hasSubmitted();
575  }
576 
577  return $access;
578  }
579 }
getCommonDeadlinePresentation()
Get common deadline presentation.
getIndividualStart()
Get individual start.
Exercise assignment.
isSubmissionAllowed()
Is submission currently allowed.
global $DIC
Definition: saml.php:7
exceededOfficialDeadline()
Check if official deadline exists and has ended.
getEffectiveDeadline()
Get effective deadline (max of official deadline and grace end period) for the user.
getId()
Get assignment id.
getGeneralStart()
Get general start.
inLateSubmissionPhase()
Get late submission warning.
getPeerReviewDeadline()
Get peer review deadline.
getOfficialDeadlinePresentation()
Get official deadline presentation.
hasSubmissionEnded()
Check if the submission phase has ended for the current user.
Exercise assignment team.
getRelativeDeadline()
Get relative deadline.
const IL_CAL_UNIX
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
Handles everything about the state (current phase) of a user in an assignment using assignment...
isPeerReviewAllowed()
Is submission currently allowed.
$time
Definition: cron.php:21
hasSubmissionStarted()
Check if the submission phase has started for the current user.
hasSubmissionEndedForAllUsers()
Has submission ended for all users.
getId()
get object id public
$lng
getGeneralStartPresentation()
Get start presentation.
static getInstanceByUserId($a_assignment_id, $a_user_id, $a_create_on_demand=false)
getIndividualDeadlinePresentation()
Get common deadline presentation.
static getInstance($a_ass_id, $a_participant_id, $a_is_team=false)
Get instance.
static period2String(ilDateTime $a_from, $a_to=null)
Return a string of time period.
Date and time handling
__construct(ilExAssignment $a_ass, ilObjUser $a_user, ilExcIndividualDeadline $a_idl, $a_time, ilLanguage $lng, ilExAssignmentTeam $a_team=null)
ilExcAssMemberState constructor.
getCalculatedDeadline()
Calculated deadline is only given, if a relative deadline is given and the user started the assignmen...
$user
Definition: migrateto20.php:57
getCommonDeadline()
Get common deadline (no individual deadline or grace period included)
getRemainingTimePresentation()
Remaining time presentation (based on official deadline)
getOfficialDeadline()
Get official deadline (individual deadline, fixed deadline or calculated deadline (using relative dea...
isGlobalFeedbackFileAccessible(ilExSubmission $submission)
Is global feedback file accessible?
getIndividualDeadlineObject()
Get individual deadline object.
getPeerReviewDeadlinePresentation()
Get common deadline presentation.
Exercise submission //TODO: This class has to much static methods related to delivered "files"...
language handling
getTimePresentation($a_timestamp)
Get common deadline presentation.
getIndividualDeadline()
Get individual deadline.
static getInstance(ilExAssignment $a_ass, ilObjUser $a_user, ilExcIndividualDeadline $a_idl, $a_time, ilLanguage $lng, ilExAssignmentTeam $a_team=null)
Get instance by dependencies.
getRelativeDeadlinePresentation()
Get relative deadline presentation.
areInstructionsVisible()
Instructions visible.