1 | <?php |
---|
2 | |
---|
3 | class setVacancesTask extends sfBaseTask { |
---|
4 | protected function configure() { |
---|
5 | $this->namespace = 'set'; |
---|
6 | $this->name = 'Vacances'; |
---|
7 | $this->briefDescription = 'Load Vacances from Seances'; |
---|
8 | $this->addOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'test'); |
---|
9 | $this->addOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'frontend'); |
---|
10 | } |
---|
11 | |
---|
12 | protected function execute($arguments = array(), $options = array()) { |
---|
13 | $semaines = array(); |
---|
14 | |
---|
15 | $manager = new sfDatabaseManager($this->configuration); |
---|
16 | $q = Doctrine_Query::create()->select('s.annee, s.numero_semaine') |
---|
17 | ->from('Seance s') |
---|
18 | ->groupBy('s.annee, s.numero_semaine') |
---|
19 | ->orderBy('s.date ASC'); |
---|
20 | $seances = $q->fetchArray(); |
---|
21 | |
---|
22 | $annee = $seances[0]['annee']; |
---|
23 | $sem = $seances[0]['numero_semaine']; |
---|
24 | foreach ($seances as $seance) { |
---|
25 | while (($annee < $seance['annee']) || ($annee == $seance['annee'] && $sem < $seance['numero_semaine'])) { |
---|
26 | array_push($semaines, array("annee" => $annee, "semaine" => $sem)); |
---|
27 | if ($sem >= 53) { $annee++; $sem = 1; } |
---|
28 | else $sem++; |
---|
29 | } |
---|
30 | if ($seance['numero_semaine'] >= 53) { $annee = $seance['annee'] + 1 ; $sem = 1; } |
---|
31 | else { $annee = $seance['annee']; $sem = $seance['numero_semaine'] + 1; } |
---|
32 | } |
---|
33 | |
---|
34 | $date = time(); |
---|
35 | $last_annee = date('Y', $date); |
---|
36 | $last_sem = date('W', $date); |
---|
37 | $day = date('w', $date); |
---|
38 | if ($day < 3) $last_sem--; |
---|
39 | if ($last_sem > 53) { $last_annee++; $last_sem = 1; } |
---|
40 | if ($last_sem == 0) { $last_annee--; $last_sem = 53; } |
---|
41 | while (($annee < $last_annee) || ($annee == $last_annee && $sem <= $last_sem)) { |
---|
42 | array_push($semaines, array("annee" => $annee, "semaine" => $sem)); |
---|
43 | if ($sem >= 53) { $annee++; $sem = 1; } |
---|
44 | else $sem++; |
---|
45 | } |
---|
46 | |
---|
47 | $option = Doctrine::getTable('VariableGlobale')->findOneByChamp('vacances'); |
---|
48 | if (!$option) { |
---|
49 | $option = new VariableGlobale(); |
---|
50 | $option->setChamp('vacances'); |
---|
51 | $option->setValue(serialize($semaines)); |
---|
52 | } else $option->setValue(serialize($semaines)); |
---|
53 | $option->save(); |
---|
54 | $option->free(); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | ?> |
---|