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