ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.SurveyCategories.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 include_once "Modules/SurveyQuestionPool/classes/class.ilSurveyCategory.php";
24 
35 {
36 
40  protected $log;
41 
51 
56  function __construct()
57  {
58  $this->categories = array();
59  $this->log = ilLoggerFactory::getLogger("svy");
60  }
61 
71  function getCategoryCount()
72  {
73  return count($this->categories);
74  }
75 
86  function addCategoryAtPosition($categoryname, $position, $other = 0, $neutral = 0, $label = null)
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  }
99 
100  function moveCategoryUp($index)
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  }
109 
110  function moveCategoryDown($index)
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  }
119 
129  function addCategory($categoryname, $other = 0, $neutral = 0, $label = null, $scale = null)
130  {
131  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
132  }
133 
143  function addCategoryArray($categories)
144  {
145  $this->categories = array_merge($this->categories, $categories);
146  }
147 
157  function removeCategory($index)
158  {
159  unset($this->categories[$index]);
160  $this->categories = array_values($this->categories);
161  }
162 
172  function removeCategories($array)
173  {
174  foreach ($array as $index)
175  {
176  unset($this->categories[$index]);
177  }
178  $this->categories = array_values($this->categories);
179  }
180 
190  function removeCategoryWithName($name)
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  }
201 
212  function getCategory($index)
213  {
214  if (array_key_exists($index, $this->categories))
215  {
216  return $this->categories[$index];
217  }
218  else
219  {
220  return "";
221  }
222  }
223 
230  public function getCategoryForScale($scale)
231  {
232  foreach ($this->categories as $cat)
233  {
234  if ($cat->scale == $scale) return $cat;
235  }
236  return null;
237  }
238 
246  function getCategoryIndex($name)
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  }
257 
265  function getIndex($category)
266  {
267  foreach ($this->categories as $index => $cat)
268  {
269  if ($cat == $category)
270  {
271  return $index;
272  }
273  }
274  return null;
275  }
276 
277  public function getNewScale()
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  }
289 
290  function getScale($index)
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  }
305 
314  function flushCategories()
315  {
316  $this->categories = array();
317  }
318 
325  function getCategories()
326  {
327  return $this->categories;
328  }
329 
330 
331 }
332 ?>
getCategory($index)
Returns the name of a category for a given index.
getCategoryIndex($name)
Returns the index of a category with a given name.
getCategoryCount()
Returns the number of categories.
getIndex($category)
Returns the index of a category.
removeCategory($index)
Removes a category from the list of categories.
getCategories()
Get categories.
getCategoryForScale($scale)
Returns the name of a category for a given index.
addCategoryArray($categories)
Adds a category array.
removeCategoryWithName($name)
Removes a category from the list of categories.
addCategory($categoryname, $other=0, $neutral=0, $label=null, $scale=null)
Adds a category.
flushCategories()
Empties the categories list.
removeCategories($array)
Removes many categories from the list of categories.
Class SurveyCategories.
addCategoryAtPosition($categoryname, $position, $other=0, $neutral=0, $label=null)
Adds a category at a given position.
Create styles array
The data for the language used.
static getLogger($a_component_id)
Get component logger.
Survey category class.
__construct()
Constructor public.