24 define(
"IL_CDF_SORT_ID",
'field_id');
25 define(
"IL_CDF_SORT_NAME",
'field_name');
27 define(
'IL_CDF_TYPE_TEXT', 1);
28 define(
'IL_CDF_TYPE_SELECT', 2);
65 $this->obj_id = $a_obj_id;
66 $this->
id = $a_field_id;
82 public static function _clone($a_source_id, $a_target_id)
86 $cdf->setName($field_obj->getName());
87 $cdf->setType($field_obj->getType());
88 $cdf->setValues($field_obj->getValues());
89 $cdf->setValueOptions($field_obj->getValueOptions());
90 $cdf->enableRequired($field_obj->isRequired());
107 $ilDB = $DIC[
'ilDB'];
110 include_once(
'Modules/Course/classes/Export/class.ilCourseUserData.php');
115 $query =
"DELETE FROM crs_f_definitions " .
116 "WHERE obj_id = " .
$ilDB->quote($a_container_id,
'integer') .
" ";
144 return $fields ? $fields : array();
159 $ilDB = $DIC[
'ilDB'];
161 $query =
"SELECT * FROM crs_f_definitions " .
162 "WHERE obj_id = " .
$ilDB->quote($a_obj_id,
'integer') .
" " .
163 "AND field_required = 1";
166 $req_fields[] =
$row->field_id;
168 return $req_fields ? $req_fields : array();
183 $ilDB = $DIC[
'ilDB'];
186 $query =
"SELECT field_name FROM crs_f_definitions " .
187 "WHERE obj_id = " .
$ilDB->quote($a_obj_id,
'integer');
192 $fields[] =
$row->field_name;
194 return implode(
'<br />', $fields);
209 $ilDB = $DIC[
'ilDB'];
211 $query =
"SELECT field_id FROM crs_f_definitions " .
212 "WHERE obj_id = " .
$ilDB->quote($a_container_id,
'integer') .
" " .
216 $field_ids[] =
$row->field_id;
218 return $field_ids ? $field_ids : array();
233 $ilDB = $DIC[
'ilDB'];
235 $query =
"SELECT * FROM crs_f_definitions " .
236 "WHERE field_id = " .
$ilDB->quote($a_field_id,
'integer');
241 return $row->field_name ?
$row->field_name :
'';
266 $this->name = $a_name;
270 return $this->values ? $this->values : array();
274 $this->values = $a_values;
278 if (is_array($this->values)
and array_key_exists($a_id, $this->values)) {
279 return $this->values[$a_id];
285 return (($pos = array_search($a_value, $this->values)) ===
false) ? -1 : $pos;
294 $this->required = $a_status;
299 $this->value_options = $a_options;
324 foreach ($this->values as
$key => $value) {
338 $tmp_values = array();
340 if (!is_array($a_values)) {
343 foreach ($a_values as $idx => $value) {
344 if (strlen($value)) {
345 $tmp_values[$idx] = $value;
348 return $tmp_values ? $tmp_values : array();
358 if (!is_array($a_values)) {
361 $this->values = array_unique(array_merge($this->values, $a_values));
362 #sort($this->values); 373 if (!isset($this->values[$a_id])) {
376 unset($this->values[$a_id]);
377 array_merge($this->values);
392 $ilDB = $DIC[
'ilDB'];
394 $next_id =
$ilDB->nextId(
'crs_f_definitions');
395 $query =
"INSERT INTO crs_f_definitions (field_id,obj_id,field_name,field_type,field_values,field_required,field_values_opt) " .
397 $ilDB->quote($next_id,
'integer') .
", " .
398 $this->db->quote($this->
getObjId(),
'integer') .
", " .
399 $this->db->quote($this->
getName(),
"text") .
", " .
400 $this->db->quote($this->
getType(),
'integer') .
", " .
401 $this->db->quote(serialize($this->
getValues()),
'text') .
", " .
406 $this->
id = $next_id;
420 $ilDB = $DIC[
'ilDB'];
422 $query =
"UPDATE crs_f_definitions " .
423 "SET field_name = " . $this->db->quote($this->
getName(),
'text') .
", " .
424 "field_type = " . $this->db->quote($this->
getType(),
'integer') .
", " .
425 "field_values = " . $this->db->quote(serialize($this->
getValues()),
'text') .
", " .
426 "field_required = " .
$ilDB->quote($this->
isRequired(),
'integer') .
", " .
428 "WHERE field_id = " . $this->db->quote($this->
getId(),
'integer') .
" " .
429 "AND obj_id = " . $this->db->quote($this->
getObjId(),
'integer');
441 public function delete()
445 $ilDB = $DIC[
'ilDB'];
447 include_once(
'Modules/Course/classes/Export/class.ilCourseUserData.php');
450 $query =
"DELETE FROM crs_f_definitions " .
451 "WHERE field_id = " . $this->db->quote($this->
getId(),
'integer') .
" ";
463 $query =
"SELECT * FROM crs_f_definitions " .
464 "WHERE field_id = " . $this->db->quote($this->
getId(),
'integer') .
" " .
465 "AND obj_id = " . $this->db->quote($this->
getObjId(),
'integer') .
" ";
appendValues($a_values)
Append Values.
static _fieldsToInfoString($a_obj_id)
Fields to info string.
enableRequired($a_status)
setValueOptions($a_options)
static _getFieldIds($a_container_id, $a_sort=IL_CDF_SORT_ID)
Get all field ids of a container.
static _getRequiredFieldIds($a_obj_id)
Get required filed id's.
static _deleteByField($a_field_id)
Delete by field.
static _deleteByContainer($a_container_id)
Delete all fields of a container.
static _clone($a_source_id, $a_target_id)
Clone fields.
prepareSelectBox()
Prepare an array of options for ilUtil::formSelect()
__construct($a_obj_id, $a_field_id=0)
Constructor.
deleteValue($a_id)
Delete value by id.
foreach($_POST as $key=> $value) $res
static _hasFields($a_container_id)
Check if there are any define fields.
prepareValues($a_values)
Prepare values from POST.
static _lookupName($a_field_id)
Lookup field name.
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.