|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MySociety\TheyWorkForYou\Homepage; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Base { |
|
6
|
|
|
public function display() { |
|
7
|
|
|
global $this_page; |
|
8
|
|
|
$this_page = $this->page; |
|
9
|
|
|
|
|
10
|
|
|
$data = []; |
|
11
|
|
|
|
|
12
|
|
|
$common = new \MySociety\TheyWorkForYou\Common(); |
|
13
|
|
|
|
|
14
|
|
|
$data['debates'] = $this->getDebatesData(); |
|
15
|
|
|
|
|
16
|
|
|
$user = new \MySociety\TheyWorkForYou\User(); |
|
17
|
|
|
$data['mp_data'] = $user->getRep($this->cons_type, $this->mp_house); |
|
18
|
|
|
|
|
19
|
|
|
$data['regional'] = $this->getRegionalList(); |
|
|
|
|
|
|
20
|
|
|
$data['popular_searches'] = $common->getPopularSearches(); |
|
21
|
|
|
$data['featured'] = $this->getEditorialContent($data); |
|
22
|
|
|
$data['divisions'] = $this->getRecentDivisions(); |
|
23
|
|
|
$data['search_box'] = $this->getSearchBox($data); |
|
24
|
|
|
|
|
25
|
|
|
return $data; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
abstract protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox; |
|
29
|
|
|
abstract protected function getEditorialContent(array &$data); |
|
30
|
|
|
|
|
31
|
|
|
protected function getRegionalList() { |
|
32
|
|
|
return null; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
private function getRecentDivisions() { |
|
36
|
|
|
$divisions = new \MySociety\TheyWorkForYou\Divisions(); |
|
37
|
|
|
return $divisions->getRecentDebatesWithDivisions(5, $this->houses); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function getDebatesData() { |
|
41
|
|
|
$debates = []; // holds the most recent data there is data for, indexed by type |
|
42
|
|
|
|
|
43
|
|
|
$recent_content = []; |
|
44
|
|
|
|
|
45
|
|
|
foreach ($this->recent_types as $class => $recent) { |
|
46
|
|
|
$class = "\\$class"; |
|
47
|
|
|
$instance = new $class(); |
|
48
|
|
|
$more_url = new \MySociety\TheyWorkForYou\Url($recent[1]); |
|
49
|
|
|
if ($recent[0] == 'recent_pbc_debates') { |
|
50
|
|
|
$content = [ 'data' => $instance->display($recent[0], ['num' => 5], 'none') ]; |
|
51
|
|
|
} elseif ($recent[1] == 'senedddebatesfront' || $recent[1] == 'nidebatesfront') { |
|
52
|
|
|
$content = $instance->display($recent[0], ['days' => 30, 'num' => 6], 'none'); |
|
53
|
|
|
# XXX Bit hacky, for now |
|
54
|
|
|
foreach ($content['data'] as $d) { |
|
55
|
|
|
$d['more_url'] = $more_url->generate(); |
|
56
|
|
|
$d['desc'] = ''; |
|
57
|
|
|
$recent_content[] = $d; |
|
58
|
|
|
} |
|
59
|
|
|
$content = []; |
|
60
|
|
|
} else { |
|
61
|
|
|
$content = $instance->display($recent[0], ['days' => 7, 'num' => 1], 'none'); |
|
62
|
|
|
if (isset($content['data']) && count($content['data'])) { |
|
63
|
|
|
$content = $content['data'][0]; |
|
64
|
|
|
} else { |
|
65
|
|
|
$content = []; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
if ($content) { |
|
69
|
|
|
$content['more_url'] = $more_url->generate(); |
|
70
|
|
|
$content['desc'] = $recent[2]; |
|
71
|
|
|
$recent_content[] = $content; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$debates['recent'] = $recent_content; |
|
76
|
|
|
|
|
77
|
|
|
return $debates; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.