ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilCSVTestExport.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  protected string $content;
27 
28  public function withAllResults(): self
29  {
30  $rows = $this->getDatarows($this->test_obj);
31  $separator = ";";
32  $csv = "";
33  foreach ($rows as $evalrow) {
34  $csvrow = $this->test_obj->processCSVRow($evalrow, true, $separator);
35  $csv .= implode($separator, $csvrow) . "\n";
36  }
37  $this->content = $csv;
38  return $this;
39  }
40 
41  public function withAggregatedResults(): self
42  {
43  $data = $this->test_obj->getAggregatedResultsData();
44  $rows = [];
45  $rows[] = [
46  $this->lng->txt("result"),
47  $this->lng->txt("value")
48  ];
49  foreach ($data["overview"] as $key => $value) {
50  $rows[] = [
51  $key,
52  $value
53  ];
54  }
55  $rows[] = [
56  $this->lng->txt("question_id"),
57  $this->lng->txt("question_title"),
58  $this->lng->txt("average_reached_points"),
59  $this->lng->txt("points"),
60  $this->lng->txt("percentage"),
61  $this->lng->txt("number_of_answers")
62  ];
63  foreach ($data["questions"] as $key => $value) {
64  $rows[] = [
65  $key,
66  $value[0],
67  $value[4],
68  $value[5],
69  $value[6],
70  $value[3]
71  ];
72  }
73  $csv = "";
74  $separator = ";";
75  foreach ($rows as $evalrow) {
76  $csvrow = $this->test_obj->processCSVRow($evalrow, true, $separator);
77  $csv .= implode($separator, $csvrow) . "\n";
78  }
79  $this->content = $csv;
80  return $this;
81  }
82 
83 
84  public function deliver(string $title): void
85  {
86  ilUtil::deliverData($this->content, ilFileUtils::getASCIIFilename($title . ".csv"));
87  exit;
88  }
89 
90  public function getContent(): string
91  {
92  return $this->content;
93  }
94 }
exit
Definition: login.php:29
getDatarows(ilObjTest $test_obj)
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
static getASCIIFilename(string $a_filename)
string $key
Consumer key/client ID value.
Definition: System.php:193
deliver(string $title)