/**
  * save Field
  *
  * @param string $a_mode values: create | update
  */
 public function save($a_mode = "create")
 {
     global $ilCtrl, $lng;
     //check access
     if (!$this->table->hasPermissionToFields($this->parent_obj->ref_id)) {
         $this->accessDenied();
         return;
     }
     $this->initForm($a_mode == "update" ? "edit" : "create");
     if ($this->form->checkInput()) {
         $title = $this->form->getInput("title");
         if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
             ilUtil::sendInfo($lng->txt("dcl_field_title_change_warning"), true);
         }
         $this->field_obj->setTitle($title);
         $this->field_obj->setDescription($this->form->getInput("description"));
         $this->field_obj->setDatatypeId($this->form->getInput("datatype"));
         $this->field_obj->setRequired($this->form->getInput("required"));
         $this->field_obj->setUnique($this->form->getInput("unique"));
         if ($a_mode == "update") {
             $this->field_obj->doUpdate();
         } else {
             $this->field_obj->setVisible(true);
             $this->field_obj->setOrder($this->table->getNewOrder());
             $this->field_obj->doCreate();
         }
         // Get possible properties and save them
         include_once "./Modules/DataCollection/classes/class.ilDataCollectionFieldProp.php";
         foreach (ilDataCollectionDatatype::getProperties($this->field_obj->getDatatypeId()) as $property) {
             $fieldprop_obj = new ilDataCollectionFieldProp();
             $fieldprop_obj->setDatatypePropertyId($property['id']);
             $fieldprop_obj->setFieldId($this->field_obj->getId());
             $fieldprop_obj->setValue($this->form->getInput("prop_" . $property['id']));
             if ($a_mode == "update") {
                 $fieldprop_obj->doUpdate();
             } else {
                 $fieldprop_obj->doCreate();
             }
         }
         $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
         if ($a_mode == "update") {
             ilUtil::sendSuccess($lng->txt("dcl_msg_field_modified"), true);
         } else {
             $this->table->addField($this->field_obj);
             $this->table->buildOrderFields();
             ilUtil::sendSuccess($lng->txt("msg_field_created"), false);
         }
         $ilCtrl->redirectByClass(strtolower("ilDataCollectionFieldListGUI"), "listFields");
     } else {
         global $tpl;
         $this->form->setValuesByPost();
         $tpl->setContent($this->form->getHTML());
     }
 }
 /**
  * @param $originalField ilDataCollectionField
  */
 public function cloneProperties($originalField)
 {
     $orgProps = $originalField->getProperties();
     if ($orgProps == NULL) {
         return;
     }
     foreach ($orgProps as $id => $value) {
         $fieldprop_obj = new ilDataCollectionFieldProp();
         $fieldprop_obj->setDatatypePropertyId($id);
         $fieldprop_obj->setFieldId($this->getId());
         // If reference field, we must reset the referenced field, otherwise it will point to the old ID
         if ($originalField->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE && $id == ilDataCollectionField::PROPERTYID_REFERENCE) {
             $value = null;
         }
         $fieldprop_obj->setValue($value);
         $fieldprop_obj->doCreate();
     }
 }
 /**
  * @param $originalField ilDataCollectionField
  */
 public function cloneProperties($originalField)
 {
     $orgProps = $originalField->getProperties();
     if ($orgProps == NULL) {
         return;
     }
     foreach ($orgProps as $id => $value) {
         $fieldprop_obj = new ilDataCollectionFieldProp();
         $fieldprop_obj->setDatatypePropertyId($id);
         $fieldprop_obj->setFieldId($this->getId());
         $fieldprop_obj->setValue($value);
         $fieldprop_obj->doCreate();
     }
 }
 /**
  * Called before finishing import. Fix references inside DataCollections
  *
  * @param ilImportMapping $a_mapping
  */
 public function beforeFinishImport(ilImportMapping $a_mapping)
 {
     foreach ($this->import_temp_new_mob_ids as $new_mob_id) {
         ilObjMediaObject::_saveUsage($new_mob_id, "dcl:html", $a_mapping->getTargetId());
     }
     foreach ($this->import_temp_refs as $record_field_id => $old_record_id) {
         $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $old_record_id);
         $value = $new_record_id ? (int) $new_record_id : NULL;
         /** @var ilDataCollectionRecordField $record_field */
         $record_field = $this->import_record_field_cache[$record_field_id];
         $record_field->setValue($value, true);
         $record_field->doUpdate();
     }
     foreach ($this->import_temp_refs_props as $field_prop_id => $old_field_id) {
         $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $old_field_id);
         $value = $new_field_id ? (int) $new_field_id : NULL;
         $field_prop = new ilDataCollectionFieldProp($field_prop_id);
         $field_prop->setValue($value);
         $field_prop->doUpdate();
     }
 }