1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * TexteLoi |
---|
5 | * |
---|
6 | * This class has been auto-generated by the Doctrine ORM Framework |
---|
7 | * |
---|
8 | * @package cpc |
---|
9 | * @subpackage model |
---|
10 | * @author Your name here |
---|
11 | * @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ |
---|
12 | */ |
---|
13 | class TexteLoi extends BaseTexteLoi |
---|
14 | { |
---|
15 | |
---|
16 | public function setDossier($urldossier) { |
---|
17 | $this->url_an = $urldossier; |
---|
18 | //find by url_an if not find by tag_loi if Projet de loi, Proposition de loi, TA, => save url_an |
---|
19 | $section = Doctrine::getTable('Section')->findOneByUrlAn($urldossier); |
---|
20 | if ($section) { |
---|
21 | # cela parait plus cohérent que les dossiers apparaissent comme récemment modifiés uniquement s'ils sont discutés et pas si un nouveau rapport vient les compléter je pense mais on peut envisager de le mettre tout de même si c utile pour solr par exemple |
---|
22 | # $section->setMaxDate($this->date); |
---|
23 | # $section->save(); |
---|
24 | #print "$section->id, $this->url_an\n"; |
---|
25 | return true; |
---|
26 | } |
---|
27 | $sections = Doctrine_Query::create() |
---|
28 | ->select('s.id') |
---|
29 | ->from('Section s, Tagging ta, Tag t') |
---|
30 | ->where('s.section_id = s.id') |
---|
31 | ->andWhere('ta.taggable_id = s.id') |
---|
32 | ->andWhere('ta.tag_id = t.id') |
---|
33 | ->andWhere('ta.taggable_model = ?', "Section") |
---|
34 | ->andWhere('t.name = ?', "loi:numero=".$this->numero) |
---|
35 | ->fetchArray(); |
---|
36 | $res = count($sections); |
---|
37 | if ($res == O) { |
---|
38 | #print "Pas de dossier trouvé pour le texte $this->id\n"; |
---|
39 | return false; |
---|
40 | } else if ($res == 1) { |
---|
41 | $section = Doctrine::getTable('Section')->find($sections[0]['id']); |
---|
42 | $section->url_an = $urldossier; |
---|
43 | # voir plus haut |
---|
44 | # $section->setMaxDate($this->date); |
---|
45 | $section->save(); |
---|
46 | #print "$section->id, $this->url_an\n"; |
---|
47 | return true; |
---|
48 | } else { |
---|
49 | echo "$this->source : Plusieurs dossiers trouvés pour le texte $this->id de type $this->type\n"; |
---|
50 | return false; |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | public function setAuteurs($signataires) { //$debug=1; |
---|
55 | $this->signataires = $signataires; |
---|
56 | //Set signatires, auteurs via PArlemnaitreTexteDocu et Organisme |
---|
57 | $orga = null; |
---|
58 | $sexe = null; |
---|
59 | $fonction = null; |
---|
60 | $signataires = preg_replace("/(Auteur|Cosignataire|Rapporteur), /", "\\1#", $signataires); |
---|
61 | if ($debug) echo $this->source." : ".$signataires."\n"; |
---|
62 | $signataires = preg_split('/#/', $signataires); |
---|
63 | foreach ($signataires as $depute) { |
---|
64 | if (preg_match('/^(M[\.mle]+)/', $depute, $match)) |
---|
65 | continue; |
---|
66 | if (preg_match('/^(.*)(\set apparentés)?\s+(Auteur|Cosignataire|Rapporteur)/', $depute, $match)) { |
---|
67 | $orga = trim($match[1]).$match[2]; |
---|
68 | $organisme = Doctrine::getTable('Organisme')->findOneByNomType($orga, 'parlementaire'); |
---|
69 | if ($organisme) { |
---|
70 | $this->set('Organisme', $organisme); |
---|
71 | $orga = $organisme->nom; |
---|
72 | } else { |
---|
73 | $groupe = Doctrine::getTable('Organisme')->findOneByNomType($orga, 'groupe'); |
---|
74 | if ($groupe) { |
---|
75 | $this->set('Organisme', $groupe); |
---|
76 | $orga = " pour le groupe ".$orga; |
---|
77 | } |
---|
78 | } |
---|
79 | break; |
---|
80 | } |
---|
81 | } |
---|
82 | foreach ($signataires as $depute) { |
---|
83 | if (preg_match('/^(M[\.mle]+)\s+(.*)\s+(Auteur|Cosignataire|Rapporteur)/', $depute, $match)) { |
---|
84 | if (preg_match('/M[ml]/', $match[1])) |
---|
85 | $sexe = 'F'; |
---|
86 | else $sexe = 'H'; |
---|
87 | $nom = $match[2]; |
---|
88 | $fonction = $match[3]; |
---|
89 | if (preg_match('/^(.*)\((.*)\)/', $nom, $match)) { |
---|
90 | $nom = trim($match[1]); |
---|
91 | $circo = preg_replace('/\s/', '-', ucfirst(trim($match[2]))); |
---|
92 | } else $circo = null; |
---|
93 | if (preg_match('/(ministre|[eéÉ]tat|président|haut-commissaire)/i', $nom)) { |
---|
94 | if ($debug) print "WARN: Skip auteur ".$nom." for ".$this->source."\n"; |
---|
95 | continue; |
---|
96 | } |
---|
97 | $nom = ucfirst($nom); |
---|
98 | if ($debug) echo $nom."//".$sexe."//".$orga."//".$circo."//".$fonction." => "; |
---|
99 | $depute = Doctrine::getTable('Parlementaire')->findOneByNomSexeGroupeCirco($nom, $sexe, null, $circo, $this); |
---|
100 | if (!$depute) print "WARNING: Auteur introuvable in ".$this->source."/".$this->id." : ".$nom." // ".$sexe." // ".$orga."//".$fonction."\n"; |
---|
101 | else { |
---|
102 | if ($debug) echo $depute->nom."\n"; |
---|
103 | $this->addParlementaire($depute, $fonction, $orga); |
---|
104 | $depute->free(); |
---|
105 | } |
---|
106 | } |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | public function addParlementaire($depute, $fonction, $organisme = 0) { |
---|
111 | //foreach(Doctrine::getTable('ParlementaireTexteloi')->createQuery('pa')->select('parlementaire_id')->where('texteloi_id = ?', $this->id)->fetchArray() as $parldt) if ($parldt['parlementaire_id'] == $depute->id) return true; |
---|
112 | |
---|
113 | $pd = new ParlementaireTexteloi(); |
---|
114 | $pd->_set('Parlementaire', $depute); |
---|
115 | $pd->_set('Texteloi', $this); |
---|
116 | if ($fonction === "Auteur") |
---|
117 | $pd->_set('importance', 1); |
---|
118 | else if ($fonction === "Rapporteur") |
---|
119 | $pd->_set('importance', 3); |
---|
120 | else if ($fonction === "Cosignataire") |
---|
121 | $pd->_set('importance', 5); |
---|
122 | if ($organisme && $fonction != "Cosignataire") { |
---|
123 | if (!(preg_match('/^ pour le groupe/', $organisme))) { |
---|
124 | $fonction .= " pour l"; |
---|
125 | if (preg_match('/^[aeiouyh]/i', $organisme)) |
---|
126 | $fonction .= "'"; |
---|
127 | else if (preg_match('/^comit/i', $organisme)) |
---|
128 | $fonction .= "e "; |
---|
129 | else $fonction .= "a "; |
---|
130 | } |
---|
131 | $fonction .= $organisme; |
---|
132 | } |
---|
133 | $pd->_set('fonction', $fonction); |
---|
134 | if ($pd->save()) { |
---|
135 | $pd->free(); |
---|
136 | return true; |
---|
137 | } else return false; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | } |
---|