Skip to content

Commit

Permalink
Add Homepage classes for Wales/NI.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Oct 9, 2024
1 parent 522cf73 commit 5aa1127
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 201 deletions.
11 changes: 9 additions & 2 deletions classes/Homepage/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public function display() {

$data['regional'] = $this->getRegionalList();
$data['popular_searches'] = $common->getPopularSearches();
$data['featured'] = $this->getEditorialContent();
$data['featured'] = $this->getEditorialContent($data);
$data['divisions'] = $this->getRecentDivisions();
$data['search_box'] = $this->getSearchBox($data);

return $data;
}

abstract protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox;
abstract protected function getEditorialContent();
abstract protected function getEditorialContent(array $data);

protected function getRegionalList() {
return null;
Expand All @@ -48,6 +48,13 @@ protected function getDebatesData() {
$more_url = new \MySociety\TheyWorkForYou\Url($recent[1]);
if ($recent[0] == 'recent_pbc_debates') {
$content = [ 'data' => $instance->display($recent[0], ['num' => 5], 'none') ];
} elseif ($recent[1] == 'senedddebatesfront' || $recent[1] == 'nidebatesfront') {
$content = $instance->display($recent[0], ['days' => 30, 'num' => 6], 'none');
# XXX Bit hacky, for now
foreach ($content['data'] as $d) {
$recent_content[] = $d;
}
$content = [];
} else {
$content = $instance->display($recent[0], ['days' => 7, 'num' => 1], 'none');
if (isset($content['data']) && count($content['data'])) {
Expand Down
72 changes: 72 additions & 0 deletions classes/Homepage/NI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace MySociety\TheyWorkForYou\Homepage;

class NI extends Base {
protected $mp_house = 3;
protected $conts_type = 'NIE';
protected $page = 'nioverview';
protected $houses = [5];
protected $recent_types = [
'NILIST' => ['recent_debates', 'nidebatesfront', 'Northern Ireland Assembly debates'],
];

public function display() {
$data = parent::display();
$data['popular_searches'] = null;
$data['template'] = 'ni/index';
return $data;
}

protected function getEditorialContent($data) {
$featured = [];
if (count($data['debates']['recent'])) {
$MOREURL = new \MySociety\TheyWorkForYou\Url('nidebatesfront');
$MOREURL->insert([ 'more' => 1 ]);
$featured = array_shift($data['debates']['recent']);
$featured['more_url'] = $MOREURL->generate();
$featured['desc'] = 'Northern Ireland Assembly debate';
$featured['related'] = [];
$featured['featured'] = false;
}
return $featured;
}

protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox {

global $THEUSER;

if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
$postcode = $THEUSER->postcode();
} else {
$postcode = null;
}

$search_box = new \MySociety\TheyWorkForYou\Search\SearchBox();
$search_box->homepage_panel_class = "panel--homepage--niassembly";
$search_box->homepage_subhead = "Northern Ireland Assembly";
$search_box->homepage_desc = "";
$search_box->search_section = "ni";
$search_box->quick_links = [];
if (count($data["regional"])) {
$constituency = $data["regional"][0]["constituency"];
$search_box->add_quick_link('Find out more about your MLAs for ' . $constituency, '/postcode/?pc=' . $postcode, 'torso');
}
$search_box->add_quick_link('Create and manage email alerts', '/alert/', 'megaphone');
$search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail');
$search_box->add_quick_link('Donate to support our work', '/support-us/', 'heart');
$search_box->add_quick_link('Learn more about TheyWorkForYou', '/about/', 'magnifying-glass');
return $search_box;
}

protected function getRegionalList() {
global $THEUSER;

$mreg = [];
if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
return \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 3, 'NIE');
}

return $mreg;
}
}
3 changes: 1 addition & 2 deletions classes/Homepage/Scotland.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
class Scotland extends Base {
protected $mp_house = 4;
protected $cons_type = 'SPC';
protected $mp_url = 'yourmsp';
protected $page = 'spoverview';
protected $houses = [7];

Expand All @@ -32,7 +31,7 @@ protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\S
return $search_box;
}

protected function getEditorialContent() {
protected function getEditorialContent($data) {
$debatelist = new \SPLIST();
$item = $debatelist->display('recent_debates', ['days' => 7, 'num' => 1], 'none');

Expand Down
4 changes: 2 additions & 2 deletions classes/Homepage/UK.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class UK extends Base {
protected $mp_house = 1;
protected $cons_type = 'WMC';
protected $mp_url = 'yourmp';
protected $page = 'overview';
protected $houses = [1, 101];
private $mp_url = 'yourmp';

protected $recent_types = [
'DEBATELIST' => ['recent_debates', 'debatesfront', 'Commons debates'],
Expand Down Expand Up @@ -42,7 +42,7 @@ protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\S
return $search_box;
}

protected function getEditorialContent() {
protected function getEditorialContent($data) {
$debatelist = new \DEBATELIST();
$featured = new \MySociety\TheyWorkForYou\Model\Featured();
$gid = $featured->get_gid();
Expand Down
83 changes: 83 additions & 0 deletions classes/Homepage/Wales.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace MySociety\TheyWorkForYou\Homepage;

class Wales extends Base {
protected $mp_house = 5;
protected $cons_type = 'WAC';
protected $page = 'seneddoverview';

# Due to language, set things here
public function __construct() {
if (LANGUAGE == 'cy') {
$this->houses = [11];
$class = 'SENEDDCYLIST';
}
} else {
$this->houses = [10];
$class = 'SENEDDENLIST';
}
$this->recent_types = [
$class => ['recent_debates', 'senedddebatesfront', 'Senedd'],
];
parent::__construct();
}

public function display() {
$data = parent::display();
$data['popular_searches'] = null;
$data['template'] = 'senedd/index';
return $data;
}

protected function getEditorialContent($data) {
$featured = [];
if (count($data['debates']['recent'])) {
$MOREURL = new \MySociety\TheyWorkForYou\Url('senedddebatesfront');
$MOREURL->insert([ 'more' => 1 ]);
$featured = array_shift($data['debates']['recent']);
$featured['more_url'] = $MOREURL->generate();
$featured['desc'] = 'Senedd';
$featured['related'] = [];
$featured['featured'] = false;
}
return $featured;
}

protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox {
$search_box = new \MySociety\TheyWorkForYou\Search\SearchBox();
$search_box->homepage_panel_class = "panel--homepage--senedd";
$search_box->homepage_subhead = gettext("Senedd / Welsh Parliament");
$search_box->homepage_desc = "";
$search_box->search_section = "senedd";
$search_box->quick_links = [];
if (count($data["regional"])) {
// get all unique constituencies
$constituencies = [];
foreach ($data["regional"] as $member) {
$constituencies[$member["constituency"]] = 1;
}
$constituencies = array_keys($constituencies);
$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');
}
$search_box->add_quick_link(gettext('Create and manage email alerts'), '/alert/', 'megaphone');
$search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail');
$search_box->add_quick_link(gettext('Donate to support our work'), '/support-us/', 'heart');
$search_box->add_quick_link(gettext('Learn more about TheyWorkForYou'), '/about/', 'magnifying-glass');
return $search_box;
}

protected function getRegionalList() {
global $THEUSER;

$mreg = [];
if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
return array_merge(
\MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAC'),
\MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 5, 'WAE')
);
}

return $mreg;
}
}
99 changes: 2 additions & 97 deletions classes/SectionView/NiView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ protected function display_front() {
if (get_http_var('more')) {
return parent::display_front();
} else {
return $this->display_front_ni();
$homepage = new \MySociety\TheyWorkForYou\Homepage\NI();
return $homepage->display();
}
}

Expand All @@ -35,100 +36,4 @@ protected function getSearchSections() {
[ 'section' => 'ni' ],
];
}

protected function display_front_ni() {
global $this_page;
$this_page = "nioverview";

$data = [];

$data['popular_searches'] = null;


$data['urls'] = $this->getURLs($data);

$DEBATELIST = new \NILIST();

$debates = $DEBATELIST->display('recent_debates', ['days' => 30, 'num' => 6], 'none');
$MOREURL = new \MySociety\TheyWorkForYou\Url('nidebatesfront');
$MOREURL->insert([ 'more' => 1 ]);

// this makes sure that we don't repeat this debate in the list below
$random_debate = null;
if (isset($debates['data']) && count($debates['data'])) {
$random_debate = $debates['data'][0];
}

$recent = [];
if (isset($debates['data']) && count($debates['data'])) {
// at the start of a session there may be less than 6
// debates
$max = 6;
if (count($debates['data']) < 6) {
$max = count($debates['data']);
}
for ($i = 1; $i < $max; $i++) {
$debate = $debates['data'][$i];
$debate['desc'] = "Northern Ireland Assembly debates";
$debate['more_url'] = $MOREURL->generate();
$recent[] = $debate;
}
}

$featured = [];
if ($random_debate) {
$featured = $random_debate;
$featured['more_url'] = $MOREURL->generate();
$featured['desc'] = 'Northern Ireland Assembly debate';
$featured['related'] = [];
$featured['featured'] = false;
}

$data['featured'] = $featured;
$data['debates'] = [ 'recent' => $recent];

$data['regional'] = $this->getMLAList();
$data['search_box'] = $this->getSearchBox($data);
$data['template'] = 'ni/index';

return $data;
}

protected function getSearchBox(array $data): \MySociety\TheyWorkForYou\Search\SearchBox {

global $THEUSER;

if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
$postcode = $THEUSER->postcode();
} else {
$postcode = null;
}

$search_box = new \MySociety\TheyWorkForYou\Search\SearchBox();
$search_box->homepage_panel_class = "panel--homepage--niassembly";
$search_box->homepage_subhead = "Northern Ireland Assembly";
$search_box->homepage_desc = "";
$search_box->search_section = "ni";
$search_box->quick_links = [];
if (count($data["regional"])) {
$constituency = $data["regional"][0]["constituency"];
$search_box->add_quick_link('Find out more about your MLAs for ' . $constituency, '/postcode/?pc=' . $postcode, 'torso');
}
$search_box->add_quick_link('Create and manage email alerts', '/alert/', 'megaphone');
$search_box->add_quick_link(gettext('Subscribe to our newsletter'), '/about/#about-mysociety', 'mail');
$search_box->add_quick_link('Donate to support our work', '/support-us/', 'heart');
$search_box->add_quick_link('Learn more about TheyWorkForYou', '/about/', 'magnifying-glass');
return $search_box;
}

protected function getMLAList() {
global $THEUSER;

$mreg = [];
if ($THEUSER->isloggedin() && $THEUSER->postcode() != '' || $THEUSER->postcode_is_set()) {
return \MySociety\TheyWorkForYou\Member::getRegionalList($THEUSER->postcode, 3, 'NIE');
}

return $mreg;
}
}
Loading

0 comments on commit 5aa1127

Please sign in to comment.