Commit 5f2f48c78a463e0545365f682dd0d70dd5dc3b18
1 parent
ffb39cc5
[Orga] Modification classe Evenements
- Tri des evenements - Systeme de possiblités
Showing
1 changed file
with
139 additions
and
37 deletions
Show diff stats
orga.php
1 | <h2> Organisation </h2> | 1 | <h2> Organisation </h2> |
2 | 2 | ||
3 | <?php | 3 | <?php |
4 | + | ||
4 | # DEBUG | 5 | # DEBUG |
5 | # e_ : est | 6 | # e_ : est |
6 | -# r_ : a le droit de | ||
7 | - | ||
8 | $e_connecte = false; | 7 | $e_connecte = false; |
9 | $e_modo = true; | 8 | $e_modo = true; |
10 | 9 | ||
11 | $droits = array('voir', 'voter', 'ajouter', 'proposer', 'annuler', 'supprimer', 'modifier', 'valider'); | 10 | $droits = array('voir', 'voter', 'ajouter', 'proposer', 'annuler', 'supprimer', 'modifier', 'valider'); |
11 | +$time = time(); | ||
12 | 12 | ||
13 | class Evenement | 13 | class Evenement |
14 | { | 14 | { |
15 | - public $id = 0; | 15 | + private $id = 0; |
16 | + private $creationTime = 0; | ||
17 | + | ||
16 | public $nom = "Sans nom"; | 18 | public $nom = "Sans nom"; |
17 | public $description = "Sans description"; | 19 | public $description = "Sans description"; |
18 | public $annule = false; | 20 | public $annule = false; |
19 | public $valide = false; | 21 | public $valide = false; |
20 | - public $duree = 120; | 22 | + public $duree = 3600; |
23 | + public $supprime = false; | ||
21 | 24 | ||
22 | public $dates = array(); | 25 | public $dates = array(); |
26 | + public $datesVotes = array(); | ||
23 | 27 | ||
24 | public function html() { | 28 | public function html() { |
25 | - global $droits; | ||
26 | - | ||
27 | $html = ' <li class="list-group-item">'; | 29 | $html = ' <li class="list-group-item">'; |
28 | 30 | ||
29 | # Titre | 31 | # Titre |
@@ -31,10 +33,10 @@ class Evenement | @@ -31,10 +33,10 @@ class Evenement | ||
31 | if ($this->annule) { | 33 | if ($this->annule) { |
32 | $html .= ' <span class="label label-danger">Annulé</span>'; | 34 | $html .= ' <span class="label label-danger">Annulé</span>'; |
33 | } | 35 | } |
34 | - if (in_array('annuler', $droits) && !$this->annule) { # TODO | 36 | + if ($this->p_annuler()) { |
35 | $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-remove"></span></button>'; | 37 | $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-remove"></span></button>'; |
36 | } | 38 | } |
37 | - if (in_array('supprimer', $droits) && !$this->valide) { # TODO | 39 | + if ($this->p_supprimer()) { |
38 | $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-trash"></span></button>'; | 40 | $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-trash"></span></button>'; |
39 | } | 41 | } |
40 | $html .= '</h3>'; | 42 | $html .= '</h3>'; |
@@ -43,7 +45,7 @@ class Evenement | @@ -43,7 +45,7 @@ class Evenement | ||
43 | $html .= '<div class="panel panel-default">'; | 45 | $html .= '<div class="panel panel-default">'; |
44 | $html .= '<div class="panel-heading">'; | 46 | $html .= '<div class="panel-heading">'; |
45 | $html .= '<h4 class="panel-title">Description'; | 47 | $html .= '<h4 class="panel-title">Description'; |
46 | - if (in_array('modifier', $droits)) { | 48 | + if ($this->p_modifier()) { |
47 | $html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></button>'; | 49 | $html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></button>'; |
48 | } | 50 | } |
49 | $html .= '</h4>'; | 51 | $html .= '</h4>'; |
@@ -54,9 +56,12 @@ class Evenement | @@ -54,9 +56,12 @@ class Evenement | ||
54 | $html .= '</p>'; | 56 | $html .= '</p>'; |
55 | // $html .= '<hr/>'; | 57 | // $html .= '<hr/>'; |
56 | $html .= '<p>'; | 58 | $html .= '<p>'; |
57 | - $html .= 'Durée : '.$this->duree.' minutes <br/>'; | 59 | + $heures = floor($this->duree/3600); |
60 | + $minutes = floor($this->duree%3600/60); | ||
61 | + $secondes = floor($this->duree%3600%60); | ||
62 | + $html .= 'Durée : '.($heures > 0 ? $heures.' heure'.($heures > 1 ? 's' : '').' ' : '').($minutes > 0 ? $minutes.' minute'.($minutes > 1 ? 's' : '').' ' : '').($secondes > 0 ? $secondes.' seconde'.($secondes > 1 ? 's' : '').' ' : '').'<br/>'; | ||
58 | if ($this->valide) { | 63 | if ($this->valide) { |
59 | - $html .= 'Date : '.date('c', $this->valide).'<br/>'; | 64 | + $html .= 'Date : le '.date('j/m/o', $this->valide).' à '.date('H:i', $this->valide).'<br/>'; |
60 | } | 65 | } |
61 | $html .= '</p>'; | 66 | $html .= '</p>'; |
62 | if ($this->annule) { | 67 | if ($this->annule) { |
@@ -71,18 +76,23 @@ class Evenement | @@ -71,18 +76,23 @@ class Evenement | ||
71 | $html .= '<div class="panel panel-default">'; | 76 | $html .= '<div class="panel panel-default">'; |
72 | $html .= '<div class="panel-heading">'; | 77 | $html .= '<div class="panel-heading">'; |
73 | $html .= '<h4 class="panel-title">Dates possibles'; | 78 | $html .= '<h4 class="panel-title">Dates possibles'; |
74 | - if (in_array('proposer', $droits)) { | ||
75 | - $html .= '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></button>'; | 79 | + if ($this->p_proposer()) { |
80 | + $html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span></button>'; | ||
76 | } | 81 | } |
77 | $html .= '</h4>'; | 82 | $html .= '</h4>'; |
78 | $html .= '</div>'; | 83 | $html .= '</div>'; |
79 | $html .= '<div class="panel-body">'; | 84 | $html .= '<div class="panel-body">'; |
80 | - $html .= '<ul class="list-group">'; | 85 | + $html .= '<div class="list-group">'; |
86 | + $time = time(); | ||
81 | foreach ($this->dates as $dateIndex => $date) { | 87 | foreach ($this->dates as $dateIndex => $date) { |
82 | - $html .= '<li class="list-group-item">'.date('c', $date).' (6 <span class="glyphicon glyphicon-user"></span>)</li>'; | 88 | + $html .= '<a href="#"class="list-group-item'; |
89 | + if ($date < $time) { | ||
90 | + $html .= ' disabled'; | ||
91 | + } | ||
92 | + $html .= '">Le '.date('j/m/o', $date).' à '.date('H:i', $date).' ('.$this->datesVotes[$dateIndex].' <span class="glyphicon glyphicon-user"></span>)</a>'; | ||
83 | } | 93 | } |
84 | - $html .= '</ul>'; | ||
85 | - if (in_array('valider', $droits) && !$this->valide) { | 94 | + $html .= '</div>'; |
95 | + if ($this->p_valider()) { | ||
86 | $html .= '<p><button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span> Valider la date</button></p>'; | 96 | $html .= '<p><button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span> Valider la date</button></p>'; |
87 | } | 97 | } |
88 | $html .= '</div>'; | 98 | $html .= '</div>'; |
@@ -92,6 +102,107 @@ class Evenement | @@ -92,6 +102,107 @@ class Evenement | ||
92 | $html .= '</li>'; | 102 | $html .= '</li>'; |
93 | return $html; | 103 | return $html; |
94 | } | 104 | } |
105 | + | ||
106 | + public function passe() { | ||
107 | + global $time; | ||
108 | + if ($this->valide) { | ||
109 | + return $this->valide+$this->duree < $time; | ||
110 | + } else { | ||
111 | + return false; | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + # p_ : Il est possible de ... | ||
116 | + function p_annuler() { | ||
117 | + global $droits; | ||
118 | + return in_array('annuler', $droits) && !$this->annule && !$this->passe(); | ||
119 | + } | ||
120 | + | ||
121 | + function p_supprimer() { | ||
122 | + global $droits; | ||
123 | + return in_array('supprimer', $droits) && !$this->valide; | ||
124 | + } | ||
125 | + | ||
126 | + function p_modifier() { | ||
127 | + global $droits; | ||
128 | + return in_array('modifier', $droits); | ||
129 | + } | ||
130 | + | ||
131 | + function p_proposer() { | ||
132 | + global $droits; | ||
133 | + return in_array('proposer', $droits); | ||
134 | + } | ||
135 | + | ||
136 | + function p_valider() { | ||
137 | + global $droits; | ||
138 | + return in_array('valider', $droits) && !$this->valide; | ||
139 | + } | ||
140 | + | ||
141 | +} | ||
142 | + | ||
143 | +# a_ : Récupérer depuis la base de donnée | ||
144 | +function a_evenement() { | ||
145 | + # DEBUG | ||
146 | + $test1 = new Evenement; | ||
147 | + $test1->nom = 'Évènement de test n°1'; | ||
148 | + $test1->valide = time(); | ||
149 | + | ||
150 | + $test2 = new Evenement; | ||
151 | + $test2->nom = 'Évènement de test n°2'; | ||
152 | + $test2->valide = time(); | ||
153 | + $test2->annule = true; | ||
154 | + | ||
155 | + $test3 = new Evenement; | ||
156 | + $test3->nom = 'Évènement de test n°3'; | ||
157 | + $test3->dates[] = 1415482197; | ||
158 | + $test3->datesVotes[] = 42; | ||
159 | + $test3->dates[] = time(); | ||
160 | + $test3->datesVotes[] = 5; | ||
161 | + $test3->dates[] = time()+365*24*3600; | ||
162 | + $test3->datesVotes[] = 1; | ||
163 | + | ||
164 | + $test4 = new Evenement; | ||
165 | + $test4->nom = 'Évènement de test n°4'; | ||
166 | + $test4->dates[] = time(); | ||
167 | + $test4->datesVotes[] = 5; | ||
168 | + $test4->dates[] = time()+365*24*3600; | ||
169 | + $test4->datesVotes[] = 1; | ||
170 | + $test4->dates[] = time(); | ||
171 | + $test4->annule = true; | ||
172 | + | ||
173 | + $test5 = new Evenement; | ||
174 | + $test5->nom = 'Évènement de test n°5'; | ||
175 | + $test5->dates[] = time(); | ||
176 | + $test5->datesVotes[] = 0; | ||
177 | + $test5->supprime = true; | ||
178 | + | ||
179 | + $test6 = new Evenement; | ||
180 | + $test6->nom = 'Évènement de test n°6'; | ||
181 | + $test6->valide = 1415452197; | ||
182 | + | ||
183 | + return array($test1, $test2, $test3, $test4, $test5, $test6); | ||
184 | +} | ||
185 | + | ||
186 | +# Tri des évènements | ||
187 | +$evenements = a_evenement(); | ||
188 | +$evenementsPlanifies = array(); | ||
189 | +$evenementsAPlanifier = array(); | ||
190 | +$evenementsPasses = array(); | ||
191 | + | ||
192 | +$time = time(); | ||
193 | + | ||
194 | +foreach ($evenements as $evenement) { | ||
195 | + if (!$evenement->supprime) { | ||
196 | + if ($evenement->valide) { | ||
197 | + if ($evenement->passe()) { | ||
198 | + $evenementsPasses[] = $evenement; | ||
199 | + } else { | ||
200 | + $evenementsPlanifies[] = $evenement; | ||
201 | + } | ||
202 | + } else { | ||
203 | + $evenementsAPlanifier[] = $evenement; | ||
204 | + } | ||
205 | + } | ||
95 | } | 206 | } |
96 | 207 | ||
97 | ?> | 208 | ?> |
@@ -101,17 +212,9 @@ class Evenement | @@ -101,17 +212,9 @@ class Evenement | ||
101 | <h2>Plannifiés <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2> | 212 | <h2>Plannifiés <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2> |
102 | <ul class="list-group"> | 213 | <ul class="list-group"> |
103 | <? | 214 | <? |
104 | -$test1 = new Evenement; | ||
105 | -$test1->dates[] = time(); | ||
106 | -$test1->valide = time(); | ||
107 | -echo $test1->html() | ||
108 | -?> | ||
109 | -<? | ||
110 | -$test2 = new Evenement; | ||
111 | -$test2->dates[] = time(); | ||
112 | -$test2->valide = time(); | ||
113 | -$test2->annule = true; | ||
114 | -echo $test2->html() | 215 | +foreach ($evenementsPlanifies as $evenement) { |
216 | + echo $evenement->html(); | ||
217 | +} | ||
115 | ?> | 218 | ?> |
116 | </ul> | 219 | </ul> |
117 | 220 | ||
@@ -119,19 +222,18 @@ echo $test2->html() | @@ -119,19 +222,18 @@ echo $test2->html() | ||
119 | <h2>À plannifier <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2> | 222 | <h2>À plannifier <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2> |
120 | <ul class="list-group"> | 223 | <ul class="list-group"> |
121 | <? | 224 | <? |
122 | -$test3 = new Evenement; | ||
123 | -$test3->dates[] = time(); | ||
124 | -echo $test3->html() | ||
125 | -?> | ||
126 | -<? | ||
127 | -$test4 = new Evenement; | ||
128 | -$test4->dates[] = time(); | ||
129 | -$test4->annule = true; | ||
130 | -echo $test4->html() | 225 | +foreach ($evenementsAPlanifier as $evenement) { |
226 | + echo $evenement->html(); | ||
227 | +} | ||
131 | ?> | 228 | ?> |
132 | </ul> | 229 | </ul> |
133 | 230 | ||
134 | 231 | ||
135 | <h2>Évènements passés</h2> | 232 | <h2>Évènements passés</h2> |
136 | <ul class="list-group"> | 233 | <ul class="list-group"> |
234 | +<? | ||
235 | +foreach ($evenementsPasses as $evenement) { | ||
236 | + echo $evenement->html(); | ||
237 | +} | ||
238 | +?> | ||
137 | </ul> | 239 | </ul> |
138 | \ No newline at end of file | 240 | \ No newline at end of file |