ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.assFormulaQuestionUnit.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private int $id = 0;
29 private string $unit = '';
30 private float $factor = 0.0;
31 private int $category = 0;
32 private int $sequence = 0;
33 private int $baseunit = 0;
34 private ?string $baseunit_title = null;
35
36 public function initFormArray(array $data): void
37 {
38 $this->id = (int) $data['unit_id'];
39 $this->unit = $data['unit'];
40 $this->factor = (float) $data['factor'];
41 $this->baseunit = (int) $data['baseunit_fi'];
42 $this->baseunit_title = $data['baseunit_title'] ?? null;
43 $this->category = (int) $data['category_fi'];
44 $this->sequence = (int) $data['sequence'];
45 }
46
47 public function setId(int $id): void
48 {
49 $this->id = $id;
50 }
51
52 public function getId(): int
53 {
54 return $this->id;
55 }
56
57 public function setUnit(string $unit): void
58 {
59 $this->unit = $unit;
60 }
61
62 public function getUnit(): string
63 {
64 return $this->unit;
65 }
66
67 public function getSanitizedUnit(): string
68 {
69 return htmlspecialchars($this->getUnit(), ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
70 }
71
72 public function setSequence(int $sequence): void
73 {
74 $this->sequence = $sequence;
75 }
76
77 public function getSequence(): int
78 {
79 return $this->sequence;
80 }
81
82 public function setFactor(float $factor): void
83 {
84 $this->factor = $factor;
85 }
86
87 public function getFactor(): float
88 {
89 return $this->factor;
90 }
91
92 public function setBaseUnit(int $baseunit): void
93 {
94 $this->baseunit = $baseunit;
95 }
96
97 public function getBaseUnit(): int
98 {
99 if ($this->baseunit > 0) {
100 return $this->baseunit;
101 }
102
103 return $this->id;
104 }
105
106 public function setBaseunitTitle(?string $baseunit_title): void
107 {
108 $this->baseunit_title = $baseunit_title;
109 }
110
111 public function getBaseunitTitle(): ?string
112 {
114 }
115
116 public function getSanitizedBaseunitTitle(): ?string
117 {
118 return $this->sanitizeString($this->getBaseunitTitle() ?? '');
119 }
120
121 public function setCategory(int $category): void
122 {
123 $this->category = $category;
124 }
125
126 public function getCategory(): int
127 {
128 return $this->category;
129 }
130
131 public function getDisplayString(): string
132 {
133 global $DIC;
134
135 $unit = $this->getUnit();
136 $txt = $DIC->language()->txt("qpl_qst_formulaquestion_{$unit}");
137 return strcmp("-qpl_qst_formulaquestion_{$unit}-", $txt) !== 0
138 ? $this->sanitizeString($txt)
139 : $this->getSanitizedUnit();
140 }
141
142 public static function lookupUnitFactor(int $a_unit_id): float
143 {
144 global $DIC;
145 $ilDB = $DIC['ilDB'];
146
147 $res = $ilDB->queryF(
148 'SELECT factor FROM il_qpl_qst_fq_unit WHERE unit_id = %s',
149 ['integer'],
150 [$a_unit_id]
151 );
152
153 $row = $ilDB->fetchAssoc($res);
154
155 return (float) $row['factor'];
156 }
157
158 private function sanitizeString(string $string): string
159 {
160 return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
161 }
162}
setBaseunitTitle(?string $baseunit_title)
static lookupUnitFactor(int $a_unit_id)
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26