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;
|
$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)
|
|
||||||
{
|
|
||||||
$this->pagetoken = $arguments[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
$method = $this->method = strtolower($method);
|
$method = $this->method = strtolower($method);
|
||||||
$url = implode('/', array($this->base_url, $method, $this->output));
|
$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,6 +103,8 @@ class GooglePlaces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($parameters['pagetoken']))
|
||||||
|
{
|
||||||
switch ($method)
|
switch ($method)
|
||||||
{
|
{
|
||||||
case 'nearbysearch':
|
case 'nearbysearch':
|
||||||
|
@ -162,6 +141,7 @@ class GooglePlaces
|
||||||
|
|
||||||
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...
|
||||||
$querystring = '';
|
$querystring = '';
|
||||||
|
@ -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