ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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.

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

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:22
+ 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.

References _getFields().

Referenced by ilObjCourse\cloneObject(), and ilObjGroup\read().

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.
+ 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.

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

Referenced by ilObjCourse\delete().

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  }
$res
Definition: ltiservices.php:66
static _getFieldIds(int $a_container_id, string $a_sort=self::IL_CDF_SORT_ID)
global $DIC
Definition: shib_login.php:22
static _deleteByField(int $a_field_id)
+ 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.

References $DIC, $ilDB, and $res.

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

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  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ 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.

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

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

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  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ 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

Get all fields of a container.

Parameters
intcontainer obj_id
Returns
ilCourseDefinedFieldDefinition[]

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

References _getFieldIds().

Referenced by ilObjectCustomUserFieldsPlaceholderValues\__construct(), _clone(), _hasFields(), ilMemberAgreementGUI\addCustomFields(), ilMemberExport\getOrderedExportableFields(), ilObjectCustomUserFieldsPlaceholderValues\getPlaceholderValuesForPreview(), ilExportFieldsInfo\getSelectableFieldsInfo(), ilObjCourseGUI\infoScreen(), ilObjGroupGUI\infoScreen(), ilObjectCustomUserFieldsPlaceholderDescription\initPlaceholders(), ilMemberExportGUI\initSettingsForm(), ilObjectCustomUserFieldsGUI\listFields(), ilAttendanceList\readOrderedExportableFields(), ilMemberAgreementGUI\saveCourseDefinedFields(), ilObjectCustomUserFieldsGUI\saveFields(), ilMemberAgreementGUI\setCourseDefinedFieldValues(), ilRegistrationGUI\showCustomFields(), and ilRegistrationGUI\validateCustomFields().

96  : array
97  {
98  $fields = [];
99  foreach (ilCourseDefinedFieldDefinition::_getFieldIds($a_container_id, self::IL_CDF_SORT_ID) as $field_id) {
100  $fields[] = new ilCourseDefinedFieldDefinition($a_container_id, $field_id);
101  }
102  return $fields;
103  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getFieldIds(int $a_container_id, string $a_sort=self::IL_CDF_SORT_ID)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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.

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

Referenced by ilCourseUserData\_checkRequired().

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  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ 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

Check if there are any define fields.

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

References _getFields().

Referenced by ilMemberAgreement\__construct(), ilSubscriberTableGUI\__construct(), ilWaitingListTableGUI\__construct(), ilMemberAgreement\agreementRequired(), ilObjGroupGUI\checkAgreement(), ilObjCourseGUI\checkAgreement(), ilRegistrationGUI\fillAgreement(), ilParticipantTableGUI\initSettings(), ilRegistrationGUI\setAccepted(), ilObjCourseGUI\setSubTabs(), and ilObjGroupGUI\setSubTabs().

86  : int
87  {
88  return count(ilCourseDefinedFieldDefinition::_getFields($a_container_id));
89  }
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lookupName()

static ilCourseDefinedFieldDefinition::_lookupName ( int  $a_field_id)
static

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

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

Referenced by ilMemberExport\write().

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  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ 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.

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

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  }
$res
Definition: ltiservices.php:66
static _deleteByField(int $a_field_id)
+ Here is the call graph for this function:

◆ enableRequired()

ilCourseDefinedFieldDefinition::enableRequired ( bool  $a_status)

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

Referenced by read().

234  : void
235  {
236  $this->required = $a_status;
237  }
+ 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().

178  : int
179  {
180  return $this->id;
181  }
+ 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.

References $name.

Referenced by save(), and update().

193  : string
194  {
195  return $this->name;
196  }
+ 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().

173  : int
174  {
175  return $this->obj_id;
176  }
+ 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().

183  : int
184  {
185  return $this->type;
186  }
+ 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().

244  : array
245  {
246  return $this->value_options;
247  }
+ Here is the caller graph for this function:

◆ getValues()

ilCourseDefinedFieldDefinition::getValues ( )

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

References $values.

Referenced by save(), and update().

203  : array
204  {
205  return $this->values;
206  }
+ 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().

229  : bool
230  {
231  return $this->required;
232  }
+ Here is the caller graph for this function:

◆ prepareSelectBox()

ilCourseDefinedFieldDefinition::prepareSelectBox ( )

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

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

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  }
+ 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.

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

Referenced by __construct().

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  }
$res
Definition: ltiservices.php:66
+ 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.

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

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  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ setName()

ilCourseDefinedFieldDefinition::setName ( string  $a_name)

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

Referenced by read().

198  : void
199  {
200  $this->name = $a_name;
201  }
+ Here is the caller graph for this function:

◆ setType()

ilCourseDefinedFieldDefinition::setType ( int  $a_type)

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

Referenced by read().

188  : void
189  {
190  $this->type = $a_type;
191  }
+ Here is the caller graph for this function:

◆ setValueOptions()

ilCourseDefinedFieldDefinition::setValueOptions ( array  $a_options)

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

Referenced by read().

239  : void
240  {
241  $this->value_options = $a_options;
242  }
+ Here is the caller graph for this function:

◆ setValues()

ilCourseDefinedFieldDefinition::setValues ( array  $a_values)

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

Referenced by read().

208  : void
209  {
210  $this->values = $a_values;
211  }
+ Here is the caller graph for this function:

◆ update()

ilCourseDefinedFieldDefinition::update ( )

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

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

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  }
$res
Definition: ltiservices.php:66
+ 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.

◆ 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: