ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AttemptOverview.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 
31 {
32  public function __construct(
33  private readonly int $active_id,
34  private readonly int $attempt_id,
35  private readonly ResultPresentationSettings $settings,
36  private readonly string $exam_id = '',
37  private readonly float $reached_points = 0.0,
38  private readonly float $available_points = 0.0,
39  private readonly ?Mark $mark = null,
40  private readonly int $nr_of_answered_questions = 0,
41  private readonly int $nr_of_questions_in_attempt = 0,
42  private readonly ?int $requested_hints_count = null,
43  private readonly int $time_on_task = 0,
44  private readonly int $total_time_on_task = 0,
45  private readonly ?\DateTimeImmutable $attempt_started_date = null,
46  private readonly ?\DateTimeImmutable $last_access = null,
47  private readonly int $nr_of_attempts = 0,
48  private readonly ?int $scored_attempt = null,
49  private readonly ?int $rank = 0,
50  private readonly StatusOfAttempt $status_of_attempt = StatusOfAttempt::NOT_YET_STARTED
51  ) {
52  }
53 
54  public function getActiveId(): int
55  {
56  return $this->active_id;
57  }
58 
59  public function getAttempt(): int
60  {
61  return $this->attempt_id;
62  }
63 
64  public function getExamId(): string
65  {
66  return $this->exam_id;
67  }
68 
69  public function getStartedDate(): ?\DateTimeImmutable
70  {
71  return $this->attempt_started_date;
72  }
73 
74  public function getNrOfAnsweredQuestions(): int
75  {
76  return $this->nr_of_answered_questions;
77  }
78 
79  public function getNrOfTotalQuestions(): int
80  {
81  return $this->nr_of_questions_in_attempt;
82  }
83 
84  public function hasAnsweredQuestions(): bool
85  {
86  return $this->nr_of_answered_questions > 0;
87  }
88 
89  public function getMark(): ?string
90  {
91  return $this->mark?->getShortName();
92  }
93 
94  public function hasPassingMark(): bool
95  {
96  return $this->mark?->getPassed() ?? false;
97  }
98 
99  public function getReachedPoints(): float
100  {
101  return $this->reached_points;
102  }
103 
104  public function getAvailablePoints(): float
105  {
106  return $this->available_points;
107  }
108 
109  public function getReachedPointsInPercent(): float
110  {
111  if ($this->reached_points === 0.0 || $this->available_points === 0.0) {
112  return 0.0;
113  }
114  return $this->reached_points / $this->available_points * 100;
115  }
116 
118  {
119  return $this->status_of_attempt;
120  }
121 
122  public function getNrOfAttempts(): int
123  {
124  return $this->nr_of_attempts;
125  }
126 
127  public function getAsDescriptiveListing(
128  Language $lng,
129  UIFactory $ui_factory,
130  array $environment
131  ): DescriptiveListing {
132  $items = [
133  $lng->txt('tst_stat_result_resultspoints') => $this->reached_points
134  . ' ' . strtolower($lng->txt('of')) . ' ' . $this->available_points
135  . ' (' . sprintf('%2.2f', $this->getReachedPointsInPercent()) . ' %)',
136  $lng->txt('tst_stat_result_resultsmarks') => $this->mark?->getShortName() ?? ''
137  ];
138 
139  if ($this->settings->getShowHints()) {
140  $items[$lng->txt('tst_question_hints_requested_hint_count_header')] = (string) $this->requested_hints_count;
141  }
142 
143  return $ui_factory->listing()->descriptive(
144  $items + [
145  $lng->txt('tst_stat_result_timeontask') => $this->buildHumanReadableTime($this->time_on_task),
146  $lng->txt('tst_stat_result_firstvisit') => $this->attempt_started_date
147  ?->setTimezone($environment['timezone'])
148  ->format($environment['datetimeformat']) ?? '',
149  $lng->txt('tst_stat_result_lastvisit') => $this->last_access
150  ?->setTimezone($environment['timezone'])
151  ->format($environment['datetimeformat']) ?? '',
152  $lng->txt('tst_nr_of_passes') => (string) $this->nr_of_attempts,
153  $lng->txt('scored_pass') => (string) ($this->scored_attempt + 1),
154  $lng->txt('tst_stat_result_rank_participant') => (string) $this->rank
155  ]
156  );
157  }
158 
159  public function getHumanReadableTotalTimeOnTask(): string
160  {
161  return $this->buildHumanReadableTime($this->total_time_on_task);
162  }
163 
164  private function buildHumanReadableTime(int $time): string
165  {
166  $diff_seconds = $time;
167  $diff_hours = floor($diff_seconds / 3600);
168  $diff_seconds -= $diff_hours * 3600;
169  $diff_minutes = floor($diff_seconds / 60);
170  $diff_seconds -= $diff_minutes * 60;
171  return sprintf("%02d:%02d:%02d", $diff_hours, $diff_minutes, $diff_seconds);
172  }
173 }
A class defining marks for assessment test objects.
Definition: Mark.php:35
__construct(private readonly int $active_id, private readonly int $attempt_id, private readonly ResultPresentationSettings $settings, private readonly string $exam_id='', private readonly float $reached_points=0.0, private readonly float $available_points=0.0, private readonly ?Mark $mark=null, private readonly int $nr_of_answered_questions=0, private readonly int $nr_of_questions_in_attempt=0, private readonly ?int $requested_hints_count=null, private readonly int $time_on_task=0, private readonly int $total_time_on_task=0, private readonly ?\DateTimeImmutable $attempt_started_date=null, private readonly ?\DateTimeImmutable $last_access=null, private readonly int $nr_of_attempts=0, private readonly ?int $scored_attempt=null, private readonly ?int $rank=0, private readonly StatusOfAttempt $status_of_attempt=StatusOfAttempt::NOT_YET_STARTED)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
txt(string $a_topic, string $a_default_lang_fallback_mod="")
getAsDescriptiveListing(Language $lng, UIFactory $ui_factory, array $environment)
global $lng
Definition: privfeed.php:31