Completed
Push — profiles-entity ( cb5acc...05ead5 )
by Stijn
62:17
created

ProfileGroup::prePersist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backend\Modules\Profiles\Domain\ProfileGroup;
4
5
use DateTime;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\ORM\Mapping as ORM;
9
10
/**
11
 * @ORM\Table(name="profiles_groups")
12
 * @ORM\Entity
13
 * @ORM\HasLifecycleCallbacks
14
 */
15
class ProfileGroup
16
{
17
    /**
18
     * @var int
19
     *
20
     * @ORM\Id
21
     * @ORM\GeneratedValue(strategy="AUTO")
22
     * @ORM\Column(type="integer")
23
     */
24
    private $id;
25
26
    /**
27
     * @var string
28
     *
29
     * @ORM\Column(type="string")
30
     */
31
    private $name;
32
33
    /**
34
     * @var Collection;
35
     *
36
     * @ORM\OneToMany(
37
     *     targetEntity="Backend\Modules\Profiles\Domain\ProfileGroupRight\ProfileGroupRight",
38
     *     mappedBy="profile"
39
     * )
40
     */
41
    private $rights;
42
43
    /**
44
     * @var DateTime
45
     *
46
     * @ORM\Column(type="datetime", name="created_on")
47
     */
48
    private $createdOn;
49
50
    /**
51
     * @var DateTime
52
     *
53
     * @ORM\Column(type="datetime", name="edited_on")
54
     */
55
    private $editedOn;
56
57
    public function __construct(string $name)
58
    {
59
        $this->name = $name;
60
        $this->rights = new ArrayCollection();
61
    }
62
63
    public static function fromDataTransferObject(ProfileGroupDataTransferObject $dataTransferObject): self
64
    {
65
        return self::create($dataTransferObject);
66
    }
67
68
    private static function create(ProfileGroupDataTransferObject $dataTransferObject): self
69
    {
70
        return new self(
71
            $dataTransferObject->name
72
        );
73
    }
74
75
    public function getId(): int
76
    {
77
        return $this->id;
78
    }
79
80
    public function getName(): string
81
    {
82
        return $this->name;
83
    }
84
85
    public function getRights(): Collection
86
    {
87
        return $this->rights;
88
    }
89
90
    public function getCreatedOn(): DateTime
91
    {
92
        return $this->createdOn;
93
    }
94
95
    public function getEditedOn(): DateTime
96
    {
97
        return $this->editedOn;
98
    }
99
100
    /**
101
     * @ORM\PrePersist
102
     */
103
    public function prePersist(): void
104
    {
105
        $this->createdOn = $this->editedOn = new DateTime();
106
    }
107
108
    /**
109
     * @ORM\PreUpdate
110
     */
111
    public function preUpdate(): void
112
    {
113
        $this->editedOn = new DateTime();
114
    }
115
}
116