Passed
Pull Request — master (#1834)
by
unknown
05:14
created

NI::display()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace MySociety\TheyWorkForYou\Homepage;
4
5
class NI extends Base {
6
    protected $mp_house = 3;
7
    protected $cons_type = 'NIE';
8
    protected $page = 'nioverview';
9
    protected $houses = [5];
10
    protected $recent_types = [
11
        'NILIST' => ['recent_debates', 'nidebatesfront', 'Northern Ireland Assembly debates'],
12
    ];
13
14
    public function display() {
15
        $data = parent::display();
16
        $data['popular_searches'] = null;
17
        $data['template'] = 'ni/index';
18
        return $data;
19
    }
20
21
    protected function getEditorialContent(&$data) {
22
        $featured = [];
23
        if (count($data['debates']['recent'])) {
24
            $MOREURL = new \MySociety\TheyWorkForYou\Url('nidebatesfront');
25
            $MOREURL->insert([ 'more' => 1 ]);
26
            $featured = array_shift($data['debates']['recent']);
27
            $featured['more_url'] = $MOREURL->generate();
28
            $featured['desc'] = 'Northern Ireland Assembly debate';
29
            $featured['related'] = [];
30
            $featured['featured'] = false;
31
        }
32
        return $featured;
33
    }
34
35
    protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox {
36
37
        global $THEUSER;
38
39
        if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: ($THEUSER->isloggedin() ...USER->postcode_is_set(), Probably Intended Meaning: $THEUSER->isloggedin() &...SER->postcode_is_set())
Loading history...
40
            $postcode = $THEUSER->postcode();
41
        } else {
42
            $postcode = null;
43
        }
44
45
        $search_box = new \MySociety\TheyWorkForYou\Search\SearchBox();
46
        $search_box->homepage_panel_class = "panel--homepage--niassembly";
47
        $search_box->homepage_subhead = "Northern Ireland Assembly";
48
        $search_box->homepage_desc = "";
49
        $search_box->search_section = "ni";
50
        $search_box->quick_links = [];
51
        if (count($data["regional"])) {
52
            $constituency = $data["regional"][0]["constituency"];
53
            $search_box->add_quick_link('Find out more about your MLAs for ' . $constituency, '/postcode/?pc=' . $postcode, 'torso');
54
        }
55
        $search_box->add_quick_link('Create and manage email alerts', '/alert/', 'megaphone');
56
        $search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail');
57
        $search_box->add_quick_link('Donate to support our work', '/support-us/', 'heart');
58
        $search_box->add_quick_link('Learn more about TheyWorkForYou', '/about/', 'magnifying-glass');
59
        return $search_box;
60
    }
61
62
    protected function getRegionalList() {
63
        global $THEUSER;
64
65
        $mreg = [];
66
        if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
0 ignored issues
show
introduced by
Consider adding parentheses for clarity. Current Interpretation: ($THEUSER->isloggedin() ...USER->postcode_is_set(), Probably Intended Meaning: $THEUSER->isloggedin() &...SER->postcode_is_set())
Loading history...
67
            return \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 3, 'NIE');
68
        }
69
70
        return $mreg;
71
    }
72
}
73