1 | <?php |
---|
2 | |
---|
3 | class updateDeputesTask extends sfBaseTask |
---|
4 | { |
---|
5 | protected function configure() |
---|
6 | { |
---|
7 | $this->namespace = 'update'; |
---|
8 | $this->name = 'Deputes'; |
---|
9 | $this->briefDescription = 'Update Deputes'; |
---|
10 | $this->addOption('env', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'test'); |
---|
11 | $this->addOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'Changes the environment this task is run in', 'frontend'); |
---|
12 | } |
---|
13 | |
---|
14 | protected function splitArrayJson($json) { |
---|
15 | $res = array(); |
---|
16 | foreach($json as $j) { |
---|
17 | if ($j) |
---|
18 | array_push($res, explode(' / ', $j)); |
---|
19 | } |
---|
20 | return $res; |
---|
21 | } |
---|
22 | |
---|
23 | protected function execute($arguments = array(), $options = array()) |
---|
24 | { |
---|
25 | $dir = dirname(__FILE__).'/../../batch/depute/out/'; |
---|
26 | $manager = new sfDatabaseManager($this->configuration); |
---|
27 | |
---|
28 | $villes = json_decode(file_get_contents($dir.'../static/villes.json')); |
---|
29 | |
---|
30 | if (is_dir($dir)) { |
---|
31 | if ($dh = opendir($dir)) { |
---|
32 | while (($file = readdir($dh)) !== false) { |
---|
33 | $sections = array(); |
---|
34 | if (preg_match('/^\./', $file)) |
---|
35 | continue; |
---|
36 | // echo "$dir$file\n"; |
---|
37 | foreach(file($dir.$file) as $line) { |
---|
38 | $json = json_decode($line); |
---|
39 | if (!isset($json->nom) || !$json->nom) |
---|
40 | next; |
---|
41 | // echo "-".$json->nom." ".$json->id_an."\n"; |
---|
42 | $parl = Doctrine::getTable('Parlementaire')->findOneByNom($json->nom); |
---|
43 | if (!$parl) { |
---|
44 | $parl = new Parlementaire(); |
---|
45 | $parl->type = 'depute'; |
---|
46 | $parl->nom = $json->nom; |
---|
47 | $parl->nom_de_famille = $json->nom_de_famille; |
---|
48 | $parl->sexe = $json->sexe; |
---|
49 | } |
---|
50 | if ($json->circonscription) |
---|
51 | $parl->circonscription = $json->circonscription; |
---|
52 | if (count($json->adresses)) |
---|
53 | $parl->adresses = $json->adresses; |
---|
54 | if (count($json->autresmandats)) |
---|
55 | $parl->autres_mandats = $json->autresmandats; |
---|
56 | if ($json->groupe) |
---|
57 | $parl->groupe = $this->splitArrayJson($json->groupe); |
---|
58 | if (count($json->extras)) |
---|
59 | $parl->extras = $this->splitArrayJson($json->extras); |
---|
60 | if (count($json->fonctions)) |
---|
61 | $parl->fonctions = $this->splitArrayJson($json->fonctions); |
---|
62 | $parl->debut_mandat = $json->debut_mandat; |
---|
63 | $parl->fin_mandat = $json->fin_mandat; |
---|
64 | if ($json->id_an) |
---|
65 | $parl->id_an = $json->id_an; |
---|
66 | if (count($json->mails)) |
---|
67 | $parl->mails = $json->mails; |
---|
68 | if ($json->photo) |
---|
69 | $parl->photo = $json->photo; |
---|
70 | if ($json->place_hemicycle) |
---|
71 | $parl->place_hemicycle = $json->place_hemicycle; |
---|
72 | if ($json->profession) |
---|
73 | $parl->profession = $json->profession; |
---|
74 | if ($json->site_web) |
---|
75 | $parl->site_web = $json->site_web; |
---|
76 | if ($json->url_an) |
---|
77 | $parl->url_an = $json->url_an; |
---|
78 | $parl->villes = $villes->{$parl->getNumDepartement()}->{$parl->num_circo}; |
---|
79 | $parl->save(); |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|