Пример #1
0
 /**
  * Deleted checked events.
  */
 public function index_onDelete()
 {
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $eventId) {
             if (!($event = Event::find($eventId))) {
                 continue;
             }
             $event->delete();
         }
         Flash::success(Lang::get('abnmt.mrc::lang.events.delete_selected_success'));
     } else {
         Flash::error(Lang::get('abnmt.mrc::lang.events.delete_selected_empty'));
     }
     return $this->listRefresh();
 }
Пример #2
0
 public function onOrder()
 {
     extract(post());
     if (!post()) {
         return;
     }
     $user = $this->user();
     CW::info(['orderPOST' => post()]);
     // CW::info(['UserEventsId' => array_keys($course_events)]);
     // CW::info(['EventsId' => array_values($course_events)]);
     $ids = array_map('intval', $course_events);
     CW::info(['UserEventId: EventId' => $ids]);
     $_userevents = $user->userevents()->whereIn('id', array_keys($course_events))->get();
     CW::info(['UserEvents' => $_userevents]);
     $_events = EventModel::whereIn('id', $ids)->get();
     CW::info(['Events' => $_events]);
     // return;
     $_userevents->each(function ($userevent) use($ids) {
         if ($userevent->state_id == 9) {
             $userevent->delete();
         } else {
             // $event = $_events->where('id', $ids[$userevent->id]);
             $event = EventModel::find($ids[$userevent->id]);
             // CW::info(['UserEvent' => $userevent]);
             CW::info(['Event' => $event]);
             if (!$event) {
                 $userevent->state()->associate(UserEventStateModel::find(7));
                 // Статус: В списке
                 $userevent->save();
                 // Flash::info('Войдите или Зарегистрируйтесь, чтобы записаться на курс!');
                 // return ['#flashMessages' => $this->renderPartial('@message')];
             } else {
                 $userevent->event()->associate($event);
                 $userevent->state()->associate(UserEventStateModel::find(6));
                 // Статус: В обработке
                 $userevent->save();
             }
         }
     });
     // return \Redirect::refresh()->with('order_state', 'complete');
     // return \Redirect::to('personal/order/confirm');
     $user['profile'] = $user->profile;
     $userevents = $user->userevents()->select('id', 'course_id', 'event_id', 'state_id')->with(['course' => function ($q) {
         $q->select('id', 'crm_course_id', 'title');
     }, 'event' => function ($q) {
         $q->select('id', 'crm_event_id', 'hours', 'price', 'date_start', 'date_end', 'teacher');
     }, 'state' => function ($q) {
         $q->select('id', 'crm_state_id', 'title');
     }])->get();
     // CW::info(['email_data' => $_userevents]);
     // CW::info(['email_data' => $email_data]);
     $this->sendEmail(['user' => $user, 'userevents' => $userevents]);
     Flash::info('Ваша заявка оформлена!');
     return ['#layout-flash-messages' => $this->renderPartial('@message')];
     // $event     = new EventModel;
     // $userevent = new UserEventModel;
 }