ILIAS  Release_4_4_x_branch Revision 61816
 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  "org_title" => $row->title
73  );
74  }
75  }
76  else
77  {
78  if ($ilUser->getId() == $row->owner_fi)
79  {
80  $phrases[$row->phrase_id] = array(
81  "title" => $row->title,
82  "owner" => $row->owner_fi
83  );
84  }
85  }
86  }
87  return $phrases;
88  }
89 
96  public static function &_getCategoriesForPhrase($phrase_id)
97  {
98  global $ilDB;
99  global $lng;
100 
101  $categories = array();
102  $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",
103  array('integer'),
104  array($phrase_id)
105  );
106  while ($row = $ilDB->fetchObject($result))
107  {
108  if (($row->defaultvalue == 1) and ($row->owner_fi == 0))
109  {
110  $categories[$row->category_id] = $lng->txt($row->title);
111  }
112  else
113  {
114  $categories[$row->category_id] = $row->title;
115  }
116  }
117  return $categories;
118  }
119 
125  function deletePhrases($phrase_array)
126  {
127  global $ilDB;
128 
129  if ((is_array($phrase_array)) && (count($phrase_array)))
130  {
131  $affectedRows = $ilDB->manipulate("DELETE FROM svy_phrase WHERE " . $ilDB->in('phrase_id', $phrase_array, false, 'integer'));
132  $affectedRows = $ilDB->manipulate("DELETE FROM svy_phrase_cat WHERE " . $ilDB->in('phrase_fi', $phrase_array, false, 'integer'));
133  }
134  }
135 
143  function updatePhrase($phrase_id)
144  {
145  global $ilUser;
146  global $ilDB;
147 
148  $affectedRows = $ilDB->manipulateF("UPDATE svy_phrase SET title = %s, tstamp = %s WHERE phrase_id = %s",
149  array('text','integer','integer'),
150  array($this->title, time(), $phrase_id)
151  );
152 
153  $affectedRows = $ilDB->manipulateF("DELETE FROM svy_phrase_cat WHERE phrase_fi = %s",
154  array('integer'),
155  array($phrase_id)
156  );
157 
158  $counter = 1;
159  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
160  {
161  $cat = $this->categories->getCategory($i);
162  $next_id = $ilDB->nextId('svy_category');
163  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
164  array('integer','text','text','integer','integer','text'),
165  array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
166  );
167  $category_id = $next_id;
168  $next_id = $ilDB->nextId('svy_phrase_cat');
169  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
170  array('integer', 'integer', 'integer','integer'),
171  array($next_id, $phrase_id, $category_id, $counter)
172  );
173  $counter++;
174  }
175  }
176 
180  public function savePhrase()
181  {
182  global $ilUser;
183  global $ilDB;
184 
185  $next_id = $ilDB->nextId('svy_phrase');
186  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
187  array('integer','text','text','integer','integer'),
188  array($next_id, $this->title, 1, $ilUser->getId(), time())
189  );
190  $phrase_id = $next_id;
191 
192  $counter = 1;
193  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++)
194  {
195  $cat = $this->categories->getCategory($i);
196  $next_id = $ilDB->nextId('svy_category');
197  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
198  array('integer','text','text','integer','integer','text'),
199  array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
200  );
201  $category_id = $next_id;
202  $next_id = $ilDB->nextId('svy_phrase_cat');
203  $affectedRows = $ilDB->manipulateF("INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
204  array('integer', 'integer', 'integer','integer'),
205  array($next_id, $phrase_id, $category_id, $counter)
206  );
207  $counter++;
208  }
209  }
210 
214  public function __get($value)
215  {
216  switch ($value)
217  {
218  default:
219  if (array_key_exists($value, $this->arrData))
220  {
221  return $this->arrData[$value];
222  }
223  else
224  {
225  return null;
226  }
227  break;
228  }
229  }
230 
234  public function __set($key, $value)
235  {
236  switch ($key)
237  {
238  default:
239  $this->arrData[$key] = $value;
240  break;
241  }
242  }
243 }
244 ?>