24define(
"IL_CDF_SORT_ID", 
'field_id');
 
   25define(
"IL_CDF_SORT_NAME", 
'field_name');
 
   27define(
'IL_CDF_TYPE_TEXT', 1);
 
   28define(
'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());
 
  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();
 
  161        $query = 
"SELECT * FROM crs_f_definitions " .
 
  162            "WHERE obj_id = " . 
$ilDB->quote($a_obj_id, 
'integer') . 
" " .
 
  163            "AND field_required = 1";
 
  165        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  166            $req_fields[] = $row->field_id;
 
  168        return $req_fields ? $req_fields : array();
 
  186        $query = 
"SELECT field_name FROM crs_f_definitions " .
 
  187            "WHERE obj_id = " . 
$ilDB->quote($a_obj_id, 
'integer');
 
  191        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  192            $fields[] = $row->field_name;
 
  194        return implode(
'<br />', $fields);
 
  211        $query = 
"SELECT field_id FROM crs_f_definitions " .
 
  212            "WHERE obj_id = " . 
$ilDB->quote($a_container_id, 
'integer') . 
" " .
 
  215        while ($row = 
$ilDB->fetchObject(
$res)) {
 
  216            $field_ids[] = $row->field_id;
 
  218        return $field_ids ? $field_ids : array();
 
  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;
 
  322        $options[
''] = 
$lng->txt(
'select_one');
 
  324        foreach ($this->values as $key => $value) {
 
  325            $options[$this->
getId() . 
'_' . $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);
 
  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;
 
  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()
 
  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') . 
" ";
 
  470        $this->
setName($row->field_name);
 
  471        $this->
setType($row->field_type);
 
  472        $this->
setValues(unserialize($row->field_values));
 
An exception for terminatinating execution or to throw for unit testing.
static _getFieldIds($a_container_id, $a_sort=IL_CDF_SORT_ID)
Get all field ids of a container.
appendValues($a_values)
Append Values.
prepareValues($a_values)
Prepare values from POST.
enableRequired($a_status)
static _deleteByContainer($a_container_id)
Delete all fields of a container.
setValueOptions($a_options)
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.
static _hasFields($a_container_id)
Check if there are any define fields.
static _getRequiredFieldIds($a_obj_id)
Get required filed id's.
static _clone($a_source_id, $a_target_id)
Clone fields.
deleteValue($a_id)
Delete value by id.
prepareSelectBox()
Prepare an array of options for ilUtil::formSelect()
__construct($a_obj_id, $a_field_id=0)
Constructor.
static _fieldsToInfoString($a_obj_id)
Fields to info string.
static _lookupName($a_field_id)
Lookup field name.
static _deleteByField($a_field_id)
Delete by field.
foreach($_POST as $key=> $value) $res