/** * Fetch (and create, if necessary) stream on which messages are posted relating * to things happening a given number of $miles around the given location. * @method stream * @static * @param {double} $latitude The latitude of the coordinates to search around * @param {double} $longitude The longitude of the coordinates to search around * @param {double} $miles The radius, in miles, around this location. * Should be one of the array values in the Places/nearby/miles config. * @param {string} $publisherId The id of the publisher to publish this stream * Defaults to the app name in Q/app config. * @param {string} $streamName The name of the stream to create. * Defaults to Places_Nearby::streamName($latitude, $longitude, $miles). * @return {Streams_Stream} Returns the stream object that was created or fetched. */ static function stream($latitude, $longitude, $miles, $publisherId = null, $streamName = null) { list($latitude, $longGrid) = Places::quantize($latitude, $longitude, $miles); $zipcodes = Places_Zipcode::nearby($latitude, $longitude, $miles, 1); if (!isset($publisherId)) { $publisherId = Users::communityId(); } if (!isset($streamName)) { $streamName = self::streamName($latitude, $longitude, $miles); } if ($stream = Streams::fetchOne(null, $publisherId, $streamName)) { return $stream; } $zipcode = $zipcodes ? reset($zipcodes) : null; $attributes = compact('latitude', 'longitude'); if ($zipcode) { foreach (array('zipcode', 'placeName', 'state') as $attr) { $attributes[$attr] = $zipcode->{$attr}; } } $stream = Streams::create($publisherId, $publisherId, 'Places/nearby', array('name' => $streamName, 'title' => $zipcode ? "Nearby ({$latitude}, {$longitude}): {$zipcode->placeName}, zipcode {$zipcode->zipcode}" : "Nearby ({$latitude}, {$longitude})", 'attributes' => Q::json_encode($attributes))); return $stream; }
/** * Fetch a stream on which messages are posted relating to things happening * a given number of $miles around the given location. * If it doesn't exist, create it. * @method stream * @static * @param {double} $latitude The latitude of the coordinates to search around * @param {double} $longitude The longitude of the coordinates to search around * @param {double} $miles The radius, in miles, around this location. * Should be one of the array values in the Places/nearby/miles config. * @param {string} $publisherId The id of the publisher to publish this stream * Defaults to the app name in Q/app config. * @param {string} $streamName The name of the stream to create. * Defaults to Places_Nearby::streamName($latitude, $longitude, $miles). * @return {Streams_Stream} Returns the stream object that was created or fetched. */ static function stream($latitude, $longitude, $miles, $publisherId = null, $streamName = null) { list($latitude, $longGrid) = Places::quantize($latitude, $longitude, $miles); $zipcodes = Places_Zipcode::nearby($latitude, $longitude, $miles, 1); if (!isset($publisherId)) { $publisherId = Q_Config::expect('Q', 'app'); } if (!isset($streamName)) { $streamName = self::streamName($latitude, $longitude, $miles); } if ($stream = Streams::fetchOne(null, $publisherId, $streamName)) { return $stream; } $zipcode = $zipcodes ? reset($zipcodes) : null; $stream = new Streams_Stream(); $stream->publisherId = $publisherId; $stream->name = $streamName; $stream->type = "Places/nearby"; $stream->title = $zipcode ? "Nearby ({$latitude}, {$longitude}): {$zipcode->placeName}, zipcode {$zipcode->zipcode}" : "Nearby ({$latitude}, {$longitude})"; $stream->setAttribute('latitude', $latitude); $stream->setAttribute('longitude', $longitude); if ($zipcode) { $stream->setAttribute('zipcode', $zipcode->zipcode); $stream->setAttribute('placeName', $zipcode->placeName); $stream->setAttribute('state', $zipcode->state); } $stream->save(); return $stream; }