Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
JsonRequestFormatter.php
Go to the documentation of this file.
1<?php
2
4
7
17
18 public function getDatas(?string $model = null): array {
19 $datas = URequest::getRealInput ();
20 if (\count ( $datas ) > 0) {
21 $datas = \current ( \array_keys ( $datas ) );
22 return $this->updateDatasForRelationships ( \json_decode ( $datas, true ), $model );
23 }
24 return [ ];
25 }
26
27 protected function updateDatasForRelationships($datas, $model) {
28 $metas = OrmUtils::getModelMetadata ( $model );
29 $joinColumns = $metas ['#joinColumn'] ?? [ ];
30 $manyToManys = $metas ['#manyToMany'] ?? [ ];
31 foreach ( $joinColumns as $column => $infos ) {
32 if(isset($datas [$column])) {
33 $datas [$infos ['name']] = $datas [$column];
34 unset ($datas [$column]);
35 }
36 }
37 foreach ( $manyToManys as $manyColumn => $manyColumnInfos ) {
38 $targetEntity = $manyColumnInfos ['targetEntity'];
39 $idField = OrmUtils::getFirstKey ( $targetEntity );
40 $v = $datas [$manyColumn] ?? [];
41 $ids = [ ];
42 foreach ( $v as $values ) {
43 if (isset ( $values [$idField] )) {
44 $ids [] = $values [$idField];
45 }
46 }
47 $datas [$manyColumn . 'Ids'] = \implode ( ',', $ids );
48 unset ( $datas [$manyColumn] );
49 }
50 return $datas;
51 }
52}
Ubiquity\controllers\rest\formatters$JsonRequestFormatter This class is part of Ubiquity.
Ubiquity\controllers\rest\formatters$RequestFormatter This class is part of Ubiquity.
Object/relational mapping utilities.
Definition OrmUtils.php:17
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.
Definition URequest.php:18