Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp of the geocoder system #2320

Merged
merged 28 commits into from
Apr 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8f0b8ff
added willdurand/geocoder
DawoudIO Apr 17, 2017
70ed420
fixed log wan for missing sGlobalMessage
DawoudIO Apr 17, 2017
6ef953f
new static class for quick access to church info
DawoudIO Apr 17, 2017
2ae3405
replaced bUseGoogleGeocode with sGeoCoderProvider
DawoudIO Apr 17, 2017
80a0df6
new GeoCoder Service to select the provider based on system config
DawoudIO Apr 17, 2017
76f96e2
fixed typo
DawoudIO Apr 17, 2017
4fbb8b3
Lat Lng Cleanup
DawoudIO Apr 17, 2017
bfbdf99
updated json_decode to remove log warning
DawoudIO Apr 17, 2017
2201295
cleanup of the use ORM and using new ChurchMetaData Service
DawoudIO Apr 17, 2017
1ef0833
Extracted LatLonDistance & LatLonBearing into a GeoUtils
DawoudIO Apr 17, 2017
3250653
removed used code
DawoudIO Apr 17, 2017
109dd8d
Extracted LatLonDistance & LatLonBearing into a GeoUtils and ORM cle…
DawoudIO Apr 17, 2017
d645c19
Redone via ORM
DawoudIO Apr 17, 2017
b17c766
added note about how to update families and better fileter for items …
DawoudIO Apr 17, 2017
d078635
no longer needed
DawoudIO Apr 17, 2017
ca7204d
moved to GeoCoderService
DawoudIO Apr 17, 2017
e890cb4
update lat/lang after new create or update
DawoudIO Apr 17, 2017
db5d16b
added sBingMapKey for Bing Maps
DawoudIO Apr 17, 2017
907665a
added iMapZoom
DawoudIO Apr 17, 2017
a72aaf0
Apply fixes from StyleCI (#2319)
DawoudIO Apr 17, 2017
4f0c6c0
moved GeoCoderService logic into a static call in GeoUtils
DawoudIO Apr 17, 2017
577fc14
comments cleanup
DawoudIO Apr 17, 2017
9740579
No longer need getMailingAddress as we have getAddress
DawoudIO Apr 17, 2017
bb1d588
Merge branch 'master' into feature/update-family-latlon
crossan007 Apr 19, 2017
17176f7
Merge branch 'master' into feature/update-family-latlon
DawoudIO Apr 20, 2017
f712135
Aadded Missing Imports
DawoudIO Apr 20, 2017
be66b03
Merge branch 'master' into feature/update-family-latlon
crossan007 Apr 22, 2017
e47b54b
Merge branch 'master' into feature/update-family-latlon
DawoudIO Apr 22, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/ChurchCRM/Service/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ class NotificationService
public static function updateNotifications()
{
/* Get the latest notifications from the source. Store in session variable
*
*
*/
try {
$TempNotificaions = json_decode(file_get_contents(SystemConfig::getValue("sCloudURL")."notifications.json", false, $context));
$TempNotificaions = json_decode(file_get_contents(SystemConfig::getValue("sCloudURL")."notifications.json" ));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was a log warning about $context is not a valid var

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a reason for this.... I just can't remember what lol. I'll try to find a resolution - not blocking merge.

if (isset($TempNotificaions->TTL) ) {
$_SESSION['SystemNotifications'] = $TempNotificaions;
$_SESSION['SystemNotifications']->expires = new \DateTime();
$_SESSION['SystemNotifications']->expires->add(new \DateInterval("PT".$_SESSION['SystemNotifications']->TTL."S"));
}
} catch (\Exception $ex) {
//a failure here should never prevent the page from loading.
//a failure here should never prevent the page from loading.
//Possibly log an exception when a unified logger is implemented.
//for now, do nothing.
}
}

public static function getNotifications()
{
/* retreive active notifications from the session variable for display
*
*
*/
if (isset($_SESSION['SystemNotifications']))
{
Expand All @@ -45,12 +45,12 @@ public static function getNotifications()
return $notifications;
}
}

public static function hasActiveNotifications()
{
return count(NotificationService::getNotifications()) > 0;
}

public static function isUpdateRequired()
{
/*
Expand All @@ -63,5 +63,5 @@ public static function isUpdateRequired()
}
return false;
}
}

}
89 changes: 89 additions & 0 deletions src/ChurchCRM/dto/ChurchMetaData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
namespace ChurchCRM\dto;

use ChurchCRM\Utils\GeoUtils;

class ChurchMetaData
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we get that info in many places this is now a single place to get the Church Info... I'm planning to use this in the email system after both PRs are merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

{
public static function getChurchName()
{
return SystemConfig::getValue('sChurchName');
}

public static function getChurchFullAddress()
{
$address = [];
if (!empty(self::getChurchAddress())) {
array_push($address, self::getChurchAddress());
}

if (!empty(self::getChurchCity())) {
array_push($address, self::getChurchCity() . ',');
}

if (!empty(self::getChurchState())) {
array_push($address, self::getChurchState());
}

if (!empty(self::getChurchZip())) {
array_push($address, self::getChurchZip());
}
if (!empty(self::getChurchCountry())) {
array_push($address, self::getChurchCountry());
}

return implode(' ', $address);
}

public static function getChurchAddress()
{
return SystemConfig::getValue('sChurchAddress');
}

public static function getChurchCity()
{
return SystemConfig::getValue('sChurchCity');
}

public static function getChurchState()
{
return SystemConfig::getValue('sChurchState');
}

public static function getChurchZip()
{
return SystemConfig::getValue('sChurchZip');
}

public static function getChurchCountry()
{
return SystemConfig::getValue('sChurchCountry');
}

public static function getChurchLatitude()
{
if (empty(SystemConfig::getValue('nChurchLatitude'))) {
self::updateLatLng();
}
return SystemConfig::getValue('nChurchLatitude');
}

public static function getChurchLongitude()
{
if (empty(SystemConfig::getValue('nChurchLongitude'))) {
self::updateLatLng();
}
return SystemConfig::getValue('nChurchLongitude');
}

private static function updateLatLng()
{
if (!empty(self::getChurchFullAddress())) {
$latLng = GeoUtils::getLatLong(self::getChurchFullAddress());
if (!empty($latLng['Latitude']) && !empty($latLng['Longitude'])) {
SystemConfig::setValue('nChurchLatitude', $latLng['Latitude']);
SystemConfig::setValue('nChurchLongitude', $latLng['Longitude']);
}
}
}
}
12 changes: 7 additions & 5 deletions src/ChurchCRM/dto/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ private static function buildConfigs()
"sXML_RPC_PATH" => new ConfigItem(41, "sXML_RPC_PATH", "text", "XML/RPC.php", gettext("Path to RPC.php, required for Lat/Lon address lookup")),
"sGeocoderID" => new ConfigItem(42, "sGeocoderID", "text", "", gettext("User ID for rpc.geocoder.us")),
"sGeocoderPW" => new ConfigItem(43, "sGeocoderPW", "text", "", gettext("Password for rpc.geocoder.us")),
"sGoogleMapKey" => new ConfigItem(44, "sGoogleMapKey", "text", "", gettext("Google map API requires a unique key from https://developers.google.com/maps/documentation/javascript/get-api-key")),
"sGoogleMapKey" => new ConfigItem(44, "sGoogleMapKey", "text", "", gettext("Google map API requires a unique key") . " - https://developers.google.com/maps/documentation/javascript/get-api-key"),
"sBingMapKey" => new ConfigItem(10000, "sBingMapKey", "text", "", gettext("Bing map API requires a unique key") . " - https://www.microsoft.com/maps/create-a-bing-maps-key.aspx"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new Issue to so that we can another icon that is for external docs so that we do not put URLs in tool tips #2321

"iMapZoom" => new ConfigItem(10001, "iMapZoom", "number", "10", gettext("Google Maps Zoom")),
"nChurchLatitude" => new ConfigItem(45, "nChurchLatitude", "number", "", gettext("Latitude of the church, used to center the Google map")),
"nChurchLongitude" => new ConfigItem(46, "nChurchLongitude", "number", "", gettext("Longitude of the church, used to center the Google map")),
"bHidePersonAddress" => new ConfigItem(47, "bHidePersonAddress", "boolean", "1", gettext("Set true to disable entering addresses in Person Editor. Set false to enable entering addresses in Person Editor.")),
Expand All @@ -91,9 +93,9 @@ private static function buildConfigs()
"bHideLatLon" => new ConfigItem(51, "bHideLatLon", "boolean", "0", gettext("Set true to disable entering Latitude and Longitude in Family Editor. Set false to enable entering Latitude and Longitude in Family Editor. Lookups are still performed, just not displayed.")),
"bUseDonationEnvelopes" => new ConfigItem(52, "bUseDonationEnvelopes", "boolean", "0", gettext("Set true to enable use of donation envelopes")),
"sHeader" => new ConfigItem(53, "sHeader", "textarea", "", gettext("Enter in HTML code which will be displayed as a header at the top of each page. Be sure to close your tags! Note: You must REFRESH YOUR BROWSER A SECOND TIME to view the new header.")),
"sISTusername" => new ConfigItem(54, "sISTusername", "text", "username", gettext("Intelligent Search Technolgy, Ltd. CorrectAddress Username for https://www.intelligentsearch.com/Hosted/User")),
"sISTpassword" => new ConfigItem(55, "sISTpassword", "text", "", gettext("Intelligent Search Technolgy, Ltd. CorrectAddress Password for https://www.intelligentsearch.com/Hosted/User")),
"bUseGoogleGeocode" => new ConfigItem(56, "bUseGoogleGeocode", "boolean", "1", gettext("Set true to use the Google geocoder. Set false to use rpc.geocoder.us.")),
"sISTusername" => new ConfigItem(54, "sISTusername", "text", "username", gettext("Intelligent Search Technolgy, Ltd. CorrectAddress Username for") . " - https://www.intelligentsearch.com/Hosted/User"),
"sISTpassword" => new ConfigItem(55, "sISTpassword", "text", "", gettext("Intelligent Search Technolgy, Ltd. CorrectAddress Password for") . " - https://www.intelligentsearch.com/Hosted/User"),
"sGeoCoderProvider" => new ConfigItem(56, "sGeoCoderProvider", "choice", "GoogleMaps", gettext("Select GeoCoder Provider") . " - https://github.com/geocoder-php/Geocoder/blob/3.x/README.md#address-based-providers", '{"Choices":["GoogleMaps", "BingMaps"]}'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

"iChecksPerDepositForm" => new ConfigItem(57, "iChecksPerDepositForm", "number", "14", gettext("Number of checks for Deposit Slip Report")),
"bUseScannedChecks" => new ConfigItem(58, "bUseScannedChecks", "boolean", "0", gettext("Set true to enable use of scanned checks")),
"sDistanceUnit" => new ConfigItem(64, "sDistanceUnit", "choice", "miles", gettext("Unit used to measure distance, miles or km."), '{"Choices":["'.gettext("miles").'","'.gettext("kilometers").'"]}'),
Expand Down Expand Up @@ -178,7 +180,7 @@ private static function buildCategories()
gettext('Email Setup') => ["sSMTPHost","sSMTPAuth","sSMTPUser","sSMTPPass", "iSMTPTimeout","sToEmailAddress","mailChimpApiKey"],
gettext('Member Setup') => ["sDirClassifications","sDirRoleHead","sDirRoleSpouse","sDirRoleChild","sDefaultCity","sDefaultState","sDefaultCountry","bShowFamilyData","bHidePersonAddress","bHideFriendDate","bHideFamilyNewsletter","bHideWeddingDate","bHideLatLon","cfgForceUppercaseZip","sEnableGravatarPhotos","sEnableSelfRegistration", "bAllowEmptyLastName", "iPersonNameStyle"],
gettext('System Settings') => ["sLastBackupTimeStamp","sExternalBackupAutoInterval","sExternalBackupPassword","sEnableExternalBackupTarget","sExternalBackupType","sExternalBackupEndpoint","sExternalBackupUsername","debug","sLogFile", "bRegistered","sXML_RPC_PATH","sGZIPname","sZIPname","sPGPname","bCSVAdminOnly","sHeader","sEnableIntegrityCheck","sIntegrityCheckInterval","sLastIntegrityCheckTimeStamp"],
gettext('Map Settings') => ["sGoogleMapKey","bUseGoogleGeocode","sGMapIcons","sISTusername","sISTpassword","sGeocoderID","sGeocoderPW"],
gettext('Map Settings') => ["sGeoCoderProvider","sGoogleMapKey","sBingMapKey","sGMapIcons", "iMapZoom","sISTusername","sISTpassword","sGeocoderID","sGeocoderPW"],
gettext('Report Settings') => ["sQBDTSettings","leftX","incrementY","sTaxReport1","sTaxReport2","sTaxReport3","sTaxSigner","sReminder1","sReminderSigner","sReminderNoPledge","sReminderNoPayments","sConfirm1","sConfirm2","sConfirm3","sConfirm4","sConfirm5","sConfirm6","sDear","sConfirmSincerely","sConfirmSigner","sPledgeSummary1","sPledgeSummary2","sDirectoryDisclaimer1","sDirectoryDisclaimer2","bDirLetterHead","sZeroGivers","sZeroGivers2","sZeroGivers3"],
gettext('Localization') => ["sLanguage","sDistanceUnit","sPhoneFormat","sPhoneFormatWithExt","sDateFormatLong","sDateFormatNoYear","sDateFormatShort","sDateTimeFormat","sDateFilenameFormat"],
gettext('Financial Settings') => ["sDepositSlipType","iChecksPerDepositForm","bDisplayBillCounts","bUseScannedChecks","sElectronicTransactionProcessor","bEnableNonDeductible","iFYMonth","bUseDonationEnvelopes","aFinanceQueries"],
Expand Down
38 changes: 18 additions & 20 deletions src/ChurchCRM/model/ChurchCRM/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ChurchCRM\Base\Family as BaseFamily;
use Propel\Runtime\Connection\ConnectionInterface;
use ChurchCRM\dto\Photo;
use ChurchCRM\Utils\GeoUtils;

/**
* Skeleton subclass for representing a row from the 'family_fam' table.
Expand All @@ -19,6 +20,7 @@
*/
class Family extends BaseFamily implements iPhoto
{

public function getAddress()
{
$address = [];
Expand Down Expand Up @@ -187,22 +189,22 @@ public function getSaluation()
$notChildren[] = $person;
}
}

$notChildrenCount = count($notChildren);
if ($notChildrenCount === 1) {
return $notChildren[0]->getFullName();
}

if ($notChildrenCount === 2) {
if ($notChildren[0]->getLastName() == $notChildren[1]->getLastName()) {
return $notChildren[0]->getFirstName() .' & '. $notChildren[1]->getFirstName() .' '. $notChildren[0]->getLastName();
}
return $notChildren[0]->getFullName() .' & '. $notChildren[1]->getFullName();
}

return $this->getName() . ' Family';
}

private function getPhoto()
{
$photo = new Photo("Family", $this->getId());
Expand Down Expand Up @@ -282,27 +284,23 @@ public function getFamilyString()
{
return $this->getName(). " " . $this->getAddress();
}

/**

public function hasLatitudeAndLongitude() {
return !empty($this->getLatitude()) && !empty($this->getLongitude());
}

/**
* if the latitude or longitude is empty find the lat/lng from the address and update the lat lng for the family.
* @return array of Lat/Lng
*/
public function getLatLng() {
if ($this->getLatitude() == 0 || $this->getLongitude() == 0 ) {
$prepAddr = str_replace(' ','+',$this->getAddress());
$geocode=file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=".$prepAddr."&key=". SystemConfig::getValue('sGoogleMapKey'));
$output= json_decode($geocode);
if($output->results[0]->geometry->location->lat && $output->results[0]->geometry->location->lng) {
$this->setLatitude($output->results[0]->geometry->location->lat);
$this->setLongitude($output->results[0]->geometry->location->lng);
public function updateLanLng() {
if (!empty($this->getAddress()) && (!$this->hasLatitudeAndLongitude())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we want to update the lat/lng of an existing family?

$latLng = GeoUtils::getLatLong($this->getAddress());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this causes a traceback:

vagrant@scotchbox:~$ tail -f /tmp/ChurchCRM.log
[2017-04-18 21:06:22] defaultLogger.INFO: INSERT INTO note_nte (nte_ID, nte_per_ID, nte_Text, nte_DateEntered, nte_EnteredBy, nte_Type) VALUES (NULL, 2, 'Created via Family', '2017-04-18 21:06:22.000000', 1, 'create') [] []
[2017-04-18 21:06:22] defaultLogger.INFO: INSERT INTO note_nte (nte_ID, nte_per_ID, nte_Text, nte_DateEntered, nte_EnteredBy, nte_Type) VALUES (NULL, 3, 'Created via Family', '2017-04-18 21:06:22.000000', 1, 'create') [] []
[2017-04-18 21:06:22] defaultLogger.INFO: INSERT INTO note_nte (nte_ID, nte_fam_ID, nte_Text, nte_DateEntered, nte_EnteredBy, nte_Type) VALUES (NULL, 1, 'Created', '2017-04-18 21:06:22.000000', 1, 'create') [] []
[2017-04-18 21:06:22] defaultLogger.INFO: SELECT fam_ID, fam_Name, fam_Address1, fam_Address2, fam_City, fam_State, fam_Zip, fam_Country, fam_HomePhone, fam_WorkPhone, fam_CellPhone, fam_Email, fam_WeddingDate, fam_DateEntered, fam_DateLastEdited, fam_EnteredBy, fam_EditedBy, fam_scanCheck, fam_scanCredit, fam_SendNewsLetter, fam_DateDeactivated, fam_OkToCanvass, fam_Canvasser, fam_Latitude, fam_Longitude, fam_Envelope FROM family_fam WHERE fam_ID = '1' [] []
[18-Apr-2017 21:06:22 America/New_York] PHP Fatal error:  Uncaught Error: Class 'ChurchCRM\Utils\CurlHttpAdapter' not found in /var/www/public/ChurchCRM/utils/GeoUtils.php:15
Stack trace:
#0 /var/www/public/ChurchCRM/model/ChurchCRM/Family.php(298): ChurchCRM\Utils\GeoUtils::getLatLong('4222 Clinton Wa...')
#1 /var/www/public/FamilyEditor.php(442): ChurchCRM\Family->updateLanLng()
#2 {main}
  thrown in /var/www/public/ChurchCRM/utils/GeoUtils.php on line 15

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also what's causing the travis tests to fail

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya bad last min refactor ... i just fixed it

if(!empty( $latLng['Latitude']) && !empty($latLng['Longitude'])) {
$this->setLatitude($latLng['Latitude']);
$this->setLongitude($latLng['Longitude']);
$this->save();
}

}
return array(
'Latitude' => $this->getLatitude(),
'Longitude' => $this->getLongitude()
);
}

}
14 changes: 9 additions & 5 deletions src/ChurchCRM/model/ChurchCRM/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
class Person extends BasePerson implements iPhoto
{

public function getFullName()
{
return $this->getFormattedName(SystemConfig::getValue('iPersonNameStyle'));
Expand Down Expand Up @@ -176,12 +177,15 @@ public function getLatLng()
$address = $this->getAddress(); //if person address empty, this will get Family address
$lat = 0; $lng = 0;
if (!empty($this->getAddress1())) {
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;
$latLng = GeoUtils::getLatLong($this->getAddress());
if(!empty( $latLng['Latitude']) && !empty($latLng['Longitude'])) {
$lat = $latLng['Latitude'];
$lng = $latLng['Longitude'];
}
} else {
if (!$this->getFamily()->hasLatitudeAndLongitude()) {
$this->getFamily()->updateLanLng();
}
$lat = $this->getFamily()->getLatitude();
$lng = $this->getFamily()->getLongitude();
}
Expand Down
Loading