Esempio n. 1
0
 public function store(Request $request)
 {
     $equation = RegistrationEquation::findOrNew($request->input('id'));
     $equation->fill($request->only('university', 'level', 'grade'));
     $equation->registration_id = $this->user->id;
     $equation->save();
     /** populate files and delete unused] */
     $files_ids = [];
     foreach ($request->input('files') as $file) {
         if (!empty($file['id'])) {
             $files_ids[] = $file['id'];
         }
     }
     RegistrationEquationFile::whereIn('id', $files_ids)->update(['registration_equation_id' => $equation->id]);
     RegistrationEquationFile::whereNotIn('id', $files_ids)->where('registration_equation_id', $equation->id)->delete();
     /** end populate files  */
     /** populate subjects */
     $old_subject_ids = [];
     foreach ($request->input('subjects') as $subject) {
         if (!empty($subject['id'])) {
             $old_subject_ids[] = $subject['id'];
         }
     }
     RegistrationEquationSubject::whereNotIn('id', $old_subject_ids)->where('registration_equation_id', $equation->id)->delete();
     foreach ($request->input('subjects') as $subject) {
         if (empty($subject['id'])) {
             $subject['status'] = 'waiting';
             $equation->subjects()->create($subject);
         } else {
             RegistrationEquationSubject::where('id', $subject['id'])->update($subject);
         }
     }
     /** ned populate subjects */
     $equation->load('files', 'subjects');
     foreach ($equation->files as $file) {
         $attachments = $file->urlsForAttachment('file');
         foreach ($attachments as $key => $attachment) {
             $attachments[$key] = asset($attachment);
         }
         $file->attachments = $attachments;
     }
     // update step and dispatch it
     $next_step = RegistrationStep::find($this->user->registration_step_id)->children()->where('equation_processing', 1)->first();
     if ($next_step) {
         $this->user->registration_step_id = $next_step->id;
         $this->user->save();
         event(new RegistrationStepChanged($this->user, ['comment' => 'تم تغييرها بشكل تلقائي بعد اضافة الطالب لشهادة']));
     }
     //
     return response()->json(compact('equation'), 200, [], JSON_NUMERIC_CHECK);
 }
Esempio n. 2
0
 public function store($eq_id, EqSub $equations, Request $request)
 {
     $equations->registration_equation_id = $eq_id;
     $equations->status = 'waiting';
     $equations->fill($request->all())->save();
     $message = 'تم اضافة مادة بنجاح';
     $equal_order = Equation::with('registration', 'files', 'subjects')->findOrFail($eq_id);
     $student_id = $equal_order->registration->registration_equation_id;
     $all_subjects = Subject::pluck('name', 'id')->toArray();
     $action_need = $equal_order->subjects->filter(function ($s) {
         return $s->status == "accepted";
     })->count();
     if (request('submit') == 'save') {
         return redirect()->back()->with('success', $message);
     } else {
         return redirect()->route('registration.equations.subjects', $eq_id)->with('success', $message);
     }
 }