ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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 string IL_CDF_SORT_ID = 'field_id'
 
const string IL_CDF_SORT_NAME = 'field_name'
 
const int IL_CDF_TYPE_TEXT = 1
 
const int 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 24 of file class.ilCourseDefinedFieldDefinition.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

44 {
45 global $DIC;
46
47 $this->db = $DIC->database();
48 $this->lng = $DIC->language();
49 $this->obj_id = $a_obj_id;
50 $this->id = $a_field_id;
51
52 if ($this->id) {
53 $this->read();
54 }
55 }
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 57 of file class.ilCourseDefinedFieldDefinition.php.

57 : void
58 {
59 foreach (ilCourseDefinedFieldDefinition::_getFields($a_source_id) as $field_obj) {
60 $cdf = new ilCourseDefinedFieldDefinition($a_target_id);
61 $cdf->setName($field_obj->getName());
62 $cdf->setType($field_obj->getType());
63 $cdf->setValues($field_obj->getValues());
64 $cdf->setValueOptions($field_obj->getValueOptions());
65 $cdf->enableRequired($field_obj->isRequired());
66 $cdf->save();
67 }
68 }
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 70 of file class.ilCourseDefinedFieldDefinition.php.

70 : void
71 {
72 global $DIC;
73
74 $ilDB = $DIC->database();
75 // Delete user entries
76 foreach (ilCourseDefinedFieldDefinition::_getFieldIds($a_container_id) as $field_id) {
78 }
79 $query = "DELETE FROM crs_f_definitions " .
80 "WHERE obj_id = " . $ilDB->quote($a_container_id, 'integer') . " ";
81 $res = $ilDB->manipulate($query);
82 }
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 127 of file class.ilCourseDefinedFieldDefinition.php.

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

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 145 of file class.ilCourseDefinedFieldDefinition.php.

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

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 110 of file class.ilCourseDefinedFieldDefinition.php.

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

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 161 of file class.ilCourseDefinedFieldDefinition.php.

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

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 268 of file class.ilCourseDefinedFieldDefinition.php.

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

◆ delete()

ilCourseDefinedFieldDefinition::delete ( )

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

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

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

+ Here is the call graph for this function:

◆ enableRequired()

ilCourseDefinedFieldDefinition::enableRequired ( bool  $a_status)

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

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

Referenced by read().

+ Here is the caller graph for this function:

◆ getId()

ilCourseDefinedFieldDefinition::getId ( )

Definition at line 179 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 225 of file class.ilCourseDefinedFieldDefinition.php.

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

◆ getName()

ilCourseDefinedFieldDefinition::getName ( )

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

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

References $name.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ getObjId()

ilCourseDefinedFieldDefinition::getObjId ( )

Definition at line 174 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 184 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 214 of file class.ilCourseDefinedFieldDefinition.php.

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

◆ getValueOptions()

ilCourseDefinedFieldDefinition::getValueOptions ( )

Definition at line 245 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 204 of file class.ilCourseDefinedFieldDefinition.php.

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

References $values.

Referenced by save(), and update().

+ Here is the caller graph for this function:

◆ isRequired()

ilCourseDefinedFieldDefinition::isRequired ( )

Definition at line 230 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 250 of file class.ilCourseDefinedFieldDefinition.php.

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

References ILIAS\UI\Implementation\Component\Input\Field\$options, getId(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ prepareValues()

ilCourseDefinedFieldDefinition::prepareValues ( array  $a_values)

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

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

◆ read()

ilCourseDefinedFieldDefinition::read ( )
private

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

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

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 275 of file class.ilCourseDefinedFieldDefinition.php.

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

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 199 of file class.ilCourseDefinedFieldDefinition.php.

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

Referenced by read().

+ Here is the caller graph for this function:

◆ setType()

ilCourseDefinedFieldDefinition::setType ( int  $a_type)

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

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

Referenced by read().

+ Here is the caller graph for this function:

◆ setValueOptions()

ilCourseDefinedFieldDefinition::setValueOptions ( array  $a_options)

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

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

Referenced by read().

+ Here is the caller graph for this function:

◆ setValues()

ilCourseDefinedFieldDefinition::setValues ( array  $a_values)

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

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

Referenced by read().

+ Here is the caller graph for this function:

◆ update()

ilCourseDefinedFieldDefinition::update ( )

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

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

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 31 of file class.ilCourseDefinedFieldDefinition.php.

◆ $id

int ilCourseDefinedFieldDefinition::$id = 0
private

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

Referenced by getId().

◆ $lng

ilLanguage ilCourseDefinedFieldDefinition::$lng
protected

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

◆ $name

string ilCourseDefinedFieldDefinition::$name = ''
private

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

Referenced by getName().

◆ $obj_id

int ilCourseDefinedFieldDefinition::$obj_id
private

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

Referenced by getObjId().

◆ $required

bool ilCourseDefinedFieldDefinition::$required = false
private

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

Referenced by isRequired().

◆ $type

int ilCourseDefinedFieldDefinition::$type = 0
private

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

Referenced by getType().

◆ $value_options

array ilCourseDefinedFieldDefinition::$value_options = []
private

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

Referenced by getValueOptions().

◆ $values

array ilCourseDefinedFieldDefinition::$values = []
private

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

Referenced by getValues().

◆ IL_CDF_SORT_ID

const string ilCourseDefinedFieldDefinition::IL_CDF_SORT_ID = 'field_id'

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

Referenced by _getFieldIds().

◆ IL_CDF_SORT_NAME

const string ilCourseDefinedFieldDefinition::IL_CDF_SORT_NAME = 'field_name'

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

◆ IL_CDF_TYPE_SELECT

◆ IL_CDF_TYPE_TEXT


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