Skip to content

Commit bd376dc

Browse files
authored
Merge pull request #58 from tkuijer/master
Fix #57: Portal limit and offset result in error when using a condition
2 parents 4fcca11 + c744617 commit bd376dc

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/Supporting/FileMakerLayout.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ public function endCommunication()
6464
* @return array
6565
* @ignore
6666
*/
67-
private function buildPortalParameters($param, $shortKey = false)
67+
private function buildPortalParameters($param, $shortKey = false, $method = "GET")
6868
{
6969
$key = $shortKey ? "portal" : "portalData";
70+
$prefix = $method === "GET" ? "" : "_";
7071
$request = [];
7172
if (array_values($param) === $param) {
7273
$request[$key] = $param;
7374
} else {
7475
$request[$key] = array_keys($param);
7576
foreach ($param as $portalName => $options) {
7677
if (!is_null($options) && $options['limit']) {
77-
$request["_limit.{$portalName}"] = $options['limit'];
78+
$request["{$prefix}limit.{$portalName}"] = $options['limit'];
7879
}
7980
if (!is_null($options) && $options['offset']) {
80-
$request["_offset.{$portalName}"] = $options['offset'];
81+
$request["{$prefix}offset.{$portalName}"] = $options['offset'];
8182
}
8283
}
8384
}
@@ -165,6 +166,7 @@ public function query($condition = null, $sort = null, $offset = 0, $range = 0,
165166
if ($this->restAPI->login()) {
166167
$headers = ["Content-Type" => "application/json"];
167168
$request = [];
169+
$method = is_null($condition) ? "GET" : "POST";
168170
if (!is_null($sort)) {
169171
$request["sort"] = $sort;
170172
}
@@ -175,19 +177,18 @@ public function query($condition = null, $sort = null, $offset = 0, $range = 0,
175177
$request["limit"] = (string)$range;
176178
}
177179
if (!is_null($portal)) {
178-
$request = array_merge($request, $this->buildPortalParameters($portal, true));
180+
$request = array_merge($request, $this->buildPortalParameters($portal, true, $method));
179181
}
180182
if (!is_null($script)) {
181183
$request = array_merge($request, $this->buildScriptParameters($script));
182184
}
183185
if (!is_null($condition)) {
184186
$request["query"] = $condition;
185187
$params = ["layouts" => $this->layout, "_find" => null];
186-
$this->restAPI->callRestAPI($params, true, "POST", $request, $headers);
187188
} else {
188189
$params = ["layouts" => $this->layout, "records" => null];
189-
$this->restAPI->callRestAPI($params, true, "GET", $request, $headers);
190190
}
191+
$this->restAPI->callRestAPI($params, true, $method, $request, $headers);
191192
$this->restAPI->storeToProperties();
192193
$result = $this->restAPI->responseBody;
193194
$fmrel = null;

0 commit comments

Comments
 (0)