예제 #1
0
     $longitude = (double) $row['longitude'];
     $slug = strtolower(str_replace(' ', '-', $row['name']));
     $image_extension = 'jpg';
     $image_url = 'images/no-image.png';
     foreach ($image_extensions as $image_extension) {
         if (file_exists('images/' . $slug . '.' . $image_extension)) {
             $image_url = 'images/' . $slug . '.' . $image_extension;
         }
     }
     $categories_json = DecodeJSONField($row['category']);
     if ($category_controller->Accept($categories_json)) {
         $address_divvy = Divvy(array_merge(DecodeJSON($row['address'], true), array($row['postcode'])), 2);
         $address_split = array_map(function ($el) {
             return implode(', ', $el);
         }, $address_divvy);
         $rows[(int) $row['id']] = array('id' => (int) $row['id'], 'name' => $row['name'], 'latitude' => $latitude, 'longitude' => $longitude, 'distance' => DistanceBetween(array($latitude, $longitude), array($centre_latitude, $centre_longitude)), 'category' => $categories_json, 'email' => $row['email'], 'telephone' => DecodeJSONField($row['telephone']), 'address' => DecodeJSONField($row['address']), 'postcode' => $row['postcode'], 'address1' => $address_split[0], 'address2' => $address_split[1], 'website' => $row['website'], 'entry_rates' => DecodeJSONField($row['entry_rates']), 'opening_times' => DecodeJSONField($row['opening_times'], "<br>"), 'rating' => number_format((double) $row['rating'], 1, '.', ''), 'more_info' => $row['more_info'] != '' ? $row['more_info'] : 'Sorry no info', 'disabled_facilities' => $row['disabled_facilities'] != '' ? $row['disabled_facilities'] : 'Sorry no info', 'facilities' => $row['facilities'] != '' ? $row['facilities'] : 'Sorry no info', 'good_stuff' => $row['good_stuff'] != '' ? $row['good_stuff'] : 'Sorry no info', 'bad_stuff' => $row['bad_stuff'] != '' ? $row['bad_stuff'] : '', 'image_url' => $image_url);
     }
 }
 usort($rows, function ($a, $b) {
     return $a['distance'] - $b['distance'];
 });
 // limit results for normal users
 if (!$master) {
     $count = 0;
     foreach ($rows as $index => $row) {
         if ($row['distance'] >= 20) {
             unset($rows[$index]);
         }
         $count++;
     }
 }
예제 #2
0
function IsTargetInRange($userId, $itemId, $targetId, $gameId)
{
    /*step 1 get range of item*/
    $sql = sprintf("SELECT ItemIdentifier FROM game_items WHERE id =%d", $itemId);
    $result = RunSql($sql);
    $row = $result->fetch_assoc();
    $itemIdentifier = $row['ItemIdentifier'];
    $itemRanges = array(0, 0, 0, 100, 100, 100, 100, 100, 0);
    $range = $itemRanges[$itemIdentifier];
    /*step 2 get position of user*/
    $sql = sprintf("SELECT * FROM game_players WHERE PlayerId = %d and GameId = %d", $userId, $gameId);
    $result = RunSql($sql);
    $row = $result->fetch_assoc();
    $userLat = $row['Lat'];
    $userLng = $row['Lng'];
    /*step 3 get position of target*/
    $sql = sprintf("SELECT * FROM game_players WHERE PlayerId = %d and GameId = %d", $targetId, $gameId);
    $result = RunSql($sql);
    $row = $result->fetch_assoc();
    $targetLat = $row['Lat'];
    $targetLng = $row['Lng'];
    /*step 4 get distance between user and target return true if less than item range else return false*/
    if (DistanceBetween($targetLat, $targetLng, $userLat, $userLng) <= $range) {
        return true;
    } else {
        return false;
    }
}