-
Notifications
You must be signed in to change notification settings - Fork 55
Homepage class tidy and tweaks #1834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dracos
wants to merge
7
commits into
master
Choose a base branch
from
homepage-class-tidy-and-tweaks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f859e3
Rename Homepage classes.
dracos 5405b1b
Create shared Homepage base class.
dracos c879e8a
Add Homepage classes for Wales/NI.
dracos 7c79d42
Tweaks to vote display on Scotland and Wales home.
dracos 45c1fef
Include chamber in UK homepage votes.
dracos 92ce700
fixup! Rename Homepage classes.
dracos 674b519
fixup make sure recent_debates always includes data entry.
dracos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
|
|
||
| namespace MySociety\TheyWorkForYou\Homepage; | ||
|
|
||
| abstract class Base { | ||
| public function display() { | ||
| global $this_page; | ||
| $this_page = $this->page; | ||
|
|
||
| $data = []; | ||
|
|
||
| $common = new \MySociety\TheyWorkForYou\Common(); | ||
|
|
||
| $data['debates'] = $this->getDebatesData(); | ||
|
|
||
| $user = new \MySociety\TheyWorkForYou\User(); | ||
| $data['mp_data'] = $user->getRep($this->cons_type, $this->mp_house); | ||
|
|
||
| $data['regional'] = $this->getRegionalList(); | ||
| $data['popular_searches'] = $common->getPopularSearches(); | ||
| $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(array &$data); | ||
|
|
||
| protected function getRegionalList() { | ||
| return null; | ||
| } | ||
|
|
||
| private function getRecentDivisions() { | ||
| $divisions = new \MySociety\TheyWorkForYou\Divisions(); | ||
| return $divisions->getRecentDebatesWithDivisions(5, $this->houses); | ||
| } | ||
|
|
||
| protected function getDebatesData() { | ||
| $debates = []; // holds the most recent data there is data for, indexed by type | ||
|
|
||
| $recent_content = []; | ||
|
|
||
| foreach ($this->recent_types as $class => $recent) { | ||
| $class = "\\$class"; | ||
| $instance = new $class(); | ||
| $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) { | ||
| $d['more_url'] = $more_url->generate(); | ||
| $d['desc'] = ''; | ||
| $recent_content[] = $d; | ||
| } | ||
| $content = []; | ||
| } else { | ||
| $content = $instance->display($recent[0], ['days' => 7, 'num' => 1], 'none'); | ||
| if (isset($content['data']) && count($content['data'])) { | ||
| $content = $content['data'][0]; | ||
| } else { | ||
| $content = []; | ||
| } | ||
| } | ||
| if ($content) { | ||
| $content['more_url'] = $more_url->generate(); | ||
| $content['desc'] = $recent[2]; | ||
| $recent_content[] = $content; | ||
| } | ||
| } | ||
|
|
||
| $debates['recent'] = $recent_content; | ||
|
|
||
| return $debates; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 $cons_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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.