ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
TestError.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test\Logging;
22 
28 
30 {
31  public const IDENTIFIER = 'te';
32 
33  private int $id;
34 
35  public function __construct(
36  private readonly int $test_ref_id,
37  private readonly ?int $question_id,
38  private readonly ?int $admin_id,
39  private readonly ?int $pax_id,
40  private readonly TestErrorTypes $interaction_type,
41  private readonly int $modification_timestamp,
42  private readonly string $error_message
43  ) {
44 
45  }
46 
47  public function getUniqueIdentifier(): ?string
48  {
49  return self::IDENTIFIER . '_' . $this->id;
50  }
51 
52  public function withId(int $id): self
53  {
54  $clone = clone $this;
55  $clone->id = $id;
56  return $clone;
57  }
58 
59  public function getLogEntryAsDataTableRow(
61  TitleColumnsBuilder $title_builder,
62  DataRowBuilder $row_builder,
63  array $environment
64  ): DataRow {
65  $admin = $this->getUserForPresentation($this->admin_id);
66  $pax = $this->getUserForPresentation($this->pax_id);
67 
68  $values = [
69  'date_and_time' => \DateTimeImmutable::createFromFormat('U', (string) $this->modification_timestamp)
70  ->setTimezone($environment['timezone']),
71  'corresponding_test' => $title_builder->buildTestTitleAsLink(
72  $this->test_ref_id
73  ),
74  'admin' => $admin,
75  'participant' => $pax,
76  'log_entry_type' => $lng->txt(self::LANG_VAR_PREFIX . self::IDENTIFIER),
77  'interaction_type' => $lng->txt(self::LANG_VAR_PREFIX . $this->interaction_type->value)
78  ];
79 
80  if ($this->question_id !== null) {
81  $values['question'] = $title_builder->buildQuestionTitleAsLink(
82  $this->question_id,
83  $this->test_ref_id
84  );
85  }
86 
87  return $row_builder->buildDataRow(
88  $this->getUniqueIdentifier(),
89  $values
90  );
91  }
92 
93  public function getLogEntryAsExportRow(
95  TitleColumnsBuilder $title_builder,
96  AdditionalInformationGenerator $additional_info,
97  array $environment
98  ): array {
99  $admin = $this->getUserForPresentation($this->admin_id);
100  $pax = $this->getUserForPresentation($this->pax_id);
101 
102  return [
103  \DateTimeImmutable::createFromFormat('U', (string) $this->modification_timestamp)
104  ->setTimezone($environment['timezone'])
105  ->format($environment['date_format']),
106  $title_builder->buildTestTitleAsText($this->test_ref_id),
107  $admin,
108  $pax,
109  '',
110  $title_builder->buildQuestionTitleAsText($this->question_id),
111  $lng->txt(self::LANG_VAR_PREFIX . self::IDENTIFIER),
112  $lng->txt(self::LANG_VAR_PREFIX . $this->interaction_type->value),
113  $this->error_message
114  ];
115  }
116 
118  AdditionalInformationGenerator $additional_info,
119  UIFactory $ui_factory,
120  array $environment
121  ): Content {
122  return $ui_factory->legacy()->content($this->error_message);
123  }
124 
125  public function toStorage(): array
126  {
127  return [
128  'ref_id' => [\ilDBConstants::T_INTEGER , $this->test_ref_id],
129  'qst_id' => [\ilDBConstants::T_INTEGER , $this->question_id],
130  'admin_id' => [\ilDBConstants::T_INTEGER , $this->admin_id],
131  'pax_id' => [\ilDBConstants::T_INTEGER , $this->pax_id],
132  'interaction_type' => [\ilDBConstants::T_TEXT , $this->interaction_type->value],
133  'modification_ts' => [\ilDBConstants::T_INTEGER , $this->modification_timestamp],
134  'error_message' => [\ilDBConstants::T_TEXT , $this->error_message]
135  ];
136  }
137 
138  private function getUserForPresentation(?int $user_id): string
139  {
140  if ($user_id === null) {
141  return '';
142  }
143  return \ilUserUtil::getNamePresentation(
144  $user_id,
145  false,
146  false,
147  '',
148  true
149  );
150  }
151 }
getLogEntryAsDataTableRow(\ilLanguage $lng, TitleColumnsBuilder $title_builder, DataRowBuilder $row_builder, array $environment)
Definition: TestError.php:59
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...
getUserForPresentation(?int $user_id)
Definition: TestError.php:138
buildDataRow(string $id, array $record)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private readonly int $test_ref_id, private readonly ?int $question_id, private readonly ?int $admin_id, private readonly ?int $pax_id, private readonly TestErrorTypes $interaction_type, private readonly int $modification_timestamp, private readonly string $error_message)
Definition: TestError.php:35
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildQuestionTitleAsLink(int $question_id, int $test_ref_id)
global $lng
Definition: privfeed.php:31
getLogEntryAsExportRow(\ilLanguage $lng, TitleColumnsBuilder $title_builder, AdditionalInformationGenerator $additional_info, array $environment)
Definition: TestError.php:93
getParsedAdditionalInformation(AdditionalInformationGenerator $additional_info, UIFactory $ui_factory, array $environment)
Definition: TestError.php:117