/**
  * @return bool
  */
 public function saveObject()
 {
     if (!$this->fillObject()) {
         return false;
     }
     if ($this->placeholder->getId()) {
         $this->placeholder->update();
     } else {
         $this->placeholder->create();
         if ($this->getInput('update_definitions')) {
             $type = $this->placeholder->getCertificateType();
             $definitions = srCertificateDefinition::where(array('type_id' => $type->getId()))->get();
             /** @var $def srCertificateDefinition */
             foreach ($definitions as $def) {
                 $phv = srCertificatePlaceholderValue::where(array('definition_id' => $def->getId(), 'placeholder_id' => $this->placeholder->getId()))->first();
                 if (!is_null($phv)) {
                     continue;
                     // Extra check... should never be the case
                 }
                 $phv = new srCertificatePlaceholderValue();
                 $phv->setDefinitionId($def->getId());
                 $phv->setPlaceholderId($this->placeholder->getId());
                 foreach ($type->getLanguages() as $lang_code) {
                     $phv->setValue($this->getInput("default_value_{$lang_code}"), $lang_code);
                 }
                 $phv->create();
             }
         }
     }
     return true;
 }
 public function delete()
 {
     // Delete setting on all definitions
     foreach (srCertificateDefinition::where(array('type_id' => $this->getTypeId()))->get() as $definition) {
         /** @var srCertificateDefinition $setting */
         $setting = srCertificateCustomDefinitionSetting::where(array('definition_id' => $definition->getId(), 'identifier' => $this->getIdentifier()))->first();
         if ($setting) {
             $setting->delete();
         }
     }
     parent::delete();
 }
 public function delete()
 {
     parent::delete();
     @unlink($this->getFilePath(true));
     @unlink($this->getFilePath(true) . '.' . $this->getSuffix());
     // We must update any definitions holding this signature
     $definitions = srCertificateDefinition::where(array('signature_id' => $this->getId()))->get();
     foreach ($definitions as $definition) {
         /** @var srCertificateDefinition $definition */
         $definition->setSignatureId(0);
         $definition->update();
     }
 }
 /**
  * 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;
 }
 /**
  * Delete also related certificate definitions and assets
  */
 public function delete()
 {
     parent::delete();
     $definitions = srCertificateDefinition::where(array('type_id' => $this->getId()))->get();
     /** @var $def srCertificateDefinition */
     foreach ($definitions as $def) {
         $def->delete();
     }
 }
 /**
  * @return bool
  */
 public function saveObject()
 {
     if (!$this->checkInput()) {
         return false;
     }
     try {
         $this->setting->setTypeId((int) $_GET['type_id']);
         $this->setting->setIdentifier($this->getInput('identifier'));
         $this->setting->setSettingTypeId($this->getInput('setting_type_id'));
         $this->setting->setData($this->getInput('data'));
         $this->setting->setValue($this->getInput('value'));
         $this->setting->setEditableIn($this->getInput('editable_in'));
         /** @var srCertificateType $type */
         $type = srCertificateType::find($this->setting->getTypeId());
         foreach ($type->getLanguages() as $lang_code) {
             $this->setting->setLabel($this->getInput("label_{$lang_code}"), $lang_code);
         }
         $this->setting->save();
         // Check if existing definitions should be updated to own this setting
         if ($this->getInput('update_definitions')) {
             $definitions = srCertificateDefinition::where(array('type_id' => $type->getId()))->get();
             /** @var $def srCertificateDefinition */
             foreach ($definitions as $def) {
                 $definition_setting = new srCertificateCustomDefinitionSetting();
                 $definition_setting->setDefinitionId($def->getId());
                 $definition_setting->setIdentifier($this->setting->getIdentifier());
                 $definition_setting->setValue($this->setting->getValue());
                 $definition_setting->save();
             }
         }
     } catch (ilException $e) {
         ilUtil::sendFailure($e->getMessage());
         return false;
     }
     return true;
 }
 /**
  * Show available Placeholders of Definition
  *
  */
 public function showPlaceholders()
 {
     $this->tabs->setSubTabActive('show_placeholders');
     $this->showPreviewCertificateInToolbar();
     /** @var srCertificateDefinition $definition */
     $definition = srCertificateDefinition::where(array('ref_id' => $this->ref_id))->first();
     if (!count($definition->getPlaceholderValues()) && !$this->definition->getType()->getSignatures()) {
         ilUtil::sendInfo($this->pl->txt('msg_no_placeholders'));
     } else {
         $this->form = new srCertificateDefinitionPlaceholdersFormGUI($this, $definition);
         $this->tpl->setContent($this->form->getHTML());
     }
 }