Working on the next page logic
This commit is contained in:
parent
6ee3b05f15
commit
d055fa49dd
1 changed files with 43 additions and 68 deletions
|
@ -30,47 +30,24 @@ class GooglePlaces
|
|||
$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)
|
||||
{
|
||||
if (count($arguments) > 0)
|
||||
{
|
||||
$this->pagetoken = $arguments[0];
|
||||
}
|
||||
|
||||
$method = $this->method = strtolower($method);
|
||||
$url = implode('/', array($this->base_url, $method, $this->output));
|
||||
|
||||
$parameters = array();
|
||||
|
||||
// Loops through all of our variables to make a parameter list
|
||||
foreach (get_object_vars($this) as $variable => $value)
|
||||
{
|
||||
// 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
|
||||
if ($value !== null)
|
||||
{
|
||||
|
@ -126,6 +103,8 @@ class GooglePlaces
|
|||
}
|
||||
}
|
||||
|
||||
if (!isset($parameters['pagetoken']))
|
||||
{
|
||||
switch ($method)
|
||||
{
|
||||
case 'nearbysearch':
|
||||
|
@ -162,6 +141,7 @@ class GooglePlaces
|
|||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Couldn't seem to get http_build_query() to work right so...
|
||||
$querystring = '';
|
||||
|
@ -212,11 +192,6 @@ class GooglePlaces
|
|||
|
||||
$this->response = $response;
|
||||
|
||||
if ($this->pagetoken !== null)
|
||||
{
|
||||
$this->pagetoken = null;
|
||||
}
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue