1 | <?php |
---|
2 | |
---|
3 | class amendementActions extends sfActions |
---|
4 | { |
---|
5 | static $seuil_amdmts = 8; |
---|
6 | |
---|
7 | public function executeShow(sfWebRequest $request) |
---|
8 | { |
---|
9 | $query = Doctrine::getTable('Amendement')->createquery('a') |
---|
10 | ->where('a.texteloi_id = ?', $request->getParameter('loi')) |
---|
11 | ->andWhere('a.numero = ?', $request->getParameter('numero')) |
---|
12 | ->andWhere('a.sort <> ?', 'Rectifié') |
---|
13 | ->leftJoin('a.ParlementaireAmendement pa') |
---|
14 | ->leftJoin('pa.Parlementaire p'); |
---|
15 | |
---|
16 | $this->amendement = $query->fetchOne(); |
---|
17 | $this->forward404Unless($this->amendement); |
---|
18 | |
---|
19 | if (!($section = $this->amendement->getSection())) |
---|
20 | $this->section = NULL; |
---|
21 | else $this->section = $section->getSection(1); |
---|
22 | |
---|
23 | $this->identiques = Doctrine::getTable('Amendement')->createQuery('a') |
---|
24 | ->where('content_md5 = ?', $this->amendement->content_md5) |
---|
25 | ->orderBy('numero') |
---|
26 | ->execute(); |
---|
27 | |
---|
28 | if (count($this->identiques) < 2) { |
---|
29 | $this->identiques = array(); |
---|
30 | } |
---|
31 | |
---|
32 | $this->seance = $this->amendement->getIntervention($this->amendement->numero); |
---|
33 | foreach($this->identiques as $a) { |
---|
34 | if ($this->seance) |
---|
35 | break; |
---|
36 | $this->seance = $this->amendement->getIntervention($a->numero); |
---|
37 | } |
---|
38 | |
---|
39 | $this->sous_admts = Doctrine_Query::create() |
---|
40 | ->select('a.id, a.numero') |
---|
41 | ->from('Amendement a, Tagging tg, tg.Tag t') |
---|
42 | ->where('a.texteloi_id = ?', $this->amendement->texteloi_id) |
---|
43 | ->andWhere('a.sort <> ?', 'Rectifié') |
---|
44 | ->andWhere('a.id = tg.taggable_id') |
---|
45 | ->andWhere('t.name LIKE ?', 'loi:sous_amendement_de=%') |
---|
46 | ->andWhere('t.triple_value = ?', $this->amendement->numero) |
---|
47 | ->orderBy('a.numero') |
---|
48 | ->fetchArray(); |
---|
49 | |
---|
50 | $this->titreloi = Doctrine::getTable('TitreLoi')->findLightLoi($this->amendement->texteloi_id); |
---|
51 | $this->loi = Doctrine::getTable('Texteloi')->findLoi($this->amendement->texteloi_id); |
---|
52 | } |
---|
53 | |
---|
54 | public function executeParlementaire(sfWebRequest $request) |
---|
55 | { |
---|
56 | $this->parlementaire = Doctrine::getTable('Parlementaire') |
---|
57 | ->findOneBySlug($request->getParameter('slug')); |
---|
58 | $this->forward404Unless($this->parlementaire); |
---|
59 | $this->amendements = Doctrine::getTable('Amendement')->createQuery('a') |
---|
60 | ->leftJoin('a.ParlementaireAmendement pa') |
---|
61 | ->where('pa.parlementaire_id = ?', $this->parlementaire->id) |
---|
62 | ->andWhere('a.sort <> ?', 'Rectifié') |
---|
63 | // ->andWhere('pa.numero_signataire <= ?', self::$seuil_amdmts) |
---|
64 | ->orderBy('a.date DESC, a.texteloi_id DESC, a.numero DESC'); |
---|
65 | |
---|
66 | $request->setParameter('rss', array(array('link' => '@parlementaire_amendements_rss?slug='.$this->parlementaire->slug, 'title'=>'Les derniers amendements de '.$this->parlementaire->nom.' en RSS'))); |
---|
67 | } |
---|
68 | |
---|
69 | public function executeParlementaireSection(sfWebRequest $request) |
---|
70 | { |
---|
71 | $this->parlementaire = Doctrine::getTable('Parlementaire')->findOneBySlug($request->getParameter('slug')); |
---|
72 | $this->forward404Unless($this->parlementaire); |
---|
73 | |
---|
74 | $this->section = Doctrine::getTable('Section')->find($request->getParameter('id')); |
---|
75 | $this->forward404Unless($this->section); |
---|
76 | |
---|
77 | $lois = $this->section->getTags(array('is_triple' => true, |
---|
78 | 'namespace' => 'loi', |
---|
79 | 'key' => 'numero', |
---|
80 | 'return' => 'value')); |
---|
81 | |
---|
82 | $this->qamendements = Doctrine::getTable('Amendement')->createQuery('a') |
---|
83 | ->leftJoin('a.ParlementaireAmendement pa') |
---|
84 | ->where('pa.parlementaire_id = ?', $this->parlementaire->id) |
---|
85 | ->andWhere('a.sort <> ?', 'Rectifié') |
---|
86 | ->andWhereIn('a.texteloi_id', $lois) |
---|
87 | ->orderBy('a.texteloi_id DESC, a.date DESC, a.numero DESC'); |
---|
88 | } |
---|
89 | |
---|
90 | public function executeSearch(sfWebRequest $request) |
---|
91 | { |
---|
92 | $this->mots = $request->getParameter('search'); |
---|
93 | $mots = $this->mots; |
---|
94 | $mcle = array(); |
---|
95 | |
---|
96 | if (preg_match_all('/("[^"]+")/', $mots, $quotes)) { |
---|
97 | foreach(array_values($quotes[0]) as $q) |
---|
98 | $mcle[] = '+'.$q; |
---|
99 | $mots = preg_replace('/\s*"([^\"]+)"\s*/', ' ', $mots); |
---|
100 | } |
---|
101 | |
---|
102 | foreach(split(' ', $mots) as $mot) { |
---|
103 | if ($mot && !preg_match('/^[\-\+]/', $mot)) |
---|
104 | $mcle[] = '+'.$mot; |
---|
105 | } |
---|
106 | |
---|
107 | $this->high = array(); |
---|
108 | foreach($mcle as $m) { |
---|
109 | $this->high[] = preg_replace('/^[+-]"?([^"]*)"?$/', '\\1', $m); |
---|
110 | } |
---|
111 | $sql = 'SELECT a.id FROM amendement a WHERE MATCH (a.texte,a.expose) AGAINST (\''.implode(' ', $mcle).'\' IN BOOLEAN MODE)'; |
---|
112 | $search = Doctrine_Manager::connection() |
---|
113 | ->getDbh() |
---|
114 | ->query($sql)->fetchAll(); |
---|
115 | $ids = array(); |
---|
116 | foreach($search as $s) |
---|
117 | $ids[] = $s['id']; |
---|
118 | |
---|
119 | $this->query = Doctrine::getTable('Amendement')->createQuery('a'); |
---|
120 | if (count($ids)) |
---|
121 | $this->query->whereIn('a.id', $ids); |
---|
122 | else if (count($mcle)) foreach($mcle as $m) { |
---|
123 | $this->query->andWhere('a.texte LIKE ?', '% '.$m.' %'); |
---|
124 | $this->query->orWhere('a.expose LIKE ?', '% '.$m.' %'); |
---|
125 | } else { |
---|
126 | $this->query->where('0'); |
---|
127 | return ; |
---|
128 | } |
---|
129 | |
---|
130 | if ($slug = $request->getParameter('parlementaire')) { |
---|
131 | $this->parlementaire = Doctrine::getTable('Parlementaire') |
---|
132 | ->findOneBySlug($slug); |
---|
133 | if ($this->parlementaire) |
---|
134 | $this->query->leftJoin('a.ParlementaireAmendement pa') |
---|
135 | ->andWhere('pa.parlementaire_id = ?', $this->parlementaire->id); |
---|
136 | } |
---|
137 | $this->query->orderBy('a.date DESC, a.texteloi_id DESC, a.numero DESC'); |
---|
138 | if ($request->getParameter('rss')) { |
---|
139 | $this->setTemplate('rss'); |
---|
140 | $this->feed = new sfRssFeed(); |
---|
141 | } else $request->setParameter('rss', array(array('link' => '@search_amendements_mots_rss?search='.$this->mots, 'title'=>'Les derniers amendements sur '.$this->mots.' en RSS'))); |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | public function executeFind(sfWebRequest $request) |
---|
146 | { |
---|
147 | $this->lois = split(',', $request->getParameter('loi')); |
---|
148 | $amdt = $request->getParameter('numero'); |
---|
149 | $this->forward404Unless(count($this->lois) && $amdt); |
---|
150 | if ($amdt == 'all' || $amdt == 'new' ) { |
---|
151 | if (count($this->lois) == 1) { |
---|
152 | $this->loi = Doctrine::getTable('TitreLoi')->findLightLoi($this->lois[0]); |
---|
153 | if (!$this->loi) |
---|
154 | $this->loi = Doctrine::getTable('Texteloi')->findLoi($this->lois[0]); |
---|
155 | } |
---|
156 | $this->amendements_query = Doctrine::getTable('Amendement') |
---|
157 | ->createQuery('a') |
---|
158 | ->where('a.sort <> ?', 'Rectifié'); |
---|
159 | for ($ct=0;$ct<count($this->lois);$ct++) |
---|
160 | $this->amendements_query->andWhere('a.texteloi_id = ?', $this->lois[$ct]); |
---|
161 | if ($amdt == 'new') |
---|
162 | $this->amendements_query->orderBy('a.texteloi_id DESC, a.created_at DESC, a.source'); |
---|
163 | else $this->amendements_query->orderBy('a.texteloi_id DESC, a.source'); |
---|
164 | return ; |
---|
165 | } |
---|
166 | $numeros = array(); |
---|
167 | if (count($this->lois) == 1 && preg_match('/^(\d+)([A-Z])$/i', $amdt, $match)) { |
---|
168 | $numero = ($match[1]+0).strtoupper($match[2]); |
---|
169 | $this->redirect('@amendement?loi='.$this->lois[0].'&numero='.$numero); |
---|
170 | } else if (preg_match('/(\d+[A-Z]?)-(\d+[A-Z]?)/i', $amdt, $match)) { |
---|
171 | if (preg_match('/^(\d+)[A-Z]$/i', $match[1], $match2)) $numsta = $match2[1]; |
---|
172 | else $numsta = $match[1]; |
---|
173 | if (preg_match('/^(\d+)[A-Z]$/i', $match[2], $match2)) $numsto = $match2[1]; |
---|
174 | else $numsto = $match[2]; |
---|
175 | for($cpt = $numsta ; $cpt <= $numsto ; $cpt++) |
---|
176 | array_push($numeros, $cpt); |
---|
177 | } else { |
---|
178 | preg_match_all('/\D*(\d+)[A-Z]?\D*/i', $amdt, $match); |
---|
179 | $numeros = $match[1]; |
---|
180 | } |
---|
181 | $amendements = array(); |
---|
182 | foreach($this->lois as $loi) foreach($numeros as $numero) { |
---|
183 | $query = PluginTagTable::getObjectTaggedWithQuery('Amendement', array('loi:amendement='.$numero)); |
---|
184 | $query->andWhere('texteloi_id = ?', $loi) |
---|
185 | ->andWhere('sort <> ?', 'Rectifié'); |
---|
186 | $res = $query->execute(); |
---|
187 | if (count($res)) foreach ($res as $amd) { |
---|
188 | $amendements[$amd->id] = $amd; |
---|
189 | } |
---|
190 | } |
---|
191 | if (count($amendements) == 1) { |
---|
192 | $a = array_keys($amendements); |
---|
193 | $this->redirect('@amendement_id?id='.$a[0]); |
---|
194 | } |
---|
195 | $this->amendements = array_values($amendements); |
---|
196 | } |
---|
197 | |
---|
198 | public function executeRedirect(sfWebRequest $request) |
---|
199 | { |
---|
200 | $id = $request->getParameter('id'); |
---|
201 | $a = Doctrine::getTable('Amendement')->find($id); |
---|
202 | $this->forward404Unless($a); |
---|
203 | $this->redirect('@amendement?loi='.$a->texteloi_id.'&numero='.$a->numero); |
---|
204 | } |
---|
205 | } |
---|