diff --git a/classes/AlertView/Standard.php b/classes/AlertView/Standard.php
index 6c4feaaec9..6c6d711498 100644
--- a/classes/AlertView/Standard.php
+++ b/classes/AlertView/Standard.php
@@ -158,18 +158,24 @@ private function getBasicData() {
$this->data['pid'] = trim(get_http_var("pid"));
$this->data['pc'] = get_http_var('pc');
$this->data['submitted'] = get_http_var('submitted') || $this->data['pid'] || $this->data['keyword'] || $this->data['step'];
+ $this->data['ignore_speaker_votes'] = get_http_var('ignore_speaker_votes');
if ($this->data['addword'] || $this->data['step']) {
$alert = $this->alert->check_token($this->data['token']);
$criteria = '';
+ $alert_ignore_speaker_votes = 0;
if ($alert) {
$criteria = $alert['criteria'];
+ $alert_ignore_speaker_votes = $alert['ignore_speaker_votes'];
}
+ $ignore_speaker_votes = get_http_var('ignore_speaker_votes', $alert_ignore_speaker_votes);
+ $this->data['ignore_speaker_votes'] = ($ignore_speaker_votes == 'on' || $ignore_speaker_votes == 1);
+
$this->data['alert'] = $alert;
- $this->data['alert_parts'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($criteria, $alert['ignore_speaker_votes'], true);
+ $this->data['alert_parts'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($criteria, $alert_ignore_speaker_votes, true);
$existing_rep = '';
if (isset($this->data['alert_parts']['spokenby'])) {
@@ -237,6 +243,22 @@ private function getBasicData() {
$this->data['results'] = '';
$this->getSearchSections();
+ } else if ($this->data['mp_step'] == 'mp_alert') {
+ $alert = $this->alert->check_token($this->data['token']);
+ if ($alert) {
+ $ignore_speaker_votes = get_http_var('ignore_speaker_votes', $alert['ignore_speaker_votes']);
+ $this->data['ignore_speaker_votes'] = ($ignore_speaker_votes == 'on' || $ignore_speaker_votes == 1);
+
+ $existing_rep = '';
+ if (isset($alert['criteria'])) {
+ $alert_parts = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($alert['criteria'], $alert['ignore_speaker_votes'], true);
+ $existing_rep = $alert_parts['spokenby'][0];
+ $this->data['pid'] = $alert_parts['pid'];
+ }
+ $this->data['keyword'] = get_http_var('mp_search', $existing_rep);
+ } else {
+ $this->data['ignore_speaker_votes'] = get_http_var('ignore_speaker_votes');
+ }
} # XXX probably should do something here if $alertsearch is set
$this->data['sign'] = get_http_var('sign');
diff --git a/classes/Utility/Alert.php b/classes/Utility/Alert.php
index 33a518912e..a4fdcdfc5e 100644
--- a/classes/Utility/Alert.php
+++ b/classes/Utility/Alert.php
@@ -74,6 +74,7 @@ public static function forUser($email) {
'status' => $status,
'criteria' => $criteria,
'raw' => $row['criteria'],
+ 'ignore_speaker_votes' => $row['ignore_speaker_votes'],
'keywords' => [],
'exclusions' => [],
'sections' => [],
@@ -89,7 +90,7 @@ public static function forUser($email) {
public static function prettifyCriteria($alert_criteria, $ignore_speaker_votes = false, $as_parts = false) {
$text = '';
- $parts = ['words' => [], 'sections' => [], 'exclusions' => [], 'match_all' => true];
+ $parts = ['words' => [], 'sections' => [], 'exclusions' => [], 'match_all' => true, 'pid' => false];
if ($alert_criteria) {
# check for phrases
if (strpos($alert_criteria, ' OR ') !== false) {
@@ -116,7 +117,13 @@ public static function prettifyCriteria($alert_criteria, $ignore_speaker_votes =
$exclusions = [];
$sections = [];
$sections_verbose = [];
- $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($alert_criteria));
+ $speaker_parts = \MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($alert_criteria);
+ $pids = array_keys($speaker_parts);
+ $spokenby = array_values($speaker_parts);
+
+ if (count($pids) == 1) {
+ $parts['pid'] = $pids[0];
+ }
foreach ($criteria as $c) {
if (preg_match('#^section:(\w+)#', $c, $m)) {
diff --git a/tests/AlertsPageTest.php b/tests/AlertsPageTest.php
index 91a2b15f24..6f70c18d48 100644
--- a/tests/AlertsPageTest.php
+++ b/tests/AlertsPageTest.php
@@ -26,7 +26,7 @@ public function testFetchPage() {
public function testKeywordOnly() {
$page = $this->fetch_page([ 'alertsearch' => 'elephant']);
- $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page);
$this->assertStringContainsString('fetch_page([ 'step' => 'define']);
- $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page);
$this->assertStringContainsString('fetch_page([ 'step' => 'review', 'email' => 'test@example.org', 'words[]' => 'fish']);
@@ -76,7 +76,7 @@ public function testBasicKeyWordAlertsCreation() {
public function testMultipleKeyWordAlertsCreation() {
$page = $this->fetch_page([ 'step' => 'define']);
- $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page);
$this->assertStringContainsString('fetch_page([ 'step' => 'review', 'email' => 'test@example.org', 'words[]' => ['fish', 'salmon']]);
@@ -90,7 +90,7 @@ public function testMultipleKeyWordAlertsCreation() {
public function testMultipleKeyWordAlertsCreationLoggedIn() {
$page = $this->get_page(['step' => 'define']);
- $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page);
$this->assertStringContainsString('get_page([ 'step' => 'review', 'words[]' => ['fish', 'salmon']]);
@@ -104,7 +104,7 @@ public function testMultipleKeyWordAlertsCreationLoggedIn() {
public function testKeyWordAndSectionAlertsCreationLoggedIn() {
$page = $this->get_page(['step' => 'define']);
- $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page);
$this->assertStringContainsString('get_page(['step' => 'review', 'words[]' => 'fish', 'search_section' => 'debates']);
@@ -117,7 +117,7 @@ public function testKeyWordAndSectionAlertsCreationLoggedIn() {
public function testKeyWordAndSpeakerAlertsCreationLoggedIn() {
$page = $this->get_page(['step' => 'define']);
- $this->assertStringContainsString('What word or phrase would you like to recieve alerts about', $page);
+ $this->assertStringContainsString('What word or phrase would you like to receive alerts about', $page);
$this->assertStringContainsString('get_page(['step' => 'review', 'words[]' => 'fish', 'representative' => 'Mrs Test Current-MP']);
diff --git a/tests/AlertsTest.php b/tests/AlertsTest.php
index ce212441e7..263461350a 100644
--- a/tests/AlertsTest.php
+++ b/tests/AlertsTest.php
@@ -74,6 +74,7 @@ public function testAdd() {
'email' => 'test@theyworkforyou.com',
'keyword' => 'test',
'pc' => 'SW1A 1AA',
+ 'ignore_speaker_votes' => 0,
];
$response = $ALERT->add($details, false, true);
@@ -96,6 +97,7 @@ public function testAddExisting() {
'email' => 'test3@theyworkforyou.com',
'keyword' => 'test3',
'pc' => 'SW1A 1AA',
+ 'ignore_speaker_votes' => 0,
];
$response = $ALERT->add($details, false, true);
@@ -117,6 +119,7 @@ public function testAddDeleted() {
'email' => 'test6@theyworkforyou.com',
'keyword' => 'test6',
'pc' => 'SW1A 1AA',
+ 'ignore_speaker_votes' => 0,
];
$response = $ALERT->add($details, false, true);
@@ -162,6 +165,7 @@ public function testCheckTokenCorrect() {
'id' => 1,
'email' => 'test@theyworkforyou.com',
'criteria' => 'test1',
+ 'ignore_speaker_votes' => '0',
], $response);
}
diff --git a/tests/_fixtures/alerts.xml b/tests/_fixtures/alerts.xml
index 45924603e9..64547d5503 100644
--- a/tests/_fixtures/alerts.xml
+++ b/tests/_fixtures/alerts.xml
@@ -6,6 +6,7 @@
= gettext("Or edit the name") ?>
+Alert when = _htmlspecialchars(implode(', ', $person_alerts[0]['spokenby'])) ?> is mentioned
@@ -25,12 +26,16 @@ + + + +- + diff --git a/www/includes/easyparliament/templates/html/alert/_own_mp_alerts.php b/www/includes/easyparliament/templates/html/alert/_own_mp_alerts.php index d8d51e2fdb..de22105d70 100644 --- a/www/includes/easyparliament/templates/html/alert/_own_mp_alerts.php +++ b/www/includes/easyparliament/templates/html/alert/_own_mp_alerts.php @@ -4,6 +4,7 @@
Alert when = _htmlspecialchars($own_mp_criteria) ?> is mentioned