_sendAdminNotification('userCertificateAdminEmail', $data); } public function sendFailAdminNotification(array $data) { return $this->_sendAdminNotification('userCertificateFailAdminEmail', $data); } protected function _sendAdminNotification($prefix, $data) { $subject = Settings::get($prefix . 'Subject'); $from = Settings::getEmailFrom($prefix . 'From'); $to = Settings::getFormEmails($prefix . 'To'); $body = Settings::get($prefix . 'Body'); $this->_replacePlaceHolders($body, $data); $this->_sendMail(compact('subject', 'from', 'to', 'body')); return $this; } protected function _replacePlaceHolders(&$body, $data) { foreach ($data as $field => $value) { if (is_array($value)) { continue; } $value = htmlspecialchars($value); $body = str_replace('{' . $field . '}', $value, $body); } return $this; } public function sendCertificate(UserEntity $user, array $test, $resultId, $attemptId = null) { if (empty($test['certificateId'])) { return $this; } $from = Settings::getEmailFrom('certificateEmailFrom'); $to = $user->email; $subject = Settings::get('certificateEmailSubject'); $body = Settings::get('certificateEmailBody'); $baseData = array( 'name' => $user->getName(), 'businessName' => $user->businessName, 'email' => $user->email, 'address' => $user->address, 'city' => $user->city, 'state' => $user->state, 'zip' => $user->zip, ); $this->_getDataObj()->setPrimaryKey($test['certificateId']); $certFile = (new Renderer())->generatePdf( $test['title'], $user->getName(), $this->_getDataObj()->getData('signature'), date('Y-m-d') ); $this->_replacePlaceHolders($body, $baseData); $mail = new Qs_Mail(); $mail->setFrom($from); $mail->setSubject($subject); Qs_Mail::cutImageBaseUrl($body, constant('BASE_URL')); $mail->setHtml($body, null, constant('WWW_PATH')); $mail->addTo($to); try { $data = $baseData; $data['test'] = $test['title']; $data['link'] = AttemptView::getPage('url') . ($attemptId ? '/' . $attemptId : '?id=' . $resultId); $this->sendDoneAdminNotification($data); } catch (\Exception $e) { \Qs_Debug::processExceptionSilent($e); } if ($certFile && ($fileData = file_get_contents($certFile))) { $certName = Qs_FileFs::escapeName($test['title']) . '_Certificate.pdf'; $mail->attachFile($fileData, $certName, 'application/pdf'); } $mail->send(); return $this; } public function sendFailNotification(UserEntity $user, array $test, $resultId, $attemptId = null) { // fail notification for admin try { $this->sendFailAdminNotification([ 'name' => $user->getName(), 'businessName' => $user->businessName, 'email' => $user->email, 'address' => $user->address, 'city' => $user->city, 'state' => $user->state, 'zip' => $user->zip, 'test' => $test['title'], 'link' => AttemptView::getPage('url') . ($attemptId ? '/' . $attemptId : '?id=' . $resultId), ]); } catch (\Exception $e) { \Qs_Debug::processExceptionSilent($e); } return $this; } }