Beispiel #1
0
 /**
  * Update Events from CRM
  */
 public function onUpdateFromCrm()
 {
     $crmuserevents = CRMUserEvent::isNotUpdated()->with(['user', 'event'])->get();
     \CW::info(['userevents' => $crmuserevents]);
     if (count($crmuserevents) == 0) {
         Flash::info("No UserEvents to Create/Update");
         // echo "ERROR!";
         return;
     }
     $crmuserevents->each(function ($userevent) {
         if ($userevent->user && $userevent->event) {
             \CW::info([$userevent]);
             $cmsuser = User::where('email', $userevent->user->email)->first();
             $cmsevent = Event::where('crm_event_id', $userevent->event->id)->with('course')->first();
             $cmscourse = $cmsevent->course;
             $cmsusereventstate = UserEventState::where('crm_state_id', $userevent->state_id)->first();
             // $cmsuserevent = UserEvent::firstOrNew(['crm_event_id' => $userevent->event->id, 'user_id' => $cmsuser->id]);
             // $cmsuserevent = $cmsuser->userevents()
             // $cmsuserevent = $cmsuserevent
             $cmsuserevent = UserEvent::where('user_id', $cmsuser->id)->where('event_id', $cmsevent->id)->first();
             if (!$cmsuserevent) {
                 $cmsuserevent = new UserEvent();
             }
             \CW::info([$cmsuser, $cmsevent, $cmscourse, $cmsuserevent, $cmsusereventstate]);
             // if (!$cmsuser) {
             //     Log::warning("CMSUser is NULL\n");
             // }
             // if (!$cmsevent) {
             //     Log::warning("CMSEvent is NULL\n");
             // }
             // if (!$cmscourse) {
             //     Log::warning("CMSCourse is NULL\n");
             // }
             // if (!$cmsuserevent) {
             //     Log::warning("CMSUserEvent is NULL\n");
             // }
             // if (!$cmsusereventstate) {
             //     Log::warning("CMSUserEventState is NULL\n");
             // }
             $cmsuserevent->user()->associate($cmsuser);
             $cmsuserevent->course()->associate($cmscourse);
             $cmsuserevent->state()->associate($cmsusereventstate);
             $cmsuserevent->event()->associate($cmsevent);
             $cmsuserevent->fill(['course_type_id' => $cmscourse->course_type_id, 'course_category_id' => $cmscourse->course_category_id, 'crm_event_id' => $userevent->event->id]);
             \CW::info([$cmsuserevent]);
             $cmsuserevent->save();
             $userevent->update(['is_updated' => true]);
         }
     });
     Flash::success("UserEvents is update");
 }
 /**
  * Deleted checked usereventstates.
  */
 public function index_onDelete()
 {
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $usereventstateId) {
             if (!($usereventstate = UserEventState::find($usereventstateId))) {
                 continue;
             }
             $usereventstate->delete();
         }
         Flash::success(Lang::get('abnmt.mrc::lang.usereventstates.delete_selected_success'));
     } else {
         Flash::error(Lang::get('abnmt.mrc::lang.usereventstates.delete_selected_empty'));
     }
     return $this->listRefresh();
 }
Beispiel #3
0
 public function onAddCourse()
 {
     extract(post());
     $user = $this->user();
     if (!$user) {
         Flash::info('Войдите или Зарегистрируйтесь, чтобы записаться на курс!');
         return ['#layout-flash-messages' => $this->renderPartial('@message')];
     }
     $course = CourseModel::find($course_id);
     // $userevents = $user->userevents()->isInOrder();
     try {
         $el = '#js' . $course_id . $type_id . $cat_id;
         // CW::info(['check' => $order->courses->contains('id', $course->id)]);
         if ($user->userevents->contains('course_id', $course->id)) {
             Flash::info('Учебная программа уже в личном кабинете');
             return [$el => $this->renderPartial('@button'), '#layout-flash-messages' => $this->renderPartial('@message')];
         }
         $userevent = new UserEventModel();
         $userevent->user()->associate($user);
         $userevent->course()->associate($course);
         $userevent->state()->associate(UserEventStateModel::find(1));
         // Статус: В заявке
         $userevent->fill(['course_type_id' => $type_id, 'course_category_id' => $cat_id]);
         $userevent->save();
         Flash::success('Учебная программа добавлена в личный кабинет');
         return [$el => $this->renderPartial('@button'), '#layout-flash-messages' => $this->renderPartial('@message')];
     } catch (Exception $e) {
         Flash::error('Ошибка!');
         return ['#layout-flash-messages' => $this->renderPartial('@message')];
     }
 }
Beispiel #4
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;
 }