DatasetFamily.php 1.95 KB
Newer Older
1
<?php declare(strict_types=1);
François Agneray's avatar
François Agneray committed
2
3
4
5
6
7
8
9
10
/*
 * This file is part of ANIS SERVER API.
 *
 * (c) François Agneray <francois.agneray@lam.fr>
 * (c) Chrystel Moreau <chrystel.moreau@lam.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
11
namespace App\Entity\Metamodel;
François Agneray's avatar
François Agneray committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

use Doctrine\Common\Collections\ArrayCollection;

/**
* @Entity
* @Table(name="dataset_family")
*/
class DatasetFamily implements \JsonSerializable
{
    /**
     * @var integer
     *
     * @Id
     * @Column(type="integer", nullable=false)
     * @GeneratedValue
     */
    protected $id;
  
    /**
     * @var string
     *
     * @Column(type="string", nullable=false)
     */
    protected $label;

    /**
     * @var integer
     *
     * @Column(type="integer", nullable=false)
     */
    protected $display;

    /**
     * @var Anis\Entity\Dataset[]
     *
     * @OneToMany(targetEntity="Dataset", mappedBy="datasetFamily")
     */
    protected $datasets;

François Agneray's avatar
François Agneray committed
51
52
    public function __construct()
    {
François Agneray's avatar
François Agneray committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
        $this->datasets = new ArrayCollection;
    }

    public function getId()
    {
        return $this->id;
    }

    public function getLabel()
    {
        return $this->label;
    }

    public function setLabel($label)
    {
        $this->label = $label;
    }

    public function getDisplay()
    {
        return $this->display;
    }

    public function setDisplay($display)
    {
        $this->display = (int) $display;
    }

    public function getDatasets()
    {
        return $this->datasets;
    }

    public function jsonSerialize()
    {
        $datasets = array();
        foreach ($this->getDatasets() as $dataset) {
            $datasets[] = $dataset->getName();
        }
        return [
            'id' => $this->getId(),
            'label' => $this->getLabel(),
            'display' => $this->getDisplay(),
            'type' => 'dataset',
            'datasets' => $datasets
        ];
    }
}