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/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 @@
= 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