ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCourseDefinedFieldDefinition 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 ilCourseDefinedFieldDefinition:

Public Member Functions

 __construct (int $a_obj_id, int $a_field_id=0)
 
 getObjId ()
 
 getId ()
 
 getType ()
 
 setType (int $a_type)
 
 getName ()
 
 setName (string $a_name)
 
 getValues ()
 
 setValues (array $a_values)
 
 getValueById (int $a_id)
 
 getIdByValue (string $a_value)
 
 isRequired ()
 
 enableRequired (bool $a_status)
 
 setValueOptions (array $a_options)
 
 getValueOptions ()
 
 prepareSelectBox ()
 
 prepareValues (array $a_values)
 
 appendValues (array $a_values)
 
 save ()
 
 update ()
 
 delete ()
 

Static Public Member Functions

static _clone (int $a_source_id, int $a_target_id)
 
static _deleteByContainer (int $a_container_id)
 
static _hasFields (int $a_container_id)
 Check if there are any define fields. More...
 
static _getFields (int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
 Get all fields of a container. More...
 
static _getRequiredFieldIds (int $a_obj_id)
 Get required filed id's. More...
 
static _fieldsToInfoString (int $a_obj_id)
 
static _getFieldIds (int $a_container_id, string $a_sort=self::IL_CDF_SORT_ID)
 
static _lookupName (int $a_field_id)
 

Data Fields

const IL_CDF_SORT_ID = 'field_id'
 
const IL_CDF_SORT_NAME = 'field_name'
 
const IL_CDF_TYPE_TEXT = 1
 
const IL_CDF_TYPE_SELECT = 2
 

Protected Attributes

ilDBInterface $db
 
ilLanguage $lng
 

Private Member Functions

 read ()
 

Private Attributes

int $obj_id
 
int $id = 0
 
string $name = ''
 
int $type = 0
 
array $values = []
 
array $value_options = []
 
bool $required = false
 

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

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$ \/

Definition at line 23 of file class.ilCourseDefinedFieldDefinition.php.

Constructor & Destructor Documentation

◆ __construct()

ilCourseDefinedFieldDefinition::__construct ( int  $a_obj_id,
int  $a_field_id = 0 
)

Definition at line 42 of file class.ilCourseDefinedFieldDefinition.php.

43 {
44 global $DIC;
45
46 $this->db = $DIC->database();
47 $this->lng = $DIC->language();
48 $this->obj_id = $a_obj_id;
49 $this->id = $a_field_id;
50
51 if ($this->id) {
52 $this->read();
53 }
54 }
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\lng(), and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ _clone()

static ilCourseDefinedFieldDefinition::_clone ( int  $a_source_id,
int  $a_target_id 
)
static

Definition at line 56 of file class.ilCourseDefinedFieldDefinition.php.

56 : void
57 {
58 foreach (ilCourseDefinedFieldDefinition::_getFields($a_source_id) as $field_obj) {
59 $cdf = new ilCourseDefinedFieldDefinition($a_target_id);
60 $cdf->setName($field_obj->getName());
61 $cdf->setType($field_obj->getType());
62 $cdf->setValues($field_obj->getValues());
63 $cdf->setValueOptions($field_obj->getValueOptions());
64 $cdf->enableRequired($field_obj->isRequired());
65 $cdf->save();
66 }
67 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.

References _getFields().

Referenced by ilObjCourse\cloneObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleteByContainer()

static ilCourseDefinedFieldDefinition::_deleteByContainer ( int  $a_container_id)
static

Definition at line 69 of file class.ilCourseDefinedFieldDefinition.php.

69 : void
70 {
71 global $DIC;
72
73 $ilDB = $DIC->database();
74 // Delete user entries
75 foreach (ilCourseDefinedFieldDefinition::_getFieldIds($a_container_id) as $field_id) {
77 }
78 $query = "DELETE FROM crs_f_definitions " .
79 "WHERE obj_id = " . $ilDB->quote($a_container_id, 'integer') . " ";
80 $res = $ilDB->manipulate($query);
81 }
static _getFieldIds(int $a_container_id, string $a_sort=self::IL_CDF_SORT_ID)
static _deleteByField(int $a_field_id)
$res
Definition: ltiservices.php:69

References $DIC, $ilDB, $res, ilCourseUserData\_deleteByField(), and _getFieldIds().

Referenced by ilObjCourse\delete().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _fieldsToInfoString()

static ilCourseDefinedFieldDefinition::_fieldsToInfoString ( int  $a_obj_id)
static

Definition at line 126 of file class.ilCourseDefinedFieldDefinition.php.

126 : string
127 {
128 global $DIC;
129
130 $ilDB = $DIC->database();
131 $query = "SELECT field_name FROM crs_f_definitions " .
132 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer');
133 $res = $ilDB->query($query);
134 $fields = [];
135 while ($row = $ilDB->fetchObject($res)) {
136 $fields[] = $row->field_name;
137 }
138 return implode('<br />', $fields);
139 }

References $DIC, $ilDB, and $res.

Referenced by ilObjCourseGUI\infoScreen(), and ilObjGroupGUI\infoScreen().

+ Here is the caller graph for this function:

◆ _getFieldIds()

static ilCourseDefinedFieldDefinition::_getFieldIds ( int  $a_container_id,
string  $a_sort = self::IL_CDF_SORT_ID 
)
static
Returns
int[]

Definition at line 144 of file class.ilCourseDefinedFieldDefinition.php.

144 : array
145 {
146 global $DIC;
147
148 $ilDB = $DIC->database();
149 $query = "SELECT field_id FROM crs_f_definitions " .
150 "WHERE obj_id = " . $ilDB->quote($a_container_id, 'integer') . " " .
151 "ORDER BY " . self::IL_CDF_SORT_ID;
152 $res = $ilDB->query($query);
153 $field_ids = [];
154 while ($row = $ilDB->fetchObject($res)) {
155 $field_ids[] = (int) $row->field_id;
156 }
157 return $field_ids;
158 }

References $DIC, $ilDB, $res, IL_CDF_SORT_ID, and ILIAS\Repository\int().

Referenced by _deleteByContainer(), _getFields(), and ilCourseUserData\_getValuesByObjId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getFields()

static ilCourseDefinedFieldDefinition::_getFields ( int  $a_container_id,
  $a_sort = self::IL_CDF_SORT_NAME 
)
static

◆ _getRequiredFieldIds()

static ilCourseDefinedFieldDefinition::_getRequiredFieldIds ( int  $a_obj_id)
static

Get required filed id's.

Returns
int[]

Definition at line 109 of file class.ilCourseDefinedFieldDefinition.php.

109 : array
110 {
111 global $DIC;
112
113 $ilDB = $DIC->database();
114
115 $query = "SELECT * FROM crs_f_definitions " .
116 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
117 "AND field_required = 1";
118 $res = $ilDB->query($query);
119 $req_fields = [];
120 while ($row = $ilDB->fetchObject($res)) {
121 $req_fields[] = (int) $row->field_id;
122 }
123 return $req_fields;
124 }

References $DIC, $ilDB, $res, and ILIAS\Repository\int().

Referenced by ilCourseUserData\_checkRequired().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _hasFields()

static ilCourseDefinedFieldDefinition::_hasFields ( int  $a_container_id)
static

◆ _lookupName()

static ilCourseDefinedFieldDefinition::_lookupName ( int  $a_field_id)
static

Definition at line 160 of file class.ilCourseDefinedFieldDefinition.php.

160 : string
161 {
162 global $DIC;
163
164 $ilDB = $DIC->database();
165 $query = "SELECT * FROM crs_f_definitions " .
166 "WHERE field_id = " . $ilDB->quote($a_field_id, 'integer');
167
168 $res = $ilDB->query($query);
169 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
170 return $row->field_name ?: '';
171 }

References $DIC, $ilDB, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilMemberExport\write().

+ Here is the caller graph for this function:

◆ appendValues()

ilCourseDefinedFieldDefinition::appendValues ( array  $a_values)

Definition at line 267 of file class.ilCourseDefinedFieldDefinition.php.

267 : bool
268 {
269 $this->values = array_unique(array_merge($this->values, $a_values));
270 #sort($this->values);
271 return true;
272 }

◆ delete()

ilCourseDefinedFieldDefinition::delete ( )

Definition at line 304 of file class.ilCourseDefinedFieldDefinition.php.

304 : void
305 {
307 $query = "DELETE FROM crs_f_definitions " .
308 "WHERE field_id = " . $this->db->quote($this->getId(), 'integer') . " ";
309 $res = $this->db->manipulate($query);
310 }

References $res, ilCourseUserData\_deleteByField(), and getId().

+ Here is the call graph for this function:

◆ enableRequired()

ilCourseDefinedFieldDefinition::enableRequired ( bool  $a_status)

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

234 : void
235 {
236 $this->required = $a_status;
237 }

Referenced by read().

+ Here is the caller graph for this function:

◆ getId()

ilCourseDefinedFieldDefinition::getId ( )

Definition at line 178 of file class.ilCourseDefinedFieldDefinition.php.

References $id.

Referenced by delete(), prepareSelectBox(), read(), and update().

+ Here is the caller graph for this function:

◆ getIdByValue()

ilCourseDefinedFieldDefinition::getIdByValue ( string  $a_value)

Definition at line 224 of file class.ilCourseDefinedFieldDefinition.php.

224 : int
225 {
226 return (($pos = array_search($a_value, $this->values)) === false) ? -1 : $pos;
227 }

◆ getName()

ilCourseDefinedFieldDefinition::getName ( )

Definition at line 193 of file class.ilCourseDefinedFieldDefinition.php.

193 : string
194 {
195 return $this->name;
196 }

References $name.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ getObjId()

ilCourseDefinedFieldDefinition::getObjId ( )

Definition at line 173 of file class.ilCourseDefinedFieldDefinition.php.

References $obj_id.

Referenced by read(), save(), and update().

+ Here is the caller graph for this function:

◆ getType()

ilCourseDefinedFieldDefinition::getType ( )

Definition at line 183 of file class.ilCourseDefinedFieldDefinition.php.

References $type.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ getValueById()

ilCourseDefinedFieldDefinition::getValueById ( int  $a_id)

Definition at line 213 of file class.ilCourseDefinedFieldDefinition.php.

213 : string
214 {
215 if (
216 is_array($this->values) &&
217 array_key_exists($a_id, $this->values)
218 ) {
219 return $this->values[$a_id];
220 }
221 return '';
222 }

◆ getValueOptions()

ilCourseDefinedFieldDefinition::getValueOptions ( )

Definition at line 244 of file class.ilCourseDefinedFieldDefinition.php.

References $value_options.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ getValues()

ilCourseDefinedFieldDefinition::getValues ( )

Definition at line 203 of file class.ilCourseDefinedFieldDefinition.php.

203 : array
204 {
205 return $this->values;
206 }

References $values.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ isRequired()

ilCourseDefinedFieldDefinition::isRequired ( )

Definition at line 229 of file class.ilCourseDefinedFieldDefinition.php.

References $required.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ prepareSelectBox()

ilCourseDefinedFieldDefinition::prepareSelectBox ( )

Definition at line 249 of file class.ilCourseDefinedFieldDefinition.php.

249 : array
250 {
251 $options = array();
252 $options[''] = $this->lng->txt('select_one');
253
254 foreach ($this->values as $key => $value) {
255 $options[$this->getId() . '_' . $key] = $value;
256 }
257 return $options;
258 }

References getId(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ prepareValues()

ilCourseDefinedFieldDefinition::prepareValues ( array  $a_values)

Definition at line 260 of file class.ilCourseDefinedFieldDefinition.php.

260 : array
261 {
262 $tmp_values = [];
263 $tmp_values = array_filter($a_values, 'strlen');
264 return $tmp_values;
265 }

◆ read()

ilCourseDefinedFieldDefinition::read ( )
private

Definition at line 312 of file class.ilCourseDefinedFieldDefinition.php.

312 : void
313 {
314 $query = "SELECT * FROM crs_f_definitions " .
315 "WHERE field_id = " . $this->db->quote($this->getId(), 'integer') . " " .
316 "AND obj_id = " . $this->db->quote($this->getObjId(), 'integer') . " ";
317
318 $res = $this->db->query($query);
319 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
320
321 $this->setName((string) $row->field_name);
322 $this->setType((int) $row->field_type);
323 $this->setValues(unserialize($row->field_values) ?: []);
324 $this->setValueOptions(unserialize($row->field_values_opt) ?: []);
325 $this->enableRequired((bool) $row->field_required);
326 }

References $res, enableRequired(), ilDBConstants\FETCHMODE_OBJECT, getId(), getObjId(), setName(), setType(), setValueOptions(), and setValues().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilCourseDefinedFieldDefinition::save ( )

Definition at line 274 of file class.ilCourseDefinedFieldDefinition.php.

274 : void
275 {
276 $next_id = $this->db->nextId('crs_f_definitions');
277 $query = "INSERT INTO crs_f_definitions (field_id,obj_id,field_name,field_type,field_values,field_required,field_values_opt) " .
278 "VALUES ( " .
279 $this->db->quote($next_id, 'integer') . ", " .
280 $this->db->quote($this->getObjId(), 'integer') . ", " .
281 $this->db->quote($this->getName(), "text") . ", " .
282 $this->db->quote($this->getType(), 'integer') . ", " .
283 $this->db->quote(serialize($this->getValues()), 'text') . ", " .
284 $this->db->quote($this->isRequired(), 'integer') . ", " .
285 $this->db->quote(serialize($this->getValueOptions()), 'text') . ' ' .
286 ") ";
287 $res = $this->db->manipulate($query);
288 $this->id = $next_id;
289 }

References $res, getName(), getObjId(), getType(), getValueOptions(), getValues(), and isRequired().

+ Here is the call graph for this function:

◆ setName()

ilCourseDefinedFieldDefinition::setName ( string  $a_name)

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

198 : void
199 {
200 $this->name = $a_name;
201 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setType()

ilCourseDefinedFieldDefinition::setType ( int  $a_type)

Definition at line 188 of file class.ilCourseDefinedFieldDefinition.php.

188 : void
189 {
190 $this->type = $a_type;
191 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setValueOptions()

ilCourseDefinedFieldDefinition::setValueOptions ( array  $a_options)

Definition at line 239 of file class.ilCourseDefinedFieldDefinition.php.

239 : void
240 {
241 $this->value_options = $a_options;
242 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setValues()

ilCourseDefinedFieldDefinition::setValues ( array  $a_values)

Definition at line 208 of file class.ilCourseDefinedFieldDefinition.php.

208 : void
209 {
210 $this->values = $a_values;
211 }

Referenced by read().

+ Here is the caller graph for this function:

◆ update()

ilCourseDefinedFieldDefinition::update ( )

Definition at line 291 of file class.ilCourseDefinedFieldDefinition.php.

291 : void
292 {
293 $query = "UPDATE crs_f_definitions " .
294 "SET field_name = " . $this->db->quote($this->getName(), 'text') . ", " .
295 "field_type = " . $this->db->quote($this->getType(), 'integer') . ", " .
296 "field_values = " . $this->db->quote(serialize($this->getValues()), 'text') . ", " .
297 "field_required = " . $this->db->quote($this->isRequired(), 'integer') . ", " .
298 'field_values_opt = ' . $this->db->quote(serialize($this->getValueOptions()), 'text') . ' ' .
299 "WHERE field_id = " . $this->db->quote($this->getId(), 'integer') . " " .
300 "AND obj_id = " . $this->db->quote($this->getObjId(), 'integer');
301 $res = $this->db->manipulate($query);
302 }

References $res, getId(), getName(), getObjId(), getType(), getValueOptions(), getValues(), and isRequired().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilCourseDefinedFieldDefinition::$db
protected

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

◆ $id

int ilCourseDefinedFieldDefinition::$id = 0
private

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

Referenced by getId().

◆ $lng

ilLanguage ilCourseDefinedFieldDefinition::$lng
protected

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

◆ $name

string ilCourseDefinedFieldDefinition::$name = ''
private

Definition at line 36 of file class.ilCourseDefinedFieldDefinition.php.

Referenced by getName().

◆ $obj_id

int ilCourseDefinedFieldDefinition::$obj_id
private

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

Referenced by getObjId().

◆ $required

bool ilCourseDefinedFieldDefinition::$required = false
private

Definition at line 40 of file class.ilCourseDefinedFieldDefinition.php.

Referenced by isRequired().

◆ $type

int ilCourseDefinedFieldDefinition::$type = 0
private

Definition at line 37 of file class.ilCourseDefinedFieldDefinition.php.

Referenced by getType().

◆ $value_options

array ilCourseDefinedFieldDefinition::$value_options = []
private

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

Referenced by getValueOptions().

◆ $values

array ilCourseDefinedFieldDefinition::$values = []
private

Definition at line 38 of file class.ilCourseDefinedFieldDefinition.php.

Referenced by getValues().

◆ IL_CDF_SORT_ID

const ilCourseDefinedFieldDefinition::IL_CDF_SORT_ID = 'field_id'

Definition at line 25 of file class.ilCourseDefinedFieldDefinition.php.

Referenced by _getFieldIds().

◆ IL_CDF_SORT_NAME

const ilCourseDefinedFieldDefinition::IL_CDF_SORT_NAME = 'field_name'

Definition at line 26 of file class.ilCourseDefinedFieldDefinition.php.

◆ IL_CDF_TYPE_SELECT

◆ IL_CDF_TYPE_TEXT


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