-
Notifications
You must be signed in to change notification settings - Fork 0
/
fab3-bailiffs-endpoint.php
97 lines (80 loc) · 3.11 KB
/
fab3-bailiffs-endpoint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Drupal\api\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
/**
* Provides a Get All Resource
*
* @RestResource(
* id = "getall_resource",
* label = @Translation("Get All Resource"),
* uri_paths = {
* "canonical" = "/api/getall",
* "https://www.drupal.org/link-relations/create" = "/api/search"
* }
* )
*/
class GetAllResource extends ResourceBase {
/**
* Responds to entity GET requests.
* @return \Drupal\rest\ResourceResponse
*/
public function get() {
$nids = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'bailiff')
->condition('nid','9','!=')
->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
$competentBodies=array();
if($nodes) {
foreach ($nodes as $node) {
$details=array();
array_push($details, array('name'=>$node->field_name_latin->value.' '.$node->field_surname_latin->value,'lang'=>'el', 'address'=>transliterator_transliterate('Any-Latin;Latin-ASCII;', $node->field_streetname->value.' '.$node->field_number->value), 'postalCode'=>$node->field_postalCode->value, 'municipality'=>transliterator_transliterate('Any-Latin;Latin-ASCII;', $node->field_city->value), 'tel'=>$node->field_telephone->value));
array_push($competentBodies, array('id'=>$node->getOwnerId(),'country'=>'GR','details'=>$details));
}
$response = ['state' => 'answered', 'competentBodies'=>$competentBodies];
}
else {
$response = ['state' => 'answered'];
}
return new ResourceResponse($response);
}
/**
* Responds to POST requests.
* @return \Drupal\rest\ResourceResponse
* Returns a list of bundles for specified entity.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* Throws exception expected.
*/
public function post(array $data) {
$nids = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type','bailiff')
->condition('nid','9','!=')
->condition('field_postalCode',$data['postalCode'])
->execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);
$competentBodies=array();
if($nodes) {
foreach ($nodes as $node) {
$details=array();
array_push($details, array('name'=>$node->field_name_latin->value.' '.$node->field_surname_latin->value,'lang'=>'el', 'address'=>transliterator_transliterate('Any-Latin;Latin-ASCII;', $node->field_street ->value.' '.$node->field_number->value), 'postalCode'=>$node->field_postalCode->value, 'municipality'=>transliterator_transliterate('Any-Latin;Latin-ASCII;', $node->field_city->value), 'tel'=>$node->field_telephone->value));
array_push($competentBodies, array('id'=>$node->getOwnerId(),'country'=>'GR','details'=>$details));
}
$response = ['state' => 'answered', 'competentBodies'=>$competentBodies];
}
else {
$response = ['state' => 'answered'];
}
return new ResourceResponse($response);
/* $build = array(
'#cache' => array(
'max-age' => 0,
),
);
return (new ResourceResponse($response))->addCacheableDependency($build);*/
}
}
?>