/** * Returns class instance * * @return SKADATE_BOL_SpeedmatchRelationDao */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function findSpeedmatchOpponents($userId, $first, $count, $criteria, $exclude = array()) { if (!$userId) { return null; } if (isset($criteria['birthdate'])) { $range = explode('-', $criteria['birthdate']); if (!empty($range[0]) && !empty($range[1])) { $criteria['birthdate'] = array('from' => $range[0], 'to' => $range[1]); } else { unset($criteria['birthdate']); } } $addQuery['join'] = ' LEFT JOIN `' . $this->relationDao->getTableName() . '` AS `relation` ON (`user`.`id` = `relation`.`oppUserId` AND `relation`.`userId` = ' . OW::getDbo()->escapeString($userId) . ') '; $addQuery['where'] = ' AND `relation`.`id` IS NULL AND `user`.`id` != ' . OW::getDbo()->escapeString($userId); if (!empty($criteria['googlemap_location']['latitude']) && !empty($criteria['googlemap_location']['longitude'])) { $location = $criteria['googlemap_location']; unset($criteria['googlemap_location']); $coord = GOOGLELOCATION_BOL_LocationService::getInstance()->getNewCoordinates($location['latitude'], $location['longitude'], 225, (double) $location['distance']); $location['southWestLat'] = $coord['lat']; $location['southWestLng'] = $coord['lng']; $coord = GOOGLELOCATION_BOL_LocationService::getInstance()->getNewCoordinates($location['latitude'], $location['longitude'], 45, (double) $location['distance']); $location['northEastLat'] = $coord['lat']; $location['northEastLng'] = $coord['lng']; $sql = GOOGLELOCATION_BOL_LocationService::getInstance()->getSearchInnerJoinSql('user', $location['southWestLat'], $location['southWestLng'], $location['northEastLat'], $location['northEastLng'], null, 'LEFT'); $locationDao = SKADATE_BOL_CurrentLocationDao::getInstance(); $sql .= ' LEFT JOIN `' . $locationDao->getTableName() . '` current_location ON (user.id = current_location.userId AND ( current_location.latitude >= ' . $location['southWestLat'] . ' AND current_location.latitude <= ' . $location['northEastLat'] . ' ) AND ( current_location.longitude >= ' . $location['southWestLng'] . ' AND current_location.longitude <= ' . $location['northEastLng'] . ' )) '; $addQuery['join'] .= $sql; $addQuery['where'] .= ' AND (current_location.id IS NOT NULL OR location.id IS NOT NULL) '; $addQuery['order'] = ' current_location.id IS NOT NULL DESC, `user`.`activityStamp` DESC '; } if (!empty($exclude)) { $addQuery['where'] .= ' AND `user`.`id` NOT IN (' . implode(',', array_map('intval', array_filter($exclude))) . ') '; } $idList = BOL_UserDao::getInstance()->findUserIdListByQuestionValues($criteria, $first, $count, false, $addQuery); return $idList; }