1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Models; |
4
|
|
|
|
5
|
|
|
use Lifeboat\Exceptions\ApiException; |
6
|
|
|
use Lifeboat\Exceptions\InvalidArgumentException; |
7
|
|
|
use Lifeboat\Exceptions\OAuthException; |
8
|
|
|
use Lifeboat\Resource\ListResource; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Address |
12
|
|
|
* @package Lifeboat\Models |
13
|
|
|
* |
14
|
|
|
* @property string $Name |
15
|
|
|
* @property string $Address |
16
|
|
|
* @property string $AddressL2 |
17
|
|
|
* @property string $City |
18
|
|
|
* @property string $SubdivisionCode |
19
|
|
|
* @property string $CountryCode |
20
|
|
|
* @property string $PostCode |
21
|
|
|
* @property string $Notes |
22
|
|
|
* @property string $Latitude |
23
|
|
|
* @property string $Longitude |
24
|
|
|
* @property string $Email |
25
|
|
|
* @property string $Tel |
26
|
|
|
* @property string $VATNo |
27
|
|
|
* @property int $isDefault |
28
|
|
|
* @property string $Country |
29
|
|
|
* @property string $Subdivision |
30
|
|
|
* @property int $CustomerID |
31
|
|
|
*/ |
32
|
|
|
class Address extends Model { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $id |
36
|
|
|
* @return Model|null |
37
|
|
|
* @throws ApiException |
38
|
|
|
* @throws OAuthException |
39
|
|
|
* @throws InvalidArgumentException If param $id is less than 1 |
40
|
|
|
*/ |
41
|
|
|
public function retrieve(int $id = -1): ?Model |
42
|
|
|
{ |
43
|
|
|
if ($id <= 0) { |
44
|
|
|
throw new InvalidArgumentException("Address::fetch() expects parameter 1 to be a positive integer"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->curl_for_model('api/addresses/address/' . $id); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return ListResource |
52
|
|
|
*/ |
53
|
|
|
public function all(): ListResource |
54
|
|
|
{ |
55
|
|
|
return new ListResource($this->getClient(), 'api/addresses/all', [], 20); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $search |
60
|
|
|
* @return ListResource |
61
|
|
|
*/ |
62
|
|
|
public function search(string $search): ListResource |
63
|
|
|
{ |
64
|
|
|
$all = $this->all(); |
65
|
|
|
return $all->setParams(['search' => $search]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
protected function getSaveURL(): string |
72
|
|
|
{ |
73
|
|
|
return 'api/addresses/address/' . $this->ID; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|