42     public function __construct(
int $a_obj_id, 
int $a_field_id = 0)
    46         $this->db = $DIC->database();
    47         $this->
lng = $DIC->language();
    48         $this->obj_id = $a_obj_id;
    49         $this->
id = $a_field_id;
    56     public static function _clone(
int $a_source_id, 
int $a_target_id): void
    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());
    73         $ilDB = $DIC->database();
    78         $query = 
"DELETE FROM crs_f_definitions " .
    79             "WHERE obj_id = " . 
$ilDB->quote($a_container_id, 
'integer') . 
" ";
    96     public static function _getFields(
int $a_container_id, $a_sort = self::IL_CDF_SORT_NAME): array
   113         $ilDB = $DIC->database();
   115         $query = 
"SELECT * FROM crs_f_definitions " .
   116             "WHERE obj_id = " . 
$ilDB->quote($a_obj_id, 
'integer') . 
" " .
   117             "AND field_required = 1";
   120         while ($row = 
$ilDB->fetchObject(
$res)) {
   121             $req_fields[] = (
int) $row->field_id;
   130         $ilDB = $DIC->database();
   131         $query = 
"SELECT field_name FROM crs_f_definitions " .
   132             "WHERE obj_id = " . 
$ilDB->quote($a_obj_id, 
'integer');
   135         while ($row = 
$ilDB->fetchObject(
$res)) {
   136             $fields[] = $row->field_name;
   138         return implode(
'<br />', $fields);
   144     public static function _getFieldIds(
int $a_container_id, 
string $a_sort = self::IL_CDF_SORT_ID): array
   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;
   154         while ($row = 
$ilDB->fetchObject(
$res)) {
   155             $field_ids[] = (
int) $row->field_id;
   164         $ilDB = $DIC->database();
   165         $query = 
"SELECT * FROM crs_f_definitions " .
   166             "WHERE field_id = " . 
$ilDB->quote($a_field_id, 
'integer');
   170         return $row->field_name ?: 
'';
   190         $this->type = $a_type;
   200         $this->name = $a_name;
   210         $this->values = $a_values;
   216             is_array($this->values) &&
   217             array_key_exists($a_id, $this->values)
   219             return $this->values[$a_id];
   226         return (($pos = array_search($a_value, $this->values)) === 
false) ? -1 : $pos;
   236         $this->required = $a_status;
   241         $this->value_options = $a_options;
   252         $options[
''] = $this->
lng->txt(
'select_one');
   254         foreach ($this->values as $key => $value) {
   255             $options[$this->
getId() . 
'_' . $key] = $value;
   263         $tmp_values = array_filter($a_values, 
'strlen');
   269         $this->values = array_unique(array_merge($this->values, $a_values));
   270         #sort($this->values);   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) " .
   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') . 
", " .
   287         $res = $this->db->manipulate($query);
   288         $this->
id = $next_id;
   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);
   304     public function delete(): 
void   307         $query = 
"DELETE FROM crs_f_definitions " .
   308             "WHERE field_id = " . $this->db->quote($this->
getId(), 
'integer') . 
" ";
   309         $res = $this->db->manipulate($query);
   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') . 
" ";
   318         $res = $this->db->query($query);
   321         $this->
setName((
string) $row->field_name);
   322         $this->
setType((
int) $row->field_type);
   323         $this->
setValues(unserialize($row->field_values) ?: []);
 setValues(array $a_values)
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
setValueOptions(array $a_options)
 
static _deleteByContainer(int $a_container_id)
 
static _lookupName(int $a_field_id)
 
static _getFieldIds(int $a_container_id, string $a_sort=self::IL_CDF_SORT_ID)
 
getIdByValue(string $a_value)
 
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container. 
 
static _clone(int $a_source_id, int $a_target_id)
 
static _deleteByField(int $a_field_id)
 
__construct(int $a_obj_id, int $a_field_id=0)
 
appendValues(array $a_values)
 
enableRequired(bool $a_status)
 
static _getRequiredFieldIds(int $a_obj_id)
Get required filed id's. 
 
static _fieldsToInfoString(int $a_obj_id)
 
static _hasFields(int $a_container_id)
Check if there are any define fields. 
 
prepareValues(array $a_values)