ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 25 of file class.SurveyCategories.php.

Constructor & Destructor Documentation

◆ __construct()

SurveyCategories::__construct ( )

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

36 {
37 $this->categories = array();
38 $this->log = ilLoggerFactory::getLogger("svy");
39 }
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 84 of file class.SurveyCategories.php.

90 : void {
91 $this->categories[] = new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale);
92 }
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 97 of file class.SurveyCategories.php.

97 : void
98 {
99 $this->categories = array_merge($this->categories, $categories);
100 }
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 50 of file class.SurveyCategories.php.

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 }

◆ flushCategories()

SurveyCategories::flushCategories ( )

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

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

◆ getCategories()

SurveyCategories::getCategories ( )

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

200 : array
201 {
202 return $this->categories;
203 }

◆ getCategory()

SurveyCategories::getCategory ( int  $index)

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

133 return $this->categories[$index] ?? null;
134 }

◆ getCategoryCount()

SurveyCategories::getCategoryCount ( )

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

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

◆ getCategoryForScale()

SurveyCategories::getCategoryForScale ( int  $scale)

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

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

◆ getCategoryIndex()

SurveyCategories::getCategoryIndex ( string  $name)

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

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 }

◆ getIndex()

SurveyCategories::getIndex ( ilSurveyCategory  $category)

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

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

◆ getNewScale()

SurveyCategories::getNewScale ( )

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

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

◆ getScale()

SurveyCategories::getScale ( int  $index)

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

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 }

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown ( int  $index)

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

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

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp ( int  $index)

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

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

◆ removeCategories()

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

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

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

◆ removeCategory()

SurveyCategories::removeCategory ( int  $index)

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

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

◆ removeCategoryWithName()

SurveyCategories::removeCategoryWithName ( string  $name)

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

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 }

Field Documentation

◆ $categories

array SurveyCategories::$categories

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

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

◆ $log

ilLogger SurveyCategories::$log
protected

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


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