Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $date = new \DateTime();
     $date->modify('+1 days');
     $formatted_date = $date->format('Y-m-d');
     $classLessons = ClassLesson::whereDate('time', '=', $formatted_date)->get();
     foreach ($classLessons as $classLesson) {
         $lesson = $classLesson->lesson;
         $class = $classLesson->studyClass;
         $surveys = $lesson->surveys;
         foreach ($surveys as $survey) {
             $classSurvey = new ClassSurvey();
             $classSurvey->class_id = $class->id;
             $classSurvey->survey_id = $survey->id;
             $classSurvey->send_status = 1;
             $gen = $class->gen;
             foreach ($class->registers()->where("status", 1)->get() as $register) {
                 $student = $register->user;
                 $surveyUser = SurveyUser::where('gen_id', $gen->id)->where('survey_id', $survey->id)->where('user_id', $student->id)->first();
                 if ($surveyUser == null) {
                     $surveyUser = new SurveyUser();
                     $surveyUser->survey_id = $survey->id;
                     $surveyUser->user_id = $student->id;
                     $surveyUser->gen_id = $gen->id;
                     $surveyUser->save();
                 }
             }
             $classSurvey->save();
         }
     }
     $this->info('The surveys were sent successfully!');
 }
Ejemplo n.º 2
0
 public function ajax_send_survey(Request $request)
 {
     $classSurvey = new ClassSurvey();
     $classSurvey->class_id = $request->class_id;
     $classSurvey->survey_id = $request->survey_id;
     $classSurvey->send_status = 1;
     $class = StudyClass::find($request->class_id);
     $gen = $class->gen;
     foreach ($class->registers()->where("status", 1)->get() as $register) {
         $student = $register->user;
         $surveyUser = SurveyUser::where('gen_id', $gen->id)->where('survey_id', $request->survey_id)->where('user_id', $student->id)->first();
         if ($surveyUser == null) {
             $surveyUser = new SurveyUser();
             $surveyUser->survey_id = $request->survey_id;
             $surveyUser->user_id = $student->id;
             $surveyUser->gen_id = $gen->id;
             $surveyUser->save();
             //                send_mail_goodbye($register, ['*****@*****.**']);
         }
     }
     $classSurvey->save();
     return '  <i class=" teal-text material-icons">done</i>';
 }