Skip to content

Commit 155170d

Browse files
committed
improved getLayoutMetadata and documentation improvements
1 parent 0310942 commit 155170d

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ performScript
265265
setContainer
266266
duplicate
267267
createRecord
268+
getLayoutMetadata
268269
```
269270

270271
#### Examples:
@@ -278,6 +279,16 @@ Find the 10 most recent invoices for a customer
278279
$invoices = FM::layout('invoice')->where('customer_id', $customer->id)->orderByDesc('date')->limit(10)->get();
279280
```
280281

282+
Get layout metadata, which includes field, portal, and value list information
283+
```
284+
$layoutMetadata = FM::layout('MyLayoutName')->getLayoutMetadata('MyLayoutName');
285+
```
286+
287+
Get layout metadata for a specific record
288+
```
289+
$layoutMetadata = FM::layout('MyLayoutName')->recordId(879)->getLayoutMetadata();
290+
```
291+
281292
Run a script
282293
```
283294
$result = FM::layout('MyLayoutName')->performScript('MyScriptName');

src/Database/Query/FMBaseBuilder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ protected function bulkDeleteFromQuery(): int
248248
/**
249249
* Delete a record using the internal FileMaker record ID
250250
*
251-
* @param $recordId
251+
* @param Int $recordId
252252
* @return int
253253
* @throws FileMakerDataApiException
254254
*/
255-
public function deleteByRecordId($recordId): int
255+
public function deleteByRecordId(Int $recordId): int
256256
{
257257

258258
$this->recordId = $recordId;
@@ -821,6 +821,14 @@ public function executeScript($script = null, $param = null)
821821
return $result;
822822
}
823823

824+
public function getLayoutMetadata($layoutName = null)
825+
{
826+
if ($layoutName) {
827+
$this->layout($layoutName);
828+
}
829+
return $this->connection->getLayoutMetadata($this);
830+
}
831+
824832
/**
825833
* Prepare the value and operator for a where clause.
826834
*

src/Services/FileMakerConnection.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GearboxSolutions\EloquentFileMaker\Database\Query\Grammars\FMGrammar;
1010
use GearboxSolutions\EloquentFileMaker\Database\Schema\FMBuilder;
1111
use GearboxSolutions\EloquentFileMaker\Exceptions\FileMakerDataApiException;
12-
use GuzzleHttp\Exception\ConnectException;
1312
use GuzzleHttp\Exception\TransferException;
1413
use GuzzleHttp\Middleware;
1514
use Illuminate\Database\Connection;
@@ -576,6 +575,7 @@ public function performScript(FMBaseBuilder $query)
576575
return $this->executeScript($query);
577576
}
578577

578+
579579
protected function getSessionTokenCacheKey()
580580
{
581581
return 'filemaker-session-' . $this->getName();
@@ -717,10 +717,36 @@ protected function getDefaultQueryGrammar()
717717
return new FMGrammar();
718718
}
719719

720-
public function getLayoutMetadata($layout = null)
720+
// public function getLayoutMetadata($layout = null)
721+
// {
722+
// $response = $this->makeRequest('get', $this->getLayoutUrl($layout));
723+
// return $response['response'];
724+
// }
725+
726+
/**
727+
* @param String | FMBaseBuilder $query
728+
* @return mixed
729+
* @throws FileMakerDataApiException
730+
*/
731+
public function getLayoutMetadata(FMBaseBuilder|string $query = null)
721732
{
722-
$response = $this->makeRequest('get', $this->getLayoutUrl($layout));
723-
return $response['response'];
733+
// if the query is just a string, it means that it's a layout name
734+
if (is_string($query)) {
735+
$query = $this->table($query);
736+
}
737+
738+
$this->setLayout($query->from);
739+
$url = $this->getLayoutUrl();
740+
741+
$queryParams = [];
742+
$param = $query->getRecordId();
743+
if ($param !== null) {
744+
$queryParams['recordId'] = $param;
745+
}
746+
747+
$response = $this->makeRequest('get', $url, $queryParams);
748+
749+
return $response;
724750
}
725751

726752
public function getSchemaBuilder()

src/Support/Facades/FM.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
* Executes against DatabaseManager. If DatabaseManager doesn't have the functionality, it uses __call to call against
1515
* the connection, which would be a FileMakerConnection.
1616
*
17-
* @method static FileMakerConnection connection(string $name = null)
1817
* @method static FMBaseBuilder layout($layoutName)
1918
* @method static FMBaseBuilder table($layoutName)
19+
* @method static FMBaseBuilder delete($recordId)
20+
* @method static FMBaseBuilder deleteByRecordId($recordId)
21+
22+
2023
* @method static array setGlobalFields(array $globalFields)
24+
* @method static FileMakerConnection connection(string $name = null)
2125
* @method static FileMakerConnection setRetries(int $retries)
26+
* @method static FileMakerConnection getLayoutMetadata($layoutName = null)
27+
2228
*
2329
*
2430
* @see \Illuminate\Database\DatabaseManager

0 commit comments

Comments
 (0)