Skip to content
85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Install via [Composer](http://getcomposer.org/):
$ composer require robgridley/pace-api
```

PHP 8.1+ with the SOAP, SimpleXML and Fileinfo extensions required.

## Testing

PHPUnit tests with 100% code coverage for `Model`, `KeyCollection` and `XPath\Builder` classes.
Expand Down Expand Up @@ -168,6 +170,40 @@ $jobs = $pace->job
->find();
```

### Limiting

Use the `offset()` and `limit()` methods to limit your results. The default offset is 0 if it is not specified.

```php
$jobs = $pace->job
->filter('adminStatus/@openJob', true)
->sort('@dateSetup', true)
->limit(50)
->find();
```

You can also use the `paginate()` method to set the offset and limit for a page.

```php
$jobs = $pace->job
->filter('adminStatus/@openJob', true)
->sort('@dateSetup', true)
->paginate(1, 50)
->find();
```

### Eager loading

The `load()` method preloads the models as part of the find request, using the find object aggregate service. It does not read the entire object; you must specify a list of fields in XPath. If the offset and limit are not specified, then 0 and 1,000 will be used by default.

```php
$employees = $pace->model('Employee')->filter('@status', 'A')->load([
'@firstName',
'@lastName',
'department' => 'department/@description',
])->find();
```

## Dates

Dates are automatically converted to and from [Carbon](http://carbon.nesbot.com/) instances. Check out the `Soap\DateTimeMapper` and `Soap\Factory` classes if you want to see how this happens.
Expand All @@ -189,7 +225,7 @@ foreach ($estimates as $estimate) {
}
```

KeyCollection also has a number of useful methods such as `all()`, `paginate()` and `first()`. In fact, the single object find example from earlier is just a shortcut to the `KeyCollection::first()` method.
KeyCollection also has a number of useful methods such as `all()`, `paginate()` and `first()`.

## Relationships

Expand Down Expand Up @@ -409,6 +445,53 @@ $pace->report(100)
->print();
```

## Invoke Action

The invoke action service methods are exposed as PHP methods. You can find a list of methods and their arguments in the InvokeAction.wsdl file provided with the Pace SDK. Arguments must be passed in the order specified in the WSDL.

```php
$estimate = $pace->model('Estimate')->read(100000);
$pace->invokeAction()->calculateEstimate($estimate);
```

You can also use named arguments to pass the arguments out of order, or you can mix ordered and named arguments.

```php
$poLine = $pace->model('PurchaseOrder')->read(50000)->purchaseOrderLines()->first();
$pace->invokeAction()->receivePurchaseOrderLine($poLine, Carbon::now(), in3: 'Receiving note.', in5: 1);
```

If the method requires a complex type, you will need to pass an array.

If one of the arguments is an instance of a model, it will automatically be converted to a complex type containing the model's primary key. The two examples above make use of this feature. Additionally, if your complex type array contains a model, it will automatically be converted to the model's primary key.

```php
$productType = $pace->model('JobProductType')->read('FL');
$result = $pace->invokeAction()->createEstimate([
'customer' => 'HOUSE',
'estimateDescription' => 'Testing',
'estimatePartInfo' => [
'product' => $productType,
'quantity1' => 100,
'finalSizeW' => 8.5,
'finalSizeH' => 11,
'colorsSide1' => 4,
'colorsSide2' => 0,
'totalColors' => 4,
'eachOf' => 1,
'grainSpecifications' => 1,
],
]);
```

Finally, the result of the invoke action call can be accessed like an array, converted to an array, or converted to a model (if the method returns the matching complex type).

```php
$result['estimateNumber']; // returns the estimate number
$result->toArray(); // returns an array
$result->toModel('Estimate'); // returns an estimate model
```

## Version

Identify the version of Pace running on the server.
Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
],
"license": "MIT",
"require": {
"php": ">=7.1.0",
"php": "^8.1",
"ext-fileinfo": "*",
"ext-simplexml": "*",
"ext-soap": "*",
"nesbot/carbon": "^1.20 || ^2.0",
"doctrine/inflector": "~1.0"
"nesbot/carbon": "^2.0|^3.0",
"doctrine/inflector": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"mockery/mockery": "^1.3",
"symfony/var-dumper": "^5.0"
"phpunit/phpunit": "^10.5|11.5|12.5|^13.0",
"mockery/mockery": "^1.6",
"symfony/var-dumper": "^6.4|^7.4|^8.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading