Skip to content

Commit

Permalink
use a single page for alert form
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Oct 24, 2024
1 parent aea3119 commit 77ac3eb
Show file tree
Hide file tree
Showing 7 changed files with 1,057 additions and 354 deletions.
27 changes: 26 additions & 1 deletion classes/AlertView/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,28 @@ protected function checkInput() {

protected function searchForConstituenciesAndMembers() {
// Do the search
if ($this->data['alertsearch']) {
$errors = [];
if ($this->data['alertsearch'] != '') {
$this->data['members'] = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookupWithNames($this->data['alertsearch'], true);
[$this->data['constituencies'], $this->data['valid_postcode']] = \MySociety\TheyWorkForYou\Utility\Search::searchConstituenciesByQuery($this->data['alertsearch']);
} elseif ($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 (isset($this->data['representative']) && $this->data['representative'] != '') {
$this->data['members'] = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookupWithNames($this->data['representative'], true);

$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'] = [];
}
Expand All @@ -88,6 +107,12 @@ protected function searchForConstituenciesAndMembers() {
}
$this->data['constituencies'] = $cons;
}

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

protected function addAlert() {
Expand Down
Loading

0 comments on commit 77ac3eb

Please sign in to comment.