static $cityData = false;
static $citySearchSelect = false;
static $citySearchSelected = false;
+ static $citySearch = false;
+ static $cityName = false;
static $featuredMembers = false;
static $filterArchived = false;
static $filterFeatured = false;
// SELECT id FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
// WHERE name SOUNDS LIKE '%$textSearch%' OR name LIKE '%$textSearch%'
// )
- $appendSelect = " match(member_name) against('$textSearch') as rel_name ";
- $whereSep = ' AND ';
- $textSearch = stripslashes($textSearch);
+ $appendSelect = " match(member_name) against('$textSearch') as rel_name ";
+ $whereSep = ' AND ';
+ $textSearch = stripslashes($textSearch);
$fullTextSearch = true;
}
$categoryCityList = '';
$categoryCitySep = '';
if (isset($_REQUEST) && is_array($cityData) && (isset($_REQUEST['cityUserSearch']) && count($_REQUEST['cityUserSearch']) > 0) || (isset($_REQUEST['citySearch']) && $_REQUEST['citySearch'] != "")) {
+ $citySearch = true;
foreach ($cityData as $r) {
$id = $r['id'];
$cityData[$id]['default'] = false;
if ( (isset($_REQUEST['cityUserSearch']) && in_array($id, $_REQUEST['cityUserSearch'])) || (isset($_REQUEST['citySearch']) && $id == $_REQUEST['citySearch']) ) {
$cityData[$id]['default'] = true;
$citySearchSelected = $id;
- $where .= $whereSep." T.city = $id";
- $whereSep = ' AND ';
+ // $where .= $whereSep." T.city = $id";
+ // $whereSep = ' AND ';
$categoryCityList .= $categoryCitySep."$id";
$categoryCitySep = ', ';
}
}
} else {
- // Double check that we have an array from $regionData
+ // Double check that we have an array from $cityData
if ( isset( $cityData ) && is_array( $cityData ) ) {
reset($cityData);
foreach ($cityData as $r) {
// Get a simplified full list of member data for the map. Limit by selected Alpha is used.
// require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/memberDataByLatLon.php';
// $MapItems = new GlmMembersFront_members_memberDataByLatLon($this->wpdb, $this->config);
- $mapItems = $this->getSimpleMemberInfoList($where.$alphaWhere, true);
/*
* Get a current list of members - unless this is a blank start
*/
if (!$blankStart) {
- // Get stats for the current selection
- $membersFound = $this->getStats(str_replace('T.', '', $where));
-
- // Get stats for number of members found matching current selection criteria (includes alpha selection)
- $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
-
// If there's a full text search, handle separately
if ( $fullTextSearch ) {
+ // Get stats for the current selection
+ $membersFound = $this->getStats(str_replace('T.', '', $where));
+
+ // Get stats for number of members found matching current selection criteria (includes alpha selection)
+ $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
+
// echo '<pre>$fullTextSearch: ' . print_r( $fullTextSearch, true ) . '</pre>';
if ( $appendSelect ) {
$order = " rel_name DESC, member_name ASC ";
'', // prohibitListOptions
$appendSelect
);
+ } elseif ( $citySearchSelected ) {
+ // Setup city search for distance
+
+ $cityCoordinates = $this->getCityCoordinates( $citySearchSelected );
+ if ( $cityCoordinates ) {
+ $cityName = $cityCoordinates['name'];
+ // Distance query
+ $distanceQuery = $this->getDistanceQuery( $cityCoordinates['lat'], $cityCoordinates['lon'] );
+ $where .= $whereSep." ( $distanceQuery < 40 )";
+ $whereSep = ' AND ';
+ $appendSelect = "
+ CASE
+ WHEN T.city = {$citySearchSelected} THEN 0
+ ELSE " . $distanceQuery . "
+ END AS distance";
+
+ $order = " distance ASC, city ASC, member_name ASC ";
+ } else {
+ $appendSelect = "";
+ $order = " member_name ASC ";
+ }
+
+ // Get stats for the current selection
+ $membersFound = $this->getStats(str_replace('T.', '', $where));
+
+ // Get stats for number of members found matching current selection criteria (includes alpha selection)
+ $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
+
+ // $where .= " ";
+ // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
+
+ ${$resultParam} = $this->getList(
+ $where.$alphaWhere, // where
+ $order, // order
+ true, // fieldVals
+ 'id', // idField
+ $start, // start
+ $limit, // limit
+ '', // prohibitListOptions
+ $appendSelect
+ );
// When not full text search sort according to settings
} else {
+ // Get stats for the current selection
+ $membersFound = $this->getStats(str_replace('T.', '', $where));
+
+ // Get stats for number of members found matching current selection criteria (includes alpha selection)
+ $filteredMembersFound = $this->getStats(str_replace('T.', '', $where.$alphaWhere));
+
// Get member list sorted as specified
switch ($this->config['settings']['list_order_list']) {
}
}
+ $mapItems = $this->getSimpleMemberInfoList($where.$alphaWhere, true);
+
+ } else {
+
+ $mapItems = $this->getSimpleMemberInfoList($where.$alphaWhere, true);
}
if ($paging) {
'view' => $view,
'haveFeaturedMembers' => $haveFeaturedMembers,
'featuredMembers' => $featuredMembers,
+ 'cityName' => $cityName,
// Paging parameters
'filteredMembersFound' => $filteredMembersFound,
}
-}
+ public function getDistanceQuery( $lat, $lng )
+ {
+ $foo = "
+ (pow(sin(((T.lat * pi()/180.0) - ($lat * pi()/180.0)) / 2.0), 2) + cos(($lat * pi() / 180.0)) * cos((T.lat * pi() / 180.0)) * pow(sin(((T.lon * pi() / 180.0) - ($lng * pi() / 180.0)) / 2.0), 2))";
+
+ return "ceil(3956 * 2 *
+ atan2(sqrt($foo),
+ sqrt(1 - ($foo))))";
+ }
+
+ public function getCityCoordinates( $cityId )
+ {
+ return $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT name, lat, lon
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities
+ WHERE id = %d",
+ $cityId
+ ),
+ ARRAY_A
+ );
+
+ }
+
+}