1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Services; |
4
|
|
|
|
5
|
|
|
use Lifeboat\Exceptions\ApiException; |
6
|
|
|
use Lifeboat\Exceptions\InvalidArgumentException; |
7
|
|
|
use Lifeboat\Exceptions\OAuthException; |
8
|
|
|
use Lifeboat\Models\CustomPage; |
9
|
|
|
use Lifeboat\Resource\ListResource; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class CustomPages |
13
|
|
|
* @package Lifeboat\Services |
14
|
|
|
*/ |
15
|
|
|
class CustomPages extends Pages { |
16
|
|
|
|
17
|
|
|
const SORT_TITLE_ASC = 'title_az'; |
18
|
|
|
const SORT_TITLE_DESC = 'title_za'; |
19
|
|
|
const SORT_CREATED_ASC = 'created_az'; |
20
|
|
|
const SORT_CREATED_DESC = 'created_za'; |
21
|
|
|
const SORT_EDITED_ASC = 'edited_az'; |
22
|
|
|
const SORT_EDITED_DESC = 'edited_za'; |
23
|
|
|
const SORT_DEFAULT = ''; |
24
|
|
|
|
25
|
|
|
const SORT_OPTIONS = [ |
26
|
|
|
self::SORT_TITLE_ASC, self::SORT_TITLE_DESC, self::SORT_CREATED_ASC, |
27
|
|
|
self::SORT_CREATED_DESC, self::SORT_EDITED_ASC, self::SORT_EDITED_DESC, |
28
|
|
|
self::SORT_DEFAULT |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param int $id |
33
|
|
|
* @return CustomPage|null |
34
|
|
|
* @throws ApiException |
35
|
|
|
* @throws OAuthException |
36
|
|
|
*/ |
37
|
|
|
public function fetch(int $id): ?CustomPage |
38
|
|
|
{ |
39
|
|
|
/** @var CustomPage|null $fetch */ |
40
|
|
|
$fetch = $this->_get('api/pages/page' . $id); |
41
|
|
|
return $fetch; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param array $data |
46
|
|
|
* @return CustomPage|null |
47
|
|
|
* @throws ApiException |
48
|
|
|
* @throws OAuthException |
49
|
|
|
*/ |
50
|
|
|
public function create(array $data): ?CustomPage |
51
|
|
|
{ |
52
|
|
|
/** @var CustomPage|null $create */ |
53
|
|
|
$create = $this->_post('api/pages/page/', $data); |
54
|
|
|
return $create; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param int $id |
59
|
|
|
* @param array $data |
60
|
|
|
* @return CustomPage|null |
61
|
|
|
* @throws ApiException |
62
|
|
|
* @throws OAuthException |
63
|
|
|
*/ |
64
|
|
|
public function update(int $id, array $data): ?CustomPage |
65
|
|
|
{ |
66
|
|
|
/** @var CustomPage|null $post */ |
67
|
|
|
$post = $this->_post('api/pages/page/' . $id, $data); |
68
|
|
|
return $post; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $search |
73
|
|
|
* @param string $sort |
74
|
|
|
* @return ListResource |
75
|
|
|
*/ |
76
|
|
|
public function all(string $search = '', string $sort = self::SORT_DEFAULT): ListResource |
77
|
|
|
{ |
78
|
|
|
if (!in_array($sort, self::SORT_OPTIONS)) { |
79
|
|
|
throw new InvalidArgumentException("Customers::all() expects parameter 2 to be a valid sort option"); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return new ListResource($this->getClient(), 'api/pages/page/all', ['search' => $search, 'sort' => $sort], 20); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|