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 @@ 1 0 0 + 0 token1 test@theyworkforyou.com test1 @@ -15,6 +16,7 @@ 3 0 1 + 0 token3 test3@theyworkforyou.com test3 @@ -24,6 +26,7 @@ 5 0 1 + 0 token5 test5@theyworkforyou.com speaker:1234 @@ -33,6 +36,7 @@ 6 2 1 + 0 token6 test6@theyworkforyou.com test6 diff --git a/www/includes/easyparliament/alert.php b/www/includes/easyparliament/alert.php index 72c29f3777..eaf6e3314e 100644 --- a/www/includes/easyparliament/alert.php +++ b/www/includes/easyparliament/alert.php @@ -167,7 +167,7 @@ public function add($details, $confirmation_email = false, $instantly_confirm = ':criteria' => $criteria, ])->first(); if ($q) { - if ($q['deleted']) { + if ($q['deleted'] || $q['ignore_speaker_votes'] != $ignore_speaker_votes) { $this->db->query("UPDATE alerts SET deleted=0, ignore_speaker_votes=:ignore_speaker_votes WHERE email = :email AND criteria = :criteria diff --git a/www/includes/easyparliament/templates/html/alert/_alert_form.php b/www/includes/easyparliament/templates/html/alert/_alert_form.php index 91a39f82a6..a3789351ec 100644 --- a/www/includes/easyparliament/templates/html/alert/_alert_form.php +++ b/www/includes/easyparliament/templates/html/alert/_alert_form.php @@ -105,6 +105,10 @@

+
+ > + +
diff --git a/www/includes/easyparliament/templates/html/alert/_list_accordian.php b/www/includes/easyparliament/templates/html/alert/_list_accordian.php index fb1065f292..f2e16b854e 100644 --- a/www/includes/easyparliament/templates/html/alert/_list_accordian.php +++ b/www/includes/easyparliament/templates/html/alert/_list_accordian.php @@ -186,27 +186,45 @@ - + - - + + +
- - - + + + + + + + + + + + + + +
@@ -214,7 +232,7 @@

Alert when is mentioned

- +
+ + - + + + + + + + + + + +
@@ -40,7 +59,8 @@

Alert when is mentioned

- + +