ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
39  protected $db;
40 
44  protected $user;
45 
46  protected $arrData;
47 
51  public function __construct()
52  {
53  global $DIC;
54 
55  $this->db = $DIC->database();
56  $this->user = $DIC->user();
57  $this->arrData = array();
58  }
59 
66  public static function _getAvailablePhrases($useronly = 0)
67  {
68  global $DIC;
69 
70  $ilUser = $DIC->user();
71  global $DIC;
72 
73  $ilDB = $DIC->database();
74  global $DIC;
75 
76  $lng = $DIC->language();
77 
78  $phrases = array();
79  $result = $ilDB->queryF(
80  "SELECT * FROM svy_phrase WHERE defaultvalue = %s OR owner_fi = %s ORDER BY title",
81  array('text', 'integer'),
82  array('1', $ilUser->getId())
83  );
84  while ($row = $ilDB->fetchObject($result)) {
85  if (($row->defaultvalue == 1) and ($row->owner_fi == 0)) {
86  if (!$useronly) {
87  $phrases[$row->phrase_id] = array(
88  "title" => $lng->txt($row->title),
89  "owner" => $row->owner_fi,
90  "org_title" => $row->title
91  );
92  }
93  } else {
94  if ($ilUser->getId() == $row->owner_fi) {
95  $phrases[$row->phrase_id] = array(
96  "title" => $row->title,
97  "owner" => $row->owner_fi
98  );
99  }
100  }
101  }
102  return $phrases;
103  }
104 
111  public static function _getCategoriesForPhrase($phrase_id)
112  {
113  global $DIC;
114 
115  $ilDB = $DIC->database();
116  global $DIC;
117 
118  $lng = $DIC->language();
119 
120  $categories = array();
121  $result = $ilDB->queryF(
122  "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",
123  array('integer'),
124  array($phrase_id)
125  );
126  while ($row = $ilDB->fetchObject($result)) {
127  if (($row->defaultvalue == 1) and ($row->owner_fi == 0)) {
128  $categories[$row->category_id] = $lng->txt($row->title);
129  } else {
130  $categories[$row->category_id] = $row->title;
131  }
132  }
133  return $categories;
134  }
135 
141  public function deletePhrases($phrase_array)
142  {
143  $ilDB = $this->db;
144 
145  if ((is_array($phrase_array)) && (count($phrase_array))) {
146  $affectedRows = $ilDB->manipulate("DELETE FROM svy_phrase WHERE " . $ilDB->in('phrase_id', $phrase_array, false, 'integer'));
147  $affectedRows = $ilDB->manipulate("DELETE FROM svy_phrase_cat WHERE " . $ilDB->in('phrase_fi', $phrase_array, false, 'integer'));
148  }
149  }
150 
158  public function updatePhrase($phrase_id)
159  {
161  $ilDB = $this->db;
162 
163  $affectedRows = $ilDB->manipulateF(
164  "UPDATE svy_phrase SET title = %s, tstamp = %s WHERE phrase_id = %s",
165  array('text','integer','integer'),
166  array($this->title, time(), $phrase_id)
167  );
168 
169  $affectedRows = $ilDB->manipulateF(
170  "DELETE FROM svy_phrase_cat WHERE phrase_fi = %s",
171  array('integer'),
172  array($phrase_id)
173  );
174 
175  $counter = 1;
176  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
177  $cat = $this->categories->getCategory($i);
178  $next_id = $ilDB->nextId('svy_category');
179  $affectedRows = $ilDB->manipulateF(
180  "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
181  array('integer','text','text','integer','integer','text'),
182  array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
183  );
184  $category_id = $next_id;
185  $next_id = $ilDB->nextId('svy_phrase_cat');
186  $affectedRows = $ilDB->manipulateF(
187  "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
188  array('integer', 'integer', 'integer','integer'),
189  array($next_id, $phrase_id, $category_id, $counter)
190  );
191  $counter++;
192  }
193  }
194 
198  public function savePhrase()
199  {
201  $ilDB = $this->db;
202 
203  $next_id = $ilDB->nextId('svy_phrase');
204  $affectedRows = $ilDB->manipulateF(
205  "INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
206  array('integer','text','text','integer','integer'),
207  array($next_id, $this->title, 1, $ilUser->getId(), time())
208  );
209  $phrase_id = $next_id;
210 
211  $counter = 1;
212  for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
213  $cat = $this->categories->getCategory($i);
214  $next_id = $ilDB->nextId('svy_category');
215  $affectedRows = $ilDB->manipulateF(
216  "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
217  array('integer','text','text','integer','integer','text'),
218  array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
219  );
220  $category_id = $next_id;
221  $next_id = $ilDB->nextId('svy_phrase_cat');
222  $affectedRows = $ilDB->manipulateF(
223  "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
224  array('integer', 'integer', 'integer','integer'),
225  array($next_id, $phrase_id, $category_id, $counter)
226  );
227  $counter++;
228  }
229  }
230 
234  public function __get($value)
235  {
236  switch ($value) {
237  default:
238  if (array_key_exists($value, $this->arrData)) {
239  return $this->arrData[$value];
240  } else {
241  return null;
242  }
243  break;
244  }
245  }
246 
250  public function __set($key, $value)
251  {
252  switch ($key) {
253  default:
254  $this->arrData[$key] = $value;
255  break;
256  }
257  }
258 }
static _getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
$result
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
$counter
deletePhrases($phrase_array)
Delete phrases from the database.
updatePhrase($phrase_id)
Saves a set of categories to a default phrase.
__set($key, $value)
Object setter.
$ilUser
Definition: imgupload.php:18
__get($value)
Object getter.
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
savePhrase()
Saves a set of categories to a default phrase.
global $ilDB
static _getAvailablePhrases($useronly=0)
Gets the available phrases from the database.
$i
Definition: disco.tpl.php:19
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$key
Definition: croninfo.php:18
__construct()
ilSurveyPhrases constructor
Survey phrases class.