From 3ef1f8567cbb419598cb830946faddea3a9ad81b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 30 Oct 2024 14:41:03 +0000 Subject: [PATCH 01/13] add ignore_speaker_votes flag to alerts table Used to allow people to suppress seeing votes in speaker alerts. --- db/0026-add-ignore-votes-alerts.sql | 1 + db/schema.sql | 1 + 2 files changed, 2 insertions(+) create mode 100644 db/0026-add-ignore-votes-alerts.sql diff --git a/db/0026-add-ignore-votes-alerts.sql b/db/0026-add-ignore-votes-alerts.sql new file mode 100644 index 0000000000..2425dd136f --- /dev/null +++ b/db/0026-add-ignore-votes-alerts.sql @@ -0,0 +1 @@ +ALTER TABLE `alerts` ADD `ignore_speaker_votes` tinyint(1) NOT NULL default '0'; diff --git a/db/schema.sql b/db/schema.sql index ef43d99edb..c976243153 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -307,6 +307,7 @@ CREATE TABLE `alerts` ( `confirmed` tinyint(1) NOT NULL default '0', `created` datetime NOT NULL default '0000-00-00 00:00:00', `postcode` varchar(10) NOT NULL default '', + `ignore_speaker_votes` tinyint(1) NOT NULL default '0', `lang` varchar(2) NOT NULL default 'en', PRIMARY KEY (`alert_id`), KEY `email` (`email`), From 075ce8d0d8cb8239680697b1c016b2dc5dc17534 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 30 Oct 2024 14:43:38 +0000 Subject: [PATCH 02/13] do not include votes in alerts if ignore_speaker_votes flag set Skips over the vote section if the flag is present. --- scripts/alertmailer.php | 3 ++- www/includes/easyparliament/alert.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index 03faba7b63..7766461c92 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -195,6 +195,7 @@ function mlog($message) { continue; } $criteria_raw = $alertitem['criteria']; + $include_votes = $alertitem['ignore_speaker_votes'] == 0; if (preg_match('#\bOR\b#', $criteria_raw)) { $criteria_raw = "($criteria_raw)"; } @@ -249,7 +250,7 @@ function mlog($message) { mlog(", hits " . $total_results . ", time " . (getmicrotime() - $start) . "\n"); # Divisions - if (preg_match('#^speaker:(\d+)$#', $criteria_raw, $m)) { + if ($include_votes && preg_match('#^speaker:(\d+)$#', $criteria_raw, $m)) { $pid = $m[1]; $q = $db->query('SELECT * FROM persondivisionvotes pdv JOIN divisions USING(division_id) WHERE person_id=:person_id AND pdv.lastupdate >= :time', [ diff --git a/www/includes/easyparliament/alert.php b/www/includes/easyparliament/alert.php index 226b6991e6..54f99adc61 100644 --- a/www/includes/easyparliament/alert.php +++ b/www/includes/easyparliament/alert.php @@ -90,6 +90,7 @@ public function fetch($confirmed, $deleted) { criteria, registrationtoken, lang, + ignore_speaker_votes, deleted, confirmed FROM alerts From 649e4d8e48fb5bfb6935593288d7120f37c98080 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 Dec 2024 15:45:27 +0000 Subject: [PATCH 03/13] add front end for creating MP alerts without votes --- classes/AlertView/Standard.php | 6 +++--- classes/Utility/Alert.php | 9 ++++++--- www/includes/easyparliament/alert.php | 17 +++++++++++++---- .../templates/html/alert/_mp_alert_form.php | 7 +++++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/classes/AlertView/Standard.php b/classes/AlertView/Standard.php index 011d91fc1f..6c4feaaec9 100644 --- a/classes/AlertView/Standard.php +++ b/classes/AlertView/Standard.php @@ -52,7 +52,7 @@ private function processAction() { if ($success) { $this->data['results'] = 'alert-confirmed'; $this->data['criteria'] = $this->alert->criteria; - $this->data['display_criteria'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->alert->criteria); + $this->data['display_criteria'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->alert->criteria, $this->alert->ignore_speaker_votes); } } elseif ($action == 'Suspend') { $success = $this->suspendAlert($token); @@ -169,7 +169,7 @@ private function getBasicData() { $this->data['alert'] = $alert; - $this->data['alert_parts'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($criteria, 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'])) { @@ -470,7 +470,7 @@ protected function addAlert() { $this->data['results'] = $result; $this->data['criteria'] = $this->alert->criteria; - $this->data['display_criteria'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->alert->criteria); + $this->data['display_criteria'] = \MySociety\TheyWorkForYou\Utility\Alert::prettifyCriteria($this->alert->criteria, $this->alert->ignore_speaker_votes); } diff --git a/classes/Utility/Alert.php b/classes/Utility/Alert.php index 6e87183132..33a518912e 100644 --- a/classes/Utility/Alert.php +++ b/classes/Utility/Alert.php @@ -58,8 +58,8 @@ public static function forUser($email) { $alerts = []; foreach ($q as $row) { - $criteria = self::prettifyCriteria($row['criteria']); - $parts = self::prettifyCriteria($row['criteria'], true); + $criteria = self::prettifyCriteria($row['criteria'], $row['ignore_speaker_votes']); + $parts = self::prettifyCriteria($row['criteria'], $row['ignore_speaker_votes'], true); $token = $row['alert_id'] . '-' . $row['registrationtoken']; $status = 'confirmed'; @@ -87,7 +87,7 @@ public static function forUser($email) { return $alerts; } - public static function prettifyCriteria($alert_criteria, $as_parts = false) { + public static function prettifyCriteria($alert_criteria, $ignore_speaker_votes = false, $as_parts = false) { $text = ''; $parts = ['words' => [], 'sections' => [], 'exclusions' => [], 'match_all' => true]; if ($alert_criteria) { @@ -137,6 +137,9 @@ public static function prettifyCriteria($alert_criteria, $as_parts = false) { $parts['words'] = $words; } elseif ($spokenby) { $text = implode(' or ', $spokenby) . " speaks"; + if ($ignore_speaker_votes) { + $text .= " excluding votes"; + } $parts['spokenby'] = $spokenby; } diff --git a/www/includes/easyparliament/alert.php b/www/includes/easyparliament/alert.php index 54f99adc61..72c29f3777 100644 --- a/www/includes/easyparliament/alert.php +++ b/www/includes/easyparliament/alert.php @@ -41,6 +41,7 @@ class ALERT { private $alert_id = ""; public $email = ""; public $criteria = ""; // Sets the terms that are used to produce the search results. + public $ignore_speaker_votes = 0; private $db; @@ -123,15 +124,17 @@ public function get_related_terms($term) { public function update($id, $details) { $criteria = \MySociety\TheyWorkForYou\Utility\Alert::detailsToCriteria($details); + $ignore_speaker_votes = $details['ignore_speaker_votes'] ? 1 : 0; $q = $this->db->query("SELECT * FROM alerts WHERE alert_id = :id", [ ':id' => $id, ])->first(); if ($q) { - $q = $this->db->query("UPDATE alerts SET deleted = 0, criteria = :criteria, confirmed = 1 + $q = $this->db->query("UPDATE alerts SET deleted = 0, criteria = :criteria, ignore_speaker_votes = :ignore_speaker_votes, confirmed = 1 WHERE alert_id = :id", [ ":criteria" => $criteria, + ":ignore_speaker_votes" => $ignore_speaker_votes, ":id" => $id, ]); @@ -154,6 +157,7 @@ public function add($details, $confirmation_email = false, $instantly_confirm = // ) $criteria = \MySociety\TheyWorkForYou\Utility\Alert::detailsToCriteria($details); + $ignore_speaker_votes = $details['ignore_speaker_votes'] ? 1 : 0; $q = $this->db->query("SELECT * FROM alerts WHERE email = :email @@ -164,12 +168,13 @@ public function add($details, $confirmation_email = false, $instantly_confirm = ])->first(); if ($q) { if ($q['deleted']) { - $this->db->query("UPDATE alerts SET deleted=0 + $this->db->query("UPDATE alerts SET deleted=0, ignore_speaker_votes=:ignore_speaker_votes WHERE email = :email AND criteria = :criteria AND confirmed=1", [ ':email' => $details['email'], ':criteria' => $criteria, + ':ignore_speaker_votes' => $ignore_speaker_votes, ]); return 1; } else { @@ -178,17 +183,19 @@ public function add($details, $confirmation_email = false, $instantly_confirm = } $q = $this->db->query("INSERT INTO alerts ( - email, criteria, postcode, lang, deleted, confirmed, created + email, criteria, postcode, lang, ignore_speaker_votes, deleted, confirmed, created ) VALUES ( :email, :criteria, :pc, :lang, + :ignore_speaker_votes, '0', '0', NOW() ) ", [ ':email' => $details['email'], ':criteria' => $criteria, + ':ignore_speaker_votes' => $ignore_speaker_votes, ':pc' => $details['pc'], ':lang' => LANGUAGE, ]); @@ -199,6 +206,7 @@ public function add($details, $confirmation_email = false, $instantly_confirm = $this->alert_id = $q->insert_id(); $this->criteria = $criteria; + $this->ignore_speaker_votes = $ignore_speaker_votes; // We have to set the alert's registration token. // This will be sent to them via email, so we can confirm they exist. @@ -381,7 +389,7 @@ public function check_token($token) { return false; } - $q = $this->db->query("SELECT alert_id, email, criteria + $q = $this->db->query("SELECT alert_id, email, criteria, ignore_speaker_votes FROM alerts WHERE alert_id = :alert_id AND registrationtoken = :registration_token @@ -396,6 +404,7 @@ public function check_token($token) { 'id' => $q['alert_id'], 'email' => $q['email'], 'criteria' => $q['criteria'], + 'ignore_speaker_votes' => $q['ignore_speaker_votes'], ]; } diff --git a/www/includes/easyparliament/templates/html/alert/_mp_alert_form.php b/www/includes/easyparliament/templates/html/alert/_mp_alert_form.php index 5746c14aed..98123537cc 100644 --- a/www/includes/easyparliament/templates/html/alert/_mp_alert_form.php +++ b/www/includes/easyparliament/templates/html/alert/_mp_alert_form.php @@ -37,6 +37,13 @@

+
+
+ > + +
+
+

- + - - + + +

- - - + + + + + + + + + + + + + +
@@ -214,7 +232,7 @@

Alert when is mentioned

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

Alert when is mentioned

- + +
+
+ + + + + + $word) { ?> + + + + + + +
+ +
+
+ > +
+
+ +
+ + +
+ +
+ + +
+ + + 0) { ?> + + $member) { + $name = member_full_name($member['house'], $member['title'], $member['given_name'], $member['family_name'], $member['lordofname']); + if ($member['constituency']) { + $name .= ' (' . gettext($member['constituency']) . ')'; + } ?> + +
+ + +

+ +
- > - + > +
-
+ -
- - -
-
- - -
+ + + + -
- - - 0) { ?> - - $member) { - $name = member_full_name($member['house'], $member['title'], $member['given_name'], $member['family_name'], $member['lordofname']); - if ($member['constituency']) { - $name .= ' (' . gettext($member['constituency']) . ')'; - } ?> - -
+ + + + + + + + + + + +
+

+
+

+
    + +
  • + +
+
+ +

+ +
+ +
+ + + + - -
- > - -
+
+
+ 0) { ?> +
+
+
+
+ - - -
- - - - - - - - - - - - - -
-

-
-

-
    - -
  • - -
-
- -

- -
- -
- - - - - + +
+
+
30 May 2024
-
- -
- 0) { ?> -
-
-
-
- + - -
-
-
30 May 2024
-
- + +
- - + + + +
+ - - - + + + + + + + + + + + + + + + +
+

+ +
+ +

:

+ +

:

+ +
    + +
  • + +
- - - - - - - - - - - - - - - - - -
-

- -
- -

:

- -

:

+ + +
+

:

+
    + +
  • +
+
+ + +
+ 0) { ?> +

:

    - +
  • - +
-
+ +

+ +
- -
-

:

-
    - -
  • - -
-
- + 0) { ?> +
+

+
    + +
  • + +
+
+ -
- 0) { ?> -

:

-
    - -
  • - -
- -

- -
+ 0 || isset($lastmention)) { ?> +
+
+

See mentions for this alert

- 0) { ?> -
-

-
    - -
  • +
    + 0) { ?> +
    +
    +
    +
    -
-
- - 0 || isset($lastmention)) { ?> -
-
-

See mentions for this alert

- -
- 0) { ?> -
-
-
-
- - - -
-
-
30 May 2024
-
- -
- - -
- + +
+
+
30 May 2024
+
+ +
-
- - - - - - -
+ + - -
+
+ + + + + + + + + + diff --git a/www/includes/easyparliament/templates/html/alert/_keyword_alert_list.php b/www/includes/easyparliament/templates/html/alert/_keyword_alert_list.php new file mode 100644 index 0000000000..5ac6238f92 --- /dev/null +++ b/www/includes/easyparliament/templates/html/alert/_keyword_alert_list.php @@ -0,0 +1,240 @@ +
+ $alert) { ?> +
+ + +
+ +
+ +
+ +
+
+

Representative alerts

+
+
+ + +
+
+ + +

+
    +
  • + ' . htmlspecialchars($current_mp->full_name()) . '') ?>, speaks. +
    + + +
    +
  • +
+ 0) { ?> +
+

+ +

+ + + +

Alert when is mentioned

+
+ + +
+ + + 0) { ?> +
+

+ +
+ + + +
+
+

+ +

+
+
+ + + + + + + + + +
+
+ + + + + + + + + + + + + + + +
+
+ + +

Alert when is mentioned

+
+ + +
+ +
+ \ No newline at end of file diff --git a/www/includes/easyparliament/templates/html/alert/_list_accordian.php b/www/includes/easyparliament/templates/html/alert/_list_accordian.php deleted file mode 100644 index f2e16b854e..0000000000 --- a/www/includes/easyparliament/templates/html/alert/_list_accordian.php +++ /dev/null @@ -1,244 +0,0 @@ -
- $alert) { ?> -
- - -
- - -
- -
-
-

Representative alerts

-
-
- - -
-
- -

-
    -
  • - ' . htmlspecialchars($current_mp->full_name()) . '') ?>, speaks. -
    - - -
    -
  • -
- 0) { ?> -
-

- -

- - - -

Alert when is mentioned

-
- - -
- - - 0) { ?> -
-

- - -
- - - -
-
-

- - -

-

-
- - - - - - - - - -
-
- - - - - - - - - - - - - - - -
-
- - -

Alert when is mentioned

-
- - -
- -
- -
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 de22105d70..da8069171d 100644 --- a/www/includes/easyparliament/templates/html/alert/_own_mp_alerts.php +++ b/www/includes/easyparliament/templates/html/alert/_own_mp_alerts.php @@ -1,7 +1,7 @@

-
+
diff --git a/www/includes/easyparliament/templates/html/alert/index.php b/www/includes/easyparliament/templates/html/alert/index.php index 8782a49b71..0f97512f4c 100644 --- a/www/includes/easyparliament/templates/html/alert/index.php +++ b/www/includes/easyparliament/templates/html/alert/index.php @@ -278,7 +278,7 @@

-
+

Create an alert for a phrase or keyword

@@ -292,7 +292,7 @@

or

-
+

Create an alert when an MP speaks

@@ -312,7 +312,7 @@
-
+

@@ -320,21 +320,19 @@

-
- - - - -
+
+ + +
- +
From acf886092fc5c2e3a884cc07c86b00634acf434f Mon Sep 17 00:00:00 2001 From: Lucas Cumsille M Date: Tue, 17 Dec 2024 10:10:17 +0000 Subject: [PATCH 13/13] Fixed type alert page --- www/includes/easyparliament/templates/html/alert/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/includes/easyparliament/templates/html/alert/index.php b/www/includes/easyparliament/templates/html/alert/index.php index 0f97512f4c..5d9f50e0c7 100644 --- a/www/includes/easyparliament/templates/html/alert/index.php +++ b/www/includes/easyparliament/templates/html/alert/index.php @@ -317,7 +317,7 @@

-

+