public function addRequest($vks_id)
 {
     try {
         $vks = Vks::with('tech_support_requests')->findOrFail($vks_id);
     } catch (Exception $e) {
         $this->error('404');
     }
     $available_points = Attendance::techSupportable()->get()->toArray();
     array_walk($available_points, function (&$e) {
         $e['selectable'] = true;
     });
     if (count($vks->tech_support_requests)) {
         foreach ($vks->tech_support_requests as $request) {
             foreach ($available_points as &$point) {
                 if ($request->att_id == $point['id']) {
                     $point['selectable'] = false;
                 }
             }
         }
     }
     return $this->render('techsupport/addRequest', compact('vks', 'available_points'));
 }
예제 #2
0
 public function joinCaCreate($referral = false)
 {
     Token::checkToken();
     $request = $this->request->request;
     if ($referral) {
         $request->set('referrer', $referral);
     }
     $this->validator->validate(['Приглашение от ЦА' => [$request->get('referrer'), 'required']]);
     //if no passes
     if (!$this->validator->passes()) {
         App::$instance->MQ->setMessage($this->validator->errors()->all());
         ST::redirect("back");
     }
     //check codes
     $caWS = CAVks::where('referral', $request->get('referrer'))->with('owner', 'connection_codes', 'insideParp', 'phoneParp', 'outsideParp')->first();
     $caNS = CAVksNoSupport::where('referral', $request->get('referrer'))->first();
     if (!$caWS && !$caNS) {
         App::$instance->MQ->setMessage("Приглашение {$request->get('referrer')}  не действительно");
         ST::redirectToRoute("Vks/select");
     }
     $caVks = $caWS ? $caWS : $caNS;
     $this->convertToLocalTime($caVks);
     $valid = true;
     if (isset($caVks->status)) {
         if (!in_array($caVks->status, [VKS_STATUS_APPROVED, VKS_STATUS_TRANSPORT_FOR_TB])) {
             $valid = false;
         }
     } else {
         if (!in_array($caVks->status, [VKS_STATUS_APPROVED, VKS_STATUS_TRANSPORT_FOR_TB])) {
             $valid = false;
         }
     }
     if (!$valid) {
         App::$instance->MQ->setMessage("Приглашение {$request->get('referrer')}  не действительно, в ЦА поменяли статус этой ВКС и теперь она недоступна");
         ST::redirectToRoute("Vks/select");
     }
     //my tb is can be accepted?
     $participants = isset($caVks->insideParp) ? $caVks->insideParp : $caVks->participants;
     $flag = false;
     foreach ($participants as $parp) {
         if ($parp->attendance_id == App::$instance->tbId) {
             $flag = true;
         }
     }
     $referral = $request->get('referrer');
     if ($this->isAlreadyEnd(date_create($caVks->end_date_time))) {
         App::$instance->MQ->setMessage("Приглашение {$request->get('referrer')}  не действительно, ВКС уже закончилась", 'danger');
         ST::redirectToRoute("Vks/select");
     }
     if (!$flag && $caVks->local->start_date_time->getTimestamp() - date_create()->getTimestamp() < 1800) {
         App::$instance->MQ->setMessage("Ваш ТБ не заявлен на эту ВКС и до начала ВКС осталось менее 30 минут, заявиться на такую ВКС уже не получится, обратитесь к администратору системы", 'danger');
         ST::redirectToRoute("Vks/select");
     }
     $departments = Department::orderBy('prefix')->get();
     $vks = ST::lookAtBackPack();
     $vks = $vks->request;
     if (!$vks->has('inner_participants') && !count($vks->get('inner_participants'))) {
         LocalStorage_controller::staticRemove('vks_participants_create');
     }
     $available_points = Attendance::techSupportable()->get()->toArray();
     array_walk($available_points, function (&$e) {
         $e['selectable'] = true;
     });
     $this->render('vks/joinCa', compact('vks', 'caVks', 'departments', 'referral', 'flag', 'available_points'));
 }