ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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*/
23include_once "Modules/SurveyQuestionPool/classes/class.ilSurveyCategory.php";
24
35{
45
51 {
52 $this->categories = array();
53 }
54
64 function getCategoryCount()
65 {
66 return count($this->categories);
67 }
68
79 function addCategoryAtPosition($categoryname, $position, $other = 0, $neutral = 0, $label = null)
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 }
92
93 function moveCategoryUp($index)
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 }
102
103 function moveCategoryDown($index)
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 }
112
122 function addCategory($categoryname, $other = 0, $neutral = 0, $label = null, $scale = null)
123 {
124 array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
125 }
126
137 {
138 $this->categories = array_merge($this->categories, $categories);
139 }
140
150 function removeCategory($index)
151 {
152 unset($this->categories[$index]);
153 $this->categories = array_values($this->categories);
154 }
155
165 function removeCategories($array)
166 {
167 foreach ($array as $index)
168 {
169 unset($this->categories[$index]);
170 }
171 $this->categories = array_values($this->categories);
172 }
173
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 }
194
205 function getCategory($index)
206 {
207 if (array_key_exists($index, $this->categories))
208 {
209 return $this->categories[$index];
210 }
211 else
212 {
213 return "";
214 }
215 }
216
223 public function getCategoryForScale($scale)
224 {
225 foreach ($this->categories as $cat)
226 {
227 if ($cat->scale == $scale) return $cat;
228 }
229 return null;
230 }
231
239 function getCategoryIndex($name)
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 }
250
258 function getIndex($category)
259 {
260 foreach ($this->categories as $index => $cat)
261 {
262 if ($cat == $category)
263 {
264 return $index;
265 }
266 }
267 return null;
268 }
269
270 public function getNewScale()
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 }
282
283 function getScale($index)
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 }
296
305 function flushCategories()
306 {
307 $this->categories = array();
308 }
309
310} // END class.SurveyCategories
311?>
Class SurveyCategories.
getCategoryIndex($name)
Returns the index of a category with a given name.
getIndex($category)
Returns the index of a category.
removeCategory($index)
Removes a category from the list of categories.
getCategory($index)
Returns the name of a category for a given index.
removeCategoryWithName($name)
Removes a category from the list of categories.
addCategoryAtPosition($categoryname, $position, $other=0, $neutral=0, $label=null)
Adds a category at a given position.
SurveyCategories()
Constructor @access public.
getCategoryForScale($scale)
Returns the name of a category for a given index.
flushCategories()
Empties the categories list.
addCategory($categoryname, $other=0, $neutral=0, $label=null, $scale=null)
Adds a category.
addCategoryArray($categories)
Adds a category array.
removeCategories($array)
Removes many categories from the list of categories.
getCategoryCount()
Returns the number of categories.
Survey category class.