ILIAS  release_8 Revision v8.24
class.SurveyCategories.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilLogger $log;
26
31 public array $categories;
32
33 public function __construct()
34 {
35 $this->categories = array();
36 $this->log = ilLoggerFactory::getLogger("svy");
37 }
38
39 public function getCategoryCount(): int
40 {
41 return count($this->categories);
42 }
43
48 public function addCategoryAtPosition(
49 string $categoryname,
50 int $position,
51 int $other = 0,
52 int $neutral = 0,
53 ?string $label = null
54 ): void {
55 if (array_key_exists($position, $this->categories)) {
56 $head = array_slice($this->categories, 0, $position);
57 $tail = array_slice($this->categories, $position);
58 $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
59 } else {
60 $this->categories[] = new ilSurveyCategory($categoryname, $other, $neutral, $label);
61 }
62 }
63
64 public function moveCategoryUp(int $index): void
65 {
66 if ($index > 0) {
67 $temp = $this->categories[$index - 1];
68 $this->categories[$index - 1] = $this->categories[$index];
69 $this->categories[$index] = $temp;
70 }
71 }
72
73 public function moveCategoryDown(int $index): void
74 {
75 if ($index < (count($this->categories) - 1)) {
76 $temp = $this->categories[$index + 1];
77 $this->categories[$index + 1] = $this->categories[$index];
78 $this->categories[$index] = $temp;
79 }
80 }
81
82 public function addCategory(
83 string $categoryname,
84 int $other = 0,
85 int $neutral = 0,
86 ?string $label = null,
87 ?int $scale = null
88 ): void {
89 $this->categories[] = new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale);
90 }
91
95 public function addCategoryArray(array $categories): void
96 {
97 $this->categories = array_merge($this->categories, $categories);
98 }
99
100 public function removeCategory(int $index): void
101 {
102 unset($this->categories[$index]);
103 $this->categories = array_values($this->categories);
104 }
105
109 public function removeCategories(array $array): void
110 {
111 foreach ($array as $index) {
112 unset($this->categories[$index]);
113 }
114 $this->categories = array_values($this->categories);
115 }
116
117 public function removeCategoryWithName(
118 string $name
119 ): void {
120 foreach ($this->categories as $index => $category) {
121 if (strcmp($category->title, $name) == 0) {
122 $this->removeCategory($index);
123 return;
124 }
125 }
126 }
127
128 public function getCategory(
129 int $index
130 ): ?ilSurveyCategory {
131 return $this->categories[$index] ?? null;
132 }
133
134 public function getCategoryForScale(
135 int $scale
136 ): ?ilSurveyCategory {
137 foreach ($this->categories as $cat) {
138 if ($cat->scale == $scale) {
139 return $cat;
140 }
141 }
142 return null;
143 }
144
145 public function getCategoryIndex(
146 string $name
147 ): ?int {
148 foreach ($this->categories as $index => $category) {
149 if (strcmp($category->title, $name) == 0) {
150 return $index;
151 }
152 }
153 return null;
154 }
155
156 public function getIndex(ilSurveyCategory $category): ?int
157 {
158 foreach ($this->categories as $index => $cat) {
159 if ($cat == $category) {
160 return $index;
161 }
162 }
163 return null;
164 }
165
166 public function getNewScale(): int
167 {
168 $max = 0;
169 foreach ($this->categories as $index => $category) {
170 if (is_object($category) && $category->scale > 0) {
171 if ($category->scale > $max) {
172 $max = $category->scale;
173 }
174 }
175 }
176 return $max + 1;
177 }
178
179 // note, if the index is not found, we get a new scale back
180 public function getScale(
181 int $index
182 ): int {
183 $obj = $this->categories[$index];
184 if (is_object($obj) && $obj->scale > 0) {
185 $this->log->debug("getScale has scale =" . $obj->scale);
186 } else {
187 $obj->scale = $this->getNewScale();
188 $this->log->debug("getScale needed new scale, scale =" . $obj->scale);
189 }
190 return $obj->scale;
191 }
192
193 public function flushCategories(): void
194 {
195 $this->categories = array();
196 }
197
198 public function getCategories(): array
199 {
200 return $this->categories;
201 }
202}
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.
addCategory(string $categoryname, int $other=0, int $neutral=0, ?string $label=null, ?int $scale=null)
getCategoryIndex(string $name)
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...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
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', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
if($format !==null) $name
Definition: metadata.php:247
$index
Definition: metadata.php:145