|
@@ -0,0 +1,189 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Entity;
|
|
4
|
+
|
|
5
|
+use Doctrine\ORM\Mapping as ORM;
|
|
6
|
+use \Doctrine\Common\Collections\ArrayCollection;
|
|
7
|
+use Gedmo\Mapping\Annotation as Gedmo;
|
|
8
|
+
|
|
9
|
+/**
|
|
10
|
+ * L'Element est l'Element central de l'application. C'est cet
|
|
11
|
+ * entité qui stocke le media partagé sur le réseau.
|
|
12
|
+ *
|
|
13
|
+ * @ORM\Entity
|
|
14
|
+ * @ORM\Table(name="event")
|
|
15
|
+ * @ORM\Entity(repositoryClass="Muzich\CoreBundle\Repository\EventRepository")
|
|
16
|
+ *
|
|
17
|
+ */
|
|
18
|
+class Event
|
|
19
|
+{
|
|
20
|
+
|
|
21
|
+ const TYPE_COMMENT_ADDED_OWNED_ELEMENT = "com.add.ow.e";
|
|
22
|
+
|
|
23
|
+ /**
|
|
24
|
+ * @ORM\Id
|
|
25
|
+ * @ORM\Column(type="integer")
|
|
26
|
+ * @ORM\GeneratedValue(strategy="AUTO")
|
|
27
|
+ * @var type int
|
|
28
|
+ */
|
|
29
|
+ protected $id;
|
|
30
|
+
|
|
31
|
+ /**
|
|
32
|
+ * array json des id d'éléments/users/...
|
|
33
|
+ *
|
|
34
|
+ * @ORM\Column(type="text", nullable=true)
|
|
35
|
+ * @var string
|
|
36
|
+ */
|
|
37
|
+ protected $ids;
|
|
38
|
+
|
|
39
|
+ /**
|
|
40
|
+ * Compteur d'élément/users concernés
|
|
41
|
+ *
|
|
42
|
+ * @ORM\Column(type="integer", nullable=true)
|
|
43
|
+ * @var int
|
|
44
|
+ */
|
|
45
|
+ protected $count;
|
|
46
|
+
|
|
47
|
+ /**
|
|
48
|
+ * Type (constitué de la valeur d'une des
|
|
49
|
+ *
|
|
50
|
+ * @ORM\Column(type = "string", length = 12)
|
|
51
|
+ * @var type string
|
|
52
|
+ */
|
|
53
|
+ protected $type;
|
|
54
|
+
|
|
55
|
+ /**
|
|
56
|
+ * Propriétaire de l'event
|
|
57
|
+ *
|
|
58
|
+ * @ORM\ManyToOne(targetEntity="User", inversedBy="events")
|
|
59
|
+ * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
|
|
60
|
+ */
|
|
61
|
+ protected $user;
|
|
62
|
+
|
|
63
|
+ /**
|
|
64
|
+ * Si $view est a vrai, cela se traduit par le fait que l'user a vue l'événement
|
|
65
|
+ * ou qu'il l'a supprimé.
|
|
66
|
+ *
|
|
67
|
+ * @ORM\Column(type="boolean")
|
|
68
|
+ * @var type string
|
|
69
|
+ */
|
|
70
|
+ protected $view;
|
|
71
|
+
|
|
72
|
+ /*
|
|
73
|
+ *
|
|
74
|
+ * getters / setters
|
|
75
|
+ *
|
|
76
|
+ */
|
|
77
|
+
|
|
78
|
+ public function getId()
|
|
79
|
+ {
|
|
80
|
+ return $this->id;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ public function getIds()
|
|
84
|
+ {
|
|
85
|
+ return json_decode($this->ids, true);
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ public function setIds($ids)
|
|
89
|
+ {
|
|
90
|
+ $this->ids = json_encode($ids);
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ public function getCount()
|
|
94
|
+ {
|
|
95
|
+ return $this->count;
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ public function setCount($count)
|
|
99
|
+ {
|
|
100
|
+ $this->count = $count;
|
|
101
|
+ }
|
|
102
|
+
|
|
103
|
+ public function getType()
|
|
104
|
+ {
|
|
105
|
+ return $this->type;
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ public function setType($type)
|
|
109
|
+ {
|
|
110
|
+ $this->type = $type;
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ public function getUser()
|
|
114
|
+ {
|
|
115
|
+ return $this->user;
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+ public function setUser($user)
|
|
119
|
+ {
|
|
120
|
+ $this->user = $user;
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ public function getView()
|
|
124
|
+ {
|
|
125
|
+ return $this->view;
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ public function setView($view)
|
|
129
|
+ {
|
|
130
|
+ $this->view = $view;
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ /*
|
|
134
|
+ * other methods
|
|
135
|
+ *
|
|
136
|
+ */
|
|
137
|
+
|
|
138
|
+ public function addId($id)
|
|
139
|
+ {
|
|
140
|
+ $ids = $this->getIds();
|
|
141
|
+ if (!count($ids))
|
|
142
|
+ {
|
|
143
|
+ $ids = array();
|
|
144
|
+ }
|
|
145
|
+
|
|
146
|
+ if (!$this->hasId($id))
|
|
147
|
+ {
|
|
148
|
+ $ids[] = (string)$id;
|
|
149
|
+ $this->setCount($this->getCount()+1);
|
|
150
|
+ }
|
|
151
|
+ $this->setIds($ids);
|
|
152
|
+ }
|
|
153
|
+
|
|
154
|
+ public function removeVoteGood($id_remove)
|
|
155
|
+ {
|
|
156
|
+ if (count($ids = $this->getIds()))
|
|
157
|
+ {
|
|
158
|
+ $ids_n = array();
|
|
159
|
+ foreach ($ids as $id)
|
|
160
|
+ {
|
|
161
|
+ if ($id != $id_remove)
|
|
162
|
+ {
|
|
163
|
+ $ids_n[] = (string)$id;
|
|
164
|
+ }
|
|
165
|
+ else
|
|
166
|
+ {
|
|
167
|
+ $this->setCount($this->getCount()-1);
|
|
168
|
+ }
|
|
169
|
+ }
|
|
170
|
+ $this->setIds($ids_n);
|
|
171
|
+ }
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ public function hasId($id_check)
|
|
175
|
+ {
|
|
176
|
+ if (count($ids = $this->getIds()))
|
|
177
|
+ {
|
|
178
|
+ foreach ($ids as $id)
|
|
179
|
+ {
|
|
180
|
+ if ($id == $id_check)
|
|
181
|
+ {
|
|
182
|
+ return true;
|
|
183
|
+ }
|
|
184
|
+ }
|
|
185
|
+ }
|
|
186
|
+ return false;
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+}
|