Working on the next page logic
This commit is contained in:
parent
6ee3b05f15
commit
d055fa49dd
1 changed files with 43 additions and 68 deletions
111
GooglePlaces.php
111
GooglePlaces.php
|
@ -30,47 +30,24 @@ class GooglePlaces
|
||||||
$this->$variable = $value;
|
$this->$variable = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function next($token)
|
|
||||||
{
|
|
||||||
if ($token)
|
|
||||||
{
|
|
||||||
$this->pagetoken = $token;
|
|
||||||
}
|
|
||||||
elseif (isset($this->response['next_page_token']))
|
|
||||||
{
|
|
||||||
$this->pagetoken = $this->response['next_page_token'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception('Previous call did not return a next_page_token and you didn\'t supply one. What did you expect?');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($method === null)
|
|
||||||
{
|
|
||||||
throw new Exception('You cannot call next() before making a call.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->$method();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __call($method, $arguments)
|
public function __call($method, $arguments)
|
||||||
{
|
{
|
||||||
if (count($arguments) > 0)
|
$method = $this->method = strtolower($method);
|
||||||
{
|
$url = implode('/', array($this->base_url, $method, $this->output));
|
||||||
$this->pagetoken = $arguments[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$method = $this->method = strtolower($method);
|
|
||||||
$url = implode('/', array($this->base_url, $method, $this->output));
|
|
||||||
|
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
|
|
||||||
// Loops through all of our variables to make a parameter list
|
// Loops through all of our variables to make a parameter list
|
||||||
foreach (get_object_vars($this) as $variable => $value)
|
foreach (get_object_vars($this) as $variable => $value)
|
||||||
{
|
{
|
||||||
// Except these variables
|
// Except these variables
|
||||||
if (!in_array($variable, array('base_url', 'method', 'output', 'response')))
|
if (!in_array($variable, array('base_url', 'method', 'output', 'pagetoken', 'response')))
|
||||||
{
|
{
|
||||||
|
// Google lied, all other parameters aren't ignored, they need to be suppressed
|
||||||
|
if ($this->pagetoken !== null)
|
||||||
|
{
|
||||||
|
$this->$variable == null;
|
||||||
|
}
|
||||||
|
|
||||||
// Assuming it's not null
|
// Assuming it's not null
|
||||||
if ($value !== null)
|
if ($value !== null)
|
||||||
{
|
{
|
||||||
|
@ -126,41 +103,44 @@ class GooglePlaces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($method)
|
if (!isset($parameters['pagetoken']))
|
||||||
{
|
{
|
||||||
case 'nearbysearch':
|
switch ($method)
|
||||||
if (!isset($parameters['location']))
|
{
|
||||||
{
|
case 'nearbysearch':
|
||||||
throw new Exception('You must specify a location before calling nearbysearch().');
|
if (!isset($parameters['location']))
|
||||||
}
|
|
||||||
elseif (isset($parameters['rankby']))
|
|
||||||
{
|
|
||||||
switch ($parameters['rankby'])
|
|
||||||
{
|
{
|
||||||
case 'distance':
|
throw new Exception('You must specify a location before calling nearbysearch().');
|
||||||
if (!isset($parameters['keyword']) && !isset($parameters['name']) && !isset($parameters['types']))
|
|
||||||
{
|
|
||||||
throw new Exception('You much specify at least one of the following: keyword, name, types.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($parameters['radius']))
|
|
||||||
{
|
|
||||||
unset($parameters['radius']);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'prominence':
|
|
||||||
if (!isset($parameters['radius']))
|
|
||||||
{
|
|
||||||
throw new Exception('You must specify a radius.');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
elseif (isset($parameters['rankby']))
|
||||||
|
{
|
||||||
|
switch ($parameters['rankby'])
|
||||||
|
{
|
||||||
|
case 'distance':
|
||||||
|
if (!isset($parameters['keyword']) && !isset($parameters['name']) && !isset($parameters['types']))
|
||||||
|
{
|
||||||
|
throw new Exception('You much specify at least one of the following: keyword, name, types.');
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
if (isset($parameters['radius']))
|
||||||
|
{
|
||||||
|
unset($parameters['radius']);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'prominence':
|
||||||
|
if (!isset($parameters['radius']))
|
||||||
|
{
|
||||||
|
throw new Exception('You must specify a radius.');
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't seem to get http_build_query() to work right so...
|
// Couldn't seem to get http_build_query() to work right so...
|
||||||
|
@ -212,11 +192,6 @@ class GooglePlaces
|
||||||
|
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
|
|
||||||
if ($this->pagetoken !== null)
|
|
||||||
{
|
|
||||||
$this->pagetoken = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response;
|
return $this->response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue