ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SurveyCategories Class Reference

Class SurveyCategories. More...

+ Collaboration diagram for SurveyCategories:

Public Member Functions

 __construct ()
 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...
 
 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 public.

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

References ilLoggerFactory\getLogger().

57  {
58  $this->categories = array();
59  $this->log = ilLoggerFactory::getLogger("svy");
60  }
static getLogger($a_component_id)
Get component logger.
+ 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 public
See also
$categories

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

125  {
126  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
127  }
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 138 of file class.SurveyCategories.php.

References $categories.

139  {
140  $this->categories = array_merge($this->categories, $categories);
141  }

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

References $tail.

87  {
88  if (array_key_exists($position, $this->categories)) {
89  $head = array_slice($this->categories, 0, $position);
90  $tail = array_slice($this->categories, $position);
91  $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
92  } else {
93  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label));
94  }
95  }
$tail
Definition: tail.php:20
Survey category class.

◆ flushCategories()

SurveyCategories::flushCategories ( )

Empties the categories list.

Empties the categories list

public

See also
$categories

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

298  {
299  $this->categories = array();
300  }

◆ getCategories()

SurveyCategories::getCategories ( )

Get categories.

Parameters

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

References $categories.

309  {
310  return $this->categories;
311  }

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

References $index.

205  {
206  if (array_key_exists($index, $this->categories)) {
207  return $this->categories[$index];
208  } else {
209  return "";
210  }
211  }
$index
Definition: metadata.php:60

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

220  {
221  foreach ($this->categories as $cat) {
222  if ($cat->scale == $scale) {
223  return $cat;
224  }
225  }
226  return null;
227  }

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

References $index, and $name.

237  {
238  foreach ($this->categories as $index => $category) {
239  if (strcmp($category->title, $name) == 0) {
240  return $index;
241  }
242  }
243  return null;
244  }
$index
Definition: metadata.php:60

◆ getIndex()

SurveyCategories::getIndex (   $category)

Returns the index of a category.

Parameters
string$categoryThe category object public
See also
$categories

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

References $index.

254  {
255  foreach ($this->categories as $index => $cat) {
256  if ($cat == $category) {
257  return $index;
258  }
259  }
260  return null;
261  }
$index
Definition: metadata.php:60

◆ getNewScale()

SurveyCategories::getNewScale ( )

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

References $index.

Referenced by getScale().

264  {
265  $max = 0;
266  foreach ($this->categories as $index => $category) {
267  if (is_object($category) && $category->scale > 0) {
268  if ($category->scale > $max) {
269  $max = $category->scale;
270  }
271  }
272  }
273  return $max + 1;
274  }
$index
Definition: metadata.php:60
+ Here is the caller graph for this function:

◆ getScale()

SurveyCategories::getScale (   $index)

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

References $index, and getNewScale().

277  {
278  $obj = $this->categories[$index];
279  if (is_object($obj) && $obj->scale > 0) {
280  $this->log->debug("getScale has scale =" . $obj->scale);
281  return $obj->scale;
282  } else {
283  $obj->scale = $this->getNewScale();
284  $this->log->debug("getScale needed new scale, scale =" . $obj->scale);
285  return $obj->scale;
286  }
287  }
$index
Definition: metadata.php:60
+ Here is the call graph for this function:

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown (   $index)

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

References $index.

107  {
108  if ($index < (count($this->categories) - 1)) {
109  $temp = $this->categories[$index + 1];
110  $this->categories[$index + 1] = $this->categories[$index];
111  $this->categories[$index] = $temp;
112  }
113  }
$index
Definition: metadata.php:60

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp (   $index)

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

References $index.

98  {
99  if ($index > 0) {
100  $temp = $this->categories[$index - 1];
101  $this->categories[$index - 1] = $this->categories[$index];
102  $this->categories[$index] = $temp;
103  }
104  }
$index
Definition: metadata.php:60

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

References $index.

168  {
169  foreach ($array as $index) {
170  unset($this->categories[$index]);
171  }
172  $this->categories = array_values($this->categories);
173  }
$index
Definition: metadata.php:60

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

References $index.

Referenced by removeCategoryWithName().

153  {
154  unset($this->categories[$index]);
155  $this->categories = array_values($this->categories);
156  }
$index
Definition: metadata.php:60
+ 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 184 of file class.SurveyCategories.php.

References $index, $name, and removeCategory().

185  {
186  foreach ($this->categories as $index => $category) {
187  if (strcmp($category->title, $name) == 0) {
188  $this->removeCategory($index);
189  return;
190  }
191  }
192  }
removeCategory($index)
Removes a category from the list of categories.
$index
Definition: metadata.php:60
+ 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: