public function getSpdata($res) { $content = json_decode($res->getBody(), true); $address = array(); $work_address = array(); $service = array(); $educations = array(); // retrieving addresses /* foreach ($content['address'] as $add) { $address[] = json_decode($add, true); //$temp = json_decode($temp, true); //echo '<pre>'; var_dump($temp); exit; } */ //echo '<pre>'; var_dump($content['address']); exit; // retrieving work_address foreach ($content['work_address'] as $wadd) { $work_address[] = json_decode($wadd, true); } // retrieving contact foreach ($content['contact'] as $con) { $contact = json_decode($con, true); } // retrieving details foreach ($content['details'] as $det) { $details = json_decode($det, true); } //echo '<pre>'; var_dump($details); exit; // retrieving location types foreach ($content['location'] as $loc) { $temp_loc = json_decode($loc, true); $details['locations'][] = $temp_loc['location_type']; } // retrieving services foreach ($content['service'] as $data) { $service[] = json_decode($data, true); } // retrieving educations foreach ($content['education'] as $data) { $education = json_decode($data, true); $educations[] = $education['education_label']; } if (count($service) > 0) { $tmp = array(); foreach ($service as $item) { if (!in_array($item['service_id'], $tmp)) { $service_list[] = $item; $tmp[] = $item['service_id']; } } } else { $service_list = array(); } // question answer data $i = 0; $responseTimes = array(); $answered = 0; // retrieving commision if (is_array($content['sp_commision'])) { foreach ($content['sp_commision'] as $sp_commission) { $sp_commission = json_decode($sp_commission, true); if ($sp_commission['status_id'] == 1) { $commission = $sp_commission['commision']; } } } if ($commission == 0) { $api = new Api(); $api_url = $this->getServiceLocator()->get('config')['api_url']['value']; $setting_res = $api->curl($api_url . "/api/sitesetting/1/", array(), "GET"); $setting_data = json_decode($setting_res->getBody(), true); $commission = $setting_data['setting_value']; } // setting payment price $bookingsession = new Container('bookingsession'); $bookingsession->price = $commission; // Calculating response $response = array('years' => count($responseTimes) > 0 && array_sum($responseTimes) > 0 ? floor(array_sum($responseTimes) / count($responseTimes) / 31536000) : 0, 'months' => count($responseTimes) > 0 && array_sum($responseTimes) > 0 ? floor(array_sum($responseTimes) / count($responseTimes) / 2592000) : 0, 'days' => count($responseTimes) > 0 && array_sum($responseTimes) > 0 ? floor(array_sum($responseTimes) / count($responseTimes) / 86400) : 0, 'hours' => count($responseTimes) > 0 && array_sum($responseTimes) > 0 ? floor(array_sum($responseTimes) / count($responseTimes) / 3600) : 0, 'minutes' => count($responseTimes) > 0 && array_sum($responseTimes) > 0 ? floor(array_sum($responseTimes) / count($responseTimes) / 60) : 0); $form_review = new ReviewForm($service_list); $form_ask = new AskForm(); //array_push($address, $work_address); $form_booking = new BookingForm($work_address, $service_list); $form_wishlist = new WishlistForm($address, $service_list); $session = new Container('bookingData'); if (isset($session->bookingData)) { $bookingData = $session->bookingData; $form_booking->bind($session->bookingData); $form_booking->get('service_id')->setAttributes(array('disabled' => false)); $form_booking->get('duration')->setAttributes(array('disabled' => false)); $form_booking->get('service_date')->setAttributes(array('disabled' => false)); //$session->offsetUnset('bookingData'); } // retrieving language foreach ($content['language'] as $data) { $langArr = json_decode($data, true); if (!empty($langArr)) { $lang[] = $langArr['service_language']; } } if (count($lang) > 0) { $language = implode(', ', $lang); } else { $language = ''; } return array('content' => $content, 'address' => $address, 'work_address' => $work_address, 'contact' => $contact, 'details' => $details, 'service' => $service, 'educations' => $educations, 'service_list' => $service_list, 'commission' => $commission, 'response' => $response, 'form_review' => $form_review, 'form_ask' => $form_ask, 'form_booking' => $form_booking, 'language' => $language, 'form_wishlist' => $form_wishlist); }
public function scheduleAction() { $session = new Container('bookingData'); $request = $this->getRequest(); if ($request->isPost() || isset($session->bookingData)) { $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('practitioner', array('action' => 'list')); } $bookingModel = new Bookings(); $model = new Practitioners(); $slots = $errors = array(); $address = array(); $work_address = array(); /* Validation for booking form start here */ $filter = new InputFilter(); $filter->add(array('name' => 'service_location', 'required' => true)); $filter->add(array('name' => 'service_id', 'required' => true)); $filter->add(array('name' => 'duration', 'required' => true)); $filter->add(array('name' => 'service_date', 'required' => true)); /* Validation for booking form end here */ $api = new Api(); $api_url = $this->getServiceLocator()->get('config')['api_url']['value']; $res = $api->curl($api_url . "/api/spusers/" . $id . "/", array(), "GET"); if ($res->getStatusCode() != 200) { return $this->redirect()->toRoute('practitioner', array('action' => 'list')); } $content = json_decode($res->getBody(), true); // retrieving work_address foreach ($content['work_address'] as $wadd) { $work_address[] = json_decode($wadd, true); } // retrieving services foreach ($content['service'] as $service) { $service_list[] = $temp = json_decode($service, true); $services[$temp['id']] = $temp['duration']; } $form = new BookingForm($work_address, $service_list); $auth = new FrontEndAuth(); if (!$auth->hasIdentity(4)) { if ($request->isPost()) { $form->setInputFilter($filter); $form->setData($request->getPost()); if ($form->isValid()) { $session->bookingData = $request->getPost(); } else { $errors = $form->getMessages(); isset($errors['service_location']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service location') : ''; isset($errors['service_id']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service.') : ''; isset($errors['duration']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service duration.') : ''; isset($errors['service_date']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service date.') : ''; return $this->redirect()->toRoute('practitioner', array('action' => 'view', 'id' => $id)); } } $session->sp = $id; return $this->redirect()->toRoute('login', array('action' => 'index')); } if (isset($session->bookingData)) { $bookingData = $session->bookingData; $form->bind($session->bookingData); //$session->offsetUnset('bookingData'); } if ($request->isPost() || isset($session->bookingData)) { $form->setInputFilter($filter); $request->isPost() ? $form->setData($request->getPost()) : $form->setData($session->bookingData); if ($form->isValid()) { // Create a session $bookingsession = new Container('bookingsession'); $bookingsession->locationid = $request->isPost() ? $request->getPost('service_location') : $session->bookingData->service_location; $bookingsession->serviceid = $request->isPost() ? $request->getPost('service_id') : $session->bookingData->service_id; $bookingsession->durationid = $request->isPost() ? $request->getPost('duration') : $session->bookingData->duration; $bookingsession->servicedate = $request->isPost() ? $request->getPost('service_date') : $session->bookingData->service_date; $bookingsession->serviceprice = $model->getServicePrice($api_url, $request->isPost() ? $request->getPost('duration') : $session->bookingData->duration); $bookingsession->sp_id = $id; return $this->redirect()->toRoute('booking', array('action' => 'checkout')); } else { $errors = $form->getMessages(); isset($errors['service_location']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service location') : ''; isset($errors['service_id']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service.') : ''; isset($errors['duration']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service duration.') : ''; isset($errors['service_date']['isEmpty']) ? $this->flashMessenger()->addErrorMessage('Please select service date.') : ''; return $this->redirect()->toRoute('practitioner', array('action' => 'view', 'id' => $id)); } } } else { return $this->redirect()->toRoute('practitioner', array('action' => 'list')); } exit; }