1 | <?php |
---|
2 | $sf_response->setTitle("Recherche de $query"); $style = "xneth"; |
---|
3 | |
---|
4 | function url_search($query, $args) |
---|
5 | { |
---|
6 | $extra = ''; |
---|
7 | $url = "solr/search?query=".$query; |
---|
8 | foreach($args as $key => $value) { |
---|
9 | if (is_array($value)) { |
---|
10 | if (count($value)) { $extra .= '&'.$key.'='.implode(',', array_keys($value)); } |
---|
11 | } |
---|
12 | else { $extra .= '&'.$key.'='.$value; } |
---|
13 | } |
---|
14 | return $url.$extra; |
---|
15 | } |
---|
16 | |
---|
17 | function link_search($text, $query, $args, $options) |
---|
18 | { |
---|
19 | if($options) { return link_to($text, url_search($query, $args), $options); } |
---|
20 | else { return link_to($text, url_search($query, $args)); } |
---|
21 | } |
---|
22 | |
---|
23 | function addToDate($date, $interval) { |
---|
24 | $date = explode("T", $date); |
---|
25 | $date = explode("-", $date[0]); |
---|
26 | if($interval == 'mois') { |
---|
27 | $date = mktime(0, 0, 0, $date[1] + 1, $date[2], $date[0]); |
---|
28 | #int mktime ("H","m","s","M","j","Y", -1) |
---|
29 | } |
---|
30 | else { $date = mktime(0, 0, 0, $date[1], $date[2] - 1, $date[0]); } |
---|
31 | $date = date("Y-m-d", $date).'T00%3A00%3A00Z'; |
---|
32 | return $date; |
---|
33 | } |
---|
34 | |
---|
35 | $recherche = preg_replace('/"/', '"', $query); |
---|
36 | ?> |
---|
37 | <script type="text/javascript"> |
---|
38 | function urlParams(params) { |
---|
39 | param = new Object(); |
---|
40 | if(jQuery.isArray(params)) { |
---|
41 | jQuery.each(params, function() { |
---|
42 | val = this.split('='); |
---|
43 | param[val[0]] = val[1]; |
---|
44 | }); |
---|
45 | } |
---|
46 | else { |
---|
47 | val = params.split('='); |
---|
48 | param[val[0]] = val[1]; |
---|
49 | } |
---|
50 | return param; |
---|
51 | } |
---|
52 | |
---|
53 | periode = new Array(); |
---|
54 | date_href = new Array(); |
---|
55 | nb_li = 0; |
---|
56 | bh = 0; |
---|
57 | nh = 0; |
---|
58 | if(location.search.substring(1)) { parametre = urlParams(location.search.substring(1).split('&')); } |
---|
59 | else { parametre = new Object(); } |
---|
60 | |
---|
61 | $(document).ready(function() { |
---|
62 | $(".date li").each(function() { |
---|
63 | if($(this).height() > bh) { bh = $(this).height(); } |
---|
64 | date_li = $(this).find('a').attr("title").split(':'); |
---|
65 | date_href[nb_li] = $(this).find('a').attr("href"); |
---|
66 | $(this).find("#hover_graph").attr("onclick", "document.location.replace('http://"+location.host+date_href[nb_li]+"')"); |
---|
67 | $(this).find("#hover_graph").css("cursor", "pointer"); |
---|
68 | periode[nb_li] = date_li[0]; |
---|
69 | nb_li++; |
---|
70 | }); |
---|
71 | if(bh <= 30) { |
---|
72 | $(".date li").each(function() { |
---|
73 | nh = $(this).height() * 2; $(this).height(nh); |
---|
74 | }); |
---|
75 | bh = bh * 2; |
---|
76 | } |
---|
77 | if(bh <= 170) { bh = bh + 30; $(".date").height(bh); } |
---|
78 | $(".date").fadeIn(300); /* à revoir */ |
---|
79 | $(function() { |
---|
80 | $("#slider_date_graph").slider({ |
---|
81 | range: true, |
---|
82 | min: 0, |
---|
83 | max: nb_li-1, |
---|
84 | values: [0, nb_li], |
---|
85 | slide: function(event, ui) { |
---|
86 | from = date_href[ui.values[0]].split('?'); |
---|
87 | from = urlParams(from[1].split('&')); |
---|
88 | from = from["date"].split('%2C'); |
---|
89 | to = date_href[ui.values[1]].split('?'); |
---|
90 | to = urlParams(to[1].split('&')); |
---|
91 | to = to["date"].split('%2C'); |
---|
92 | parametre["date"] = from[0]+'%2C'+to[0]; |
---|
93 | |
---|
94 | lien = "?date="+parametre.date; |
---|
95 | if(parametre.parlementaire != undefined) { lien = lien+"&parlementaire="+parametre.parlementaire; } |
---|
96 | if(parametre.object_name != undefined) { lien = lien+"&object_name="+parametre.object_name; } |
---|
97 | if(parametre.tag != undefined) { lien = lien+"&tag="+parametre.tag; } |
---|
98 | /* date parlementaire object_name tag */ |
---|
99 | if(ui.values[0] == ui.values[1]) { |
---|
100 | texte_periode = '<a href="'+lien+'">'+periode[ui.values[0]]+'</a>'; |
---|
101 | } |
---|
102 | else { |
---|
103 | texte_periode = '<a href="'+lien+'">entre '+periode[ui.values[0]]+' et '+ periode[ui.values[1]]+'</a>'; |
---|
104 | } |
---|
105 | |
---|
106 | $("#periode").text(""); |
---|
107 | $("#periode").append(texte_periode); |
---|
108 | } |
---|
109 | }); |
---|
110 | $("#periode").text('entre ' + periode[$("#slider_date_graph").slider("values", 0)] + ' et ' + periode[$("#slider_date_graph").slider("values", 1)]); |
---|
111 | }); |
---|
112 | }); |
---|
113 | </script> |
---|
114 | |
---|
115 | <div class="solr"> |
---|
116 | <div class="searchbox"> |
---|
117 | <form> |
---|
118 | <p> |
---|
119 | <input name="search" value="<?php echo $recherche; ?>" /> |
---|
120 | <input type="submit" value="Rechercher"/> |
---|
121 | </p> |
---|
122 | </form> |
---|
123 | </div> |
---|
124 | <?php |
---|
125 | $start = explode("T", $start); |
---|
126 | if($end == 'NOW') { $end = date("Y-m-d").'T00%3A00%3A00Z'; } |
---|
127 | $end = explode("T", $end); |
---|
128 | ?> |
---|
129 | <h1><?php |
---|
130 | switch ($vue) { |
---|
131 | case "jour": |
---|
132 | echo 'Résultats pour "'.$recherche.'" le '.myTools::displayShortDate($start[0]); |
---|
133 | $graph = 0; |
---|
134 | break; |
---|
135 | case "mois": |
---|
136 | echo 'Résultats pour "'.$recherche.'" en '.myTools::displayMoisAnnee($start[0]); |
---|
137 | $graph = 1; |
---|
138 | break; |
---|
139 | case "par_jour": |
---|
140 | echo 'Résultats pour "'.$recherche.'" entre le '.myTools::displayShortDate($start[0]).' et le '.myTools::displayShortDate($end[0]); |
---|
141 | $graph = 1; |
---|
142 | break; |
---|
143 | case "par_mois": |
---|
144 | echo 'Résultats pour "'.$recherche.'" entre '.myTools::displayMoisAnnee($start[0]).' et '.myTools::displayMoisAnnee($end[0]); |
---|
145 | $graph = 1; |
---|
146 | break; |
---|
147 | default: |
---|
148 | echo 'Recherche de "'.$recherche; |
---|
149 | $graph = 1; |
---|
150 | } |
---|
151 | ?></h1> |
---|
152 | <?php if($graph) { |
---|
153 | $width_date = 900; |
---|
154 | $left = 2; |
---|
155 | $espacement = 4; |
---|
156 | $width = (($width_date - $left) / count($fdates['values'])) - $espacement; |
---|
157 | ?> |
---|
158 | <div class="cont_date_graph"> |
---|
159 | <span>Affiner par date :</span> <span id="periode"></span> |
---|
160 | <div class="date" style="width: <?php echo $width_date ?>px;"> |
---|
161 | <ul> |
---|
162 | <?php $i = 0; foreach($fdates['values'] as $date => $nb) : |
---|
163 | $i++; |
---|
164 | $height = round($nb['pc']*100/($fdates['max']) * 2); |
---|
165 | $padding = 200-$height; ?> |
---|
166 | <li<?php echo ' style="list-style-image: none; width: '.$width.'px; height: '.$height.'px; left: '.$left.'px;">'; |
---|
167 | $left = $left + $width; if($i < (count($fdates['values']))) { $left = $left + $espacement; } |
---|
168 | $newargs = $selected; |
---|
169 | |
---|
170 | $title_date = explode("T", $date); |
---|
171 | |
---|
172 | $newargs['date'] = $date.'%2C'.$date; |
---|
173 | |
---|
174 | if(($vue == 'jour') or ($vue == 'par_jour') or ($vue == 'mois')){ |
---|
175 | $title_date = myTools::displayShortDate($title_date[0]).' : '.$nb['nb'].' résultats'; |
---|
176 | } |
---|
177 | if($vue == 'par_mois') { |
---|
178 | $title_date = ucfirst(myTools::displayMoisAnnee($title_date[0])).' : '.$nb['nb'].' résultats'; |
---|
179 | } |
---|
180 | if($vue == 'par_mois') { |
---|
181 | $newargs['date'] = $date.'%2C'.addToDate($date, 'mois'); |
---|
182 | } |
---|
183 | |
---|
184 | echo '<div id="hover_graph" title="'.$title_date.'" style="width: '.$width.'px; height: '.$padding.'px; bottom: '.$height.'px;"></div><span id="text_graph">'.link_search($nb['nb'], $query, $newargs, array('title' => $title_date)).'</span>'; |
---|
185 | |
---|
186 | # echo ' '.$nb['nb'].' résultats ('; printf('%02d', $nb['pc']*100/($fdates['max'])); echo '%)'; |
---|
187 | ?> |
---|
188 | </li> |
---|
189 | <?php endforeach; ?> |
---|
190 | </ul> |
---|
191 | </div> |
---|
192 | <div id="slider_date_graph"></div> |
---|
193 | </div> |
---|
194 | <?php } ?> |
---|
195 | <div class="nb_results"> |
---|
196 | <h2>Résultats <?php echo $results['start']+1; ?> à <?php echo min($results['end'],$results['numFound']); ?> sur <?php echo $results['numFound']; ?> <strong>triés par <?php echo $sort_type; ?></strong> - |
---|
197 | <span class="tri"> |
---|
198 | <?php |
---|
199 | $newargs = $selected; |
---|
200 | if ($sort) { |
---|
201 | if (isset($newargs['sort'])) { $newargs['sort'] = 0; } |
---|
202 | echo link_search('trier par pertinence', $query, $newargs, 0); |
---|
203 | } |
---|
204 | else { |
---|
205 | $newargs['sort'] = 1; |
---|
206 | echo link_search('trier par date', $query, $newargs, 0); |
---|
207 | } |
---|
208 | ?> |
---|
209 | </span></h2> |
---|
210 | </div> |
---|
211 | <div class="options"> |
---|
212 | <div class="mail"> |
---|
213 | <h3>Alerte email</h3> |
---|
214 | <?php |
---|
215 | $args = ''; |
---|
216 | foreach(array_keys($selected) as $k) { |
---|
217 | if (!is_array($selected[$k])) |
---|
218 | continue; |
---|
219 | if ($args) |
---|
220 | $args .= '&'; |
---|
221 | $args.= "$k=".implode(',', array_keys($selected[$k])); |
---|
222 | } |
---|
223 | echo link_to('Recevoir un email lorsque de nouveaux résultats seront publiés pour cette recherche', 'alerte/create?filter='.urlencode($args).'&query='.urlencode($query)); |
---|
224 | |
---|
225 | global $facetName2HumanName; |
---|
226 | $facetName2HumanName = array( |
---|
227 | 'Parlementaire' => 'Filtrer par Parlementaire', |
---|
228 | 'Types' => 'Filtrer par type de document', |
---|
229 | 'Tags' => 'Filtrer par tags', |
---|
230 | 'TexteLoi' => 'Document parlementaires', |
---|
231 | 'QuestionEcrite' => 'Questions ecrites', |
---|
232 | 'Tags' => 'Filtrer par tags' |
---|
233 | ); |
---|
234 | function facet2Human($id) { |
---|
235 | global $facetName2HumanName; |
---|
236 | if (!isset($facetName2HumanName[$id])) { |
---|
237 | return $id; |
---|
238 | } |
---|
239 | return $facetName2HumanName[$id]; |
---|
240 | } |
---|
241 | ?> |
---|
242 | </div> |
---|
243 | <div class="facets"> |
---|
244 | <h3>Affiner la recherche</h3> |
---|
245 | <?php foreach(array_keys($facet) as $k) { if (isset($facet[$k]['values']) && count($facet[$k]['values'])) : ?> |
---|
246 | <div class="<?php echo $k; ?>"> |
---|
247 | <p><?php echo facet2Human($facet[$k]['name']); ?></p> |
---|
248 | <ul> |
---|
249 | <?php foreach($facet[$k]['values'] as $value => $nb) : if ($nb) : |
---|
250 | $is_selected = isset($selected[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value]) && |
---|
251 | $selected[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value]; |
---|
252 | ?> |
---|
253 | <li<?php if ($is_selected) echo ' class="selected"'; ?>><?php |
---|
254 | $newargs = $selected; |
---|
255 | if ($is_selected) |
---|
256 | unset($newargs[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value]); |
---|
257 | else |
---|
258 | $newargs[$facet[$k]['facet_field']][$facet[$k]['prefix'].$value] = 1; |
---|
259 | echo link_search(facet2Human($value), $query, $newargs, 0); ?> (<?php echo $nb; ?>) |
---|
260 | </li> |
---|
261 | <?php endif; endforeach; ?> |
---|
262 | </ul> |
---|
263 | </div> |
---|
264 | <?php endif; } ?> |
---|
265 | </div> |
---|
266 | </div> |
---|
267 | <div class="results"> |
---|
268 | <?php foreach ($results['docs'] as $record) : ?> |
---|
269 | <div class="item"> |
---|
270 | <h4><a href="<?php echo $record['link']; ?>"><?php echo $record['titre']; ?></a></h4> |
---|
271 | <?php if ($record['photo']) { ?> |
---|
272 | <p class="photo"><a href="<?php echo $record['link']; ?>" rel="nofollow"><?php echo $record['photo']; ?></a></p> |
---|
273 | <?php } ?> |
---|
274 | <p class="intervenant"><a href="<?php echo $record['link']; ?>" rel="nofollow"><?php echo $record['personne']; ?></a></p> |
---|
275 | <p class="content"><?php echo $record['highlighting']; ?></p> |
---|
276 | <p class="more"><a href="<?php echo $record['link']; ?>">Consulter</a></p> |
---|
277 | </div> |
---|
278 | <div class="record"> |
---|
279 | </div> |
---|
280 | <?php endforeach; ?> |
---|
281 | </div> |
---|
282 | <div class="pager"> |
---|
283 | <div class="next"> |
---|
284 | <?php |
---|
285 | if ($results['end']-1 != $results['numFound']) { |
---|
286 | $newargs = $selected; |
---|
287 | $newargs['page'][$results['page'] + 1] = 1; |
---|
288 | echo link_search('page suivante', $query, $newargs, 0); |
---|
289 | } |
---|
290 | ?> |
---|
291 | </div> |
---|
292 | <div class="last"> |
---|
293 | <?php |
---|
294 | $newargs = $selected; |
---|
295 | $newargs['page'][$results['page'] - 1] = 1; |
---|
296 | if ($results['page'] > 1) { |
---|
297 | if (isset($newargs['page'][1])) |
---|
298 | unset($newargs['page'][1]); |
---|
299 | echo link_search('page précédente', $query, $newargs, 0); |
---|
300 | } |
---|
301 | ?> |
---|
302 | </div> |
---|
303 | </div> |
---|
304 | </div> |
---|