ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveyPhrases.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 
35 {
36  protected $arrData;
37 
41  function __construct()
42  {
43  $this->arrData = array();
44  }
45 
52  public static function &_getAvailablePhrases($useronly = 0)
53  {
54  global $ilUser;
55  global $ilDB;
56  global $lng;
57 
58  $phrases = array();
59  $result = $ilDB->queryF("SELECT * FROM svy_phrase WHERE defaultvalue = %s OR owner_fi = %s ORDER BY title",
60  array('text', 'integer'),
61  array('1', $ilUser->getId())
62  );
63  while ($row = $ilDB->fetchObject($result))
64  {
65  if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
66  {
67  if (!$useronly)
68  {
69  $phrases[$row->phrase_id] = array(
70  "title" => $lng->txt($row->title),
71  "owner" => $row->owner_fi
72  );
73  }
74  }
75  else
76  {
77  if ($ilUser->getId() == $row->owner_fi)
78  {
79  $phrases[$row->phrase_id] = array(
80  "title" => $row->title,
81  "owner" => $row->owner_fi
82  );
83  }
84  }
85  }
86  return $phrases;
87  }
88 
95  public static function &_getCategoriesForPhrase($phrase_id)
96  {
97  global $ilDB;
98  global $lng;
99 
100  $categories = array();
101  $result = $ilDB->queryF("SELECT svy_category.* FROM svy_category, svy_phrase_cat WHERE svy_phrase_cat.category_fi = svy_category.category_id AND svy_phrase_cat.phrase_fi = %s ORDER BY svy_phrase_cat.sequence",
102  array('integer'),
103  array($phrase_id)
104  );
105  while ($row = $ilDB->fetchObject($result))
106  {
107  if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
108  {
109  $categories[$row->category_id] = $lng->txt($row->title);
110  }
111  else
112  {
113  $categories[$row->category_id] = $row->title;
114  }
115  }
116  return $categories;
117  }
118 
124  function deletePhrases($phrase_array)
125  {
126  global $ilDB;
127 
128  if ((is_array($phrase_array)) && (count($phrase_array)))
129  {
130  $affectedRows = $ilDB->manipulate("DELETE FROM svy_phrase WHERE " . $ilDB->in('phrase_id', $phrase_array, false, 'integer'));
131  $affectedRows = $ilDB->manipulate("DELETE FROM svy_phrase_cat WHERE " . $ilDB->in('phrase_fi', $phrase_array, false, 'integer'));
132  }
133  }
134 
142  function updatePhrase($phrase_id)
143  {
144  global $ilUser;
145  global $ilDB;
146 
147  $affectedRows = $ilDB->manipulateF("UPDATE svy_phrase SET title = %s, tstamp = %s WHERE phrase_id = %s",
148  array('text','integer','integer'),
149  array($this->title, time(), $phrase_id)
150  );
151 
152  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_phrase_cat WHERE phrase_fi = %s",
153  array('integer'),
154  array($phrase_id)
155  );
156 
157  $counter = 1;
158  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
159  {
160  $cat = $this->categories->getCategory($i);
161  $next_id = $ilDB->nextId('svy_category');
162  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
163  array('integer','text','text','integer','integer','text'),
164  array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
165  );
166  $category_id = $next_id;
167  $next_id = $ilDB->nextId('svy_phrase_cat');
168  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
169  array('integer', 'integer', 'integer','integer'),
170  array($next_id, $phrase_id, $category_id, $counter)
171  );
172  $counter++;
173  }
174  }
175 
179  public function savePhrase()
180  {
181  global $ilUser;
182  global $ilDB;
183 
184  $next_id = $ilDB->nextId('svy_phrase');
185  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
186  array('integer','text','text','integer','integer'),
187  array($next_id, $this->title, 1, $ilUser->getId(), time())
188  );
189  $phrase_id = $next_id;
190 
191  $counter = 1;
192  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
193  {
194  $cat = $this->categories->getCategory($i);
195  $next_id = $ilDB->nextId('svy_category');
196  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
197  array('integer','text','text','integer','integer','text'),
198  array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
199  );
200  $category_id = $next_id;
201  $next_id = $ilDB->nextId('svy_phrase_cat');
202  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
203  array('integer', 'integer', 'integer','integer'),
204  array($next_id, $phrase_id, $category_id, $counter)
205  );
206  $counter++;
207  }
208  }
209 
213  public function __get($value)
214  {
215  switch ($value)
216  {
217  default:
218  if (array_key_exists($value, $this->arrData))
219  {
220  return $this->arrData[$value];
221  }
222  else
223  {
224  return null;
225  }
226  break;
227  }
228  }
229 
233  public function __set($key, $value)
234  {
235  switch ($key)
236  {
237  default:
238  $this->arrData[$key] = $value;
239  break;
240  }
241  }
242 }
243 ?>