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 | 1 | <h2> Organisation </h2> |
2 | 2 | |
3 | 3 | <?php |
4 | + | |
4 | 5 | # DEBUG |
5 | 6 | # e_ : est |
6 | -# r_ : a le droit de | |
7 | - | |
8 | 7 | $e_connecte = false; |
9 | 8 | $e_modo = true; |
10 | 9 | |
11 | 10 | $droits = array('voir', 'voter', 'ajouter', 'proposer', 'annuler', 'supprimer', 'modifier', 'valider'); |
11 | +$time = time(); | |
12 | 12 | |
13 | 13 | class Evenement |
14 | 14 | { |
15 | - public $id = 0; | |
15 | + private $id = 0; | |
16 | + private $creationTime = 0; | |
17 | + | |
16 | 18 | public $nom = "Sans nom"; |
17 | 19 | public $description = "Sans description"; |
18 | 20 | public $annule = false; |
19 | 21 | public $valide = false; |
20 | - public $duree = 120; | |
22 | + public $duree = 3600; | |
23 | + public $supprime = false; | |
21 | 24 | |
22 | 25 | public $dates = array(); |
26 | + public $datesVotes = array(); | |
23 | 27 | |
24 | 28 | public function html() { |
25 | - global $droits; | |
26 | - | |
27 | 29 | $html = ' <li class="list-group-item">'; |
28 | 30 | |
29 | 31 | # Titre |
... | ... | @@ -31,10 +33,10 @@ class Evenement |
31 | 33 | if ($this->annule) { |
32 | 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 | 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 | 40 | $html .= ' <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon glyphicon-trash"></span></button>'; |
39 | 41 | } |
40 | 42 | $html .= '</h3>'; |
... | ... | @@ -43,7 +45,7 @@ class Evenement |
43 | 45 | $html .= '<div class="panel panel-default">'; |
44 | 46 | $html .= '<div class="panel-heading">'; |
45 | 47 | $html .= '<h4 class="panel-title">Description'; |
46 | - if (in_array('modifier', $droits)) { | |
48 | + if ($this->p_modifier()) { | |
47 | 49 | $html .= ' <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-pencil"></span></button>'; |
48 | 50 | } |
49 | 51 | $html .= '</h4>'; |
... | ... | @@ -54,9 +56,12 @@ class Evenement |
54 | 56 | $html .= '</p>'; |
55 | 57 | // $html .= '<hr/>'; |
56 | 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 | 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 | 66 | $html .= '</p>'; |
62 | 67 | if ($this->annule) { |
... | ... | @@ -71,18 +76,23 @@ class Evenement |
71 | 76 | $html .= '<div class="panel panel-default">'; |
72 | 77 | $html .= '<div class="panel-heading">'; |
73 | 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 | 82 | $html .= '</h4>'; |
78 | 83 | $html .= '</div>'; |
79 | 84 | $html .= '<div class="panel-body">'; |
80 | - $html .= '<ul class="list-group">'; | |
85 | + $html .= '<div class="list-group">'; | |
86 | + $time = time(); | |
81 | 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 | 96 | $html .= '<p><button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-ok"></span> Valider la date</button></p>'; |
87 | 97 | } |
88 | 98 | $html .= '</div>'; |
... | ... | @@ -92,6 +102,107 @@ class Evenement |
92 | 102 | $html .= '</li>'; |
93 | 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 | 212 | <h2>Plannifiés <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2> |
102 | 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 | 219 | </ul> |
117 | 220 | |
... | ... | @@ -119,19 +222,18 @@ echo $test2->html() |
119 | 222 | <h2>À plannifier <button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span></button></h2> |
120 | 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 | 229 | </ul> |
133 | 230 | |
134 | 231 | |
135 | 232 | <h2>Évènements passés</h2> |
136 | 233 | <ul class="list-group"> |
234 | +<? | |
235 | +foreach ($evenementsPasses as $evenement) { | |
236 | + echo $evenement->html(); | |
237 | +} | |
238 | +?> | |
137 | 239 | </ul> |
138 | 240 | \ No newline at end of file | ... | ... |