Commit 789deb24 authored by François Agneray's avatar François Agneray
Browse files

Modification search meta (attributes selected)

parent d9b752f7
......@@ -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());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment