From cb61acf58212f5ad8c73e39af51aff04ee0b0058 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 26 Apr 2017 16:09:25 -0400 Subject: [PATCH 01/15] Update for Symphony 4.x Update release version. Update layout to fit in with Symphony 4.x. Wrap Geobuttons in div instead of label to fix hover. Remove console.logs from js. --- assets/addresslocationfield.publish.css | 106 +++++++++++++----------- assets/addresslocationfield.publish.js | 18 ++-- extension.meta.xml | 5 +- fields/field.addresslocation.php | 10 +-- 4 files changed, 75 insertions(+), 64 deletions(-) diff --git a/assets/addresslocationfield.publish.css b/assets/addresslocationfield.publish.css index c711dc1..885a858 100644 --- a/assets/addresslocationfield.publish.css +++ b/assets/addresslocationfield.publish.css @@ -1,83 +1,93 @@ -div.field-addresslocation { - clear: both; - padding-bottom: 1em; - border-bottom: 1px solid #ddc; -} -div.field-addresslocation:after { +/*div.field-addresslocation:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; -} +}*/ + div.field-addresslocation p { - border-bottom: 1px solid #ddc; - padding-bottom: 0.3em; - margin-bottom: 1em; - margin-top: 1.5em; + color: #2f77eb; + margin: 0 0 1.5rem; } + div.field-addresslocation label { - float: left; - margin-bottom: 0.5em; - width: 47%; - margin-right: 3%; -} -div.field-addresslocation label.street { - width: 97%; -} -div.field-addresslocation label.street, -div.field-addresslocation label.region, -div.field-addresslocation label.latitude, -div.field-addresslocation label.country { + box-sizing: border-box; + margin: 0 0 3rem; + padding-right: 3rem; + width: 50%; } -div.field-addresslocation label.country { + +@media (max-width: 767px) { + div.field-addresslocation label { + width: 100%; + } } -div.field-addresslocation label.city, -div.field-addresslocation label.postal-code, -div.field-addresslocation label.longitude { + +div.field-addresslocation label.street { + width: 100%; } + div.field-addresslocation label.latitude input, div.field-addresslocation label.longitude input { color: #7F7F7F; } + div.field-addresslocation label input { clear: both; } -div.field-addresslocation label.locate { + +div.field-addresslocation div.locate { + display: flex; + flex-direction: row; + align-items: flex-start; + justify-content: flex-start; + margin: 0 0 2em; width: 100%; - margin-top: 1em; } -div.field-addresslocation label.locate a.mapswitch { + +div.field-addresslocation div.locate a.mapswitch { float: right; text-decoration: none; } -div.field-addresslocation label.locate input { - float: left; - width: 47%; - clear: none; - margin-right: 3%; + +div.field-addresslocation div.locate input { + color: #fff; + font-size: 1.1rem; + text-transform: uppercase; + line-height: 1.6rem; + margin: 0 1rem 0 0; + padding: 1rem 1.5rem; + border-radius: 5px; + border: none; + background: #2f77eb; + width: auto; + cursor: pointer; } -div.field-addresslocation div.main { - width: 60%; - float: left; +div.field-addresslocation div.locate input:not(:disabled):hover { + background: #121212; } -div.field-addresslocation div.main.map { - float: right; - height: 220px; - width: 40%; + +div.field-addresslocation div.locate input:disabled { + opacity: 0.25; + pointer-events: none; } -div.field-addresslocation div.sidebar { - width: 100%; - float:left; +div.field-addresslocation div.main.address { + display: flex; + flex-direction: row; + align-items: flex-start; + justify-content: flex-start; + flex-wrap: wrap; + width: calc(100% + 3rem); } -div.field-addresslocation div.sidebar.map { + +div.field-addresslocation div.main.map { width: 100%; - margin-top: 15px; height: 200px; - float: left; } + div.field-addresslocation div.gm-style-cc { display: none; } diff --git a/assets/addresslocationfield.publish.js b/assets/addresslocationfield.publish.js index 86244ba..2da6cd2 100755 --- a/assets/addresslocationfield.publish.js +++ b/assets/addresslocationfield.publish.js @@ -39,13 +39,13 @@ map.setCenter(latlng); //map.setZoom(16); SetMarker(latlng); - helpers.toggleFieldState(field.find('label.locate input[name="locate"]'), true); + helpers.toggleFieldState(field.find('div.locate input[name="locate"]'), true); } else{ - helpers.toggleFieldState(field.find('label.locate input[name="clear"]'), true); + helpers.toggleFieldState(field.find('div.locate input[name="clear"]'), true); } - field.find('label.locate input[name="clear"]').click(function(ev){ + field.find('div.locate input[name="clear"]').click(function(ev){ ev.preventDefault(); @@ -57,16 +57,15 @@ map.setCenter(new google.maps.LatLng(0,0)); map.setZoom(1); - field.find('label.locate input[name="locate"]').removeAttr('disabled'); + field.find('div.locate input[name="locate"]').removeAttr('disabled'); }); if(field.find('div.address').hasClass('sidebar')){ - var a = $('[-] Hide Map').appendTo('label.locate') + var a = $('[-] Hide Map').appendTo('div.locate') - field.delegate('label.locate a.mapswitch', 'click', function(ev){ - console.log('clicked'); + field.delegate('div.locate a.mapswitch', 'click', function(ev){ ev.preventDefault(); var map = field.find('div.map'); if(map.hasClass('open')){ @@ -81,7 +80,7 @@ } - field.find('label.locate input[name="locate"]').click(function(ev){ + field.find('div.locate input[name="locate"]').click(function(ev){ //Reassign field to stop mime warning/error var field = $('div.field-addresslocation'); @@ -116,7 +115,7 @@ }); field.on('focus', 'input[type=text]', function(ev){ - var $btn = field.find('label.locate input[name="locate"]') + var $btn = field.find('div.locate input[name="locate"]') if ($btn.attr('disabled')) { helpers.toggleFieldState($btn); } @@ -125,7 +124,6 @@ } function GeocodeAddress(address, success, fail){ geocoder.geocode({"address":address}, function(results, status){ - console.log(status, results); if(status == google.maps.GeocoderStatus.OK){ success(results[0]); }else{ diff --git a/extension.meta.xml b/extension.meta.xml index 05acd5b..4065fbf 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -14,6 +14,9 @@ + + - Update for Symphony 4.x + - Add preferences UI (#22) @@ -37,4 +40,4 @@ - \ No newline at end of file + diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index f342406..28b2d8f 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -219,11 +219,11 @@ function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWithError $label->appendChild(Widget::Input('fields'.$fieldnamePrefix.'['.$this->get('element_name').'][longitude]'.$fieldnamePostfix, $coordinates[1], 'text', array('readonly' => 'readonly'))); $address->appendChild($label); - $label = Widget::Label(); - $label->setAttribute('class', 'locate'); - $label->appendChild(Widget::Input('locate', 'Geocode Address', 'button', array('class' => 'button'))); - $label->appendChild(Widget::Input('clear', 'Clear Address', 'button', array('class' => 'button'))); - $address->appendChild($label); + $div = new XMLElement('div'); + $div->setAttribute('class', 'locate'); + $div->appendChild(Widget::Input('locate', 'Geocode Address', 'button', array('class' => 'button'))); + $div->appendChild(Widget::Input('clear', 'Clear Address', 'button', array('class' => 'button'))); + $address->appendChild($div); $map = new XMLElement('div'); $map->setAttribute('class', 'map '.$class.' open'); From 5748a72cca1ab4124d8efe5a18f4cbc6097576f4 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 27 Apr 2017 13:10:53 -0400 Subject: [PATCH 02/15] Update release date --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 4065fbf..adb1b9b 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -14,7 +14,7 @@ - + - Update for Symphony 4.x From 848ee920d1ae36ca6d1ea362929b522700165d51 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 17 May 2017 10:54:38 -0400 Subject: [PATCH 03/15] Update php-min/php-max info --- extension.meta.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index adb1b9b..dda0d4f 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -14,7 +14,7 @@ - + - Update for Symphony 4.x From 7dc1fa97fd5c20547d3c95f526e1e6ed879e674c Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 26 May 2017 15:05:50 -0400 Subject: [PATCH 04/15] Style fixes --- assets/addresslocationfield.publish.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/addresslocationfield.publish.css b/assets/addresslocationfield.publish.css index 885a858..baafabd 100644 --- a/assets/addresslocationfield.publish.css +++ b/assets/addresslocationfield.publish.css @@ -70,7 +70,7 @@ div.field-addresslocation div.locate input:not(:disabled):hover { } div.field-addresslocation div.locate input:disabled { - opacity: 0.25; + opacity: 0.5; pointer-events: none; } From 104762ee0f8b958f7d69f4b5bb8437baea8cb111 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 24 Aug 2017 15:23:36 -0400 Subject: [PATCH 05/15] SQL and PHP cases PHP true,false,null in lowercase SQL keywords uppercase --- extension.driver.php | 22 +++++++-------- fields/field.addresslocation.php | 46 ++++++++++++++++---------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index fe11773..eb4754e 100755 --- a/extension.driver.php +++ b/extension.driver.php @@ -52,13 +52,13 @@ public function update($previousVersion = false){ foreach($addresslocation_entry_tables as $field) { Symphony::Database()->query(sprintf( - "ALTER TABLE `tbl_entries_data_%d` ADD `neighborhood` varchar(255), ADD `neighborhood_handle` varchar(255)", + "ALTER TABLE `tbl_entries_data_%d` ADD `neighborhood` VARCHAR(255), ADD `neighborhood_handle` VARCHAR(255)", $field )); } } } - + if(version_compare($previousVersion, '1.2.3', '<')){ if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables)) { @@ -78,13 +78,13 @@ public function update($previousVersion = false){ public function install() { return Symphony::Database()->query("CREATE TABLE `tbl_fields_addresslocation` ( - `id` int(11) unsigned NOT NULL auto_increment, - `field_id` int(11) unsigned NOT NULL, - `street_label` varchar(80) NOT NULL, - `city_label` varchar(80) NOT NULL, - `region_label` varchar(80) NOT NULL, - `postal_code_label` varchar(80) NOT NULL, - `country_label` varchar(80) NOT NULL, + `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `field_id` INT(11) UNSIGNED NOT NULL, + `street_label` VARCHAR(80) NOT NULL, + `city_label` VARCHAR(80) NOT NULL, + `region_label` VARCHAR(80) NOT NULL, + `postal_code_label` VARCHAR(80) NOT NULL, + `country_label` VARCHAR(80) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `field_id` (`field_id`) ) TYPE=MyISAM"); @@ -94,7 +94,7 @@ public function install() Modified from: http://www.kevinbradwick.co.uk/developer/php/free-to-script-to-calculate-the-radius-of-a-coordinate-using-latitude-and-longitude */ - public function geoRadius($lat, $lng, $rad, $kilometers=false) + public function geoRadius($lat, $lng, $rad, $kilometers = false) { $radius = ($kilometers) ? ($rad * 0.621371192) : $rad; @@ -145,4 +145,4 @@ public function geoDistance($lat1, $lon1, $lat2, $lon2, $unit) } -?> \ No newline at end of file +?> diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index 28b2d8f..81f47ce 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -77,7 +77,7 @@ public function canFilter() return true; } - function displaySettingsPanel(XMLElement &$wrapper, $errors = NULL) + function displaySettingsPanel(XMLElement &$wrapper, $errors = null) { parent::displaySettingsPanel($wrapper, $errors); @@ -90,7 +90,7 @@ function displaySettingsPanel(XMLElement &$wrapper, $errors = NULL) } - public function processRawFieldData($data, &$status, &$message=null, $simulate=false, $entry_id=null) + public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) { $status = self::__OK__; @@ -159,7 +159,7 @@ function commit() Symphony::Database()->insert($fields, 'tbl_fields_' . $this->handle()); } - function displayPublishPanel(XMLElement &$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL, $entry_id = NULL) + function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $key = Symphony::Configuration()->get('api_key','addresslocationfield'); if(empty($key)) { @@ -234,22 +234,22 @@ public function createTable() { return Symphony::Database()->query( "CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` ( - `id` int(11) unsigned NOT NULL auto_increment, - `entry_id` int(11) unsigned NOT NULL, - `street` varchar(255), - `street_handle` varchar(255), - `city` varchar(255), - `city_handle` varchar(255), - `region` varchar(255), - `region_handle` varchar(255), - `postal_code` varchar(255), - `postal_code_handle` varchar(255), - `country` varchar(255), - `country_handle` varchar(255), - `latitude` double default NULL, - `longitude` double default NULL, - `neighborhood` varchar(255), - `neighborhood_handle` varchar(255), + `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `entry_id` INT(11) UNSIGNED NOT NULL, + `street` VARCHAR(255), + `street_handle` VARCHAR(255), + `city` VARCHAR(255), + `city_handle` VARCHAR(255), + `region` VARCHAR(255), + `region_handle` VARCHAR(255), + `postal_code` VARCHAR(255), + `postal_code_handle` VARCHAR(255), + `country` VARCHAR(255), + `country_handle` VARCHAR(255), + `latitude` DOUBLE DEFAULT NULL, + `longitude` DOUBLE DEFAULT NULL, + `neighborhood` VARCHAR(255), + `neighborhood_handle` VARCHAR(255), `result_data` blob NOT NULL, PRIMARY KEY (`id`), KEY `entry_id` (`entry_id`), @@ -321,7 +321,7 @@ public function itemsToXML($parent, $items) { } } - public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = NULL, $entry_id = NULL) + public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { $field = new XMLElement($this->get('element_name'), null, array( 'latitude' => $data['latitude'], @@ -331,7 +331,7 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa foreach (array('street', 'city', 'region', 'postal_code', 'country', 'neighborhood') as $name) { - if ($encode === TRUE){ + if ($encode === true){ $data[$name] = General::sanitize($data[$name]); } $element_name = $this->get("{$name}_label"); @@ -362,7 +362,7 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa } - public function prepareTableValue($data, XMLElement $link = NULL, $entry_id = NULL) + public function prepareTableValue($data, XMLElement $link = null, $entry_id = null) { if (empty($data)) return; @@ -377,7 +377,7 @@ public function prepareTableValue($data, XMLElement $link = NULL, $entry_id = NU return trim($string,", "); } - function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation=false) + function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false) { $columns_to_labels = array(); From c2418b37074d9c2826a869fafde7e5c2ebf3eb84 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Mon, 18 Dec 2017 14:44:14 -0500 Subject: [PATCH 06/15] Adjust layout in group style --- assets/addresslocationfield.publish.css | 16 ++++++++-------- fields/field.addresslocation.php | 7 +++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/assets/addresslocationfield.publish.css b/assets/addresslocationfield.publish.css index baafabd..8633dbb 100644 --- a/assets/addresslocationfield.publish.css +++ b/assets/addresslocationfield.publish.css @@ -1,11 +1,3 @@ -/*div.field-addresslocation:after { - content: "."; - display: block; - height: 0; - clear: both; - visibility: hidden; -}*/ - div.field-addresslocation p { color: #2f77eb; margin: 0 0 1.5rem; @@ -74,6 +66,14 @@ div.field-addresslocation div.locate input:disabled { pointer-events: none; } +div.field-addresslocation div.main-wrapper { + border-radius: 5px; + -webkit-border-radius: 5px; + margin: 0 0 3rem; + padding: 1.5rem; + border: 1px solid #d3dce2; +} + div.field-addresslocation div.main.address { display: flex; flex-direction: row; diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index 81f47ce..09be70d 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -178,11 +178,12 @@ function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError $label = new XMLElement('p', $this->get('label')); $label->setAttribute('class', 'title'); $wrapper->appendChild($label); + $wrapinner = new XMLElement('div', null, array('class' => 'main-wrapper')); // Address Fields $address = new XMLElement('div'); $address->setAttribute('class', 'address '.$class); - $wrapper->appendChild($address); + $wrapinner->appendChild($address); $label = Widget::Label($this->get('street_label')); $label->setAttribute('class', 'street'); @@ -227,7 +228,9 @@ function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError $map = new XMLElement('div'); $map->setAttribute('class', 'map '.$class.' open'); - $wrapper->appendChild($map); + $wrapinner->appendChild($map); + + $wrapper->appendChild($wrapinner); } public function createTable() From 2f97617fa949ea14854ef777cb567fc3ccc4c0b3 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 18 May 2018 16:24:26 -0400 Subject: [PATCH 07/15] Code refactoring for Database --- extension.driver.php | 74 ++++++++++++------- extension.meta.xml | 3 +- fields/field.addresslocation.php | 122 ++++++++++++++++++------------- 3 files changed, 124 insertions(+), 75 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index eb4754e..b345064 100755 --- a/extension.driver.php +++ b/extension.driver.php @@ -27,21 +27,30 @@ public function addCustomPreferenceFieldsets($context) { public function uninstall() { - Symphony::Database()->query("DROP TABLE `tbl_fields_addresslocation`"); + return Symphony::Database() + ->drop('tbl_fields_addresslocation') + ->ifExists() + ->execute() + ->success(); } public function update($previousVersion = false){ - $addresslocation_entry_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_addresslocation`"); + $addresslocation_entry_tables = Symphony::Database() + ->select(['field_id']) + ->from('tbl_fields_addresslocation') + ->execute() + ->column('field_id'); if(version_compare($previousVersion, '1.2.1', '<')){ if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables)) { foreach($addresslocation_entry_tables as $field) { - Symphony::Database()->query(sprintf( - "ALTER TABLE `tbl_entries_data_%d` ADD `result_data` blob", - $field - )); + Symphony::Database() + ->alter("tbl_entries_data_$field") + ->add(['result_data' => 'blob']) + ->execute() + ->success(); } } } @@ -51,10 +60,14 @@ public function update($previousVersion = false){ { foreach($addresslocation_entry_tables as $field) { - Symphony::Database()->query(sprintf( - "ALTER TABLE `tbl_entries_data_%d` ADD `neighborhood` VARCHAR(255), ADD `neighborhood_handle` VARCHAR(255)", - $field - )); + Symphony::Database() + ->alter("tbl_entries_data_$field") + ->add([ + 'neighborhood' => 'varchar(255)', + 'neighborhood_handle' => 'varchar(255)', + ]) + ->execute() + ->success(); } } } @@ -64,10 +77,11 @@ public function update($previousVersion = false){ { foreach($addresslocation_entry_tables as $field) { - Symphony::Database()->query(sprintf( - "ALTER TABLE `tbl_entries_data_%d` MODIFY COLUMN `result_data` blob", - $field - )); + Symphony::Dabatase() + ->alter("tbl_entries_data_$field") + ->modify(['result_data' => 'blob']) + ->execute() + ->success(); } } } @@ -77,17 +91,27 @@ public function update($previousVersion = false){ public function install() { - return Symphony::Database()->query("CREATE TABLE `tbl_fields_addresslocation` ( - `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `field_id` INT(11) UNSIGNED NOT NULL, - `street_label` VARCHAR(80) NOT NULL, - `city_label` VARCHAR(80) NOT NULL, - `region_label` VARCHAR(80) NOT NULL, - `postal_code_label` VARCHAR(80) NOT NULL, - `country_label` VARCHAR(80) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `field_id` (`field_id`) - ) TYPE=MyISAM"); + Symphony::Database() + ->create('tbl_fields_addresslocation') + ->ifNotExists() + ->fields([ + 'id' => [ + 'type' => 'int(11)', + 'auto' => true, + ], + 'field_id' => 'int(11)', + 'street_label' => 'varchar(80)', + 'city_label' => 'varchar(80)', + 'region_label' => 'varchar(80)', + 'postal_code_label' => 'varchar(80)', + 'country_label' => 'varchar(80)', + ]) + ->keys([ + 'id' => 'primary', + 'field_id' => 'unique', + ]) + ->execute() + ->success(); } /* diff --git a/extension.meta.xml b/extension.meta.xml index dda0d4f..f382780 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -14,8 +14,9 @@ - + - Update for Symphony 4.x + - Code refactoring for Database and EQFA - Add preferences UI (#22) diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index 09be70d..eb8e403 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -26,7 +26,7 @@ private function __geocodeAddress($address) $cache_id = md5('addresslocationfield_' . $address); $cache = new Cacheable(Symphony::Database()); - $cachedData = $cache->check($cache_id); + $cachedData = $cache->read($cache_id); // no data has been cached if(!$cachedData) { @@ -146,17 +146,25 @@ function commit() if($id === false) return false; - $fields = array( - 'field_id' => $id, - 'street_label' => $this->get('street_label'), - 'city_label' => $this->get('city_label'), - 'region_label' => $this->get('region_label'), - 'postal_code_label' => $this->get('postal_code_label'), - 'country_label' => $this->get('country_label') - ); - - Symphony::Database()->query("DELETE FROM `tbl_fields_".$this->handle()."` WHERE `field_id` = '$id' LIMIT 1"); - Symphony::Database()->insert($fields, 'tbl_fields_' . $this->handle()); + Symphony::Database() + ->delete('tbl_fields_' . $this->handle()) + ->where(['field_id' => $id]) + ->limit(1) + ->execute() + ->success(); + + Symphony::database() + ->insert('tbl_fields_' . $this->handle()) + ->values([ + 'field_id' => $id, + 'street_label' => $this->get('street_label'), + 'city_label' => $this->get('city_label'), + 'region_label' => $this->get('region_label'), + 'postal_code_label' => $this->get('postal_code_label'), + 'country_label' => $this->get('country_label'), + ]) + ->execute() + ->success(); } function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) @@ -235,43 +243,59 @@ function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError public function createTable() { - return Symphony::Database()->query( - "CREATE TABLE IF NOT EXISTS `tbl_entries_data_" . $this->get('id') . "` ( - `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, - `entry_id` INT(11) UNSIGNED NOT NULL, - `street` VARCHAR(255), - `street_handle` VARCHAR(255), - `city` VARCHAR(255), - `city_handle` VARCHAR(255), - `region` VARCHAR(255), - `region_handle` VARCHAR(255), - `postal_code` VARCHAR(255), - `postal_code_handle` VARCHAR(255), - `country` VARCHAR(255), - `country_handle` VARCHAR(255), - `latitude` DOUBLE DEFAULT NULL, - `longitude` DOUBLE DEFAULT NULL, - `neighborhood` VARCHAR(255), - `neighborhood_handle` VARCHAR(255), - `result_data` blob NOT NULL, - PRIMARY KEY (`id`), - KEY `entry_id` (`entry_id`), - KEY `latitude` (`latitude`), - KEY `longitude` (`longitude`), - INDEX `street` (`street`), - INDEX `street_handle` (`street_handle`), - INDEX `city` (`city`), - INDEX `city_handle` (`city_handle`), - INDEX `region` (`region`), - INDEX `region_handle` (`region_handle`), - INDEX `postal_code` (`postal_code`), - INDEX `postal_code_handle` (`postal_code_handle`), - INDEX `country` (`country`), - INDEX `country_handle` (`country_handle`), - INDEX `neighborhood` (`neighborhood`), - INDEX `neighborhood_handle` (`neighborhood_handle`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;" - ); + return Symphony::Database() + ->create('tbl_entries_data_' . $this->get('id')) + ->ifNotExists() + ->charset('utf8') + ->collate('utf8_unicode_ci') + ->fields([ + 'id' => [ + 'type' => 'int(11)', + 'auto' => true, + ], + 'entry_id' => 'int(11)', + 'street' => 'varchar(255)', + 'street_handle' => 'varchar(255)', + 'city' => 'varchar(255)', + 'city_handle' => 'varchar(255)', + 'region' => 'varchar(255)', + 'region_handle' => 'varchar(255)', + 'postal_code' => 'varchar(255)', + 'postal_code_handle' => 'varchar(255)', + 'country' => 'varchar(255)', + 'country_handle' => 'varchar(255)', + 'latitude' => [ + 'type' => 'double', + 'null' => true, + ], + 'longitude' => [ + 'type' => 'double', + 'null' => true, + ], + 'neighborhood' => 'varchar(255)', + 'neighborhood_handle' => 'varchar(255)', + 'result_data' => 'blob', + ]) + ->keys([ + 'id' => 'primary', + 'entry_id' => 'key', + 'latitude' => 'key', + 'longitude' => 'key', + 'street' => 'index', + 'street_handle' => 'index', + 'city' => 'index', + 'city_handle' => 'index', + 'region' => 'index', + 'region_handle' => 'index', + 'postal_code' => 'index', + 'postal_code_handle' => 'index', + 'country' => 'index', + 'country_handle' => 'index', + 'neighborhood' => 'index', + 'neighborhood_handle' => 'index', + ]) + ->execute() + ->success(); } public function convertObjectToArray($data) From c297e9194cca2ea9df7de3ae566cc9fcfc95d7a5 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 29 May 2018 13:53:09 -0400 Subject: [PATCH 08/15] Begin code refactoring for EQFA --- extension.driver.php | 2 +- fields/field.addresslocation.php | 47 +++++-- ...class.entryqueryaddresslocationadapter.php | 123 ++++++++++++++++++ 3 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 lib/class.entryqueryaddresslocationadapter.php diff --git a/extension.driver.php b/extension.driver.php index b345064..5476d00 100755 --- a/extension.driver.php +++ b/extension.driver.php @@ -130,7 +130,7 @@ public function geoRadius($lat, $lng, $rad, $kilometers = false) (float)$latMAX = $lat + $usrRLAT; // Longitude calculation - (float)$mpdLON = 69.1703234283616 * cos($lat * (pi/180)); + (float)$mpdLON = 69.1703234283616 * cos($lat * (pi()/180)); (float)$dpmLON = 1 / $mpdLON; // degrees per mile longintude $usrRLON = $dpmLON * $radius; diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index eb8e403..e0611cf 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -1,26 +1,29 @@ entryQueryFieldAdapter = new EntryQueryAddressLocationAdapter($this); + $this->_name = 'Address Location'; - $this->_driver = Symphony::ExtensionManager()->create('addresslocationfield'); + $this->driver = Symphony::ExtensionManager()->create('addresslocationfield'); } - private function __geocodeAddress($address) + public function geocodeAddress($address) { $coordinates = null; @@ -103,7 +106,7 @@ public function processRawFieldData($data, &$status, &$message = null, $simulate 'postal_code' => General::sanitize($data['postal_code']), 'country' => General::sanitize($data['country']), ); - $geocoded_result = $this->__geocodeAddress(implode(',', $result)); + $geocoded_result = $this->geocodeAddress(implode(',', $result)); $neighborhood = ''; if( is_object($geocoded_result) ) { @@ -379,11 +382,11 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa // Add back Google Maps result data - if (count($this->_filter_origin['latitude']) > 0) { + if (count($this->filter_origin['latitude']) > 0) { $distance = new XMLElement('distance'); - $distance->setAttribute('from', $this->_filter_origin['latitude'] . ',' . $this->_filter_origin['longitude']); - $distance->setAttribute('distance', $this->_driver->geoDistance($this->_filter_origin['latitude'], $this->_filter_origin['longitude'], $data['latitude'], $data['longitude'], $this->_filter_origin['unit'])); - $distance->setAttribute('unit', ($this->_filter_origin['unit'] == 'k') ? 'km' : 'miles'); + $distance->setAttribute('from', $this->filter_origin['latitude'] . ',' . $this->filter_origin['longitude']); + $distance->setAttribute('distance', $this->driver->geoDistance($this->filter_origin['latitude'], $this->filter_origin['longitude'], $data['latitude'], $data['longitude'], $this->filter_origin['unit'])); + $distance->setAttribute('unit', ($this->filter_origin['unit'] == 'k') ? 'km' : 'miles'); $field->appendChild($distance); } @@ -404,6 +407,22 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu return trim($string,", "); } + public function fetchFilterableOperators() + { + return array( + array( + 'title' => 'in', + 'filter' => 'in:', + 'help' => __('Find values that match the given query.') + ), + array( + 'title' => 'within', + 'filter' => 'within:', + 'help' => __('Find values that match the given query.') + ), + ); + } + function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false) { @@ -458,7 +477,7 @@ function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false) } // otherwise the origin needs geocoding else { - $geocoded_result = $this->__geocodeAddress($origin); + $geocoded_result = $this->geocodeAddress($origin); $coordinates = $geocoded_result->geometry->location; if ($geocoded_result) { @@ -470,12 +489,12 @@ function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false) // if we don't have a decent set of coordinates, we can't query if (is_null($lat) || is_null($lng)) return true; - $this->_filter_origin['latitude'] = $lat; - $this->_filter_origin['longitude'] = $lng; - $this->_filter_origin['unit'] = $unit[0]; + $this->filter_origin['latitude'] = $lat; + $this->filter_origin['longitude'] = $lng; + $this->filter_origin['unit'] = $unit[0]; // build the bounds within the query should look - $radius = $this->_driver->geoRadius($lat, $lng, $radius, ($unit[0] == 'k')); + $radius = $this->driver->geoRadius($lat, $lng, $radius, ($unit[0] == 'k')); $where .= sprintf( " AND `t%d`.`latitude` BETWEEN %s AND %s AND `t%d`.`longitude` BETWEEN %s AND %s", diff --git a/lib/class.entryqueryaddresslocationadapter.php b/lib/class.entryqueryaddresslocationadapter.php new file mode 100644 index 0000000..328bab4 --- /dev/null +++ b/lib/class.entryqueryaddresslocationadapter.php @@ -0,0 +1,123 @@ +field->get('id')); + $filter = $this->field->cleanValue($filter); + $matches = []; + preg_match("/^in:? ?($columns) of (.+)$/", $filter, $matches); + + $column = $columns_to_labels[$matches[1]]; + $value = $matches[2]; + + $conditions = []; + $conditions[] = [$this->formatColumn($column, $field_id) => $value]; + $conditions[] = [$this->formatColumn($column . '_handle', $field_id) => $value]; + + if (count($conditions) < 2) { + return $conditions; + } + return ['or' => $conditions]; + } + + public function isFilterWithin($filter) + { + return preg_match('/^within:? ?([0-9]+)\s?(km|mile|miles) of (.+)$/', $filter); + } + + public function createFilterWithin($filter) + { + $field_id = General::intval($this->field->get('id')); + $filter = $this->field->cleanValue($filter); + $matches = []; + preg_match('/^within:? ?([0-9]+)\s?(km|mile|miles) of (.+)$/', $filter, $matches); + + $radius = trim($matches[1]); + $unit = strtolower(trim($matches[2])); + $origin = trim($matches[3]); + + $lat = null; + $lng = null; + + // is a lat/long pair + if (preg_match('/^(-?[.0-9]+),?\s?(-?[.0-9]+)$/', $origin, $latlng)) { + $lat = $latlng[1]; + $lng = $latlng[2]; + } + // otherwise the origin needs geocoding + else { + $geocoded_result = $this->field->geocodeAddress($origin); + $coordinates = $geocoded_result->geometry->location; + + if ($geocoded_result) { + $lat = $coordinates->lat; + $lng = $coordinates->lng; + } + } + + // if we don't have a decent set of coordinates, we can't query + if (is_null($lat) || is_null($lng)) return true; + + $this->field->filter_origin['latitude'] = $lat; + $this->field->filter_origin['longitude'] = $lng; + $this->field->filter_origin['unit'] = $unit[0]; + + // build the bounds within the query should look + $radius = $this->field->driver->geoRadius($lat, $lng, $radius, ($unit[0] == 'k')); + + $conditions = []; + $conditions[] = [$this->formatColumn('latitude', $field_id) => ['between' => [$radius['latMIN'], $radius['latMAX']]]]; + $conditions[] = [$this->formatColumn('longitude', $field_id) => ['between' => [$radius['lonMIN'], $radius['lonMAX']]]]; + + if (count($conditions) < 2) { + return $conditions; + } + return ['or' => $conditions]; + } + + /** + * @see EntryQueryFieldAdapter::filterSingle() + * + * @param EntryQuery $query + * @param string $filter + * @return array + */ + protected function filterSingle(EntryQuery $query, $filter) + { + General::ensureType([ + 'filter' => ['var' => $filter, 'type' => 'string'], + ]); + + $columns_to_labels = array(); + + foreach (array('street', 'city', 'region', 'postal_code', 'country') as $name) + { + $columns_to_labels[Lang::createHandle($this->field->get("{$name}_label"))] = $name; + } + + $columns = implode('|', array_keys($columns_to_labels)); + $this->_key++; + + if ($this->isFilterIn($filter, $columns)) { + return $this->createFilterIn($filter, $columns, $columns_to_labels); + } elseif ($this->isFilterWithin($filter)) { + return $this->createFilterWithin($filter); + } + } +} From f7f829ac4aa435b6db59aa1acce99323b941636f Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 29 May 2018 14:21:29 -0400 Subject: [PATCH 09/15] Fix "within" condition --- lib/class.entryqueryaddresslocationadapter.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/class.entryqueryaddresslocationadapter.php b/lib/class.entryqueryaddresslocationadapter.php index 328bab4..c9efbb3 100644 --- a/lib/class.entryqueryaddresslocationadapter.php +++ b/lib/class.entryqueryaddresslocationadapter.php @@ -85,10 +85,7 @@ public function createFilterWithin($filter) $conditions[] = [$this->formatColumn('latitude', $field_id) => ['between' => [$radius['latMIN'], $radius['latMAX']]]]; $conditions[] = [$this->formatColumn('longitude', $field_id) => ['between' => [$radius['lonMIN'], $radius['lonMAX']]]]; - if (count($conditions) < 2) { - return $conditions; - } - return ['or' => $conditions]; + return ['and' => $conditions]; } /** From a122707317aff45b48a3971962fb3d90b72bcf72 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Wed, 30 May 2018 16:28:42 -0400 Subject: [PATCH 10/15] Fix filters labels and help --- fields/field.addresslocation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index e0611cf..e7308a8 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -412,13 +412,13 @@ public function fetchFilterableOperators() return array( array( 'title' => 'in', - 'filter' => 'in:', - 'help' => __('Find values that match the given query.') + 'filter' => 'in ', + 'help' => __('in street|city|region|postal_code|country of %s') ), array( 'title' => 'within', - 'filter' => 'within:', - 'help' => __('Find values that match the given query.') + 'filter' => 'within ', + 'help' => __('Within %skm|mile|miles of %s') ), ); } From fb990d25a3ad7e1a971015033d49086738d74cd4 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 31 May 2018 10:04:02 -0400 Subject: [PATCH 11/15] Add forgotten "return" for install method --- extension.driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.driver.php b/extension.driver.php index 5476d00..f31bc10 100755 --- a/extension.driver.php +++ b/extension.driver.php @@ -91,7 +91,7 @@ public function update($previousVersion = false){ public function install() { - Symphony::Database() + return Symphony::Database() ->create('tbl_fields_addresslocation') ->ifNotExists() ->fields([ From 6a17be7b14400ddec060f72621c8b12e611083ee Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Thu, 31 May 2018 13:29:55 -0400 Subject: [PATCH 12/15] Set neigborhood default null in createTable --- extension.meta.xml | 2 +- fields/field.addresslocation.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/extension.meta.xml b/extension.meta.xml index f382780..2e308b4 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -1,6 +1,6 @@ - Address Location Field + Field: Address Location Geocode an address, then refine the latlng returned for precision. https://github.com/designermonkey/addresslocationfield http://getsymphony.com/discuss/thread/70238/ diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index e7308a8..83d2b0e 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -275,8 +275,14 @@ public function createTable() 'type' => 'double', 'null' => true, ], - 'neighborhood' => 'varchar(255)', - 'neighborhood_handle' => 'varchar(255)', + 'neighborhood' => [ + 'type' => 'varchar(255)', + 'null' => true, + ], + 'neighborhood_handle' => [ + 'type' => 'varchar(255)', + 'null' => true, + ], 'result_data' => 'blob', ]) ->keys([ From f80cbbcdcda44ed9c090ce81f0acf74e548bc8bf Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Tue, 18 Dec 2018 09:42:12 -0500 Subject: [PATCH 13/15] Remote SQL collate and charset definitions. --- fields/field.addresslocation.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index 83d2b0e..d040acc 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -249,8 +249,6 @@ public function createTable() return Symphony::Database() ->create('tbl_entries_data_' . $this->get('id')) ->ifNotExists() - ->charset('utf8') - ->collate('utf8_unicode_ci') ->fields([ 'id' => [ 'type' => 'int(11)', From 015c2ae0211df5cd1aaf80d305e6622021f998fd Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Mon, 25 Feb 2019 09:28:36 -0500 Subject: [PATCH 14/15] Apply patch @nitriques : Fix broken count on php 7.2 --- fields/field.addresslocation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fields/field.addresslocation.php b/fields/field.addresslocation.php index d040acc..b305e5f 100755 --- a/fields/field.addresslocation.php +++ b/fields/field.addresslocation.php @@ -386,7 +386,7 @@ public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = fa // Add back Google Maps result data - if (count($this->filter_origin['latitude']) > 0) { + if (!empty($this->filter_origin['latitude'])) { $distance = new XMLElement('distance'); $distance->setAttribute('from', $this->filter_origin['latitude'] . ',' . $this->filter_origin['longitude']); $distance->setAttribute('distance', $this->driver->geoDistance($this->filter_origin['latitude'], $this->filter_origin['longitude'], $data['latitude'], $data['longitude'], $this->filter_origin['unit'])); From e7a4104e7de55e695aac936fc47dbe1692d020e2 Mon Sep 17 00:00:00 2001 From: Alexandra Nantel Date: Fri, 1 Mar 2019 13:12:20 -0500 Subject: [PATCH 15/15] Fix sizes when not main. --- assets/addresslocationfield.publish.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/addresslocationfield.publish.css b/assets/addresslocationfield.publish.css index 8633dbb..531a8eb 100644 --- a/assets/addresslocationfield.publish.css +++ b/assets/addresslocationfield.publish.css @@ -74,7 +74,7 @@ div.field-addresslocation div.main-wrapper { border: 1px solid #d3dce2; } -div.field-addresslocation div.main.address { +div.field-addresslocation div.address { display: flex; flex-direction: row; align-items: flex-start; @@ -83,7 +83,7 @@ div.field-addresslocation div.main.address { width: calc(100% + 3rem); } -div.field-addresslocation div.main.map { +div.field-addresslocation div.map { width: 100%; height: 200px; }