Skip to content

Commit

Permalink
disambiguate names when creating/editing alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Oct 22, 2024
1 parent a91ed9a commit c0f1843
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
27 changes: 19 additions & 8 deletions classes/AlertView/NewAlert.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,34 @@ private function processAction() {

protected function searchForConstituenciesAndMembers() {
// Do the search
if ($this->data['representative']) {
$errors = [];
if ($this->data['pid']) {
$MEMBER = new \MEMBER(['person_id' => $this->data['pid']]);
$this->data['members'] = [[
"person_id" => $MEMBER->person_id,
"given_name" => $MEMBER->given_name,
"family_name" => $MEMBER->family_name,
]];
} elseif ($this->data['representative']) {
$this->data['members'] = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookupWithNames($this->data['representative'], true);

if (count($this->data['members']) == 0) {
if (sizeof($this->data["errors"])) {
$this->data["errors"]["representative"] = "No matching representative found";
} else {
$this->data["errors"] = ["representative" => "No matching representative found"];
}
$member_count = count($this->data['members']);
if ($member_count == 0) {
$errors["representative"] = gettext("No matching representative found");
} elseif ($member_count > 1) {
$errors["representative"] = gettext("Multiple matching representatives found, please select one.");
} else {
$this->data['pid'] = $this->data['members'][0]['person_id'];
}
} else {
$this->data['members'] = [];
}

error_log(print_r($this->data['members'], true));
if (count($this->data["errors"]) > 0) {
$this->data["errors"] = array_merge($this->data["errors"], $errors);
} else {
$this->data["errors"] = $errors;
}
}

private function wrap_phrase_in_quotes($phrase) {
Expand Down
5 changes: 5 additions & 0 deletions www/docs/style/sass/parts/_accordion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ button {

}

.alert-page-option-label {
display: inline;
margin-left: 0.5em;
}

.button.red {
background-color: $color-red;
color: #fff;
Expand Down
21 changes: 16 additions & 5 deletions www/includes/easyparliament/templates/html/alert/new.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,23 @@
</select>
</div>

<div class="alert-page-subsection">
<label for="representative"><?= gettext('Would you like to only alert when a particular person speaks? (optional)') ?></label>
<input type="text" id="representative" name="representative" value="<?= _htmlspecialchars($representative) ?>" aria-required="true">
<?php if (isset($errors["representative"])) { ?>
<span class="alert-page-error"><?= $errors["representative"] ?></span>
<div class="alert-page-subsection">
<label for="representative"><?= gettext('Would you like to only alert when a particular person speaks? (optional)') ?></label>
<?php if (isset($errors["representative"])) { ?>
<?php if (count($members) > 0) { ?>
<span class="alert-page-error"><?= $errors["representative"] ?></span>
<?php foreach ($members as $index => $member) {
$name = member_full_name($member['house'], $member['title'], $member['given_name'], $member['family_name'], $member['lordofname']);
if ($member['constituency']) {
$name .= ' (' . gettext($member['constituency']) . ')';
} ?>
<input type="radio" name="pid" id="representative_<?= $index ?>" value="<?= $member['person_id'] ?>">
<label class="alert-page-option-label" for="representative_<?= $index ?>"><?= $name ?></label><br>
<?php } ?>
<?php } ?>
<p><?= gettext("Or edit the name") ?></p>
<?php } ?>
<input type="text" id="representative" name="representative" value="<?= _htmlspecialchars($representative) ?>" aria-required="true">
</div>


Expand Down

0 comments on commit c0f1843

Please sign in to comment.