43 public function __construct(
int $a_obj_id,
int $a_field_id = 0)
47 $this->db =
$DIC->database();
48 $this->
lng = $DIC->language();
49 $this->obj_id = $a_obj_id;
50 $this->
id = $a_field_id;
57 public static function _clone(
int $a_source_id,
int $a_target_id): void
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());
79 $query =
"DELETE FROM crs_f_definitions " .
80 "WHERE obj_id = " .
$ilDB->quote($a_container_id,
'integer') .
" ";
97 public static function _getFields(
int $a_container_id, $a_sort = self::IL_CDF_SORT_NAME): array
116 $query =
"SELECT * FROM crs_f_definitions " .
117 "WHERE obj_id = " .
$ilDB->quote($a_obj_id,
'integer') .
" " .
118 "AND field_required = 1";
121 while ($row =
$ilDB->fetchObject(
$res)) {
122 $req_fields[] = (
int) $row->field_id;
132 $query =
"SELECT field_name FROM crs_f_definitions " .
133 "WHERE obj_id = " .
$ilDB->quote($a_obj_id,
'integer');
136 while ($row =
$ilDB->fetchObject(
$res)) {
137 $fields[] = $row->field_name;
139 return implode(
'<br />', $fields);
145 public static function _getFieldIds(
int $a_container_id,
string $a_sort = self::IL_CDF_SORT_ID): array
150 $query =
"SELECT field_id FROM crs_f_definitions " .
151 "WHERE obj_id = " .
$ilDB->quote($a_container_id,
'integer') .
" " .
155 while ($row =
$ilDB->fetchObject(
$res)) {
156 $field_ids[] = (
int) $row->field_id;
166 $query =
"SELECT * FROM crs_f_definitions " .
167 "WHERE field_id = " .
$ilDB->quote($a_field_id,
'integer');
171 return $row->field_name ?:
'';
191 $this->type = $a_type;
201 $this->name = $a_name;
211 $this->values = $a_values;
217 is_array($this->values) &&
218 array_key_exists($a_id, $this->values)
220 return $this->values[$a_id];
227 return (($pos = array_search($a_value, $this->values)) ===
false) ? -1 : $pos;
237 $this->required = $a_status;
242 $this->value_options = $a_options;
255 foreach ($this->values as $key => $value) {
264 $tmp_values = array_filter($a_values,
'strlen');
270 $this->values = array_unique(array_merge($this->values, $a_values));
271 #sort($this->values);
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) " .
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') .
", " .
288 $res = $this->db->manipulate($query);
289 $this->
id = $next_id;
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);
305 public function delete():
void
308 $query =
"DELETE FROM crs_f_definitions " .
309 "WHERE field_id = " . $this->db->quote($this->
getId(),
'integer') .
" ";
310 $res = $this->db->manipulate($query);
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') .
" ";
319 $res = $this->db->query($query);
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) ?: []));
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
appendValues(array $a_values)
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
static _deleteByContainer(int $a_container_id)
const int IL_CDF_TYPE_TEXT
const string IL_CDF_SORT_ID
const string IL_CDF_SORT_NAME
static _clone(int $a_source_id, int $a_target_id)
setValues(array $a_values)
static _getFieldIds(int $a_container_id, string $a_sort=self::IL_CDF_SORT_ID)
enableRequired(bool $a_status)
setValueOptions(array $a_options)
static _fieldsToInfoString(int $a_obj_id)
__construct(int $a_obj_id, int $a_field_id=0)
prepareValues(array $a_values)
static _hasFields(int $a_container_id)
Check if there are any define fields.
static _lookupName(int $a_field_id)
const int IL_CDF_TYPE_SELECT
static _getRequiredFieldIds(int $a_obj_id)
Get required filed id's.
getIdByValue(string $a_value)
static _deleteByField(int $a_field_id)