1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * This class has been auto-generated by the Doctrine ORM Framework |
---|
5 | */ |
---|
6 | class Intervention extends BaseIntervention |
---|
7 | { |
---|
8 | public function getLink() { |
---|
9 | sfProjectConfiguration::getActive()->loadHelpers(array('Url')); |
---|
10 | return url_for('@interventions_seance?seance='.$this->getSeance()->id).'#inter_'.$this->getMd5(); |
---|
11 | } |
---|
12 | |
---|
13 | public function getPersonne() { |
---|
14 | sfProjectConfiguration::getActive()->loadHelpers(array('Url')); |
---|
15 | return $this->getIntervenant()->getNom(); |
---|
16 | } |
---|
17 | |
---|
18 | public function __toString() { |
---|
19 | if (strlen($this->intervention) > 1024) |
---|
20 | return substr($this->intervention, 0, 512).'...'; |
---|
21 | return $this->intervention; |
---|
22 | } |
---|
23 | |
---|
24 | public function getTitre() { |
---|
25 | $titre = 'Intervention du '.$this->date.' '; |
---|
26 | if ($this->type == 'commission') { |
---|
27 | $titre .= 'en commission'; |
---|
28 | }else{ |
---|
29 | $titre .= 'en hémicycle'; |
---|
30 | } |
---|
31 | return $titre; |
---|
32 | } |
---|
33 | |
---|
34 | public function setSeance($type, $date, $heure, $session, $commission = null) { |
---|
35 | $this->setType($type); |
---|
36 | if ($type == 'commission') { |
---|
37 | $commission = Doctrine::getTable('Organisme')->findOneByNomOrCreateIt($commission, 'parlementaire'); |
---|
38 | $seance = $commission->getSeanceByDateAndMomentOrCreateIt($date, $heure, $session); |
---|
39 | $commission->free(); |
---|
40 | } else{ |
---|
41 | $seance = Doctrine::getTable('Seance')->findOneOrCreateIt('hemicycle', $date, $heure, $session); |
---|
42 | } |
---|
43 | $id = $this->_set('seance_id', $seance->id); |
---|
44 | $seance->free(); |
---|
45 | return $id; |
---|
46 | } |
---|
47 | public function setPersonnaliteByNom($nom, $fonction = null) |
---|
48 | { |
---|
49 | $this->setFonction($fonction); |
---|
50 | if (!preg_match('/ministre|secr[^t]+taire [^t]+tat|commissaire|garde des sceaux/i', $fonction)) { |
---|
51 | $personne = Doctrine::getTable('Parlementaire')->findOneByNom($nom); |
---|
52 | if (!$personne) { |
---|
53 | $personne = Doctrine::getTable('Parlementaire')->similarTo($nom); |
---|
54 | } |
---|
55 | if ($personne) { |
---|
56 | return $this->setParlementaire($personne); |
---|
57 | } |
---|
58 | } |
---|
59 | $personne = Doctrine::getTable('Personnalite')->findOneByNom($nom); |
---|
60 | if (!$personne) { |
---|
61 | $personne = Doctrine::getTable('Personnalite')->similarTo($nom); |
---|
62 | } |
---|
63 | if (!$personne) { |
---|
64 | $personne = new Personnalite(); |
---|
65 | $personne->setNom($nom); |
---|
66 | $personne->save(); |
---|
67 | } |
---|
68 | if ($personne) { |
---|
69 | return $this->setPersonnalite($personne,$fonction); |
---|
70 | } |
---|
71 | } |
---|
72 | public function setParlementaire($parlementaire, $from_db = null) { |
---|
73 | if (isset($parlementaire->id)) { |
---|
74 | $this->_set('parlementaire_id', $parlementaire->id); |
---|
75 | if (!$from_db) |
---|
76 | $this->getSeance()->addPresence($parlementaire, 'intervention', $this->source); |
---|
77 | $parlementaire->free(); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | public function hasIntervenant() { |
---|
82 | if ($this->parlementaire_id) { |
---|
83 | return true; |
---|
84 | } |
---|
85 | if ($this->personnalite_id) { |
---|
86 | return true; |
---|
87 | } |
---|
88 | return false; |
---|
89 | } |
---|
90 | |
---|
91 | public function getIntervenant() { |
---|
92 | $perso = $this->Parlementaire; |
---|
93 | if (!$perso->id) |
---|
94 | $perso = $this->Personnalite; |
---|
95 | return $perso; |
---|
96 | } |
---|
97 | |
---|
98 | public function getNomAndFonction() { |
---|
99 | $res = null; |
---|
100 | if ($this->hasIntervenant()) { |
---|
101 | $res = $this->getIntervenant()->getNom(); |
---|
102 | if ($this->getFonction()) |
---|
103 | $res .= ', '.$this->getFonction(); |
---|
104 | } |
---|
105 | return $res; |
---|
106 | } |
---|
107 | |
---|
108 | public function setContexte($contexte, $date = null, $timestamp = null, $tlois = null, $debug = 0) { |
---|
109 | $tlois = preg_replace('/[^,\d]+/', '', $tlois); |
---|
110 | $tlois = preg_replace('/\s+,/', ',', $tlois); |
---|
111 | $tlois = preg_replace('/,\s+/', ',', $tlois); |
---|
112 | $lois = explode(',', $tlois); |
---|
113 | $loisstring = ""; |
---|
114 | foreach($lois as $loi) if ($loi) { |
---|
115 | $tag = 'loi:numero='.$loi; |
---|
116 | $this->addTag($tag); |
---|
117 | if ($loisstring == "") $loisstring = "t.numero = $loi"; |
---|
118 | else $loisstring .= " OR t.numero = $loi"; |
---|
119 | } |
---|
120 | if ($lois[0]) { |
---|
121 | $urls = Doctrine_Query::create() |
---|
122 | ->select('distinct(t.url_an)') |
---|
123 | ->from('Texteloi t') |
---|
124 | ->where('t.type = ? OR t.type = ? OR t.type = ? OR t.type = ?', array("Proposition de loi", "Proposition de résolution", "Projet de loi", "Texte de la commission")) |
---|
125 | ->andWhere($loisstring) |
---|
126 | ->fetchArray(); |
---|
127 | $ct = count($urls); |
---|
128 | if ($ct == 0) $urls = Doctrine_Query::create() |
---|
129 | ->select('distinct(t.url_an)') |
---|
130 | ->from('Texteloi t') |
---|
131 | ->where($loisstring) |
---|
132 | ->fetchArray(); |
---|
133 | $ct = count($urls); |
---|
134 | if ($ct > 1) { |
---|
135 | $this->setSection(Doctrine::getTable('Section')->findOneByContexteOrCreateIt($contexte, $date, $timestamp)); |
---|
136 | if ($debug) { |
---|
137 | print "WARNING : Intervention $this->id has tags lois corresponding to multiple url_ans : "; |
---|
138 | foreach ($urls as $url) |
---|
139 | print $url['distinct']." ; "; |
---|
140 | print " => Saving to section $this->Section->id\n"; |
---|
141 | $debug = 0; |
---|
142 | } |
---|
143 | return $debug; |
---|
144 | } |
---|
145 | if ($ct == 0) $this->setSection(Doctrine::getTable('Section')->findOneByContexteOrCreateIt($contexte, $date, $timestamp)); |
---|
146 | else if ($ct == 1) { |
---|
147 | $section1 = Doctrine::getTable('Section')->findOneByContexte($contexte); |
---|
148 | $section2 = Doctrine::getTable('Section')->findOneByUrlAn($urls[0]['distinct']); |
---|
149 | if ($section2) { |
---|
150 | if (!$section1) |
---|
151 | $this->setSection(Doctrine::getTable('Section')->findOneByContexteOrCreateIt(str_replace(trim(preg_replace('/^([^>])(>.*)?$/', '\\1', $contexte)), $section2->titre, $contexte), $date, $timestamp)); |
---|
152 | else if ($section1->section_id == $section2->id) |
---|
153 | $this->setSection(Doctrine::getTable('Section')->findOneByContexteOrCreateIt($section1->titre_complet, $date, $timestamp)); |
---|
154 | else { |
---|
155 | $this->setSection(Doctrine::getTable('Section')->findOneByContexteOrCreateIt($contexte, $date, $timestamp)); |
---|
156 | if ($debug) { |
---|
157 | print "WARNING : Intervention $this->id has tags lois corresponding to another section $section2->id"; |
---|
158 | print " => Saving to section $this->Section->id\n"; |
---|
159 | $debug = 0; |
---|
160 | } |
---|
161 | return $debug; |
---|
162 | } |
---|
163 | } |
---|
164 | else { |
---|
165 | $section1 = Doctrine::getTable('Section')->findOneByContexteOrCreateIt($contexte, $date, $timestamp); |
---|
166 | $this->setSection($section1); |
---|
167 | $section1->setUrlAn($urls[0]['distinct']); |
---|
168 | $section1->save(); |
---|
169 | } |
---|
170 | } |
---|
171 | if ($this->section_id != 1) { |
---|
172 | $titre = $this->Section->Section->getTitre(); |
---|
173 | if (!(preg_match('/(cloture|ouverture|question|ordre du jour|calendrier|élection.*nouveau|démission|reprise|examen simplifié|cessation.*mandat|proclamation|souhaits)/i', $titre))) { |
---|
174 | foreach($lois as $loi) { |
---|
175 | $tag = 'loi:numero='.$loi; |
---|
176 | $this->Section->addTag($tag); |
---|
177 | if ($this->Section->section_id && $this->Section->Section->id && $this->Section->section_id != $this->section_id) |
---|
178 | $this->Section->Section->addTag($tag); |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | return $debug; |
---|
183 | } else { |
---|
184 | $this->setSection(Doctrine::getTable('Section')->findOneByContexteOrCreateIt($contexte, $date, $timestamp)); |
---|
185 | return $debug; |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | public function setAmendements($tamendements) { |
---|
190 | $tamendements = preg_replace('/[^,\d]+/', '', $tamendements); |
---|
191 | $amends = preg_split('/\s*,\s*/', $tamendements); |
---|
192 | foreach($amends as $amend) { |
---|
193 | $tag = 'loi:amendement='.$amend; |
---|
194 | $this->addTag($tag); |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | public function setIntervention($s) { |
---|
199 | $this->_set('nb_mots', str_word_count($s)); |
---|
200 | return $this->_set('intervention', $s); |
---|
201 | } |
---|
202 | |
---|
203 | public function getIntervention($args = array()) { |
---|
204 | $inter = $this->_get('intervention'); |
---|
205 | if ($this->type == 'loi' && isset($args['linkify_amendements']) && $linko = $args['linkify_amendements']) { |
---|
206 | $inter = preg_replace('/\(([^\)]+)\)/', '(<i>\\1</i>)', $inter); |
---|
207 | if (preg_match_all('/(amendements?[,\s]+(identiques?)?[,\s]*)((n[°os\s]*|\d+\s*|,\s*|à\s*|et\s*|rectifié\s*)+)/', $inter, $match)) { |
---|
208 | $lois = implode(',', $this->getTags(array('is_triple' => true, |
---|
209 | 'namespace' => 'loi', |
---|
210 | 'key' => 'numero', |
---|
211 | 'return' => 'value'))); |
---|
212 | for ($i = 0 ; $i < count($match[0]) ; $i++) { |
---|
213 | $match_protected = preg_replace('/(\s*)(\d[\d\s\à]*rectifiés?|\d[\d\s\à]*)(,\s*|\s*et\s*)*/', '\1%\2%\3', $match[3][$i]); |
---|
214 | if (preg_match_all('/\s*%([^%]+)%(,\s*|\s*et\s*)*/', $match_protected, $amends)) { |
---|
215 | $replace = $match_protected; |
---|
216 | foreach($amends[1] as $amend) { |
---|
217 | $am = preg_replace('/à+/', '-', $amend); |
---|
218 | $am = preg_replace('/[^\d\-]+/', '',$am); |
---|
219 | $link = str_replace('LLL', urlencode($lois), $linko); |
---|
220 | $link = str_replace('AAA', urlencode($am), $link); |
---|
221 | $replace = preg_replace('/%'.$amend.'%/', '<a name="amend_'.$am.'" href="'.$link.'">'.$amend.'</a> ', $replace); |
---|
222 | } |
---|
223 | $inter = preg_replace('/'.$match[1][$i].$match[3][$i].'/', $match[1][$i].$replace, $inter); |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | } |
---|
228 | return $inter; |
---|
229 | } |
---|
230 | } |
---|