ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
25 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyCategory.php";
26 
37 {
47 
52  function SurveyCategories()
53  {
54  $this->categories = array();
55  }
56 
66  function getCategoryCount()
67  {
68  return count($this->categories);
69  }
70 
81  function addCategoryAtPosition($categoryname, $position, $other = 0, $neutral = 0, $label = null)
82  {
83  if (array_key_exists($position, $this->categories))
84  {
85  $head = array_slice($this->categories, 0, $position);
86  $tail = array_slice($this->categories, $position);
87  $this->categories = array_merge($head, array(new ilSurveyCategory($categoryname, $other, $neutral, $label)), $tail);
88  }
89  else
90  {
91  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label));
92  }
93  }
94 
95  function moveCategoryUp($index)
96  {
97  if ($index > 0)
98  {
99  $temp = $this->categories[$index-1];
100  $this->categories[$index - 1] = $this->categories[$index];
101  $this->categories[$index] = $temp;
102  }
103  }
104 
105  function moveCategoryDown($index)
106  {
107  if ($index < (count($this->categories)-1))
108  {
109  $temp = $this->categories[$index+1];
110  $this->categories[$index + 1] = $this->categories[$index];
111  $this->categories[$index] = $temp;
112  }
113  }
114 
124  function addCategory($categoryname, $other = 0, $neutral = 0, $label = null, $scale = null)
125  {
126  array_push($this->categories, new ilSurveyCategory($categoryname, $other, $neutral, $label, $scale));
127  }
128 
139  {
140  $this->categories = array_merge($this->categories, $categories);
141  }
142 
152  function removeCategory($index)
153  {
154  unset($this->categories[$index]);
155  $this->categories = array_values($this->categories);
156  }
157 
167  function removeCategories($array)
168  {
169  foreach ($array as $index)
170  {
171  unset($this->categories[$index]);
172  }
173  $this->categories = array_values($this->categories);
174  }
175 
185  function removeCategoryWithName($name)
186  {
187  foreach ($this->categories as $index => $category)
188  {
189  if (strcmp($category->title, $name) == 0)
190  {
191  $this->removeCategory($index);
192  return;
193  }
194  }
195  }
196 
207  function getCategory($index)
208  {
209  if (array_key_exists($index, $this->categories))
210  {
211  return $this->categories[$index];
212  }
213  else
214  {
215  return "";
216  }
217  }
218 
225  public function getCategoryForScale($scale)
226  {
227  foreach ($this->categories as $cat)
228  {
229  if ($cat->scale == $scale) return $cat;
230  }
231  return null;
232  }
233 
241  function getCategoryIndex($name)
242  {
243  foreach ($this->categories as $index => $category)
244  {
245  if (strcmp($category->title, $name) == 0)
246  {
247  return $index;
248  }
249  }
250  return null;
251  }
252 
260  function getIndex($category)
261  {
262  foreach ($this->categories as $index => $cat)
263  {
264  if ($cat == $category)
265  {
266  return $index;
267  }
268  }
269  return null;
270  }
271 
272  public function getNewScale()
273  {
274  $max = 0;
275  foreach ($this->categories as $index => $category)
276  {
277  if (is_object($category) && $category->scale > 0)
278  {
279  if ($category->scale > $max) $max = $category->scale;
280  }
281  }
282  return $max+1;
283  }
284 
285  function getScale($index)
286  {
287  $obj = $this->categories[$index];
288  if (is_object($obj) && $obj->scale > 0)
289  {
290  return $obj->scale;
291  }
292  else
293  {
294  $obj->scale = $this->getNewScale();
295  return $obj->scale;
296  }
297  }
298 
307  function flushCategories()
308  {
309  $this->categories = array();
310  }
311 
312 } // END class.SurveyCategories
313 ?>