ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
SurveyCategories Class Reference

Class SurveyCategories. More...

+ Collaboration diagram for SurveyCategories:

Public Member Functions

 SurveyCategories ()
 Constructor 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...
 

Data Fields

 $categories
 

Detailed Description

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 public
See also
$categories

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

123  {
124  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
125  }
Survey category class.

◆ addCategoryArray()

SurveyCategories::addCategoryArray (   $categories)

Adds a category array.

Adds a category array

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

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

137  {
138  $this->categories = array_merge($this->categories, $categories);
139  }

◆ 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) public
See also
$categories

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

80  {
81  if (array_key_exists($position, $this->categories))
82  {
83  $head = array_slice($this->categories, 0, $position);
84  $tail = array_slice($this->categories, $position);
85  $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
86  }
87  else
88  {
89  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label));
90  }
91  }
Survey category class.

◆ flushCategories()

SurveyCategories::flushCategories ( )

Empties the categories list.

Empties the categories list

public

See also
$categories

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

306  {
307  $this->categories = array();
308  }

◆ 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 public
See also
$categories

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

206  {
207  if (array_key_exists($index, $this->categories))
208  {
209  return $this->categories[$index];
210  }
211  else
212  {
213  return "";
214  }
215  }

◆ getCategoryCount()

SurveyCategories::getCategoryCount ( )

Returns the number of categories.

Returns the number of categories

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

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

65  {
66  return count($this->categories);
67  }

◆ 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 223 of file class.SurveyCategories.php.

224  {
225  foreach ($this->categories as $cat)
226  {
227  if ($cat->scale == $scale) return $cat;
228  }
229  return null;
230  }

◆ getCategoryIndex()

SurveyCategories::getCategoryIndex (   $name)

Returns the index of a category with a given name.

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

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

240  {
241  foreach ($this->categories as $index => $category)
242  {
243  if (strcmp($category->title, $name) == 0)
244  {
245  return $index;
246  }
247  }
248  return null;
249  }

◆ getIndex()

SurveyCategories::getIndex (   $category)

Returns the index of a category.

Parameters
string$categoryThe category object public
See also
$categories

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

259  {
260  foreach ($this->categories as $index => $cat)
261  {
262  if ($cat == $category)
263  {
264  return $index;
265  }
266  }
267  return null;
268  }

◆ getNewScale()

SurveyCategories::getNewScale ( )

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

Referenced by getScale().

271  {
272  $max = 0;
273  foreach ($this->categories as $index => $category)
274  {
275  if (is_object($category) && $category->scale > 0)
276  {
277  if ($category->scale > $max) $max = $category->scale;
278  }
279  }
280  return $max+1;
281  }
+ Here is the caller graph for this function:

◆ getScale()

SurveyCategories::getScale (   $index)

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

References getNewScale().

284  {
285  $obj = $this->categories[$index];
286  if (is_object($obj) && $obj->scale > 0)
287  {
288  return $obj->scale;
289  }
290  else
291  {
292  $obj->scale = $this->getNewScale();
293  return $obj->scale;
294  }
295  }
+ Here is the call graph for this function:

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown (   $index)

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

104  {
105  if ($index < (count($this->categories)-1))
106  {
107  $temp = $this->categories[$index+1];
108  $this->categories[$index + 1] = $this->categories[$index];
109  $this->categories[$index] = $temp;
110  }
111  }

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp (   $index)

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

94  {
95  if ($index > 0)
96  {
97  $temp = $this->categories[$index-1];
98  $this->categories[$index - 1] = $this->categories[$index];
99  $this->categories[$index] = $temp;
100  }
101  }

◆ 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 public
See also
$categories

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

166  {
167  foreach ($array as $index)
168  {
169  unset($this->categories[$index]);
170  }
171  $this->categories = array_values($this->categories);
172  }

◆ 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 public
See also
$categories

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

Referenced by removeCategoryWithName().

151  {
152  unset($this->categories[$index]);
153  $this->categories = array_values($this->categories);
154  }
+ 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 public
See also
$categories

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

References removeCategory().

184  {
185  foreach ($this->categories as $index => $category)
186  {
187  if (strcmp($category->title, $name) == 0)
188  {
189  $this->removeCategory($index);
190  return;
191  }
192  }
193  }
removeCategory($index)
Removes a category from the list of categories.
+ Here is the call graph for this function:

◆ SurveyCategories()

SurveyCategories::SurveyCategories ( )

Constructor public.

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

51  {
52  $this->categories = array();
53  }

Field Documentation

◆ $categories

SurveyCategories::$categories

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


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