Mail Sms Handler Laravel - PullRequest
       3

Mail Sms Handler Laravel

0 голосов
/ 18 января 2019

Здравствуйте, этот код системы управления школой в Laravel. В этом AttendenceController.php учащемуся, если он отмечен как отсутствующий, SMS и почта отправляются непосредственно родителю.

Теперь я также хотел бы, чтобы родитель также мог получать SMS и почту, когда учащемуся назначен подарок.

открытая функция saveAttendance () {

    if(!$this->panelInit->can( "Attendance.takeAttendance" )){
        exit;
    }

    $vacationArray = array();
    $vacationList = \vacation::where('vacDate',$this->panelInit->date_to_unix(\Input::get('attendanceDay')))->where('acYear',$this->panelInit->selectAcYear)->where('role','student')->get();
    foreach ($vacationList as $vacation) {
        $vacationArray[$vacation->userid] = $vacation->id;
    }

    if($this->panelInit->settingsArray['absentNotif'] == "mail" || $this->panelInit->settingsArray['absentNotif'] == "mailsms"){
        $mail = true;
    }
    if($this->panelInit->settingsArray['absentNotif'] == "sms" || $this->panelInit->settingsArray['absentNotif'] == "mailsms"){
        $sms = true;
    }
    if(isset($mail) || isset($sms)){
        $mailTemplate = \mailsms_templates::where('templateTitle','Student Absent')->first();
    }

    $stAttendance = \Input::get('stAttendance');
    foreach($stAttendance as $key => $value){
        if(isset($value['attendance']) AND strlen($value['attendance']) > 0){

            $attendanceN = \attendance::where('studentId',$value['id'])->where('date',$this->panelInit->date_to_unix(\Input::get('attendanceDay')))->where('classId',\Input::get('classId'));
            if($this->data['panelInit']->settingsArray['attendanceModel'] == "subject"){
                $attendanceN = $attendanceN->where('subjectId', \Input::get('subjectId') );
            }

            if($attendanceN->count() == 0){
                $attendanceN = new \attendance();
            }else{
                $attendanceN = $attendanceN->first();
            }

            $attendanceN->classId = \Input::get('classId');
            $attendanceN->date = $this->panelInit->date_to_unix(\Input::get('attendanceDay'));
            $attendanceN->studentId = $value['id'];
            $attendanceN->status = $value['attendance'];
            if(isset($value['attNotes'])){
                $attendanceN->attNotes = $value['attNotes'];                        
            }
            if($this->data['panelInit']->settingsArray['attendanceModel'] == "subject"){
                $attendanceN->subjectId = \Input::get('subjectId');
            }
            $attendanceN->save();

            if($value['attendance'] != "1" AND $this->panelInit->settingsArray['absentNotif'] != "0"){
                $parents = \User::where('parentOf','like','%"'.$value['id'].'"%')->orWhere('parentOf','like','%:'.$value['id'].'}%')->get();
                $student = \User::where('id',$value['id'])->first();

                $absentStatus = "";
                switch ($value['attendance']) {
                    case '0':
                        $absentStatus = $this->panelInit->language['Absent'];
                        break;
                    case '2':
                        $absentStatus = $this->panelInit->language['Late'];
                        break;
                    case '3':
                        $absentStatus = $this->panelInit->language['LateExecuse'];
                        break;
                    case '4':
                        $absentStatus = $this->panelInit->language['earlyDismissal'];
                        break;
                    case '9':
                        $absentStatus = $this->panelInit->language['acceptedVacation'];
                        break;
                }
                $MailSmsHandler = new \MailSmsHandler();
                foreach ($parents as $parent) {
                    if(isset($mail) AND strpos($parent->comVia, 'mail') !== false){
                        $studentTemplate = $mailTemplate->templateMail;
                        $examGradesTable = "";
                        $searchArray = array("{studentName}","{studentRoll}","{studentEmail}","{studentUsername}","{parentName}","{parentEmail}","{absentDate}","{absentStatus}","{schoolTitle}");
                        $replaceArray = array($student->fullName,$student->studentRollId,$student->email,$student->username,$parent->fullName,$parent->email,\Input::get('attendanceDay'),$absentStatus,$this->panelInit->settingsArray['siteTitle']);
                        $studentTemplate = str_replace($searchArray, $replaceArray, $studentTemplate);
                        $MailSmsHandler->mail($parent->email,$this->panelInit->language['absentReport'],$studentTemplate);
                    }
                    if(isset($sms) AND $parent->mobileNo != "" AND strpos($parent->comVia, 'sms') !== false){
                        $origin_template = $mailTemplate->templateSMS;
                        $examGradesTable = "";
                        $searchArray = array("{studentName}","{studentRoll}","{studentEmail}","{studentUsername}","{parentName}","{parentEmail}","{absentDate}","{absentStatus}","{schoolTitle}");
                        $replaceArray = array($student->fullName,$student->studentRollId,$student->email,$student->username,$parent->fullName,$parent->email,\Input::get('attendanceDay'),$absentStatus,$this->panelInit->settingsArray['siteTitle']);
                        $studentTemplate = str_replace($searchArray, $replaceArray, $origin_template);
                        $MailSmsHandler->sms($parent->mobileNo,$studentTemplate);
                    }

Что я ожидаю, так это то, что если я получу правильный код, я смогу заставить родителя получать SMS и почту, когда учащегося тоже отмечают. Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...