Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
anis
anis-server
Commits
789deb24
Commit
789deb24
authored
Apr 24, 2019
by
François Agneray
Browse files
Modification search meta (attributes selected)
parent
d9b752f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/Action/Search/SearchMetaAction.php
View file @
789deb24
...
...
@@ -15,6 +15,8 @@ use Doctrine\ORM\EntityManagerInterface;
use
Psr\Http\Message\ServerRequestInterface
as
Request
;
use
Psr\Http\Message\ResponseInterface
as
Response
;
use
App\Entity\Dataset
;
use
App\Entity\Attribute
;
use
App\Utils\ActionTrait
;
use
App\Utils\DBALConnectionFactory
;
use
App\utils\AnisQueryBuilderFactory
;
...
...
@@ -122,6 +124,25 @@ final class SearchMetaAction
)
->
withStatus
(
400
);
}
$queryParams
=
$request
->
getQueryParams
();
if
(
!
array_key_exists
(
'a'
,
$queryParams
))
{
return
$this
->
dispatchHttpError
(
$response
,
'Invalid request'
,
'Param a is required for this request'
)
->
withStatus
(
400
);
}
$listOfIds
=
explode
(
';'
,
$queryParams
[
'a'
]);
$attributesSelected
=
array
();
foreach
(
$listOfIds
as
$id
)
{
$attribute
=
$this
->
getAttribute
(
$dataset
,
(
int
)
$id
);
$attributesSelected
[]
=
array
(
'name'
=>
$attribute
->
getName
(),
'label'
=>
$attribute
->
getLabel
()
);
}
$database
=
$dataset
->
getProject
()
->
getDatabase
();
$decryptedPassword
=
$this
->
decryptData
(
$database
->
getPassword
());
$connection
=
$this
->
dcf
->
create
(
$database
,
$decryptedPassword
);
...
...
@@ -137,10 +158,22 @@ final class SearchMetaAction
$result
=
$anisQueryBuilder
->
fetchAll
();
$meta
=
array
();
$meta
[
'dataset-selected'
]
=
$dataset
->
getLabel
();
$meta
[
'total-items'
]
=
$result
[
0
][
'nb'
];
$meta
[
'url'
]
=
$dataset
->
getName
()
.
'?'
.
$request
->
getUri
()
->
getQuery
();
$meta
[
'dataset_selected'
]
=
$dataset
->
getLabel
();
$meta
[
'attributes_selected'
]
=
$attributesSelected
;
$meta
[
'total_items'
]
=
$result
[
0
][
'nb'
];
// $meta['url'] = $dataset->getName() . '?' . $request->getUri()->getQuery();
return
$response
->
withJson
(
$meta
);
}
private
function
getAttribute
(
Dataset
$dataset
,
int
$id
):
Attribute
{
$attributes
=
$dataset
->
getAttributes
();
foreach
(
$attributes
as
$attribute
)
{
if
(
$attribute
->
getId
()
===
$id
)
{
return
$attribute
;
}
}
throw
SearchException
::
attributeNotFound
(
$id
,
$dataset
->
getLabel
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment