ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestArchiveService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 {
30 
31  public function __construct(
32  protected ilObjTest $test_obj,
33  protected ilLanguage $lng,
34  protected ilObjectDataCache $obj_cache,
35  protected ilTestHTMLGenerator $html_generator
36  ) {
37  $this->participantData = null;
38  }
39 
41  {
43  }
44 
45  public function setParticipantData(ilTestParticipantData $participantData): void
46  {
47  $this->participantData = $participantData;
48  }
49 
50  public function archivePassesByActives($passesByActives): void
51  {
52  foreach ($passesByActives as $activeId => $passes) {
53  foreach ($passes as $pass) {
54  $this->archiveActivesPass($activeId, $pass);
55  }
56  }
57  }
58 
59  public function archiveActivesPass(int $active_id, int $pass): void
60  {
61  $content = $this->renderOverviewContent($active_id, $pass);
62  $filename = $this->buildOverviewFilename($active_id, $pass);
63  $this->html_generator->generateHTML($content, $filename);
64  $archiver = new ilTestArchiver($this->test_obj->getId());
65  $archiver->setParticipantData($this->getParticipantData());
66  $archiver->handInTestResult($active_id, $pass, $filename);
67  $archiver->handInParticipantUploadedResults($active_id, $pass, $this->test_obj);
68  unlink($filename);
69  }
70 
76  private function renderOverviewContent($activeId, $pass): string
77  {
78  $results = $this->test_obj->getTestResult(
79  $activeId,
80  $pass,
81  false
82  );
83 
84  $gui = new ilTestServiceGUI($this->test_obj);
85  $testResultHeaderLabelBuilder = new ilTestResultHeaderLabelBuilder($this->lng, $this->obj_cache);
86 
87  return $gui->getPassListOfAnswers(
88  $results,
89  $activeId,
90  $pass,
91  true,
92  false,
93  false,
94  true,
95  false,
96  null,
97  $testResultHeaderLabelBuilder
98  );
99  }
100 
106  private function buildOverviewFilename($activeId, $pass): string
107  {
108  $tmpFileName = ilFileUtils::ilTempnam();
109  return dirname($tmpFileName) . '/scores-' . $this->test_obj->getId() . '-' . $activeId . '-' . $pass . '.html';
110  }
111 }
renderOverviewContent($activeId, $pass)
__construct(protected ilObjTest $test_obj, protected ilLanguage $lng, protected ilObjectDataCache $obj_cache, protected ilTestHTMLGenerator $html_generator)
setParticipantData(ilTestParticipantData $participantData)
archiveActivesPass(int $active_id, int $pass)
archivePassesByActives($passesByActives)
$lng
$results
$filename
Definition: buildRTE.php:78
Class that handles PDF generation for test and assessment.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
Class ilTestArchiver.
Service GUI class for tests.
buildOverviewFilename($activeId, $pass)
ilTestParticipantData $participantData
setParticipantData($participantData)