ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SurveyCategories Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for SurveyCategories:

Public Member Functions

 __construct ()
 
 getCategoryCount ()
 
 addCategoryAtPosition (string $categoryname, int $position, int $other=0, int $neutral=0, ?string $label=null)
 Adds a category at a given position. More...
 
 moveCategoryUp (int $index)
 
 moveCategoryDown (int $index)
 
 addCategory (string $categoryname, int $other=0, int $neutral=0, ?string $label=null, ?int $scale=null)
 
 addCategoryArray (array $categories)
 
 removeCategory (int $index)
 
 removeCategories (array $array)
 
 removeCategoryWithName (string $name)
 
 getCategory (int $index)
 
 getCategoryForScale (int $scale)
 
 getCategoryIndex (string $name)
 
 getIndex (ilSurveyCategory $category)
 
 getNewScale ()
 
 getScale (int $index)
 
 flushCategories ()
 
 getCategories ()
 

Data Fields

array $categories
 An array containing the categories of a nominal or ordinal question object. More...
 

Protected Attributes

ilLogger $log
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class SurveyCategories

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m

Definition at line 23 of file class.SurveyCategories.php.

Constructor & Destructor Documentation

◆ __construct()

SurveyCategories::__construct ( )

Definition at line 33 of file class.SurveyCategories.php.

34 {
35 $this->categories = array();
36 $this->log = ilLoggerFactory::getLogger("svy");
37 }
static getLogger(string $a_component_id)
Get component logger.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ addCategory()

SurveyCategories::addCategory ( string  $categoryname,
int  $other = 0,
int  $neutral = 0,
?string  $label = null,
?int  $scale = null 
)

Definition at line 82 of file class.SurveyCategories.php.

88 : void {
89 $this->categories[] = new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale);
90 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ addCategoryArray()

SurveyCategories::addCategoryArray ( array  $categories)
Parameters
array$categoriesarray with categories

Definition at line 95 of file class.SurveyCategories.php.

95 : void
96 {
97 $this->categories = array_merge($this->categories, $categories);
98 }
array $categories
An array containing the categories of a nominal or ordinal question object.

◆ addCategoryAtPosition()

SurveyCategories::addCategoryAtPosition ( string  $categoryname,
int  $position,
int  $other = 0,
int  $neutral = 0,
?string  $label = null 
)

Adds a category at a given position.

Parameters
int$positionThe position of the category (starting with index 0)

Definition at line 48 of file class.SurveyCategories.php.

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 }

◆ flushCategories()

SurveyCategories::flushCategories ( )

Definition at line 193 of file class.SurveyCategories.php.

193 : void
194 {
195 $this->categories = array();
196 }

◆ getCategories()

SurveyCategories::getCategories ( )

Definition at line 198 of file class.SurveyCategories.php.

198 : array
199 {
200 return $this->categories;
201 }

◆ getCategory()

SurveyCategories::getCategory ( int  $index)

Definition at line 128 of file class.SurveyCategories.php.

131 return $this->categories[$index] ?? null;
132 }

◆ getCategoryCount()

SurveyCategories::getCategoryCount ( )

Definition at line 39 of file class.SurveyCategories.php.

39 : int
40 {
41 return count($this->categories);
42 }

◆ getCategoryForScale()

SurveyCategories::getCategoryForScale ( int  $scale)

Definition at line 134 of file class.SurveyCategories.php.

137 foreach ($this->categories as $cat) {
138 if ($cat->scale == $scale) {
139 return $cat;
140 }
141 }
142 return null;
143 }

◆ getCategoryIndex()

SurveyCategories::getCategoryIndex ( string  $name)

Definition at line 145 of file class.SurveyCategories.php.

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 }

◆ getIndex()

SurveyCategories::getIndex ( ilSurveyCategory  $category)

Definition at line 156 of file class.SurveyCategories.php.

156 : ?int
157 {
158 foreach ($this->categories as $index => $cat) {
159 if ($cat == $category) {
160 return $index;
161 }
162 }
163 return null;
164 }

◆ getNewScale()

SurveyCategories::getNewScale ( )

Definition at line 166 of file class.SurveyCategories.php.

166 : 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 }

◆ getScale()

SurveyCategories::getScale ( int  $index)

Definition at line 180 of file class.SurveyCategories.php.

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 }

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown ( int  $index)

Definition at line 73 of file class.SurveyCategories.php.

73 : 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 }

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp ( int  $index)

Definition at line 64 of file class.SurveyCategories.php.

64 : 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 }

◆ removeCategories()

SurveyCategories::removeCategories ( array  $array)
Parameters
int[]$arrayindex positions

Definition at line 109 of file class.SurveyCategories.php.

109 : void
110 {
111 foreach ($array as $index) {
112 unset($this->categories[$index]);
113 }
114 $this->categories = array_values($this->categories);
115 }

◆ removeCategory()

SurveyCategories::removeCategory ( int  $index)

Definition at line 100 of file class.SurveyCategories.php.

100 : void
101 {
102 unset($this->categories[$index]);
103 $this->categories = array_values($this->categories);
104 }

◆ removeCategoryWithName()

SurveyCategories::removeCategoryWithName ( string  $name)

Definition at line 117 of file class.SurveyCategories.php.

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 }

Field Documentation

◆ $categories

array SurveyCategories::$categories

An array containing the categories of a nominal or ordinal question object.

Definition at line 31 of file class.SurveyCategories.php.

◆ $log

ilLogger SurveyCategories::$log
protected

Definition at line 25 of file class.SurveyCategories.php.


The documentation for this class was generated from the following file: