ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.SurveyCategories.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
27 protected ilLogger $log;
28
33 public array $categories;
34
35 public function __construct()
36 {
37 $this->categories = array();
38 $this->log = ilLoggerFactory::getLogger("svy");
39 }
40
41 public function getCategoryCount(): int
42 {
43 return count($this->categories);
44 }
45
50 public function addCategoryAtPosition(
51 string $categoryname,
52 int $position,
53 int $other = 0,
54 int $neutral = 0,
55 ?string $label = null
56 ): void {
57 if (array_key_exists($position, $this->categories)) {
58 $head = array_slice($this->categories, 0, $position);
59 $tail = array_slice($this->categories, $position);
60 $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
61 } else {
62 $this->categories[] = new ilSurveyCategory($categoryname, $other, $neutral, $label);
63 }
64 }
65
66 public function moveCategoryUp(int $index): void
67 {
68 if ($index > 0) {
69 $temp = $this->categories[$index - 1];
70 $this->categories[$index - 1] = $this->categories[$index];
71 $this->categories[$index] = $temp;
72 }
73 }
74
75 public function moveCategoryDown(int $index): void
76 {
77 if ($index < (count($this->categories) - 1)) {
78 $temp = $this->categories[$index + 1];
79 $this->categories[$index + 1] = $this->categories[$index];
80 $this->categories[$index] = $temp;
81 }
82 }
83
84 public function addCategory(
85 ?string $categoryname,
86 int $other = 0,
87 int $neutral = 0,
88 ?string $label = null,
89 ?int $scale = null
90 ): void {
91 $this->categories[] = new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale);
92 }
93
97 public function addCategoryArray(array $categories): void
98 {
99 $this->categories = array_merge($this->categories, $categories);
100 }
101
102 public function removeCategory(int $index): void
103 {
104 unset($this->categories[$index]);
105 $this->categories = array_values($this->categories);
106 }
107
111 public function removeCategories(array $array): void
112 {
113 foreach ($array as $index) {
114 unset($this->categories[$index]);
115 }
116 $this->categories = array_values($this->categories);
117 }
118
119 public function removeCategoryWithName(
120 string $name
121 ): void {
122 foreach ($this->categories as $index => $category) {
123 if (strcmp($category->title, $name) == 0) {
124 $this->removeCategory($index);
125 return;
126 }
127 }
128 }
129
130 public function getCategory(
131 int $index
132 ): ?ilSurveyCategory {
133 return $this->categories[$index] ?? null;
134 }
135
136 public function getCategoryForScale(
137 int $scale
138 ): ?ilSurveyCategory {
139 foreach ($this->categories as $cat) {
140 if ($cat->scale == $scale) {
141 return $cat;
142 }
143 }
144 return null;
145 }
146
147 public function getCategoryIndex(
148 string $name
149 ): ?int {
150 foreach ($this->categories as $index => $category) {
151 if (strcmp($category->title, $name) == 0) {
152 return $index;
153 }
154 }
155 return null;
156 }
157
158 public function getIndex(ilSurveyCategory $category): ?int
159 {
160 foreach ($this->categories as $index => $cat) {
161 if ($cat == $category) {
162 return $index;
163 }
164 }
165 return null;
166 }
167
168 public function getNewScale(): int
169 {
170 $max = 0;
171 foreach ($this->categories as $index => $category) {
172 if (is_object($category) && $category->scale > 0) {
173 if ($category->scale > $max) {
174 $max = $category->scale;
175 }
176 }
177 }
178 return $max + 1;
179 }
180
181 // note, if the index is not found, we get a new scale back
182 public function getScale(
183 int $index
184 ): int {
185 $obj = $this->categories[$index];
186 if (is_object($obj) && $obj->scale > 0) {
187 $this->log->debug("getScale has scale =" . $obj->scale);
188 } else {
189 $obj->scale = $this->getNewScale();
190 $this->log->debug("getScale needed new scale, scale =" . $obj->scale);
191 }
192 return (int) $obj->scale;
193 }
194
195 public function flushCategories(): void
196 {
197 $this->categories = array();
198 }
199
200 public function getCategories(): array
201 {
202 return $this->categories;
203 }
204}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
array $categories
An array containing the categories of a nominal or ordinal question object.
getCategoryIndex(string $name)
addCategory(?string $categoryname, int $other=0, int $neutral=0, ?string $label=null, ?int $scale=null)
addCategoryAtPosition(string $categoryname, int $position, int $other=0, int $neutral=0, ?string $label=null)
Adds a category at a given position.
getIndex(ilSurveyCategory $category)
removeCategoryWithName(string $name)
addCategoryArray(array $categories)
removeCategories(array $array)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
foreach( $report as $row)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))