|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* The Imaging Source Download System PHP Wrapper |
|
6
|
|
|
* |
|
7
|
|
|
* PHP wrapper for The Imaging Source Download System Web API. Authored and supported by The Imaging Source Europe GmbH. |
|
8
|
|
|
* |
|
9
|
|
|
* @link http://dl-gui.theimagingsource.com to learn more about The Imaging Source Download System |
|
10
|
|
|
* @link https://github.com/jonathanmaron/theimagingsource-tisd-sdk for the canonical source repository |
|
11
|
|
|
* @license https://github.com/jonathanmaron/theimagingsource-tisd-sdk/blob/master/LICENSE.md |
|
12
|
|
|
* @copyright © 2022 The Imaging Source Europe GmbH |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Tisd\Sdk; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Trait PackagesTrait |
|
19
|
|
|
* |
|
20
|
|
|
* @package Tisd\Sdk |
|
21
|
|
|
*/ |
|
22
|
|
|
trait PackagesTrait |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Filter the packages by key |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $packages |
|
28
|
|
|
* @param string $key |
|
29
|
|
|
* @param array|string $value |
|
30
|
|
|
* @param bool $fuzzy |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
abstract protected function filter(array $packages, string $key, array|string $value, bool $fuzzy = false): array; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get the array of consolidated data |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
abstract protected function getConsolidated(): array; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get the array of packages data |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $categoryId |
|
47
|
|
|
* @param string $sectionId |
|
48
|
|
|
* @param string $packageId |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
24 |
|
public function getPackages(string $categoryId = '', string $sectionId = '', string $packageId = ''): array |
|
53
|
|
|
{ |
|
54
|
24 |
|
$consolidated = $this->getConsolidated(); |
|
55
|
|
|
|
|
56
|
24 |
|
$packages = $consolidated['packages']; |
|
57
|
|
|
|
|
58
|
24 |
|
if ('' !== $categoryId && '' !== $sectionId && '' !== $packageId) { |
|
59
|
|
|
|
|
60
|
1 |
|
$packages = $this->filter($packages, 'category_id', $categoryId); |
|
61
|
1 |
|
$packages = $this->filter($packages, 'section_id', $sectionId); |
|
62
|
1 |
|
$packages = $this->filter($packages, 'package_id', $packageId); |
|
63
|
|
|
|
|
64
|
1 |
|
if (isset($packages['children'][$categoryId]['children'][$sectionId]['children'][$packageId])) { |
|
65
|
1 |
|
return $packages['children'][$categoryId]['children'][$sectionId]['children'][$packageId]; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return []; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
23 |
|
if ('' !== $categoryId && '' !== $sectionId) { |
|
72
|
|
|
|
|
73
|
1 |
|
$packages = $this->filter($packages, 'category_id', $categoryId); |
|
74
|
1 |
|
$packages = $this->filter($packages, 'section_id', $sectionId); |
|
75
|
|
|
|
|
76
|
1 |
|
if (isset($packages['children'][$categoryId]['children'][$sectionId])) { |
|
77
|
1 |
|
return $packages['children'][$categoryId]['children'][$sectionId]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return []; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
22 |
|
if ('' !== $categoryId) { |
|
84
|
|
|
|
|
85
|
1 |
|
$packages = $this->filter($packages, 'category_id', $categoryId); |
|
86
|
|
|
|
|
87
|
1 |
|
if (isset($packages['children'][$categoryId])) { |
|
88
|
1 |
|
return $packages['children'][$categoryId]; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
return []; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
21 |
|
return $packages; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get array of package data for the specified product codes |
|
99
|
|
|
* |
|
100
|
|
|
* @param array $productCodes |
|
101
|
|
|
* |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function getPackagesByProductCodes(array $productCodes): array |
|
105
|
|
|
{ |
|
106
|
1 |
|
$consolidated = $this->getConsolidated(); |
|
107
|
|
|
|
|
108
|
1 |
|
return $this->filter($consolidated['packages'], 'product_code', $productCodes); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get array of package data for the specified search term (starting with) |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $q |
|
115
|
|
|
* |
|
116
|
|
|
* @return array |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function getPackagesByProductCodeSearch(string $q): array |
|
119
|
|
|
{ |
|
120
|
1 |
|
$consolidated = $this->getConsolidated(); |
|
121
|
|
|
|
|
122
|
1 |
|
return $this->filter($consolidated['packages'], 'product_code', $q, true); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|