OpenEyes is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenEyes is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenEyes in a file titled COPYING. If not, see .
저자: OpenEyes (info@openeyes.org.uk)
상속: extends BaseActiveRecordVersioned
예제 #1
0
 /**
  * Appends information about the submission of the application to the $record.
  *
  * @param array $record
  * @param int   $event_id
  */
 protected function appendSubmissionValues(&$record, $event_id)
 {
     if (@$_GET['submission']) {
         $event = Event::model()->findByPk($event_id);
         $svc = new OphCoTherapyapplication_Processor($event);
         $record['submission_status'] = $svc->getApplicationStatus();
         if ($record['submission_status'] == OphCoTherapyapplication_Processor::STATUS_SENT) {
             $most_recent = OphCoTherapyapplication_Email::model()->forEvent($event)->unarchived()->findAll(array('limit' => 1));
             $record['submission_date'] = Helper::convertDate2NHS($most_recent[0]->created_date);
         } else {
             $record['submission_date'] = 'N/A';
         }
     }
 }
 private function createEmail(Event $event)
 {
     $email = new OphCoTherapyapplication_Email();
     $email->event_id = $event->id;
     $email->save();
     return $email;
 }
 /**
  * @param CController $controller
  * @param array       $template_data
  * @param int         $eye_id
  * @param User        $notify_user
  *
  * @throws Exception
  *
  * @return bool
  */
 private function processEventForEye(CController $controller, array $template_data, $eye_id, User $notify_user = null)
 {
     $eye_name = $this->getEyeNameById($eye_id);
     $template_data += $this->getSideSpecificTemplateData($eye_name);
     $attachments = array();
     $attach_size = 0;
     if ($app_file = $this->createAndSavePdfForSide($controller, $template_data, $eye_name)) {
         $attachments[] = $app_file;
         $attach_size += $app_file->size;
     }
     if ($ec = $this->getElement('Element_OphCoTherapyapplication_ExceptionalCircumstances')) {
         foreach ($ec->{"{$eye_name}_filecollections"} as $fc) {
             $attachments[] = $fc->getZipFile();
             $attach_size += $fc->getZipFile()->size;
         }
     }
     $service_info = $this->getServiceInfo();
     $link_to_attachments = $attach_size > Helper::convertToBytes(Yii::app()->params['OphCoTherapyapplication_email_size_limit']);
     $template_data['link_to_attachments'] = $link_to_attachments;
     $email_text = $this->generateEmailForSide($controller, $template_data, $eye_name);
     $message = Yii::app()->mailer->newMessage();
     if ($template_data['compliant']) {
         $recipient_type = 'Compliant';
         $message->setSubject(Yii::app()->params['OphCoTherapyapplication_compliant_email_subject']);
     } else {
         $recipient_type = 'Non-compliant';
         $message->setSubject(Yii::app()->params['OphCoTherapyapplication_noncompliant_email_subject']);
     }
     $recipient_type = $template_data['compliant'] ? 'Compliant' : 'Non-compliant';
     try {
         $recipients = $this->getEmailRecipients($service_info, $recipient_type);
     } catch (Exception $e) {
         Yii::app()->user->setFlash('error', $e->getMessage());
         $controller->redirect('/OphCoTherapyapplication/default/view/' . $this->event->id);
     }
     $email_recipients = array();
     foreach ($recipients as $recipient) {
         if (!$recipient->isAllowed()) {
             throw new Exception("Recipient email address {$recipient->recipient_email} is not in the list of allowed domains");
         }
         $email_recipients[$recipient->recipient_email] = $recipient->recipient_name;
     }
     $message->setFrom(Yii::app()->params['OphCoTherapyapplication_sender_email']);
     $message->setTo($email_recipients);
     if ($notify_user && $notify_user->email) {
         $cc = true;
         if (Yii::app()->params['restrict_email_domains']) {
             $domain = preg_replace('/^.*?@/', '', $notify_user->email);
             if (!in_array($domain, Yii::app()->params['restrict_email_domains'])) {
                 Yii::app()->user->setFlash('warning.warning', 'You will not receive a copy of the submission because your email address ' . $notify_user->email . ' is not on a secure domain');
                 $cc = false;
             }
         }
         if ($cc) {
             $message->setCc($notify_user->email);
         }
     }
     $message->setBody($email_text);
     if (!$link_to_attachments) {
         foreach ($attachments as $att) {
             $message->attach(Swift_Attachment::fromPath($att->getPath())->setFilename($att->name));
         }
     }
     if (Yii::app()->mailer->sendMessage($message)) {
         $email = new OphCoTherapyapplication_Email();
         $email->event_id = $this->event->id;
         $email->eye_id = $eye_id;
         $email->email_text = $email_text;
         if (!$email->save()) {
             throw new Exception('Unable to save email: ' . print_r($email->getErrors(), true));
         }
         $email->addAttachments($attachments);
         $this->event->audit('therapy-application', 'submit');
         $this->event->info = self::STATUS_SENT;
         if (!$this->event->save()) {
             throw new Exception('Unable to save event: ' . print_r($this->event->getErrors(), true));
         }
         return true;
     } else {
         OELog::log("Failed to send email for therapy application event_id '{$this->event->id}', eye_id '{$eye_id}'");
         // clean up
         if ($app_file) {
             $app_file->delete();
         }
         return false;
     }
 }
예제 #4
0
 /**
  * After an update, mark any existing emails as archived.
  */
 protected function afterUpdateElements($event)
 {
     OphCoTherapyapplication_Email::model()->archiveForEvent($event);
 }