/**
  * Update type of definition
  *
  */
 public function updateType()
 {
     $new_type_id = (int) $_POST['type_id'];
     if ($new_type_id && $new_type_id != $this->definition->getTypeId()) {
         $this->definition->setTypeId($new_type_id);
         $this->definition->update();
         ilUtil::sendSuccess($this->pl->txt('msg_type_updated'), true);
     }
     $this->ctrl->redirect($this, 'showDefinition');
 }
 /**
  * @return bool
  */
 protected function fillObject()
 {
     $this->setValuesByPost();
     if (!$this->checkInput()) {
         return false;
     }
     if (isset($_POST['type_id'])) {
         $this->definition->setTypeId($this->getInput('type_id'));
     }
     $this->definition->setRefId((int) $_GET['ref_id']);
     if ($this->isNew) {
         return true;
     } else {
         // Set new settings values
         /** @var $setting srCertificateDefinitionSetting */
         foreach ($this->definition->getSettings() as $setting) {
             if (!$setting->isEditable()) {
                 continue;
             }
             // Don't set values if setting can't change its value
             $value = $this->getInput($setting->getIdentifier());
             if ($setting->getIdentifier() == srCertificateTypeSetting::IDENTIFIER_VALIDITY) {
                 $validity_type = $this->getInput(srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE);
                 $value = $this->getInput(srCertificateTypeSetting::IDENTIFIER_VALIDITY_TYPE . '_' . $validity_type);
             }
             $setting->setValue($value);
         }
         foreach ($this->definition->getCustomSettings() as $setting) {
             if (!$setting->isEditable()) {
                 continue;
             }
             $value = $this->getInput('custom_setting_' . $setting->getIdentifier());
             $setting->setValue($value);
         }
     }
     return true;
 }
 /**
  * Clone/copy this definition for a new course
  *
  * @param int $ref_id ref-ID of new course
  * @return srCertificateDefinition
  */
 public function copy($ref_id)
 {
     $this->log('Certificate: copy definitions from ' . $this->getRefId() . ' to ' . $ref_id);
     $new_definition = srCertificateDefinition::where(array("ref_id" => $ref_id))->first();
     if (!$new_definition) {
         $this->log('there is no existing definition for ' . $ref_id . ', generating a new one.');
         $new_definition = new srCertificateDefinition();
         $new_definition->setRefId($ref_id);
         $new_definition->setTypeId($this->getTypeId());
         $new_definition->create();
     } else {
         $this->log('used existing definition for ' . $ref_id . '.');
     }
     $this->log('ID of clone: ' . $new_definition->getId());
     $new_definition->setRefId($ref_id);
     $new_definition->setTypeId($this->getTypeId());
     // Clone Signature setting
     if ($this->getSignatureId()) {
         $new_definition->setSignatureId($this->getSignatureId());
     }
     $new_definition->setTypeChanged(false);
     $new_definition->update();
     // Settings and placeholder values now contain default values inherited from type.
     // We overwrite them with the values from this definition
     /** @var $setting srCertificateDefinitionSetting */
     $this->log('copy srCertificateDefinitionSetting');
     foreach ($this->getSettings() as $setting) {
         $s = $new_definition->getSettingByIdentifier($setting->getIdentifier());
         $this->log($setting->getIdentifier());
         if (!$s instanceof srCertificateDefinitionSetting) {
             $this->log('not found, generating new one');
             $s = new srCertificateDefinitionSetting();
             $s->setDefinitionId($new_definition->getId());
             $s->setIdentifier($setting->getIdentifier());
             $s->create();
         }
         $s->setValue($setting->getValue());
         $s->update();
     }
     /** @var $ph_value srCertificatePlaceholderValue */
     $this->log('copy srCertificatePlaceholderValue');
     foreach ($this->getPlaceholderValues() as $ph_value) {
         $ph = $new_definition->getPlaceholderValueByPlaceholderId($ph_value->getPlaceholderId());
         $this->log($ph_value->getPlaceholderId());
         if (!$ph instanceof srCertificatePlaceholderValue) {
             $this->log('not found, generating new one');
             $ph = new srCertificatePlaceholderValue();
             $ph->setDefinitionId($new_definition->getId());
             $ph->setPlaceholderId($ph_value->getPlaceholderId());
             $ph->create();
         }
         $ph->setValue($ph_value->getValue());
         // This does set the values for each language
         $ph->update();
     }
     /** @var $cust_setting srCertificateCustomDefinitionSetting */
     foreach ($this->getCustomSettings() as $cust_setting) {
         $cs = $new_definition->getCustomSettingByIdentifier($cust_setting->getIdentifier());
         $this->log($cust_setting->getIdentifier());
         if (!$cs instanceof srCertificateCustomDefinitionSetting) {
             $this->log('not found, generating new one');
             $cs = new srCertificateCustomDefinitionSetting();
             $cs->setDefinitionId($new_definition->getId());
             $cs->setIdentifier($cust_setting->getIdentifier());
             $cs->create();
         }
         $cs->setValue($cust_setting->getValue());
         // This does set the values for each language
         $cs->update();
         $this->log('old value: ' . $cust_setting->getValue());
         $this->log('cloned value: ' . $cs->getValue());
     }
     $this->log('finished');
     return $new_definition;
 }