Skip to content

Commit c8a9b15

Browse files
author
Russ P
committed
Changes for dynamic collection size calculation
1 parent 3b1c931 commit c8a9b15

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

aweber_api/aweber_collection.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ public function getById($id) {
4141
* @return void
4242
*/
4343
protected function _getPageParams($start=0, $size=20) {
44-
$params = array(
45-
'ws.start' => $start,
46-
'ws.size' => $size,
47-
);
48-
ksort($params);
44+
if ($start > 0) {
45+
$params = array(
46+
'ws.start' => $start,
47+
'ws.size' => $size,
48+
);
49+
ksort($params);
50+
} else {
51+
$params = array();
52+
}
4953
return $params;
5054
}
5155

@@ -64,6 +68,28 @@ protected function _type() {
6468
return $type;
6569
}
6670

71+
/**
72+
* _calculatePageSize
73+
*
74+
* Calculates the page size of this collection based on the data in the
75+
* next and prev links.
76+
*
77+
* @access protected
78+
* @return integer
79+
*/
80+
protected function _calculatePageSize() {
81+
if (isset($this->data['next_collection_link'])) {
82+
$url = $this->data['next_collection_link'];
83+
$urlParts = parse_url($url);
84+
if (empty($urlParts['query'])) return $this->pageSize;
85+
$query = array();
86+
parse_str($urlParts['query'], $query);
87+
if (empty($query['ws_size'])) return $this->pageSize;
88+
$this->pageSize = $query['ws_size'];
89+
}
90+
return $this->pageSize;
91+
}
92+
6793
/**
6894
* _loadPageForOffset
6995
*
@@ -77,6 +103,7 @@ protected function _type() {
77103
* @return void
78104
*/
79105
protected function _loadPageForOffset($offset, $attempt=1) {
106+
$this->_calculatePageSize();
80107
$start = round($offset / $this->pageSize) * $this->pageSize;
81108
$params = $this->_getPageParams($start, $this->pageSize);
82109

aweber_api/aweber_entry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __get($value) {
7373
if (in_array($value, $this->_privateData)) {
7474
return null;
7575
}
76-
if (array_key_exists($value, $this->data)) {
76+
if (!empty($this->data) && array_key_exists($value, $this->data)) {
7777
return $this->data[$value];
7878
}
7979
if ($value == 'type') return $this->_type();

0 commit comments

Comments
 (0)