1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * section actions. |
---|
5 | * |
---|
6 | * @package cpc |
---|
7 | * @subpackage section |
---|
8 | * @author Your name here |
---|
9 | * @version SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $ |
---|
10 | */ |
---|
11 | class sectionActions extends sfActions |
---|
12 | { |
---|
13 | /** |
---|
14 | * Executes index action |
---|
15 | * |
---|
16 | * @param sfRequest $request A request object |
---|
17 | */ |
---|
18 | public function executeParlementaire(sfWebRequest $request) |
---|
19 | { |
---|
20 | $this->parlementaire = Doctrine::getTable('Parlementaire')->findOneBySlug($request->getParameter('slug')); |
---|
21 | $this->forward404Unless($this->parlementaire); |
---|
22 | $this->titre = 'Dossiers parlementaires'; |
---|
23 | $this->response->setTitle($this->titre.' de '.$this->parlementaire->nom); |
---|
24 | } |
---|
25 | |
---|
26 | public function executeParlementaireSection(sfWebRequest $request) |
---|
27 | { |
---|
28 | $this->parlementaire = Doctrine::getTable('Parlementaire')->findOneBySlug($request->getParameter('slug')); |
---|
29 | $this->forward404Unless($this->parlementaire); |
---|
30 | |
---|
31 | $this->section = Doctrine::getTable('Section')->find($request->getParameter('id')); |
---|
32 | $this->forward404Unless($this->section); |
---|
33 | |
---|
34 | $this->qinterventions = Doctrine::getTable('Intervention')->createQuery('i') |
---|
35 | ->where('i.parlementaire_id = ?', $this->parlementaire->id) |
---|
36 | ->leftJoin('i.Section s') |
---|
37 | ->andWhere('(s.section_id = ? OR s.id = ?)', array($this->section->id, $this->section->id)) |
---|
38 | ->andWhere('i.nb_mots > 20') |
---|
39 | ->orderBy('i.date DESC, i.timestamp ASC'); |
---|
40 | } |
---|
41 | public function executeShow(sfWebRequest $request) |
---|
42 | { |
---|
43 | $secid = $request->getParameter('id'); |
---|
44 | $this->forward404Unless($secid); |
---|
45 | if ($option = Doctrine::getTable('VariableGlobale')->findOneByChamp('linkdossiers')) { |
---|
46 | $links = unserialize($option->getValue()); |
---|
47 | if (isset($links[$secid])) |
---|
48 | $secid = $links[$secid]; |
---|
49 | } |
---|
50 | $this->section = Doctrine::getTable('Section')->find($secid); |
---|
51 | $this->forward404Unless($this->section); |
---|
52 | |
---|
53 | $lois = $this->section->getTags(array('is_triple' => true, |
---|
54 | 'namespace' => 'loi', |
---|
55 | 'key' => 'numero', |
---|
56 | 'return' => 'value')); |
---|
57 | $this->docs = array(); |
---|
58 | if ($this->section->url_an || $lois) { |
---|
59 | $qtextes = Doctrine_Query::create() |
---|
60 | ->select('t.id, t.type, t.type_details, t.titre') |
---|
61 | ->from('Texteloi t') |
---|
62 | ->whereIn('t.numero', $lois); |
---|
63 | if ($this->section->url_an) |
---|
64 | $qtextes->orWhere('t.url_an = ?', $this->section->url_an); |
---|
65 | $qtextes->orderBy('t.numero, t.annexe'); |
---|
66 | $textes = $qtextes->fetchArray(); |
---|
67 | |
---|
68 | $textes_loi = Doctrine_Query::create() |
---|
69 | ->select('t.texteloi_id, t.titre') |
---|
70 | ->from('TitreLoi t') |
---|
71 | ->whereIn('t.texteloi_id', $lois) |
---|
72 | ->andWhere('t.chapitre IS NULL') |
---|
73 | ->andWhere('t.section is NULL') |
---|
74 | ->orderBy('t.texteloi_id') |
---|
75 | ->fetchArray(); |
---|
76 | |
---|
77 | foreach ($textes_loi as $doc) |
---|
78 | $this->docs[$doc['texteloi_id']] = $doc; |
---|
79 | foreach ($textes as $texte) |
---|
80 | $this->docs[$texte['id']] = $texte; |
---|
81 | foreach ($lois as $loi) { |
---|
82 | $loi = sprintf("%04d", $loi); |
---|
83 | if (!isset($this->docs["$loi"])) |
---|
84 | $this->docs["$loi"] = null; |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | $amdmts_lois = Doctrine_Query::create()->select('distinct(a.texteloi_id)')->from('Amendement a')->whereIn('a.texteloi_id', $lois)->fetchArray(); |
---|
89 | $this->lois_amendees = array(); |
---|
90 | foreach($amdmts_lois as $loi) |
---|
91 | array_push($this->lois_amendees, $loi['distinct']); |
---|
92 | sort($this->lois_amendees); |
---|
93 | |
---|
94 | $inters = Doctrine_Query::create() |
---|
95 | ->select('i.id') |
---|
96 | ->from('Intervention i') |
---|
97 | ->leftJoin('i.Section s') |
---|
98 | ->where('(i.section_id = ? OR s.section_id = ?)', array($this->section->id, $this->section->id)) |
---|
99 | ->andWhere('i.nb_mots > 20') |
---|
100 | ->fetchArray(); |
---|
101 | |
---|
102 | $interventions = array(); |
---|
103 | foreach($inters as $i) { |
---|
104 | $interventions[] = $i['id']; |
---|
105 | } |
---|
106 | |
---|
107 | // $this->forward404Unless(count($interventions)); |
---|
108 | |
---|
109 | $this->qtag = Doctrine_Query::create() |
---|
110 | ->from('Tagging tg, tg.Tag t'); |
---|
111 | if (count($interventions)) |
---|
112 | $this->qtag->whereIn('tg.taggable_id', $interventions); |
---|
113 | else |
---|
114 | $this->qtag->where('false'); |
---|
115 | |
---|
116 | $this->ptag = Doctrine_Query::create() |
---|
117 | ->from('Intervention i') |
---|
118 | ->leftJoin('i.Parlementaire p') |
---|
119 | ->where('p.id IS NOT NULL') |
---|
120 | ->andWhere('((i.fonction != ? AND i.fonction != ? ) OR i.fonction IS NULL)', array('président', 'présidente')) |
---|
121 | ->groupBy('p.id') |
---|
122 | ->limit(30); |
---|
123 | if (count($interventions)) |
---|
124 | $this->ptag->whereIn('i.id', $interventions); |
---|
125 | else |
---|
126 | $this->ptag->where('false'); |
---|
127 | |
---|
128 | $request->setParameter('rss', array(array('link' => '@section_rss_commentaires?id='.$this->section->id, 'title'=>'Les commentaires sur '.$this->section->titre))); |
---|
129 | } |
---|
130 | |
---|
131 | public function executeList(sfWebRequest $request) |
---|
132 | { |
---|
133 | if (!($this->order = $request->getParameter('order'))) |
---|
134 | $this->order = 'plus'; |
---|
135 | $query = Doctrine::getTable('Section')->createQuery('s') |
---|
136 | ->where('s.id = s.section_id') |
---|
137 | ->andWhere('s.nb_interventions > 5'); |
---|
138 | if ($this->order == 'date') { |
---|
139 | $query->orderBy('s.max_date DESC'); |
---|
140 | $this->titre = 'Les derniers dossiers à l\'Assemblée'; |
---|
141 | } else if ($this->order == 'plus') { |
---|
142 | $query->orderBy('s.nb_interventions DESC'); |
---|
143 | $this->titre = 'Les dossiers les plus discutés à l\'Assemblée'; |
---|
144 | } else if ($this->order == 'coms') { |
---|
145 | $query->orderBy('s.nb_commentaires DESC'); |
---|
146 | $this->titre = 'Les dossiers de l\'Assemblée les plus commentés par les citoyens'; |
---|
147 | } else $this->forward404(); |
---|
148 | $this->getResponse()->setTitle(str_replace('Assemblée', 'Assemblée nationale', $this->titre)." - NosDéputés.fr"); |
---|
149 | $this->sections = $query->execute(); |
---|
150 | |
---|
151 | } |
---|
152 | } |
---|