ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
SurveyCategories Class Reference

Class SurveyCategories. More...

+ Collaboration diagram for SurveyCategories:

Public Member Functions

 __construct ()
 Constructor @access public. More...
 
 getCategoryCount ()
 Returns the number of categories. More...
 
 addCategoryAtPosition ($categoryname, $position, $other=0, $neutral=0, $label=null)
 Adds a category at a given position. More...
 
 moveCategoryUp ($index)
 
 moveCategoryDown ($index)
 
 addCategory ($categoryname, $other=0, $neutral=0, $label=null, $scale=null)
 Adds a category. More...
 
 addCategoryArray ($categories)
 Adds a category array. More...
 
 removeCategory ($index)
 Removes a category from the list of categories. More...
 
 removeCategories ($array)
 Removes many categories from the list of categories. More...
 
 removeCategoryWithName ($name)
 Removes a category from the list of categories. More...
 
 getCategory ($index)
 Returns the name of a category for a given index. More...
 
 getCategoryForScale ($scale)
 Returns the name of a category for a given index. More...
 
 getCategoryIndex ($name)
 Returns the index of a category with a given name. More...
 
 getIndex ($category)
 Returns the index of a category. More...
 
 getNewScale ()
 
 getScale ($index)
 
 flushCategories ()
 Empties the categories list. More...
 
 getCategories ()
 Get categories. More...
 

Data Fields

 $categories
 

Protected Attributes

 $log
 

Detailed Description

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
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

SurveyCategories::__construct ( )

Constructor @access public.

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

57 {
58 $this->categories = array();
59 $this->log = ilLoggerFactory::getLogger("svy");
60 }
static getLogger($a_component_id)
Get component logger.

References ilLoggerFactory\getLogger().

+ Here is the call graph for this function:

Member Function Documentation

◆ addCategory()

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

Adds a category.

Adds a category

Parameters
integer$categorynameThe name of the category @access public
See also
$categories

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

130 {
131 array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
132 }
Survey category class.

◆ addCategoryArray()

SurveyCategories::addCategoryArray (   $categories)

Adds a category array.

Adds a category array

Parameters
array$categoriesAn array with categories @access public
See also
$categories

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

144 {
145 $this->categories = array_merge($this->categories, $categories);
146 }

References $categories.

◆ addCategoryAtPosition()

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

Adds a category at a given position.

Adds a category at a given position

Parameters
string$categorynameThe name of the category
integer$positionThe position of the category (starting with index 0) @access public
See also
$categories

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

87 {
88 if (array_key_exists($position, $this->categories))
89 {
90 $head = array_slice($this->categories, 0, $position);
91 $tail = array_slice($this->categories, $position);
92 $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
93 }
94 else
95 {
96 array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label));
97 }
98 }

◆ flushCategories()

SurveyCategories::flushCategories ( )

Empties the categories list.

Empties the categories list

@access public

See also
$categories

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

315 {
316 $this->categories = array();
317 }

◆ getCategories()

SurveyCategories::getCategories ( )

Get categories.

Parameters

return

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

326 {
327 return $this->categories;
328 }

References $categories.

◆ getCategory()

SurveyCategories::getCategory (   $index)

Returns the name of a category for a given index.

Returns the name of a category for a given index

Parameters
integer$indexThe index of the category
Returns
string Category name @access public
See also
$categories

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

213 {
214 if (array_key_exists($index, $this->categories))
215 {
216 return $this->categories[$index];
217 }
218 else
219 {
220 return "";
221 }
222 }

◆ getCategoryCount()

SurveyCategories::getCategoryCount ( )

Returns the number of categories.

Returns the number of categories

Returns
integer The number of contained categories @access public
See also
$categories

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

72 {
73 return count($this->categories);
74 }

◆ getCategoryForScale()

SurveyCategories::getCategoryForScale (   $scale)

Returns the name of a category for a given index.

Parameters
integer$scaleThe scale of the category
Returns
string Category object

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

231 {
232 foreach ($this->categories as $cat)
233 {
234 if ($cat->scale == $scale) return $cat;
235 }
236 return null;
237 }

◆ getCategoryIndex()

SurveyCategories::getCategoryIndex (   $name)

Returns the index of a category with a given name.

Parameters
string$nameThe name of the category @access public
See also
$categories

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

247 {
248 foreach ($this->categories as $index => $category)
249 {
250 if (strcmp($category->title, $name) == 0)
251 {
252 return $index;
253 }
254 }
255 return null;
256 }

◆ getIndex()

SurveyCategories::getIndex (   $category)

Returns the index of a category.

Parameters
string$categoryThe category object @access public
See also
$categories

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

266 {
267 foreach ($this->categories as $index => $cat)
268 {
269 if ($cat == $category)
270 {
271 return $index;
272 }
273 }
274 return null;
275 }

◆ getNewScale()

SurveyCategories::getNewScale ( )

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

278 {
279 $max = 0;
280 foreach ($this->categories as $index => $category)
281 {
282 if (is_object($category) && $category->scale > 0)
283 {
284 if ($category->scale > $max) $max = $category->scale;
285 }
286 }
287 return $max+1;
288 }

Referenced by getScale().

+ Here is the caller graph for this function:

◆ getScale()

SurveyCategories::getScale (   $index)

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

291 {
292 $obj = $this->categories[$index];
293 if (is_object($obj) && $obj->scale > 0)
294 {
295 $this->log->debug("getScale has scale =". $obj->scale);
296 return $obj->scale;
297 }
298 else
299 {
300 $obj->scale = $this->getNewScale();
301 $this->log->debug("getScale needed new scale, scale =". $obj->scale);
302 return $obj->scale;
303 }
304 }

References getNewScale().

+ Here is the call graph for this function:

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown (   $index)

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

111 {
112 if ($index < (count($this->categories)-1))
113 {
114 $temp = $this->categories[$index+1];
115 $this->categories[$index + 1] = $this->categories[$index];
116 $this->categories[$index] = $temp;
117 }
118 }

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp (   $index)

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

101 {
102 if ($index > 0)
103 {
104 $temp = $this->categories[$index-1];
105 $this->categories[$index - 1] = $this->categories[$index];
106 $this->categories[$index] = $temp;
107 }
108 }

◆ removeCategories()

SurveyCategories::removeCategories (   $array)

Removes many categories from the list of categories.

Removes many categories from the list of categories

Parameters
array$arrayAn array containing the index positions of the categories to be removed @access public
See also
$categories

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

173 {
174 foreach ($array as $index)
175 {
176 unset($this->categories[$index]);
177 }
178 $this->categories = array_values($this->categories);
179 }

◆ removeCategory()

SurveyCategories::removeCategory (   $index)

Removes a category from the list of categories.

Removes a category from the list of categories

Parameters
integer$indexThe index of the category to be removed @access public
See also
$categories

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

158 {
159 unset($this->categories[$index]);
160 $this->categories = array_values($this->categories);
161 }

Referenced by removeCategoryWithName().

+ Here is the caller graph for this function:

◆ removeCategoryWithName()

SurveyCategories::removeCategoryWithName (   $name)

Removes a category from the list of categories.

Removes a category from the list of categories

Parameters
string$nameThe name of the category to be removed @access public
See also
$categories

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

191 {
192 foreach ($this->categories as $index => $category)
193 {
194 if (strcmp($category->title, $name) == 0)
195 {
196 $this->removeCategory($index);
197 return;
198 }
199 }
200 }
removeCategory($index)
Removes a category from the list of categories.

References removeCategory().

+ Here is the call graph for this function:

Field Documentation

◆ $categories

SurveyCategories::$categories

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

Referenced by addCategoryArray(), and getCategories().

◆ $log

SurveyCategories::$log
protected

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


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