| ... | ... |
@@ -16,6 +16,7 @@ use Contao\System; |
| 16 | 16 |
use Symfony\Component\Serializer\SerializerInterface; |
| 17 | 17 |
use Symfony\Contracts\HttpClient\HttpClientInterface; |
| 18 | 18 |
use vossmedien\AloxBundle\Model\KatalogModel; |
| 19 |
+use vossmedien\AloxBundle\Model\StelleModel; |
|
| 19 | 20 |
use vossmedien\AloxBundle\Model\StellenModel; |
| 20 | 21 |
|
| 21 | 22 |
class Zvoove |
| ... | ... |
@@ -97,6 +98,37 @@ class Zvoove |
| 97 | 98 |
return null; |
| 98 | 99 |
} |
| 99 | 100 |
|
| 101 |
+ public function getStelleById(string $uuid, array $params=[]): ?StelleModel |
|
| 102 |
+ {
|
|
| 103 |
+ $options = [ |
|
| 104 |
+ 'headers' => $this->getAuthorizeRequestHeader(), |
|
| 105 |
+ 'query' => [ |
|
| 106 |
+ 'stelleUuid' => $uuid |
|
| 107 |
+ ] |
|
| 108 |
+ ]; |
|
| 109 |
+ |
|
| 110 |
+ if (count($params)) |
|
| 111 |
+ {
|
|
| 112 |
+ $options['query'] = array_merge($options['query'],$params); |
|
| 113 |
+ } |
|
| 114 |
+ |
|
| 115 |
+ $response = $this->sendRequest('Stelle/GetStelleById',$options);
|
|
| 116 |
+ |
|
| 117 |
+ |
|
| 118 |
+ |
|
| 119 |
+ if ($response->getStatusCode() == 200) |
|
| 120 |
+ {
|
|
| 121 |
+ $content = $response->getContent(); |
|
| 122 |
+ |
|
| 123 |
+ /** @var StelleModel $model */ |
|
| 124 |
+ $model = $this->serializer->deserialize($content,StelleModel::class,'json'); |
|
| 125 |
+ |
|
| 126 |
+ return $model; |
|
| 127 |
+ } |
|
| 128 |
+ |
|
| 129 |
+ return null; |
|
| 130 |
+ } |
|
| 131 |
+ |
|
| 100 | 132 |
public function getKatalogByRelationName(string $entityName, string $relationName): ?KatalogModel |
| 101 | 133 |
{
|
| 102 | 134 |
$options = [ |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,127 @@ |
| 1 |
+<?php |
|
| 2 |
+ |
|
| 3 |
+declare(strict_types=1); |
|
| 4 |
+ |
|
| 5 |
+/* |
|
| 6 |
+ * This file is part of alox bundle for Contao. |
|
| 7 |
+ * |
|
| 8 |
+ * (c) Benjamin Roth |
|
| 9 |
+ * |
|
| 10 |
+ * @license commercial |
|
| 11 |
+ */ |
|
| 12 |
+ |
|
| 13 |
+namespace vossmedien\AloxBundle\API; |
|
| 14 |
+ |
|
| 15 |
+use Contao\System; |
|
| 16 |
+use Symfony\Component\Serializer\SerializerInterface; |
|
| 17 |
+use Symfony\Contracts\HttpClient\HttpClientInterface; |
|
| 18 |
+use vossmedien\AloxBundle\Model\KatalogModel; |
|
| 19 |
+use vossmedien\AloxBundle\Model\StellenModel; |
|
| 20 |
+ |
|
| 21 |
+class Zvoove |
|
| 22 |
+{
|
|
| 23 |
+ /** |
|
| 24 |
+ * @var SerializerInterface |
|
| 25 |
+ */ |
|
| 26 |
+ protected $serializer; |
|
| 27 |
+ |
|
| 28 |
+ /** |
|
| 29 |
+ * @var HttpClientInterface |
|
| 30 |
+ */ |
|
| 31 |
+ protected $httpClient; |
|
| 32 |
+ |
|
| 33 |
+ protected $apiKey; |
|
| 34 |
+ |
|
| 35 |
+ protected $apiDomain; |
|
| 36 |
+ |
|
| 37 |
+ public function __construct(SerializerInterface $serializer, HttpClientInterface $httpClient) |
|
| 38 |
+ {
|
|
| 39 |
+ $this->serializer = $serializer; |
|
| 40 |
+ $this->httpClient = $httpClient; |
|
| 41 |
+ |
|
| 42 |
+ $this->apiKey = System::getContainer()->getParameter('vossmedien_alox.zvoove.api_key');
|
|
| 43 |
+ $this->apiDomain = System::getContainer()->getParameter('vossmedien_alox.zvoove.api_domain');
|
|
| 44 |
+ } |
|
| 45 |
+ |
|
| 46 |
+ protected function getApiKey() |
|
| 47 |
+ {
|
|
| 48 |
+ return $this->apiKey; |
|
| 49 |
+ } |
|
| 50 |
+ |
|
| 51 |
+ protected function getApiDomain() |
|
| 52 |
+ {
|
|
| 53 |
+ return rtrim($this->apiDomain,'/'); |
|
| 54 |
+ } |
|
| 55 |
+ |
|
| 56 |
+ protected function getAuthorizeRequestHeader() |
|
| 57 |
+ {
|
|
| 58 |
+ $header = [ |
|
| 59 |
+ 'X-ApiKey' => $this->getApiKey() |
|
| 60 |
+ ]; |
|
| 61 |
+ |
|
| 62 |
+ return $header; |
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ protected function sendRequest(string $relEndpoint, array $options, string $method = 'GET') |
|
| 66 |
+ {
|
|
| 67 |
+ $relEndpoint = '/' . ltrim($relEndpoint,'/'); |
|
| 68 |
+ |
|
| 69 |
+ return $this->httpClient->request($method,$this->getApiDomain().$relEndpoint,$options); |
|
| 70 |
+ } |
|
| 71 |
+ |
|
| 72 |
+ public function getStellenFiltered(array $params=[]): ?StellenModel |
|
| 73 |
+ {
|
|
| 74 |
+ $options = [ |
|
| 75 |
+ 'headers' => $this->getAuthorizeRequestHeader() |
|
| 76 |
+ ]; |
|
| 77 |
+ |
|
| 78 |
+ if (count($params)) |
|
| 79 |
+ {
|
|
| 80 |
+ $options['query'] = $params; |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ $response = $this->sendRequest('Stelle/GetStellenFiltered',$options);
|
|
| 84 |
+ |
|
| 85 |
+ |
|
| 86 |
+ |
|
| 87 |
+ if ($response->getStatusCode() == 200) |
|
| 88 |
+ {
|
|
| 89 |
+ $content = $response->getContent(); |
|
| 90 |
+ |
|
| 91 |
+ /** @var StellenModel $collection */ |
|
| 92 |
+ $collection = $this->serializer->deserialize($content,StellenModel::class,'json'); |
|
| 93 |
+ |
|
| 94 |
+ return $collection; |
|
| 95 |
+ } |
|
| 96 |
+ |
|
| 97 |
+ return null; |
|
| 98 |
+ } |
|
| 99 |
+ |
|
| 100 |
+ public function getKatalogByRelationName(string $entityName, string $relationName): ?KatalogModel |
|
| 101 |
+ {
|
|
| 102 |
+ $options = [ |
|
| 103 |
+ 'headers' => $this->getAuthorizeRequestHeader(), |
|
| 104 |
+ 'query' => [ |
|
| 105 |
+ 'entityName' => $entityName, |
|
| 106 |
+ 'relationName' => $relationName |
|
| 107 |
+ ] |
|
| 108 |
+ ]; |
|
| 109 |
+ |
|
| 110 |
+ $response = $this->sendRequest('Katalog/GetByRelationName',$options);
|
|
| 111 |
+ |
|
| 112 |
+ |
|
| 113 |
+ |
|
| 114 |
+ if ($response->getStatusCode() == 200) |
|
| 115 |
+ {
|
|
| 116 |
+ $content = $response->getContent(); |
|
| 117 |
+ |
|
| 118 |
+ /** @var KatalogModel $collection */ |
|
| 119 |
+ $collection = $this->serializer->deserialize($content,KatalogModel::class,'json'); |
|
| 120 |
+ |
|
| 121 |
+ return $collection; |
|
| 122 |
+ } |
|
| 123 |
+ |
|
| 124 |
+ return null; |
|
| 125 |
+ } |
|
| 126 |
+ |
|
| 127 |
+} |