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

Wales::getSearchBox()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 17
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 21
rs 9.7
1
<?php
2
3
namespace MySociety\TheyWorkForYou\Homepage;
4
5
class Wales extends Base {
6
    protected $mp_house = 5;
7
    protected $cons_type = 'WAC';
8
    protected $page = 'seneddoverview';
9
10
    # Due to language, set things here
11
    public function __construct() {
12
        if (LANGUAGE == 'cy') {
0 ignored issues
show
introduced by
The condition MySociety\TheyWorkForYou...mepage\LANGUAGE == 'cy' is always false.
Loading history...
13
            $this->houses = [11];
14
            $class = 'SENEDDCYLIST';
15
        } else {
16
            $this->houses = [10];
0 ignored issues
show
Bug Best Practice introduced by
The property houses does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
17
            $class = 'SENEDDENLIST';
18
        }
19
        $this->recent_types = [
0 ignored issues
show
Bug Best Practice introduced by
The property recent_types does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
            $class => ['recent_debates', 'senedddebatesfront', 'Senedd'],
21
        ];
22
    }
23
24
    public function display() {
25
        $data = parent::display();
26
        $data['popular_searches'] = null;
27
        $data['template'] = 'senedd/index';
28
        return $data;
29
    }
30
31
    protected function getEditorialContent(&$data) {
32
        $featured = [];
33
        if (count($data['debates']['recent'])) {
34
            $MOREURL = new \MySociety\TheyWorkForYou\Url('senedddebatesfront');
35
            $MOREURL->insert([ 'more' => 1 ]);
36
            $featured = array_shift($data['debates']['recent']);
37
            $featured['more_url'] = $MOREURL->generate();
38
            $featured['desc'] = 'Senedd';
39
            $featured['related'] = [];
40
            $featured['featured'] = false;
41
        }
42
        return $featured;
43
    }
44
45
    protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox {
46
        $search_box = new \MySociety\TheyWorkForYou\Search\SearchBox();
47
        $search_box->homepage_panel_class = "panel--homepage--senedd";
48
        $search_box->homepage_subhead = gettext("Senedd / Welsh Parliament");
49
        $search_box->homepage_desc = "";
50
        $search_box->search_section = "senedd";
51
        $search_box->quick_links = [];
52
        if (count($data["regional"])) {
53
            // get all unique constituencies
54
            $constituencies = [];
55
            foreach ($data["regional"] as $member) {
56
                $constituencies[$member["constituency"]] = 1;
57
            }
58
            $constituencies = array_keys($constituencies);
59
            $search_box->add_quick_link(sprintf(gettext('Find out more about your MSs for %s and %s'), $constituencies[0], $constituencies[1]), '/postcode/?pc=' . $data["mp_data"]['postcode'], 'torso');
60
        }
61
        $search_box->add_quick_link(gettext('Create and manage email alerts'), '/alert/', 'megaphone');
62
        $search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail');
63
        $search_box->add_quick_link(gettext('Donate to support our work'), '/support-us/', 'heart');
64
        $search_box->add_quick_link(gettext('Learn more about TheyWorkForYou'), '/about/', 'magnifying-glass');
65
        return $search_box;
66
    }
67
68
    protected function getRegionalList() {
69
        global $THEUSER;
70
71
        $mreg = [];
72
        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...
73
            return array_merge(
74
                \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAC'),
75
                \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAE')
76
            );
77
        }
78
79
        return $mreg;
80
    }
81
}
82