-
Notifications
You must be signed in to change notification settings - Fork 1
/
yahoo_geo_planet_app_controller.php
72 lines (69 loc) · 2.82 KB
/
yahoo_geo_planet_app_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* Yahoo GeoPlanet Plugin App Controller
*
* CakePHP's Controller::paginate() method makes 2 calls to the model object
* being paginated, the first to get the total number of results in the set,
* paginateCount(), (normally a count(*) with conditions but no limit clause),
* and then paginate() to get the current page's results with limit clause.
*
* The paginate() method in this controller and the paginateCount() and
* paginate() methods in the model allow the use of CakePHP's pagination
* functionality and helper to paginate through result sets from data sources
* that include the current page's results and the total number of results in
* the whole set in one call, such as those commonly returned from web services.
*
* The approach involves setting a property in the model being paginated with
* the pagination information from the Controller::paginate property along with
* any paging params from the URL. This is so the pagination params are *all*
* available in the Model::paginateCount() method. Some relevant params are
* passed in, but ones like show/limit and page are not. Now
* Model::paginateCount() has all the pagination params, it can make the call to
* the web service, store the results in another property of the model and
* return the total number of results value included in the response from the
* web service. Controller::paginate() then calls Model::paginate() which simply
* returns the results it stored in the model property in the previous call to
* Model::paginateCount().
*
* @author Neil Crookes <neil@neilcrookes.com>
* @link http://www.neilcrookes.com
* @copyright (c) 2010 Neil Crookes
* @license MIT License - http://www.opensource.org/licenses/mit-license.php
*/
class YahooGeoPlanetAppController extends AppController {
/**
* Overrides CakePHP's default paging settings, optional.
*
* @var array
*/
public $paginate = array(
'page' => 1,
'limit' => 10,
);
/**
* Overrides Controller::paginate() to set paging options in the
* Model::paginate property so they available in the Model::paginateCount()
* method.
*
* @param mixed $object
* @param mixed $scope
* @param mixed $whitelist
* @return array The result set
*/
public function paginate($object = null, $scope = array(), $whitelist = array()) {
if (isset($this->passedArgs['page'])) {
$this->paginate['page'] = $this->passedArgs['page'];
}
if (isset($this->passedArgs['show'])) {
$this->paginate['limit'] = $this->passedArgs['show'];
}
$options = $this->paginate;
if (isset($options[$object])) {
$options = array_merge($options, $options[$object]);
unset($options[$object]);
}
$this->$object->paginate = $this->paginate[$object] = $options;
return parent::paginate($object = null, $scope = array(), $whitelist = array());
}
}
?>