Skip to content

Commit

Permalink
supporting looking up messages for tomorrow for SearchType 1 (SmsGate…
Browse files Browse the repository at this point in the history
…way too) #21
  • Loading branch information
dgershman committed Feb 23, 2018
1 parent ebaf747 commit 0d6e5b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
24 changes: 21 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function getDurationFormat() {
}
}

class MeetingResults {
public $originalListCount;
public $filteredList;
}

function getCoordinatesForAddress($address) {
$coordinates = new Coordinates();

Expand Down Expand Up @@ -77,14 +82,27 @@ function helplineSearch($latitude, $longitude) {
}

function meetingSearch($latitude, $longitude, $search_type, $today, $tomorrow) {
if ($search_type == 1) {
if ($search_type == 1) { // Close to you
$bmlt_search_endpoint = $GLOBALS['bmlt_root_server'] . "/client_interface/json/?switcher=GetSearchResults&sort_results_by_distance=1&long_val={LONGITUDE}&lat_val={LATITUDE}&geo_width=-20&weekdays=" . $today;
} else if ($search_type == 2) {
} else if ($search_type == 2) { // Upcoming
$bmlt_search_endpoint = $GLOBALS['bmlt_root_server'] . "/client_interface/json/?switcher=GetSearchResults&sort_keys=start_time&long_val={LONGITUDE}&lat_val={LATITUDE}&geo_width=-20&weekdays=" . $today . "&weekdays=" . $tomorrow;
}

$meetingResults = new MeetingResults();

$search_url = str_replace("{LONGITUDE}", $longitude, str_replace("{LATITUDE}", $latitude, $bmlt_search_endpoint));
return json_decode(get($search_url));
$search_results = json_decode(get($search_url));
$meetingResults->originalListCount = count($search_results);

$filteredList = [];
for ($i = 0; $i < count($search_results); $i++) {
if (!isItPastTime($search_results[$i]->weekday_tinyint, $search_results[$i]->start_time)) {
array_push($filteredList, $search_results[$i]);
}
}

$meetingResults->filteredList = $filteredList;
return $meetingResults;
}

function getServiceBodyCoverage($latitude, $longitude) {
Expand Down
20 changes: 9 additions & 11 deletions meeting-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,34 @@
$tomorrow = (new DateTime('tomorrow'))->format("w") + $future;

$search_results = meetingSearch($latitude, $longitude, $search_type, $today, $tomorrow);
if ($search_type == 1 && count($search_results->filteredList) == 0) {
$search_results = meetingSearch($latitude, $longitude, $search_type, $tomorrow, null);
}

$filtered_list = $search_results->filteredList;

$results_count = 5;
$text_space = "\r\n";
$message = "";
?>
<Response>
<?php
$filtered_list = [];
for ($i = 0; $i < count($search_results); $i++) {
if (!isItPastTime($search_results[$i]->weekday_tinyint, $search_results[$i]->start_time)) {
array_push($filtered_list, $search_results[$i]);
}
}

if (!isset($_REQUEST["SmsSid"])) {
if (count($search_results) == 0) {
if ($search_results->originalListCount == 0) {
echo "<Say voice=\"" . $voice . "\" language=\"" . $language . "\">No results found, you might have an invalid entry. Try again.</Say><Redirect method=\"GET\">input-method.php?Digits=2</Redirect>";
} elseif (count($filtered_list) == 0) {
echo "<Say voice=\"" . $voice . "\" language=\"" . $language . "\">There are no other meetings for today. Thank you for calling, goodbye.</Say>";
} else {
echo "<Say voice=\"" . $voice . "\" language=\"" . $language . "\">Meeting information found, listing the top " . $results_count . " results.</Say>";
}
} else {
if (count($search_results) == 0) {
if ($search_results->originalListCount == 0) {
echo "<Sms>No results found, you might have an invalid entry. Try again.</Sms>";
} elseif (count($filtered_list) == 0) {
echo "<Sms>There are no other meetings for today.</Sms>";
}
}

$results_counter = 0;
for ($i = 0; $i < count($filtered_list); $i++) {
$result_day = $filtered_list[$i]->weekday_tinyint;
Expand Down Expand Up @@ -74,7 +72,7 @@
if ($results_counter == $results_count) break;
}

if (!isset($_REQUEST["SmsSid"]) && count($search_results) > 0) {
if (!isset($_REQUEST["SmsSid"]) && count($filtered_list) > 0) {
echo "<Say voice=\"" . $voice . "\" language=\"" . $language . "\">Thank you for calling, goodbye.</Say>";
}
?>
Expand Down

0 comments on commit 0d6e5b1

Please sign in to comment.