public function run() { /** @var srCertificate $cert */ $certs = srCertificate::where(array('status' => srCertificate::STATUS_NEW))->get(); foreach ($certs as $cert) { // Force a reload of the members. If there are parallel cronjobs, only continue if status is still NEW $cert->read(); if ($cert->getStatus() != srCertificate::STATUS_NEW) { continue; } $cert->generate(); } // Also check for certificates with status DRAFT. They should be changed to NEW if the course is passed and the last access is more than xx minutes $certs = srCertificate::where(array('status' => srCertificate::STATUS_DRAFT))->get(); foreach ($certs as $cert) { $cert->read(); if ($cert->getStatus() != srCertificate::STATUS_DRAFT) { continue; } $max_diff_lp_seconds = $this->pl->config('max_diff_lp_seconds'); if ($max_diff_lp_seconds) { if ($last_access = $this->getLastLPStatus($cert)) { $diff = time() - $last_access; if ($diff > $max_diff_lp_seconds) { $cert->setStatus(srCertificate::STATUS_NEW); $cert->update(); } } } else { // If the setting max_diff_lp_seconds is "0", the NEW status is set anyway $cert->setStatus(srCertificate::STATUS_NEW); $cert->update(); } } }
/** * Update any certificates in the draft status to new, in order to process them via cronjob */ protected function updateStatusFromDraftToNew() { $certificates = srCertificate::where(array('user_id' => $this->user->getId(), 'status' => srCertificate::STATUS_DRAFT))->get(); foreach ($certificates as $certificate) { /** @var srCertificate $certificate */ $certificate->setStatus(srCertificate::STATUS_NEW); $certificate->save(); } }
?> <#6> <?php // Update database schema, added created_at timestamp and active flag to certificates require_once './Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/Certificate/classes/Certificate/class.srCertificate.php'; srCertificate::updateDB(); ?> <#7> <?php // Flag latest version of each certificate as active require_once './Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/Certificate/classes/Certificate/class.srCertificate.php'; /** @var ilDB $ilDB */ $set = $ilDB->query('SELECT user_id, definition_id, MAX(file_version) AS max_file_version FROM cert_obj GROUP BY definition_id, user_id'); while ($row = $ilDB->fetchObject($set)) { /** @var srCertificate $cert */ $cert = srCertificate::where(array('definition_id' => $row->definition_id, 'user_id' => $row->user_id, 'file_version' => $row->max_file_version))->first(); if ($cert) { $cert->setActive(true); $cert->save(); } } ?> <#8> <?php if (!$ilDB->tableColumnExists('cert_type_setting', 'value')) { $ilDB->renameTableColumn('cert_type_setting', 'default_value', 'value'); } ?> <#9> <?php require_once './Customizing/global/plugins/Services/UIComponent/UserInterfaceHook/Certificate/classes/CustomSetting/class.srCertificateCustomTypeSetting.php';
/** * Create certificate * Before calling parent::create(), the valid_from and valid_to are are calculated based on the chosen validity in the definition * If there exists already a certificate for the given definition and user, the version is increased * * @throws Exception */ public function create() { if (is_null($this->getDefinition()) || !$this->getUserId()) { throw new Exception("srCertificate::create() must have valid Definition and User-ID"); } // Set validity dates $valid_from = date("Y-m-d"); $valid_to = $this->calculateValidTo(); $this->setValidFrom($valid_from); $this->setValidTo($valid_to); // Check if we need to increase the version if a certificate for same user & definition already exists /** @var srCertificate $cert_last_version */ $certs = srCertificate::where(array('definition_id' => $this->getDefinitionId(), 'user_id' => $this->getUserId()))->orderBy('file_version', 'DESC'); $cert_last_version = $certs->first(); if (!is_null($cert_last_version)) { $this->setFileVersion((int) $cert_last_version->getFileVersion() + 1); } // Remove active flag from other versions of this certificate /** @var srCertificate $cert */ foreach ($certs->get() as $cert) { $cert->setActive(false); $cert->save(); } // Set active flag $this->setActive(true); // Set the filename for certificate $this->filename = $this->createFilename(); $this->created_at = date('Y-m-d H:i:s'); parent::create(); $this->event_handler->raise('Certificate/srCertificate', 'create', array('object' => $this)); }