ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 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 @access public
See also
$categories

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

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

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 $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 }

◆ flushCategories()

SurveyCategories::flushCategories ( )

Empties the categories list.

Empties the categories list

@access 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

return

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

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

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

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

References $index.

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

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

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

References $index, and $name.

◆ getIndex()

SurveyCategories::getIndex (   $category)

Returns the index of a category.

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

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

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

References $index.

◆ getNewScale()

SurveyCategories::getNewScale ( )

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

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 }

References $index.

Referenced by getScale().

+ Here is the caller graph for this function:

◆ getScale()

SurveyCategories::getScale (   $index)

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

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 }

References $index, and getNewScale().

+ Here is the call graph for this function:

◆ moveCategoryDown()

SurveyCategories::moveCategoryDown (   $index)

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

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 }

References $index.

◆ moveCategoryUp()

SurveyCategories::moveCategoryUp (   $index)

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

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 }

References $index.

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

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

References $index.

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

153 {
154 unset($this->categories[$index]);
155 $this->categories = array_values($this->categories);
156 }

References $index.

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

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.

References $index, $name, and 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: