Exemplo n.º 1
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $appointmentId = $this->get('appointment');
     $businessId = $this->get('business');
     $issuer = auth()->user();
     $business = Business::find($businessId);
     $appointment = Appointment::find($appointmentId);
     $authorize = $appointment->issuer->id == $issuer->id || $issuer->isOwner($business);
     # \Log::info("Authorize AlterAppointmentRequest for issuer:{$issuer->id} appointment:$appointmentId business:$businessId authorize:$authorize");
     return $authorize;
 }
 public function update(Request $request, $id)
 {
     $updatedAppointment = $this->appointmentFromRequest($request);
     $existingAppointment = \App\Appointment::find($id);
     $existingAppointment->name = $updatedAppointment->name;
     $existingAppointment->phoneNumber = $updatedAppointment->phoneNumber;
     $existingAppointment->timezoneOffset = $updatedAppointment->timezoneOffset;
     $existingAppointment->when = $updatedAppointment->when;
     $existingAppointment->notificationTime = $updatedAppointment->notificationTime;
     $existingAppointment->save();
     return redirect()->route('appointment.index');
 }
Exemplo n.º 3
0
 /**
  * post Action for booking
  *
  * @param  AlterAppointmentRequest $request
  * @return JSON                    Action result object
  */
 public function postAction(AlterAppointmentRequest $request)
 {
     $this->log->info('BookingController: postAction');
     $issuer = auth()->user();
     $businessId = $request->input('business');
     $appointmentId = $request->input('appointment');
     $action = $request->input('action');
     $widget = $request->input('widget');
     $this->log->info("AJAX postAction.request:[issuer:{$issuer->email}, action:{$action}, business:{$businessId}, appointment:{$appointmentId}]");
     $appointment = Appointment::find($appointmentId);
     switch ($action) {
         case 'annulate':
             $appointment->doAnnulate();
             break;
         case 'confirm':
             $appointment->doConfirm();
             break;
         case 'serve':
             $appointment->doServe();
             break;
         default:
             # Ignore Invalid Action
             $this->log->warning('Invalid Action request');
             break;
     }
     /**
      * Widgets MUST be rendered before being returned on Response
      * as they need to be interpreted as HTML
      *
      */
     switch ($widget) {
         case 'row':
             $html = Widget::AppointmentsTableRow(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
         case 'panel':
         default:
             $html = Widget::AppointmentPanel(['appointment' => $appointment, 'user' => auth()->user()])->render();
             break;
     }
     $appointmentPresenter = $appointment->getPresenter();
     // TODO: It is probably possible to move Notifynder to a more proper place
     $date = $appointment->start_at->toDateString();
     $code = $appointmentPresenter->code();
     Notifynder::category('appointment.' . $action)->from('App\\User', auth()->user()->id)->to('App\\Business', $appointment->business->id)->url('http://localhost')->extra(compact('code', 'action', 'date'))->send();
     $this->log->info("postAction.response:[appointment:{$appointment->toJson()}]");
     return response()->json(['code' => 'OK', 'html' => $html]);
 }