Skip to content

Commit 360de26

Browse files
committed
added offsetPortal, type hinting, updated documentation
1 parent d67b9b2 commit 360de26

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,22 @@ FM::setGlobalFields() // not chainable
247247
#### Chainable
248248
```php
249249
// standard query-builder stuff like where, orderBy, etc.
250-
->limit()
251-
->offset()
252-
->script()
253-
->scriptParam()
254-
->scriptPresort()
255-
->scriptPresortParam()
256-
->scriptPrerequest()
257-
->scriptPrerequestParam()
258-
->layoutResponse()
259-
->portal()
250+
->limit( $value )
251+
->offset( $value )
252+
->script( $scriptName, $param)
253+
->scriptParam( $param )
254+
->scriptPresort( $scriptName, $param
255+
->scriptPresortParam( $param )
256+
->scriptPrerequest( $scriptName, $param )
257+
->scriptPrerequestParam( $param )
258+
->layoutResponse( $layoutName )
259+
->portal( $portalName )
260+
->portalLimit( $portalName, $limit )
261+
->portalOffset( $portalName, $startingRecord )
260262
->sort() // alias for the native orderBy()
261263
->omit()
262-
->fieldData()
263-
->portalData()
264+
->fieldData( $array )
265+
->portalData( $array )
264266
```
265267

266268
#### Final-chain-link methods

src/Database/Query/FMBaseBuilder.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ class FMBaseBuilder extends Builder
9696
*/
9797
public array $limitPortals = [];
9898

99+
/**
100+
* An array of portals which should have the offset set it the response.
101+
* This is actually the "starting record", and so the default value is 1.
102+
*/
103+
public array $offsetPortals = [];
104+
99105
public const ASCEND = 'ascend';
100106

101107
public const DESCEND = 'descend';
@@ -112,7 +118,7 @@ class FMBaseBuilder extends Builder
112118
*
113119
* @var array
114120
*/
115-
public $portal;
121+
public $portal = [];
116122

117123
/**
118124
* @var int
@@ -334,23 +340,34 @@ public function limit($value): FMBaseBuilder
334340
return $this;
335341
}
336342

337-
public function limitPortal($portalName, $limit): FMBaseBuilder
343+
public function limitPortal(string $portalName, int $limit): FMBaseBuilder
338344
{
339345
$this->limitPortals[] = ['portalName' => $portalName, 'limit' => $limit];
340346

341347
return $this;
342348
}
343349

350+
/**
351+
* Set an offset for a given portal.
352+
* This is actually the "starting record", and so the default value is 1.
353+
*/
354+
public function offsetPortal(string $portalName, int $startingRecord): FMBaseBuilder
355+
{
356+
$this->offsetPortals[] = ['portalName' => $portalName, 'offset' => $startingRecord];
357+
358+
return $this;
359+
}
360+
344361
public function offset($value): FMBaseBuilder
345362
{
346363
$this->offset = $value;
347364

348365
return $this;
349366
}
350367

351-
public function script($name, $param = null): FMBaseBuilder
368+
public function script($scriptName, $param = null): FMBaseBuilder
352369
{
353-
$this->script = $name;
370+
$this->script = $scriptName;
354371

355372
// set the script parameter if one was passed in
356373
if ($param) {
@@ -360,16 +377,16 @@ public function script($name, $param = null): FMBaseBuilder
360377
return $this;
361378
}
362379

363-
public function scriptParam($param): FMBaseBuilder
380+
public function scriptParam(string $param): FMBaseBuilder
364381
{
365382
$this->scriptParam = $param;
366383

367384
return $this;
368385
}
369386

370-
public function scriptPresort($name, $param = null): FMBaseBuilder
387+
public function scriptPresort(string $scriptName, $param = null): FMBaseBuilder
371388
{
372-
$this->scriptPresort = $name;
389+
$this->scriptPresort = $scriptName;
373390

374391
// set the script parameter if one was passed in
375392
if ($param) {
@@ -379,16 +396,16 @@ public function scriptPresort($name, $param = null): FMBaseBuilder
379396
return $this;
380397
}
381398

382-
public function scriptPresortParam($param): FMBaseBuilder
399+
public function scriptPresortParam(string $param): FMBaseBuilder
383400
{
384401
$this->scriptPresortParam = $param;
385402

386403
return $this;
387404
}
388405

389-
public function scriptPrerequest($name, $param = null): FMBaseBuilder
406+
public function scriptPrerequest(string $scriptName, string $param = null): FMBaseBuilder
390407
{
391-
$this->scriptPrerequest = $name;
408+
$this->scriptPrerequest = $scriptName;
392409

393410
// set the script parameter if one was passed in
394411
if ($param) {
@@ -398,16 +415,16 @@ public function scriptPrerequest($name, $param = null): FMBaseBuilder
398415
return $this;
399416
}
400417

401-
public function scriptPrerequestParam($param): FMBaseBuilder
418+
public function scriptPrerequestParam(string $param): FMBaseBuilder
402419
{
403420
$this->scriptPrerequestParam = $param;
404421

405422
return $this;
406423
}
407424

408-
public function layoutResponse($name): FMBaseBuilder
425+
public function layoutResponse(string $layoutName): FMBaseBuilder
409426
{
410-
$this->layoutResponse = $name;
427+
$this->layoutResponse = $layoutName;
411428

412429
return $this;
413430
}
@@ -640,7 +657,7 @@ public function createRecord()
640657
* @param $array array
641658
* @return $this
642659
*/
643-
public function fieldData($array)
660+
public function fieldData(array $array)
644661
{
645662
$this->fieldData = $this->mapFieldNamesForArray($array);
646663

@@ -653,7 +670,7 @@ public function fieldData($array)
653670
* @param $array array
654671
* @return $this
655672
*/
656-
public function portalData($array)
673+
public function portalData(array $array)
657674
{
658675
$this->portalData = $array;
659676

@@ -797,7 +814,6 @@ public function portal($portalName)
797814
// It's a single value, so append it on the array
798815
array_push($this->portal, $portalName);
799816
}
800-
$this->portal = $portalName;
801817

802818
return $this;
803819
}

src/Services/FileMakerConnection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,20 @@ protected function buildPostDataFromQuery(FMBaseBuilder $query)
490490
}
491491
}
492492

493-
// Special handling for _limit.portal
493+
// Special handling for _limit.{portal}
494494
if (isset($query->limitPortals) && count($query->limitPortals) > 0) {
495495
foreach ($query->limitPortals as $portalArray) {
496496
$postData['limit.' . urlencode($portalArray['portalName'])] = $portalArray['limit'];
497497
}
498498
}
499499

500+
// handle _offset.{portal}
501+
if (isset($query->offsetPortals) && count($query->offsetPortals) > 0) {
502+
foreach ($query->offsetPortals as $portalArray) {
503+
$postData['offset.' . urlencode($portalArray['portalName'])] = $portalArray['offset'];
504+
}
505+
}
506+
500507
// Special handling for offset
501508
if (isset($postData['offset'])) {
502509
if ($postData['offset'] > 0) {

0 commit comments

Comments
 (0)