邮件短信处理程序Laravel

时间:2019-01-18 09:30:12

标签: php laravel-5.2

您好,这是laravel中学校管理系统的代码。在此AttendenceController.php中,如果学生标记为“缺少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);
                    }

我期望的是,如果我得到正确的代码,当学生也被标记为在场时,我可以让父母接收短信和邮件。谢谢

0 个答案:

没有答案