/** * @param $parent_gui * @param srCertificateDefinition $definition */ function __construct($parent_gui, $definition) { global $tpl, $ilCtrl, $lng, $rbacreview, $ilUser; $this->parent_gui = $parent_gui; $this->definition = $definition; $this->tpl = $tpl; $this->ctrl = $ilCtrl; $this->pl = ilCertificatePlugin::getInstance(); $this->lng = $lng; $this->isNew = $this->definition->getId() ? false : true; $this->rbac = $rbacreview; $this->user = $ilUser; $this->initForm(); }
/** * Download multiple certificates as ZIP file * */ public function downloadCertificates() { $cert_ids = (array) $_POST['cert_id']; $ids = array(); foreach ($cert_ids as $cert_id) { /** @var srCertificate $certificate */ $certificate = srCertificate::find($cert_id); if ($certificate && $certificate->getDefinitionId() == $this->definition->getId()) { $ids[] = $cert_id; } } if (count($ids)) { srCertificate::downloadAsZip($ids, $this->ref_id . '-certificates'); } $this->showCertificates(); }
/** * 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; }
/** * @param \srCertificateDefinition $definition */ public function setDefinition($definition) { $this->definition = $definition; $this->definition_id = $definition->getId(); }
/** * @param \srCertificateDefinition $definition */ public function setDefinition(srCertificateDefinition $definition) { $this->definition = $definition; $this->definition_id = $definition->getId(); }