Пример #1
0
     return;
 }
 if (empty($distance)) {
     $distance = 10;
 } else {
     if (!is_numeric($distance)) {
         $response['status'] = 412;
         $response['message'] = 'Invalid value for distance';
         echo json_encode($response);
         return;
     }
 }
 $locationsResult = $db->exec("SELECT * FROM `users` left outer join location on users.user_name = location.user_name where location_id = (select max(location_id) from location where location.user_name = users.user_name) and users.user_name != '{$user->user_name}'");
 $usersList = [];
 for ($i = 0; $i < count($locationsResult); $i++) {
     if (checkLatitude($locationsResult[$i]['latitude']) && checkLongitude($locationsResult[$i]['longitude'])) {
         if (getDistanceFromLatLonInKm($location->latitude, $location->longitude, $locationsResult[$i]['latitude'], $locationsResult[$i]['longitude']) <= $distance) {
             $obj = $locationsResult[$i];
             $obj['distanceInKm'] = getDistanceFromLatLonInKm($location->latitude, $location->longitude, $locationsResult[$i]['latitude'], $locationsResult[$i]['longitude']);
             $locationU = $locations->findone(['user_name = ?', $obj['user_name']], ['order' => 'location_id DESC']);
             $obj['location'] = $locationU->cast();
             $educations = new DB\SQL\Mapper($db, 'education');
             $educationU = $educations->findone(['username = ?', $obj['user_name']]);
             if (!empty($educationU)) {
                 $obj['education'] = $educationU->cast();
             }
             $works = new DB\SQL\Mapper($db, 'work');
             $workU = $works->findone(['user_name = ?', $obj['user_name']]);
             if (!empty($work)) {
                 $obj['work'] = $workU->cast();
             }
Пример #2
0
     }
 }
 if (!empty($designations)) {
     if (gettype($designations) === 'array') {
         $designations = "('" . implode($designations, "','") . "')";
         $query .= " and designation in " . $designations;
     } else {
         $query .= " and designation like '%" . $designations . "%'";
     }
 }
 //echo $query;
 $result = $db->exec($query);
 if (!empty($lcn) && !empty($result)) {
     $locationResult = [];
     for ($i = 0; $i < count($result); $i++) {
         if (checkLatitude($result[$i]['latitude']) && checkLongitude($result[$i]['longitude'])) {
             if (getDistanceFromLatLonInKm($lcn->latitude, $lcn->longitude, $result[$i]['latitude'], $result[$i]['longitude']) <= $distance) {
                 $result[$i]['distanceInKm'] = getDistanceFromLatLonInKm($lcn->latitude, $lcn->longitude, $result[$i]['latitude'], $result[$i]['longitude']);
                 $locationResult[] = $result[$i];
             }
         }
     }
     $result = $locationResult;
 }
 if (count($result) > 0) {
     $response['message'] = 'Successfully retrieved list';
     $response['status'] = 200;
     $response['data'] = $result;
     echo json_encode($response);
 } else {
     $response['message'] = 'List is empty';