Exemplo n.º 1
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle(Mailer $mailer)
 {
     $teachers = $this->teachers;
     foreach ($teachers as $teacher) {
         $message = new TeacherMessage();
         $message->sender_id = $this->sender_id;
         $message->email = $this->email;
         $message->sms = $this->sms;
         $message->teacher_id = $teacher->id;
         $data = ['content' => $this->email];
         $attachments = $this->attachments;
         if ($this->email) {
             $mailer->send('teachers::emails.message', $data, function ($m) use($teacher, $attachments) {
                 $m->to($teacher->email, $teacher->name)->from(config('teachers.from_email'))->subject("subject");
                 if (!empty($attachments)) {
                     foreach ($attachments as $a) {
                         $m->attach($a);
                     }
                 }
             });
             $message->email_sent = 1;
         }
         if ($this->sms) {
             $sms = new SmsGateway($this->sms, [$teacher->mobile]);
             $result = $sms->send();
             if ($result->getPushMessageResult()->PushMessageResult == 1) {
                 $message->sms_sent = 1;
             }
         }
         $message->save();
     }
     event(new TeachersMessagesQueueFinished());
 }
Exemplo n.º 2
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     //Teacher
     Teacher::created(function ($teacher) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]);
     });
     Teacher::updated(function ($teacher) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]);
     });
     Teacher::deleted(function ($teacher) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]);
     });
     //TeacherFund
     TeacherFund::created(function ($fund) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]);
     });
     TeacherFund::updated(function ($fund) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]);
     });
     TeacherFund::deleted(function ($fund) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]);
     });
     //TeacherGuide
     TeacherGuide::created(function ($guide) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]);
     });
     TeacherGuide::updated(function ($guide) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]);
     });
     TeacherGuide::deleted(function ($guide) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]);
     });
     //TeacherMessage
     TeacherMessage::created(function ($message) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]);
     });
     TeacherMessage::updated(function ($message) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]);
     });
     TeacherMessage::deleted(function ($message) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]);
     });
     //TeacherMessageAttachment
     TeacherMessageAttachment::created(function ($messageattach) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]);
     });
     TeacherMessageAttachment::updated(function ($messageattach) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]);
     });
     TeacherMessageAttachment::deleted(function ($messageattach) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]);
     });
     //TeacherSubject
     TeacherSubject::created(function ($subject) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]);
     });
     TeacherSubject::updated(function ($subject) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]);
     });
     TeacherSubject::deleted(function ($subject) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]);
     });
 }
Exemplo n.º 3
0
 public function index()
 {
     $messages = TeacherMessage::with('teacher', 'sender')->orderBy('id', 'desc')->paginate(50);
     return view('teachers::messages.index', compact('messages'));
 }