Skip to content

Commit

Permalink
better detection of MP related alerts for grouping
Browse files Browse the repository at this point in the history
If you are subscribed to any MP alerts then try to detect all other
alerts for the MP and group them. Will not detect alerts for the MP's
name plus another term.
  • Loading branch information
struan committed Dec 3, 2024
1 parent f8618d3 commit 232c65d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
20 changes: 18 additions & 2 deletions classes/AlertView/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,24 @@ protected function setUserData() {
$this->data['spoken_alerts'][$alert['spokenby'][0]] = [];
}
$this->data['spoken_alerts'][$alert['spokenby'][0]][] = $alert;
} else {
$this->data['all_keywords'][] = implode(' ', $alert['words']);
}
}
foreach ($this->data['alerts'] as $alert) {
$term = implode(' ', $alert['words']);
$add = true;
if (array_key_exists('spokenby', $alert)) {
$add = false;
} elseif (array_key_exists($term, $this->data['spoken_alerts'])) {
$add = false;
$this->data['all_keywords'][] = $term;
$this->data['spoken_alerts'][$term][] = $alert;
} elseif ($term == $own_mp_criteria) {
$add = false;
$this->data['all_keywords'][] = $term;
$this->data['own_member_alerts'][] = $alert;
}
if ($add) {
$this->data['all_keywords'][] = $term;
$this->data['keyword_alerts'][] = $alert;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@
</div>
<?php } ?>
<?php if (!in_array(implode('', $person_alerts[0]['spokenby']), $all_keywords)) { ?>
<p class="alert-page-subsection--subtitle">Alert when <?= _htmlspecialchars(implode(', ', $alert['spokenby'])) ?> is <strong>mentioned</strong></p>
<p class="alert-page-subsection--subtitle">Alert when <?= _htmlspecialchars(implode(', ', $person_alerts[0]['spokenby'])) ?> is <strong>mentioned</strong></p>
<form action="<?= $actionurl ?>" method="post">
<input type="hidden" name="keyword" value="<?= _htmlentities(implode('', $alert['spokenby'])) ?>">
<input type="hidden" name="keyword" value="<?= _htmlentities(implode('', $person_alerts[0]['spokenby'])) ?>">
<button type="submit" class="button small" name="action" value="Subscribe">
<?= gettext('Create new alert') ?>
<i aria-hidden="true" role="img" class="fi-megaphone"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
</div>
<?php } ?>

<?php if (!in_array(implode('', $own_member_alerts[0]['spokenby']), $all_keywords)) { ?>
<p class="alert-page-subsection--subtitle">Alert when <?= _htmlspecialchars(implode('', $own_member_alerts[0]['spokenby'])) ?> is <strong>mentioned</strong></p>
<?php if (!in_array($own_mp_criteria, $all_keywords)) { ?>
<p class="alert-page-subsection--subtitle">Alert when <?= _htmlspecialchars($own_mp_criteria) ?> is <strong>mentioned</strong></p>
<form action="<?= $actionurl ?>" method="post">
<input type="hidden" name="keyword" value="<?= _htmlentities(implode('', $own_member_alerts[0]['spokenby'])) ?>">
<input type="hidden" name="keyword" value="<?= _htmlentities($own_mp_criteria) ?>">
<button type="submit" class="button small" name="action" value="Subscribe">
<?= gettext('Create new alert') ?>
<i aria-hidden="true" role="img" class="fi-megaphone"></i>
Expand Down

0 comments on commit 232c65d

Please sign in to comment.