1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MySociety\TheyWorkForYou\SectionView; |
4
|
|
|
|
5
|
|
|
class SeneddView extends SectionView { |
6
|
|
|
protected $index_template = 'section/senedd_index'; |
7
|
|
|
|
8
|
|
|
public function __construct() { |
9
|
|
|
if (LANGUAGE == 'cy') { |
|
|
|
|
10
|
|
|
$this->major = 11; |
11
|
|
|
$this->class = 'SENEDDCYLIST'; |
12
|
|
|
} else { |
13
|
|
|
$this->major = 10; |
14
|
|
|
$this->class = 'SENEDDENLIST'; |
15
|
|
|
} |
16
|
|
|
parent::__construct(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function display_front() { |
20
|
|
|
if (get_http_var('more')) { |
21
|
|
|
return parent::display_front(); |
22
|
|
|
} else { |
23
|
|
|
return $this->display_front_senedd(); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function front_content() { |
28
|
|
|
return $this->list->display('biggest_debates', array('days'=>30, 'num'=>20), 'none'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function getURLs($data) { |
32
|
|
|
$urls = array(); |
33
|
|
|
|
34
|
|
|
$day = new \MySociety\TheyWorkForYou\Url('senedddebates'); |
35
|
|
|
$urls['seneddday'] = $day; |
36
|
|
|
$urls['day'] = $day; |
37
|
|
|
|
38
|
|
|
return $urls; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function getSearchSections() { |
42
|
|
|
return array( |
43
|
|
|
array( 'section' => 'wales' ) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function display_front_senedd() { |
48
|
|
|
global $this_page; |
49
|
|
|
$this_page = "seneddoverview"; |
50
|
|
|
|
51
|
|
|
$data = array(); |
52
|
|
|
|
53
|
|
|
$data['popular_searches'] = null; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
$data['urls'] = $this->getURLs($data); |
57
|
|
|
|
58
|
|
|
$DEBATELIST = new $this->class(); |
59
|
|
|
|
60
|
|
|
$debates = $DEBATELIST->display('recent_debates', array('days' => 30, 'num' => 6), 'none'); |
61
|
|
|
$MOREURL = new \MySociety\TheyWorkForYou\Url('senedddebatesfront'); |
62
|
|
|
$MOREURL->insert( array( 'more' => 1 ) ); |
63
|
|
|
|
64
|
|
|
// this makes sure that we don't repeat this debate in the list below |
65
|
|
|
$random_debate = null; |
66
|
|
|
if ( isset($debates['data']) && count($debates['data']) ) { |
67
|
|
|
$random_debate = $debates['data'][0]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$recent = array(); |
71
|
|
|
if ( isset($debates['data']) && count($debates['data']) ) { |
72
|
|
|
// at the start of a session there may be less than 6 |
73
|
|
|
// debates |
74
|
|
|
$max = 6; |
75
|
|
|
if ( count($debates['data']) < 6 ) { |
76
|
|
|
$max = count($debates['data']); |
77
|
|
|
} |
78
|
|
|
for ( $i = 1; $i < $max; $i++ ) { |
79
|
|
|
$debate = $debates['data'][$i]; |
80
|
|
|
$debate['desc'] = "Senedd"; |
81
|
|
|
$debate['more_url'] = $MOREURL->generate(); |
82
|
|
|
$recent[] = $debate; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$featured = array(); |
87
|
|
|
if ( $random_debate ) { |
88
|
|
|
$featured = $random_debate; |
89
|
|
|
$featured['more_url'] = $MOREURL->generate(); |
90
|
|
|
$featured['desc'] = 'Senedd'; |
91
|
|
|
$featured['related'] = array(); |
92
|
|
|
$featured['featured'] = false; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$data['featured'] = $featured; |
96
|
|
|
$data['debates'] = array( 'recent' => $recent); |
97
|
|
|
|
98
|
|
|
$data['regional'] = $this->getMSList(); |
99
|
|
|
$data['template'] = 'senedd/index'; |
100
|
|
|
|
101
|
|
|
return $data; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function getMSList() { |
105
|
|
|
global $THEUSER; |
106
|
|
|
|
107
|
|
|
$mreg = array(); |
108
|
|
|
if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) { |
|
|
|
|
109
|
|
|
return array_merge( |
110
|
|
|
\MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAC'), |
111
|
|
|
\MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAE') |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $mreg; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|