Commit 93b1de0f authored by François Agneray's avatar François Agneray
Browse files

#66 => done

parent fc0aa9c5
Pipeline #5154 passed with stages
in 2 minutes and 32 seconds
......@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [3.6.0]
- In progress...
### Added
- #66: Export all attributes (a=all)
- #48: Export to votable format
- #64: Data management system
### Changed
- #61: Docker images are stored on the gitlab internal registry
- #63: Update composer.json dependencies and using php version 8
......
......@@ -176,6 +176,7 @@ $container->set('App\Action\SearchAction', function (ContainerInterface $c) {
$anisQueryBuilder = (new App\Search\Query\AnisQueryBuilder())
->addQueryPart(new App\Search\Query\From())
->addQueryPart(new App\Search\Query\Count())
->addQueryPart(new App\Search\Query\SelectAll())
->addQueryPart(new App\Search\Query\Select())
->addQueryPart(new App\Search\Query\ConeSearch())
->addQueryPart(new App\Search\Query\Where(new App\Search\Query\Operator\OperatorFactory()))
......
......@@ -33,6 +33,7 @@ class Count extends AbstractQueryPart
{
if ($queryParams['a'] === 'count') {
$anisQueryBuilder->getDoctrineQueryBuilder()->select('COUNT(*) as nb');
$anisQueryBuilder->setAttributesSelected(array());
}
}
}
......@@ -31,7 +31,7 @@ class Select extends AbstractQueryPart
*/
public function __invoke(AnisQueryBuilder $anisQueryBuilder, Dataset $dataset, array $queryParams): void
{
if ($queryParams['a'] !== 'count') {
if ($queryParams['a'] !== 'count' && $queryParams['a'] !== 'all') {
$listOfIds = explode(';', $queryParams['a']);
$columns = array();
$attributes = array();
......
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Search\Query;
use App\Entity\Dataset;
/**
* Represents the Anis Select All attributes Query Part
*
* @author François Agneray <francois.agneray@lam.fr>
* @package App\Search\Query
*/
class SelectAll extends AbstractQueryPart
{
/**
* Adds the select clause to the request and set all attributes
*
* @param AnisQueryBuilder $anisQueryBuilder Represents the query being built
* @param Dataset $dataset Represents the requested dataset
* @param string[] $queryParams The query params of the url (after ?)
*/
public function __invoke(AnisQueryBuilder $anisQueryBuilder, Dataset $dataset, array $queryParams): void
{
if ($queryParams['a'] === 'all') {
$columns = array();
$attributes = array();
foreach ($dataset->getAttributes() as $attribute) {
$columns[] = $attribute->getTableName() . '.' . $attribute->getName() . ' as ' . $attribute->getLabel();
$attributes[] = $attribute;
}
$anisQueryBuilder->getDoctrineQueryBuilder()->select($columns);
$anisQueryBuilder->setAttributesSelected($attributes);
}
}
}
<?php
/*
* This file is part of Anis Server.
*
* (c) Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\Tests\Search\Query;
use PHPUnit\Framework\TestCase;
use App\Search\Query\SelectAll;
use App\Search\Query\AnisQueryBuilder;
use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
use App\Entity\Dataset;
use App\Entity\Attribute;
final class SelectAllTest extends TestCase
{
public function testCount(): void
{
$id = $this->createMock(Attribute::class);
$id->method('getId')->willReturn(1);
$ra = $this->createMock(Attribute::class);
$ra->method('getId')->willReturn(2);
$dec = $this->createMock(Attribute::class);
$dec->method('getId')->willReturn(3);
$datasetSelected = $this->createMock(Dataset::class);
$datasetSelected->method('getAttributes')->willReturn(array($id, $ra, $dec));
$doctrineQueryBuilder = $this->createMock(DoctrineQueryBuilder::class);
$doctrineQueryBuilder->expects($this->once())->method('select');
$anisQueryBuilder = $this->createMock(AnisQueryBuilder::class);
$anisQueryBuilder->method('getDoctrineQueryBuilder')->willReturn($doctrineQueryBuilder);
$queryParams = array('a' => 'all');
(new SelectAll())($anisQueryBuilder, $datasetSelected, $queryParams);
}
}
Markdown is supported
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