ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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

Constructor & Destructor Documentation

◆ __construct()

SurveyCategories::__construct ( )

Constructor public.

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

References ilLoggerFactory\getLogger().

33  {
34  $this->categories = array();
35  $this->log = ilLoggerFactory::getLogger("svy");
36  }
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 100 of file class.SurveyCategories.php.

101  {
102  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
103  }
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 114 of file class.SurveyCategories.php.

References $categories.

115  {
116  $this->categories = array_merge($this->categories, $categories);
117  }

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

63  {
64  if (array_key_exists($position, $this->categories)) {
65  $head = array_slice($this->categories, 0, $position);
66  $tail = array_slice($this->categories, $position);
67  $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
68  } else {
69  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label));
70  }
71  }
Survey category class.

◆ flushCategories()

SurveyCategories::flushCategories ( )

Empties the categories list.

Empties the categories list

public

See also
$categories

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

274  {
275  $this->categories = array();
276  }

◆ getCategories()

SurveyCategories::getCategories ( )

Get categories.

Parameters

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

References $categories.

285  {
286  return $this->categories;
287  }

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

References $index.

181  {
182  if (array_key_exists($index, $this->categories)) {
183  return $this->categories[$index];
184  } else {
185  return "";
186  }
187  }
$index
Definition: metadata.php:128

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

48  {
49  return count($this->categories);
50  }

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

196  {
197  foreach ($this->categories as $cat) {
198  if ($cat->scale == $scale) {
199  return $cat;
200  }
201  }
202  return null;
203  }

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

References $index, and $name.

213  {
214  foreach ($this->categories as $index => $category) {
215  if (strcmp($category->title, $name) == 0) {
216  return $index;
217  }
218  }
219  return null;
220  }
$index
Definition: metadata.php:128
if($format !==null) $name
Definition: metadata.php:230

◆ getIndex()

SurveyCategories::getIndex (   $category)

Returns the index of a category.

Parameters
string$categoryThe category object public
See also
$categories

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

References $index.

230  {
231  foreach ($this->categories as $index => $cat) {
232  if ($cat == $category) {
233  return $index;
234  }
235  }
236  return null;
237  }
$index
Definition: metadata.php:128

◆ getNewScale()

SurveyCategories::getNewScale ( )

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

References $index.

Referenced by getScale().

240  {
241  $max = 0;
242  foreach ($this->categories as $index => $category) {
243  if (is_object($category) && $category->scale > 0) {
244  if ($category->scale > $max) {
245  $max = $category->scale;
246  }
247  }
248  }
249  return $max + 1;
250  }
$index
Definition: metadata.php:128
+ Here is the caller graph for this function:

◆ getScale()

SurveyCategories::getScale (   $index)

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

References $index, and getNewScale().

253  {
254  $obj = $this->categories[$index];
255  if (is_object($obj) && $obj->scale > 0) {
256  $this->log->debug("getScale has scale =" . $obj->scale);
257  return $obj->scale;
258  } else {
259  $obj->scale = $this->getNewScale();
260  $this->log->debug("getScale needed new scale, scale =" . $obj->scale);
261  return $obj->scale;
262  }
263  }
$index
Definition: metadata.php:128
+ Here is the call graph for this function:

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown (   $index)

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

References $index.

83  {
84  if ($index < (count($this->categories) - 1)) {
85  $temp = $this->categories[$index + 1];
86  $this->categories[$index + 1] = $this->categories[$index];
87  $this->categories[$index] = $temp;
88  }
89  }
$index
Definition: metadata.php:128

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp (   $index)

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

References $index.

74  {
75  if ($index > 0) {
76  $temp = $this->categories[$index - 1];
77  $this->categories[$index - 1] = $this->categories[$index];
78  $this->categories[$index] = $temp;
79  }
80  }
$index
Definition: metadata.php:128

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

References $index.

144  {
145  foreach ($array as $index) {
146  unset($this->categories[$index]);
147  }
148  $this->categories = array_values($this->categories);
149  }
$index
Definition: metadata.php:128

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

References $index.

Referenced by removeCategoryWithName().

129  {
130  unset($this->categories[$index]);
131  $this->categories = array_values($this->categories);
132  }
$index
Definition: metadata.php:128
+ 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 160 of file class.SurveyCategories.php.

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

161  {
162  foreach ($this->categories as $index => $category) {
163  if (strcmp($category->title, $name) == 0) {
164  $this->removeCategory($index);
165  return;
166  }
167  }
168  }
removeCategory($index)
Removes a category from the list of categories.
$index
Definition: metadata.php:128
if($format !==null) $name
Definition: metadata.php:230
+ Here is the call graph for this function:

Field Documentation

◆ $categories

SurveyCategories::$categories

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

Referenced by addCategoryArray(), and getCategories().

◆ $log

SurveyCategories::$log
protected

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


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