1 | <?php |
||
2 | |||
3 | namespace MySociety\TheyWorkForYou\SectionView; |
||
4 | |||
5 | class PbcView extends SectionView { |
||
6 | public $major = 6; |
||
7 | protected $class = 'StandingCommittee'; |
||
8 | protected $index_template = 'section/pbc_index'; |
||
9 | |||
10 | private $bill; |
||
11 | private $session; |
||
12 | |||
13 | public function __construct() { |
||
14 | $this->session = get_http_var('session'); |
||
15 | $this->bill = str_replace('_', ' ', get_http_var('bill')); |
||
16 | $this->list = new \StandingCommittee($this->session, $this->bill); |
||
17 | parent::__construct(); |
||
18 | } |
||
19 | |||
20 | # Public Bill Committees have a somewhat different structure to the rest |
||
21 | public function display() { |
||
22 | $data = $this->public_bill_committees(); |
||
23 | $data['location'] = $this->location; |
||
24 | $data['current_assembly'] = $this->assembly; |
||
25 | return $data; |
||
26 | } |
||
27 | |||
28 | protected function public_bill_committees() { |
||
29 | global $this_page, $DATA, $PAGE; |
||
30 | |||
31 | $id = get_http_var('id'); |
||
32 | |||
33 | $bill_id = null; |
||
34 | if ($this->session && $this->bill) { |
||
35 | $q = $this->list->db->query('select id,standingprefix from bills where title = :bill |
||
36 | and session = :session', array( |
||
37 | ':bill' => $this->bill, |
||
38 | ':session' => $this->session |
||
39 | ))->first(); |
||
40 | if ($q) { |
||
41 | $bill_id = $q['id']; |
||
42 | $standingprefix = $q['standingprefix']; |
||
43 | } |
||
44 | } |
||
45 | |||
46 | if ($bill_id && $id) { |
||
47 | return $this->display_section_or_speech(array( |
||
48 | 'gid' => $standingprefix . $id, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
49 | )); |
||
50 | } elseif ($bill_id) { |
||
51 | # Display the page for a particular bill |
||
52 | $this_page = 'pbc_bill'; |
||
53 | $args = array ( |
||
54 | 'id' => $bill_id, |
||
55 | 'title' => $this->bill, |
||
56 | 'session' => $this->session, |
||
57 | ); |
||
58 | $data = array(); |
||
59 | $data['content'] = $this->list->display('bill', $args, 'none'); |
||
60 | $data['session'] = $this->session; |
||
61 | $data['template'] = 'section/pbc_bill'; |
||
62 | return $this->addCommonData($data); |
||
63 | } elseif ($this->session && $this->bill) { |
||
64 | # Illegal bill title, redirect to session page |
||
65 | $URL = new \MySociety\TheyWorkForYou\Url('pbc_session'); |
||
66 | header('Location: ' . $URL->generate() . urlencode($this->session)); |
||
67 | exit; |
||
68 | } elseif ($this->session) { |
||
69 | # Display the bills for a particular session |
||
70 | $this_page = 'pbc_session'; |
||
71 | $DATA->set_page_metadata($this_page, 'title', "Session $this->session"); |
||
72 | $args = array ( |
||
73 | 'session' => $this->session, |
||
74 | ); |
||
75 | $data = array(); |
||
76 | $data['rows'] = $this->list->display('session', $args, 'none'); |
||
77 | $data['template'] = 'section/pbc_session'; |
||
78 | $data['session'] = $this->session; |
||
79 | return $this->addCommonData($data); |
||
80 | } else { |
||
81 | return $this->display_front(); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | protected function getViewUrls() { |
||
86 | $urls = array(); |
||
87 | $day = new \MySociety\TheyWorkForYou\Url('pbc_front'); |
||
88 | $urls['pbcday'] = $day; |
||
89 | return $urls; |
||
90 | } |
||
91 | |||
92 | protected function getSearchSections() { |
||
93 | return array( |
||
94 | array( 'section' => 'pbc' ) |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | protected function front_content() { |
||
99 | return $this->list->display( 'recent_pbc_debates', array( 'num' => 50 ), 'none' ); |
||
100 | } |
||
101 | |||
102 | protected function display_front() { |
||
103 | global $DATA, $this_page; |
||
104 | $this_page = 'pbc_front'; |
||
105 | |||
106 | $data = array(); |
||
107 | $data['template'] = $this->index_template; |
||
108 | |||
109 | $content = array(); |
||
110 | $content['data'] = $this->front_content(); |
||
111 | |||
112 | $content['rssurl'] = $DATA->page_metadata($this_page, 'rss'); |
||
113 | |||
114 | $data['content'] = $content; |
||
115 | return $this->addCommonData($data); |
||
116 | } |
||
117 | } |
||
118 |