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

#42 => done

parent 5be0dc78
Pipeline #2157 passed with stages
in 3 minutes and 31 seconds
......@@ -93,9 +93,9 @@ class Dataset implements \JsonSerializable
protected $project;
/**
* @var Anis\Entity\Project
* @var Anis\Entity\DatasetFamily
*
* @ManyToOne(targetEntity="DatasetFamily")
* @ManyToOne(targetEntity="DatasetFamily", inversedBy="datasets")
* @JoinColumn(name="id_dataset_family", referencedColumnName="id", nullable=false)
*/
protected $datasetFamily;
......
......@@ -46,15 +46,21 @@ class DatasetFamily implements \JsonSerializable
/**
* @var Anis\Entity\Instance
*
* @ManyToOne(targetEntity="Instance")
* @ManyToOne(targetEntity="Instance", inversedBy="datasetFamilies")
* @JoinColumn(name="instance_name", referencedColumnName="name", nullable=false)
*/
protected $instance;
/**
* @var Anis\Entity\Dataset[]
*
* @OneToMany(targetEntity="Dataset", mappedBy="datasetFamily", cascade={"remove"})
*/
protected $datasets;
public function __construct(Instance $instance)
{
$this->instance = $instance;
$this->datasets = new ArrayCollection();
}
public function getId(): int
......@@ -82,6 +88,11 @@ class DatasetFamily implements \JsonSerializable
$this->display = $display;
}
public function getDatasets()
{
return $this->datasets;
}
public function jsonSerialize()
{
return [
......
......@@ -12,6 +12,8 @@ declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="instance")
......@@ -40,10 +42,18 @@ class Instance implements \JsonSerializable
*/
protected $clientUrl;
/**
* @var Anis\Entity\DatasetFamily[]
*
* @OneToMany(targetEntity="DatasetFamily", mappedBy="instance", cascade={"remove"})
*/
protected $datasetFamilies;
public function __construct(string $name, string $label)
{
$this->name = $name;
$this->label = $label;
$this->datasetFamilies = new ArrayCollection();
}
public function getName()
......@@ -71,12 +81,28 @@ class Instance implements \JsonSerializable
$this->clientUrl = $clientUrl;
}
public function getDatasetFamilies()
{
return $this->datasetFamilies;
}
public function getNbDatasets()
{
$nbDatasets = 0;
foreach ($this->datasetFamilies as $family) {
$nbDatasets += $family->getDatasets()->count();
}
return $nbDatasets;
}
public function jsonSerialize()
{
return [
'name' => $this->getName(),
'label' => $this->getLabel(),
'client_url' => $this->getClientUrl()
'client_url' => $this->getClientUrl(),
'nb_dataset_families' => $this->getDatasetFamilies()->count(),
'nb_datasets' => $this->getNbDatasets()
];
}
}
......@@ -69,7 +69,9 @@ final class InstanceActionTest extends TestCase
{
$fields = array(
'label' => 'AspiC',
'client_url' => 'http://aspic.lam.fr'
'client_url' => 'http://aspic.lam.fr',
'nb_dataset_families' => 0,
'nb_datasets' => 0
);
$this->addAnInstance();
$request = $this->getRequest('PUT')->withParsedBody($fields);
......
......@@ -62,7 +62,9 @@ final class InstanceListActionTest extends TestCase
$fields = array(
'name' => 'aspic',
'label' => 'Aspic',
'client_url' => 'http://cesam.lam.fr/aspic'
'client_url' => 'http://cesam.lam.fr/aspic',
'nb_dataset_families' => 0,
'nb_datasets' => 0
);
$request = $this->getRequest('POST')->withParsedBody($fields);
$response = ($this->action)($request, new Response(), array());
......
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