]> Raphaël G. Git Repositories - airbundle/blob - Entity/Slot.php
Add short to allow time detection after application form submit
[airbundle] / Entity / Slot.php
1 <?php declare(strict_types=1);
2
3 /*
4 * this file is part of the rapsys packbundle package.
5 *
6 * (c) raphaël gertz <symfony@rapsys.eu>
7 *
8 * for the full copyright and license information, please view the license
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Entity;
13
14 use Doctrine\Common\Collections\ArrayCollection;
15 use Doctrine\ORM\Event\PreUpdateEventArgs;
16
17 /**
18 * Slot
19 */
20 class Slot {
21 /**
22 * @var integer
23 */
24 private $id;
25
26 /**
27 * @var string
28 */
29 protected $title;
30
31 /**
32 * @var \DateTime
33 */
34 private $created;
35
36 /**
37 * @var \DateTime
38 */
39 private $updated;
40
41 /**
42 * @var ArrayCollection
43 */
44 private $sessions;
45
46 /**
47 * Constructor
48 */
49 public function __construct() {
50 $this->sessions = new ArrayCollection();
51 }
52
53 /**
54 * Get id
55 *
56 * @return integer
57 */
58 public function getId(): int {
59 return $this->id;
60 }
61
62 /**
63 * Set title
64 *
65 * @param string $title
66 *
67 * @return Title
68 */
69 public function setTitle(string $title) {
70 $this->title = $title;
71
72 return $this;
73 }
74
75 /**
76 * Get title
77 *
78 * @return string
79 */
80 public function getTitle(): string {
81 return $this->title;
82 }
83
84 /**
85 * Set created
86 *
87 * @param \DateTime $created
88 *
89 * @return Slot
90 */
91 public function setCreated(\DateTime $created) {
92 $this->created = $created;
93
94 return $this;
95 }
96
97 /**
98 * Get created
99 *
100 * @return \DateTime
101 */
102 public function getCreated(): \DateTime {
103 return $this->created;
104 }
105
106 /**
107 * Set updated
108 *
109 * @param \DateTime $updated
110 *
111 * @return Slot
112 */
113 public function setUpdated(\DateTime $updated) {
114 $this->updated = $updated;
115
116 return $this;
117 }
118
119 /**
120 * Get updated
121 *
122 * @return \DateTime
123 */
124 public function getUpdated(): \DateTime {
125 return $this->updated;
126 }
127
128 /**
129 * Add session
130 *
131 * @param Session $session
132 *
133 * @return Slot
134 */
135 public function addSession(Session $session): Slot {
136 $this->sessions[] = $session;
137
138 return $this;
139 }
140
141 /**
142 * Remove session
143 *
144 * @param Session $session
145 */
146 public function removeSession(Session $session): bool {
147 return $this->sessions->removeElement($session);
148 }
149
150 /**
151 * Get sessions
152 *
153 * @return ArrayCollection
154 */
155 public function getSessions(): ArrayCollection {
156 return $this->sessions;
157 }
158
159 /**
160 * {@inheritdoc}
161 */
162 public function preUpdate(PreUpdateEventArgs $eventArgs) {
163 //Check that we have a slot instance
164 if (($user = $eventArgs->getEntity()) instanceof Slot) {
165 //Set updated value
166 $user->setUpdated(new \DateTime('now'));
167 }
168 }
169
170 /**
171 * Returns a string representation of the slot
172 *
173 * @return string
174 */
175 public function __toString(): string {
176 return $this->title;
177 }
178 }