OEModule\OphCiExamination\components\ExaminationCreator::createMessage PHP Méthode

createMessage() protected méthode

protected createMessage ( $episodeId, $userId, $examination, $examinationEvent )
$episodeId
$userId
$examination
$examinationEvent
    protected function createMessage($episodeId, $userId, $examination, $examinationEvent)
    {
        if (isset(\Yii::app()->modules['OphCoMessaging']) && ($examination['patient']['comments'] || $examination['patient']['ready_for_second_eye'] === false)) {
            $episode = \Episode::model()->findByPk($episodeId);
            $recipient = \User::model()->findByPk($episode->firm->consultant_id);
            if ($recipient) {
                $sender = \User::model()->findByPk($userId);
                $type = OphCoMessaging_Message_MessageType::model()->findByAttributes(array('name' => 'General'));
                if ($examination['patient']['ready_for_second_eye'] === false) {
                    $ready = 'No';
                } elseif ($examination['patient']['ready_for_second_eye'] === true) {
                    $ready = 'Yes';
                } else {
                    $ready = 'Not Applicable';
                }
                $messageCreator = new MessageCreator($episode, $sender, $recipient, $type);
                $messageCreator->setMessageTemplate('application.modules.OphCoMessaging.views.templates.optom');
                $messageCreator->setMessageData(array('optom' => $examination['op_tom']['name'] . ' (' . $examination['op_tom']['goc_number'] . ')', 'ready' => $ready, 'comments' => $examination['patient']['comments'], 'patient' => $episode->patient));
                $message = $messageCreator->save('', array('event' => $examinationEvent->id));
                $emailSetting = \SettingInstallation::model()->find('`key` = "optom_comment_alert"');
                if ($emailSetting && $emailSetting->value) {
                    $recipients = explode(',', $emailSetting->value);
                    $messageCreator->emailAlert($recipients, 'New Optom Comment', $message->message_text);
                }
            }
        }
    }