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