doumu5023 2019-01-18 09:30
浏览 19

Mail Sms Handler Laravel

Hello this code of school management system in laravel. In this AttendenceController.php a student if marked absent an SMS & Mail is sent directly to the parent .

Now i would like also to make it possible for the parent also to receive SMS & Mail when the student is marked present.

public function 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);
                    }

What i expect is that if i get the right code i can make the parent to receive SMS & mail when the student is marked present too. Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单