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