_getPair('EventFormReq', 'efr') . ' ' . 'JOIN ' . $this->_getPair('Event', 'e') . ' ' . ' ON `e`.`id` = `efr`.`id_event` ' . 'JOIN ' . $this->_getPair('Member', 'm') . ' ON `m`.`id` = `efr`.`id_member` ' . 'JOIN ' . $this->_getPair('EventCECreditHistory', 'ech') . ' ON `ech`.`id_event` = `efr`.`id_event` AND `ech`.`id_individual` = `efr`.`id_member`' . 'LEFT JOIN ' . $this->_getPair('Location', 'l') . ' ' . ' ON `l`.`id` = `m`.`id_location` ' . 'LEFT JOIN ' . $this->_getPair('Company', 'c') . ' ' . ' ON `c`.`id` = `l`.`id_company` ' . 'JOIN ' . $this->_getPair('EventDocumentofCommerce', 'edoc') . ' ' . ' ON `edoc`.`doc_number` = `e`.`doc_number` ' . 'WHERE `efr`.`id` = ' . $this->db->quote($id, 'integer') . ' ' . $this->_filterWhere() . ' ' . 'LIMIT 1'; return $sql; } protected function _filterWhere() { $parts = array(); foreach ($this->_filter as $field => $value) { switch ($field) { case 'member_id': $parts[] = '`m`.`id` = ' . $this->db->quote($value, 'integer'); break; default: break; } } return empty($parts) ? '' : ' AND ' . implode(' AND ', $parts); } public static function getColumnCertificateAllowed($requestAlias, $eventAlias, $memberAlias, $ceHistoryAlias) { $db = S_db2::getInstance(); return " IF(`{$requestAlias}`.`attended` = 1 AND DATE(`{$eventAlias}`.`eventdate`) >= " . $db->quote(constant('CE_RELEASE_DATE'), 'text') . " AND LENGTH(`edoc`.`doc_number`) AND LENGTH(`{$memberAlias}`.`re_license_number`) AND `{$ceHistoryAlias}`.`credits` > 0 , 'y', 'n')" ; } public function generate() { $item = $this->getData(); $item['baseUrl'] = constant('BASE_URL'); if (defined('SITE_AUTH_LOGIN') && defined('SITE_AUTH_PASSWORD')) { $item['baseUrl'] = str_replace( '://', '://' . rawurlencode(constant('SITE_AUTH_LOGIN')) . ':' . rawurlencode(constant('SITE_AUTH_PASSWORD')) . '@', $item['baseUrl'] ); } $doc = new Doc(array()); $doc->assign('item', $item); Constant::set('DEBUG', false); $html = $doc->fetch('Event/certificate.tpl'); Constant::set('DEBUG', constant('DEBUG')); $fileName = constant('BASE_PATH') . '/tmp/certificate-' . uniqid() . '.pdf'; $pdfRenderer = new Qs_Html2Pdf_Render( array('renderlinks' => false, 'features' => array()), array('type' => 'memory', 'content' => $html), array('type' => 'file', 'name' => $fileName, 'width' => 800, 'margins' => array('left' => 15, 'right' => 15, 'top' => 15, 'bottom' => 15)) ); if (count($pdfRenderer->errors)) { $this->addErrors($pdfRenderer->errors); return false; } if (!$pdfRenderer->render()) { $this->addErrors($pdfRenderer->errors); return false; } require_once('class/DB/FileDB.php'); $fileObj = new FileDB(); $newFileName = $fileObj->insert('certificate.pdf', $fileName, 'application/pdf'); unlink($fileName); $this->_data['certificate'] = $newFileName; $this->getTable()->update(array('certificate' => $newFileName), 'id=' . $this->db->quote($this->id, 'integer')); return true; } public function exists() { $certificate = $this->getData('certificate'); return $certificate && file_exists(FILE_DB_FS_PATH . '/' . $certificate); } public function getFileName() { $this->initFromDB(); if (null === ($registration = $this->getData())) { $this->addError('Invalid Event Registration ID'); return false; } if ('y' != $registration['certificate_allowed']) { $this->addError('Certificate is not allowed for this member'); return false; } if (!$this->exists() && false === $this->generate()) { return false; } return $this->getData('certificate'); } public function deleteFile() { $fileName = $this->getTable()->find($this->id, array('certificate')); if ($fileName) { $fileObj = new FileDB(); $fileObj->delete($fileName['certificate']); } $this->getTable()->update( array('certificate' => ''), 'id=' . $this->db->quote($this->id, 'integer') ); } }