ILIAS  release_8 Revision v8.24
ilSurveyPhrases Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilSurveyPhrases:

Public Member Functions

 __construct ()
 
 deletePhrases (array $phrase_array)
 Delete phrases from the database. More...
 
 updatePhrase (int $phrase_id)
 
 savePhrase ()
 Saves a set of categories to a default phrase. More...
 
 __get (string $value)
 
 __set (string $key, $value)
 

Static Public Member Functions

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

Protected Attributes

ilDBInterface $db
 
ilObjUser $user
 
array $arrData
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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
Todo:
split up in dto and repo class

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

Constructor & Destructor Documentation

◆ __construct()

ilSurveyPhrases::__construct ( )

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

36 {
37 global $DIC;
38
39 $this->db = $DIC->database();
40 $this->user = $DIC->user();
41 $this->arrData = array();
42 }
global $DIC
Definition: feed.php:28

References $DIC, and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ __get()

ilSurveyPhrases::__get ( string  $value)
Returns
mixed|null

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

206 {
207 switch ($value) {
208 default:
209 return $this->arrData[$value] ?? null;
210 }
211 }

◆ __set()

ilSurveyPhrases::__set ( string  $key,
  $value 
)
Parameters
mixed | null$value

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

216 : void
217 {
218 switch ($key) {
219 default:
220 $this->arrData[$key] = $value;
221 break;
222 }
223 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

◆ _getAvailablePhrases()

static ilSurveyPhrases::_getAvailablePhrases ( bool  $useronly = false)
static

Gets the available phrases from the database.

Parameters
bool$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 50 of file class.ilSurveyPhrases.php.

52 : array {
53 global $DIC;
54
55 $ilUser = $DIC->user();
56 $ilDB = $DIC->database();
57 $lng = $DIC->language();
58
59 $phrases = array();
60 $result = $ilDB->queryF(
61 "SELECT * FROM svy_phrase WHERE defaultvalue = %s OR owner_fi = %s ORDER BY title",
62 array('text', 'integer'),
63 array('1', $ilUser->getId())
64 );
65 while ($row = $ilDB->fetchObject($result)) {
66 if ((int) $row->defaultvalue === 1 && (int) $row->owner_fi === 0) {
67 if (!$useronly) {
68 $phrases[$row->phrase_id] = array(
69 "title" => $lng->txt($row->title),
70 "owner" => $row->owner_fi,
71 "org_title" => $row->title
72 );
73 }
74 } elseif ($ilUser->getId() === (int) $row->owner_fi) {
75 $phrases[$row->phrase_id] = array(
76 "title" => $row->title,
77 "owner" => $row->owner_fi
78 );
79 }
80 }
81 return $phrases;
82 }
$ilUser
Definition: imgupload.php:34
$lng

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

+ Here is the caller graph for this function:

◆ _getCategoriesForPhrase()

static ilSurveyPhrases::_getCategoriesForPhrase ( int  $phrase_id)
static

Gets the available categories for a given phrase.

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

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

91 : array {
92 global $DIC;
93
94 $ilDB = $DIC->database();
95 $lng = $DIC->language();
96
97 $categories = array();
98 $result = $ilDB->queryF(
99 "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",
100 array('integer'),
101 array($phrase_id)
102 );
103 while ($row = $ilDB->fetchObject($result)) {
104 if ((int) $row->defaultvalue === 1 && (int) $row->owner_fi === 0) {
105 $categories[$row->category_id] = $lng->txt($row->title);
106 } else {
107 $categories[$row->category_id] = $row->title;
108 }
109 }
110 return $categories;
111 }

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

+ Here is the caller graph for this function:

◆ deletePhrases()

ilSurveyPhrases::deletePhrases ( array  $phrase_array)

Delete phrases from the database.

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

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

119 : void {
121
122 if (count($phrase_array) > 0) {
123 $ilDB->manipulate("DELETE FROM svy_phrase WHERE " . $ilDB->in('phrase_id', $phrase_array, false, 'integer'));
124 $ilDB->manipulate("DELETE FROM svy_phrase_cat WHERE " . $ilDB->in('phrase_fi', $phrase_array, false, 'integer'));
125 }
126 }

References $ilDB.

◆ savePhrase()

ilSurveyPhrases::savePhrase ( )

Saves a set of categories to a default phrase.

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

169 : void
170 {
173
174 $next_id = $ilDB->nextId('svy_phrase');
175 $ilDB->manipulateF(
176 "INSERT INTO svy_phrase (phrase_id, title, defaultvalue, owner_fi, tstamp) VALUES (%s, %s, %s, %s, %s)",
177 array('integer','text','text','integer','integer'),
178 array($next_id, $this->title, 1, $ilUser->getId(), time())
179 );
180 $phrase_id = $next_id;
181
182 $counter = 1;
183 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
184 $cat = $this->categories->getCategory($i);
185 $next_id = $ilDB->nextId('svy_category');
186 $affectedRows = $ilDB->manipulateF(
187 "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
188 array('integer','text','text','integer','integer','text'),
189 array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
190 );
191 $category_id = $next_id;
192 $next_id = $ilDB->nextId('svy_phrase_cat');
193 $affectedRows = $ilDB->manipulateF(
194 "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
195 array('integer', 'integer', 'integer','integer'),
196 array($next_id, $phrase_id, $category_id, $counter)
197 );
198 $counter++;
199 }
200 }
$i
Definition: metadata.php:41

References $i, $ilDB, and $ilUser.

◆ updatePhrase()

ilSurveyPhrases::updatePhrase ( int  $phrase_id)

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

130 : void {
133
134 $ilDB->manipulateF(
135 "UPDATE svy_phrase SET title = %s, tstamp = %s WHERE phrase_id = %s",
136 array('text','integer','integer'),
137 array($this->title, time(), $phrase_id)
138 );
139
140 $ilDB->manipulateF(
141 "DELETE FROM svy_phrase_cat WHERE phrase_fi = %s",
142 array('integer'),
143 array($phrase_id)
144 );
145
146 $counter = 1;
147 for ($i = 0; $i < $this->categories->getCategoryCount(); $i++) {
148 $cat = $this->categories->getCategory($i);
149 $next_id = $ilDB->nextId('svy_category');
150 $affectedRows = $ilDB->manipulateF(
151 "INSERT INTO svy_category (category_id, title, defaultvalue, owner_fi, tstamp, neutral) VALUES (%s, %s, %s, %s, %s, %s)",
152 array('integer','text','text','integer','integer','text'),
153 array($next_id, $cat->title, 1, $ilUser->getId(), time(), $cat->neutral)
154 );
155 $category_id = $next_id;
156 $next_id = $ilDB->nextId('svy_phrase_cat');
157 $affectedRows = $ilDB->manipulateF(
158 "INSERT INTO svy_phrase_cat (phrase_category_id, phrase_fi, category_fi, sequence) VALUES (%s, %s, %s, %s)",
159 array('integer', 'integer', 'integer','integer'),
160 array($next_id, $phrase_id, $category_id, $counter)
161 );
162 $counter++;
163 }
164 }

References $i, $ilDB, and $ilUser.

Field Documentation

◆ $arrData

array ilSurveyPhrases::$arrData
protected

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

◆ $db

ilDBInterface ilSurveyPhrases::$db
protected

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

◆ $user

ilObjUser ilSurveyPhrases::$user
protected

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


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