ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSurveyPhrases Class Reference

Survey phrases class. More...

+ Collaboration diagram for ilSurveyPhrases:

Public Member Functions

 __construct ()
 ilSurveyPhrases constructor More...
 
 deletePhrases ($phrase_array)
 Delete phrases from the database. More...
 
 updatePhrase ($phrase_id)
 Saves a set of categories to a default phrase. More...
 
 savePhrase ()
 Saves a set of categories to a default phrase. More...
 
 __get ($value)
 Object getter. More...
 
 __set ($key, $value)
 Object setter. More...
 

Static Public Member Functions

static _getAvailablePhrases ($useronly=0)
 Gets the available phrases from the database. More...
 
static _getCategoriesForPhrase ($phrase_id)
 Gets the available categories for a given phrase. More...
 

Protected Attributes

 $db
 
 $user
 
 $arrData
 

Detailed Description

Survey phrases class.

The ilSurveyPhrases class manages survey phrases (collections of survey categories) for ordinal survey question types.

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 34 of file class.ilSurveyPhrases.php.

Constructor & Destructor Documentation

◆ __construct()

ilSurveyPhrases::__construct ( )

ilSurveyPhrases constructor

Definition at line 51 of file class.ilSurveyPhrases.php.

References $DIC, array, and user().

52  {
53  global $DIC;
54 
55  $this->db = $DIC->database();
56  $this->user = $DIC->user();
57  $this->arrData = array();
58  }
global $DIC
Definition: saml.php:7
user()
Definition: user.php:4
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ __get()

ilSurveyPhrases::__get (   $value)

Object getter.

Definition at line 234 of file class.ilSurveyPhrases.php.

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  }

◆ __set()

ilSurveyPhrases::__set (   $key,
  $value 
)

Object setter.

Definition at line 250 of file class.ilSurveyPhrases.php.

References $key.

251  {
252  switch ($key) {
253  default:
254  $this->arrData[$key] = $value;
255  break;
256  }
257  }
$key
Definition: croninfo.php:18

◆ _getAvailablePhrases()

static ilSurveyPhrases::_getAvailablePhrases (   $useronly = 0)
static

Gets the available phrases from the database.

Parameters
boolean$useronlyReturns only the user defined phrases if set to true. The default is false.
Returns
array All available phrases as key/value pairs

Definition at line 66 of file class.ilSurveyPhrases.php.

References $DIC, $ilDB, $ilUser, $lng, $result, $row, and array.

Referenced by ilSurveyPhrasesGUI\deletePhrasesForm(), SurveyQuestionGUI\initPhrasesForm(), and ilSurveyPhrasesGUI\phrases().

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  }
$result
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
global $ilDB
+ Here is the caller graph for this function:

◆ _getCategoriesForPhrase()

static ilSurveyPhrases::_getCategoriesForPhrase (   $phrase_id)
static

Gets the available categories for a given phrase.

Parameters
integer$phrase_idThe database id of the given phrase
Returns
array All available categories

Definition at line 111 of file class.ilSurveyPhrases.php.

References $DIC, $ilDB, $lng, $result, $row, and array.

Referenced by ilSurveyPhrasesGUI\deletePhrasesForm(), SurveyQuestionGUI\initPhrasesForm(), and ilSurveyPhrasesGUI\phrases().

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  }
$result
global $DIC
Definition: saml.php:7
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
global $ilDB
+ Here is the caller graph for this function:

◆ deletePhrases()

ilSurveyPhrases::deletePhrases (   $phrase_array)

Delete phrases from the database.

Parameters
array$phrase_arrayAn array containing phrase id's to delete

Definition at line 141 of file class.ilSurveyPhrases.php.

References $db, and $ilDB.

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  }
global $ilDB

◆ savePhrase()

ilSurveyPhrases::savePhrase ( )

Saves a set of categories to a default phrase.

Definition at line 198 of file class.ilSurveyPhrases.php.

References $counter, $db, $i, $ilDB, $ilUser, $user, array, and time.

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  }
$counter
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $ilDB
$i
Definition: disco.tpl.php:19
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ updatePhrase()

ilSurveyPhrases::updatePhrase (   $phrase_id)

Saves a set of categories to a default phrase.

Parameters
array$phrasesThe database ids of the seleted phrases
string$titleThe title of the default phrase public

Definition at line 158 of file class.ilSurveyPhrases.php.

References $counter, $db, $i, $ilDB, $ilUser, $user, array, and time.

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  }
$counter
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
global $ilDB
$i
Definition: disco.tpl.php:19
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

Field Documentation

◆ $arrData

ilSurveyPhrases::$arrData
protected

Definition at line 46 of file class.ilSurveyPhrases.php.

◆ $db

ilSurveyPhrases::$db
protected

Definition at line 39 of file class.ilSurveyPhrases.php.

Referenced by deletePhrases(), savePhrase(), and updatePhrase().

◆ $user

ilSurveyPhrases::$user
protected

Definition at line 44 of file class.ilSurveyPhrases.php.

Referenced by savePhrase(), and updatePhrase().


The documentation for this class was generated from the following file: