public function getSplistByFilter($data, $api_url)
 {
     if ($data['service_id'] == "" && $data['auth_to_issue_insurence_rem_receipt'] == "" && $data['days_id'] == "" && $data['avg_rating'] == "" && $data['practitioners_name'] == "" && $data['company_name'] == "" && $data['booking_no'] == "" && $data['price'] == "" && $data['feedback_filter'] == "" && $data['distance'] == "" && $data['association_member'] == "" && $data['country_id'] == "" && $data['state_id'] == "" && $data['city'] == "" && $data['maxPrice'] == "0" && $data['minPrice'] == "0" && $data['zip_code'] == "" && $data['treatmentLength'] == "" && $data['treatment_for_physically_disabled_person'] == "" && $data['id'] == "" && $data['exclude_user'] == "" && isset($data['sp_availability']) && $data['sp_availability'] == "" && $data['location_type'] == "") {
         $data['date_range_filter'] = "1";
     }
     $zip_code = $data['zip_code'];
     $data['status_id'] = 9;
     $sp_list = array();
     $bookingModel = new Bookings();
     $res = $this->api->curl($api_url . "/api/spusers/", $data, "GET");
     if ($res->getStatusCode() == 200) {
         $content = json_decode($res->getBody(), true);
         isset($content['next']) ? $sp_list['next'] = $content['next'] : ($sp_list['next'] = '');
         isset($content['count']) ? $sp_list['count'] = $content['count'] : ($sp_list['count'] = '');
         if (count($content['results']) > 0) {
             $i = 0;
             $distance = array();
             foreach ($content['results'] as $data) {
                 $sp_list['result'][$i]['id'] = $data['id'];
                 $sp_list['result'][$i]['first_name'] = $data['first_name'];
                 $sp_list['result'][$i]['last_name'] = $data['last_name'];
                 $sp_list['result'][$i]['avtar_url'] = $data['avtar_url'];
                 $sp_list['result'][$i]['email'] = $data['email'];
                 $sp_list['result'][$i]['user_type_id'] = $data['user_type_id'];
                 $sp_list['result'][$i]['login_user_type_id'] = $userType;
                 $sp_list['result'][$i]['rating'] = $this->getSPRatings($data['id'], $api_url);
                 if (count($data['details']) > 0) {
                     foreach ($data['details'] as $sp_details) {
                         $details = json_decode($sp_details, true);
                         $sp_list['result'][$i]['years_of_experience'] = $details['years_of_experience'];
                         $sp_list['result'][$i]['degrees'] = $details['degrees'];
                         $sp_list['result'][$i]['specialties'] = $details['specialties'];
                         $sp_list['result'][$i]['work_days'] = $this->getSPWorkdays($data['id'], $api_url);
                     }
                 }
                 /* Calculating nearest distance starts here */
                 $sp_list['result'][$i]['distance'] = "NA";
                 if (count($data['work_address']) > 0 && $zip_code != '') {
                     $all_distances = array();
                     foreach ($data['work_address'] as $raw_add) {
                         $address = json_decode($raw_add, true);
                         $zips = array('consumer_zip' => $zip_code, 'practitioner_zip' => $address['zip_code']);
                         $dist = $this->getDistance($api_url, $zip_code, $address['zip_code']);
                         is_numeric($dist) ? $all_distances[] = round($dist) : '';
                     }
                     $sp_list['result'][$i]['distance'] = count($all_distances) > 0 ? min($all_distances) : "NA";
                     $distance[$i] = is_numeric($sp_list['result'][$i]['distance']) ? $sp_list['result'][$i]['distance'] : 0;
                 }
                 /* Calculating nearest distance ends here */
                 /* Code added by Ritesh starts here */
                 $verification_details = $this->getSPvarification($data['id'], $api_url);
                 $sp_list['result'][$i]['verified'] = $verification_details['verified'];
                 /* Code added by Ritesh ends here */
                 if (count($data['contact']) > 0) {
                     foreach ($data['contact'] as $sp_contacts) {
                         $details = json_decode($sp_contacts, true);
                         $sp_list['result'][$i]['cellphone'] = $details['cellphone'];
                     }
                 }
                 $spPrice = array();
                 $price_arr = array();
                 if (count($data['service']) > 0) {
                     foreach ($data['service'] as $value) {
                         $spPrice[] = json_decode($value, true);
                     }
                 }
                 if (count($spPrice) > 0) {
                     foreach ($spPrice as $value) {
                         $price_arr[] = $value['price'];
                     }
                 }
                 count($price_arr) > 0 ? $sp_list['result'][$i]['price'] = min($price_arr) : ($sp_list['result'][$i]['price'] = '');
                 //$sp_list['result'][$i]['price'] = min($sp_price);
                 $sp_list['result'][$i]['bookings_count'] = $bookingModel->getBookingsCount($api_url, $data['id']);
                 $sp_list['result'][$i]['reviews_count'] = $this->getReviewscount($data['id'], $api_url);
                 $i++;
             }
             //echo '<pre>'; print_r($distance); //exit;
             if (count($distance) > 0) {
                 $sortedDistance = $distance;
                 sort($sortedDistance, SORT_NUMERIC);
                 $sp_list['result'] = $this->sortArrayByArray($sp_list['result'], $sortedDistance, $distance);
             }
             //echo '<pre>'; print_r($sp_list['result']); exit;
             if ($sp_list['next'] != '') {
                 $str = str_replace("page", "@!##", $sp_list['next']);
                 $str_arr = explode('@!##=', $str);
                 $next = explode('&', $str_arr[1]);
                 $sp_list['next'] = $next[0];
             }
             echo json_encode($sp_list);
             exit;
         } else {
             $sp_list = '';
             echo json_encode($sp_list);
             // no data found
             exit;
         }
     } else {
         $sp_list = array('next' => '', 'count' => '', 'result' => '');
         echo json_encode($sp_list);
         exit;
     }
 }
 public function dashboardAction()
 {
     $auth = new FrontEndAuth();
     $model = new Practitioners();
     $bookingModel = new Bookings();
     $common = new Common();
     if (!$auth->hasIdentity(3)) {
         return $this->redirect()->toRoute('login', array('action' => 'index'));
     }
     $session = new Container('frontend');
     // 0:- both(sms & mail) are verified 1:- any one or both(sms & mail) are unverified
     $verifystatus = $session->email_verification_status == 1 && $session->sms_verification_status == 1 ? 0 : 1;
     $api = new Api();
     $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
     $res = $api->curl($api_url . "/api/spusers/" . $session->userid . "/", array(''), "GET");
     if ($res->getStatusCode() != 200) {
         return $this->redirect()->toRoute('practitioner', array('action' => 'list'));
     }
     $data = $this->getSpdata($res);
     array_pop($data['address']);
     //echo '<pre>'; print_r($data); exit;
     $services_count = $this->getservicesdata($session->userid, $api, $api_url);
     // get all services list
     //echo '<pre>'; print_r($services_count); exit;
     $parentService = isset($services_count['results'][0]['category_id']) ? $model->getParentService($api_url, $services_count['results'][0]['category_id']) : 'Not Available';
     $bussCategoryName = $parentService ? $parentService['category_name'] : 'Not Avaialable';
     $service_category_list = $this->getCategories();
     //getting services list for service provider
     $feedback_list = $this->getSPfeedback($session->userid, $api, $api_url);
     //getting feedback list for service provider
     $video_list = $this->getSPmedia($session->userid, $api, $api_url, 2, 5);
     //getting video list for service provider
     $image_list = $this->getSPmedia($session->userid, $api, $api_url, 1, 5);
     //getting images list for service provider
     $options = $model->getSPoptions($session->userid, $api_url);
     //getting available options for service provider
     $varification = $model->getSPvarification($session->userid, $api_url);
     //getting varified/unverified ids for service provider
     $bookings_count = $bookingModel->getBookingsCount($api_url, $session->userid);
     //getting bookings count for service provider
     $workdays = $model->getSPWorkdays($session->userid, $api_url);
     //getting workdays for service provider
     $addservice_form = new SPaddservicesFrom($service_category_list);
     // Getting practitioner's organization
     $org = $model->getSPOrganization($api_url, $session->userid);
     $data['details']['organization'] = isset($org['organization_name']) ? $org['organization_name'] : '';
     $subscriptionDetails = $common->getSubscriptiondetails($api_url, '', true);
     $features = $common->getFeatures($api_url, $session->userid);
     isset($features['chat']) ? $chat = $features['chat'] : ($chat = 0);
     // getting banner for this page
     $banners = $common->getBanner($api_url, 4);
     return new ViewModel(array('states' => $common->getstatesByCountry($api_url), 'countries' => $common->getCountries($api_url), 'AllEducations' => $model->getEducations($api_url), 'languages' => $model->getLanguages($api_url), 'content' => $data['content'], 'addresses' => $data['address'], 'work_address' => $data['work_address'], 'contact' => $data['contact'], 'details' => $data['details'], 'service_list' => $data['service_list'], 'form_review' => $data['form_review'], 'form_ask' => $data['form_ask'], 'form_booking' => $data['form_booking'], 'commission' => $data['commission'], 'language' => $data['language'], 'educations' => $data['educations'], 'addservice_form' => $addservice_form, 'feedback' => $feedback_list, 'ratings' => $ratings, 'workdays' => $workdays, 'available_days' => $model->getAvailableDays($api_url), 'availability' => $model->getSPWorkdays($session->userid, $api_url, '', true), 'appointment_delay' => $model->getAppointmentDelay($session->userid, $api_url), 'response' => $data['response'], 'feedback_count' => count($feedback_list), 'video_list' => $video_list, 'image_list' => $image_list, 'options' => $options, 'varification' => $varification, 'booking_count' => $bookings_count, 'services_count' => $services_count['count'], 'newsletter_count' => count($model->getSPnewsletter($session->userid, $api_url)), 'notifications' => $model->getNotifications($api_url), 'auth' => $auth, 'loggedin_userid' => $session->userid, 'successMsgs' => $this->flashMessenger()->getCurrentSuccessMessages(), 'errors' => $this->flashMessenger()->getCurrentErrorMessages(), 'baseurl' => $this->getServiceLocator()->get('config')['basepath']['url'], 'chaturl' => $this->getServiceLocator()->get('config')['chatpath']['url'], 'verifystatus' => $verifystatus, 'organizations' => $model->getOrganizations($api_url), 'location_types' => $model->getLocationTypes($api_url), 'features' => $subscriptionDetails['features'], 'successMsgs' => $this->flashMessenger()->getCurrentSuccessMessages(), 'errors' => $this->flashMessenger()->getCurrentErrorMessages(), 'banners' => $banners, 'commission' => $data['commission'], 'chat' => $chat, 'browser' => $common->getBrowser(), 'bussCategoryName' => $bussCategoryName));
 }