From a67a14b4ab7ea2661f7cdbd1e201be6a0aaf6193 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 8 May 2011 19:24:02 +0200 Subject: [PATCH] Finishes advanced search on addresses to our new geocoding engine (gmaps v3). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/direnum.php | 12 +-- classes/userfilter/conditions.inc.php | 2 +- modules/search.php | 36 +++---- templates/search/adv.form.tpl | 175 ++++++++++++++++++++++++---------- 4 files changed, 152 insertions(+), 73 deletions(-) diff --git a/classes/direnum.php b/classes/direnum.php index 2f353ae..bf18312 100644 --- a/classes/direnum.php +++ b/classes/direnum.php @@ -595,7 +595,7 @@ class DE_Nationalities extends DirEnumeration // {{{ class DE_AddressesComponents class DE_AddressesComponents extends DirEnumeration { - protected $idfield = 'profile_addresses_components_enum.short_name'; + protected $idfield = 'profile_addresses_components_enum.id'; protected $valfield = 'profile_addresses_components_enum.long_name'; protected $from = 'profile_addresses_components_enum'; @@ -612,27 +612,27 @@ class DE_Countries extends DE_AddressesComponents class DE_Admnistrativeareas1 extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'admnistrativeareas1\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_1\', profile_addresses_components_enum.types)'; } class DE_Admnistrativeareas2 extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'admnistrativeareas2\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_2\', profile_addresses_components_enum.types)'; } class DE_Admnistrativeareas3 extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'admnistrativeareas3\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'admnistrative_area_3\', profile_addresses_components_enum.types)'; } class DE_Localities extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'localities\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'locality\', profile_addresses_components_enum.types)'; } class DE_Sublocalities extends DE_AddressesComponents { - protected $where = 'WHERE FIND_IN_SET(\'sublocalities\', profile_addresses_components_enum.types)'; + protected $where = 'WHERE FIND_IN_SET(\'sublocality\', profile_addresses_components_enum.types)'; } // }}} diff --git a/classes/userfilter/conditions.inc.php b/classes/userfilter/conditions.inc.php index 85d1d03..6c9a1be 100644 --- a/classes/userfilter/conditions.inc.php +++ b/classes/userfilter/conditions.inc.php @@ -1115,7 +1115,7 @@ class UFC_AddressComponent extends UFC_Address { $sub = $uf->addAddressFilter($this->fieldtype); $conds = $this->initConds($sub, $uf->getVisibilityCondition('pa' . $sub . '.pub')); - $conds[] = XDB::format('pace' . $sub . '.short_name IN {?}', $this->val); + $conds[] = XDB::format('pace' . $sub . '.id IN {?}', $this->val); return implode(' AND ', $conds); } diff --git a/modules/search.php b/modules/search.php index b9ae916..9d7301a 100644 --- a/modules/search.php +++ b/modules/search.php @@ -29,6 +29,7 @@ class SearchModule extends PLModule 'advanced_search.php' => $this->make_hook('redir_advanced', AUTH_PUBLIC), 'search/autocomplete' => $this->make_hook('autocomplete', AUTH_COOKIE, 'directory_ax', NO_AUTH), 'search/list' => $this->make_hook('list', AUTH_COOKIE, 'directory_ax', NO_AUTH), + 'search/list/count' => $this->make_hook('list_count', AUTH_COOKIE, 'directory_ax', NO_AUTH), 'jobs' => $this->make_hook('referent', AUTH_COOKIE), 'emploi' => $this->make_hook('referent', AUTH_COOKIE), 'referent/search' => $this->make_hook('referent', AUTH_COOKIE), @@ -247,7 +248,7 @@ class SearchModule extends PLModule 'groupexTxt' => DirEnum::GROUPESX, 'sectionTxt' => DirEnum::SECTIONS, 'networking_typeTxt' => DirEnum::NETWORKS, - 'city' => DirEnum::LOCALITIES, + 'localityTxt' => DirEnum::LOCALITIES, 'countryTxt' => DirEnum::COUNTRIES, 'entreprise' => DirEnum::COMPANIES, 'jobtermTxt' => DirEnum::JOBTERMS, @@ -308,7 +309,23 @@ class SearchModule extends PLModule break; case 'country': $ids = DirEnum::getOptionsIter(DirEnum::COUNTRIES); - $page->assign('onchange', 'changeCountry(this.value)'); + $page->assign('onchange', 'changeAddressComponents(\'' . $type . '\', this.value)'); + break; + case 'administrative_area_level_1': + case 'administrative_area_level_2': + case 'administrative_area_level_3': + case 'locality': + $page->assign('onchange', 'changeAddressComponents(\'' . $type . '\', this.value)'); + case 'sublocality': + $ids = XDB::iterator("SELECT pace1.id, pace1.long_name AS field + FROM profile_addresses_components_enum AS pace1 + INNER JOIN profile_addresses_components AS pac1 ON (pac1.component_id = pace1.id) + INNER JOIN profile_addresses_components AS pac2 ON (pac1.pid = pac2.pid AND pac1.jobid = pac2.jobid AND pac1.id = pac2.id + AND pac1.groupid = pac2.groupid AND pac1.type = pac2.type) + INNER JOIN profile_addresses_components_enum AS pace2 ON (pac2.component_id = pace2.id AND FIND_IN_SET({?}, pace2.types)) + WHERE pace2.id = {?} AND FIND_IN_SET({?}, pace1.types) + GROUP BY pace1.long_name", + Env::v('previous'), Env::v('value'), $type); break; case 'diploma': if (Env::has('school') && Env::i('school') != 0) { @@ -323,21 +340,6 @@ class SearchModule extends PLModule case 'nationalite': $ids = DirEnum::getOptionsIter(DirEnum::NATIONALITIES); break; - case 'administrativearea': - if (Env::has('country')) { - $ids = DirEnum::getOptionsIter(DirEnum::ADMINAREAS, Env::v('country')); - } else { - $ids = DirEnum::getOptionsIter(DirEnum::ADMINAREAS); - } - $page->assign('onchange', 'changeAdministrativeArea(this.value)'); - break; - case 'subadministrativearea': - if (Env::has('administrativearea')) { - $ids = DirEnum::getOptionsIter(DirEnum::SUBADMINAREAS, Env::v('administrativearea')); - } else { - $ids = DirEnum::getOptionsIter(DirEnum::SUBADMINAREAS); - } - break; case 'school': $ids = DirEnum::getOptionsIter(DirEnum::EDUSCHOOLS); $page->assign('onchange', 'changeSchool(this.value)'); diff --git a/templates/search/adv.form.tpl b/templates/search/adv.form.tpl index 6596881..3806eb7 100644 --- a/templates/search/adv.form.tpl +++ b/templates/search/adv.form.tpl @@ -51,50 +51,80 @@ }; } - // when changing country, open up administrativearea choice - function changeCountry(a2) { - $(".autocompleteTarget[name='country']").attr('value',a2); + function setAddress(i, j, values) + { + var types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'locality', 'sublocality'); + var prev_type = types[i]; + var next_type = types[j]; + var next_list = next_type + '_list'; + + if (j == 3) { + $('tr#locality_text').hide() + $("select[name='localityTxt']").attr('value', ''); + } + + $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:values[i] }, function() { + if ($("select[name='" + next_type + "']").children("option").size() > 1) { + $("tr#" + next_list).show(); + $("select[name='" + next_type + "']").attr('value', values[j]); + if (j < 6) { + setAddress(j, j + 1, values); + } + } else { + $("tr#" + next_list).hide(); + $("select[name='" + next_type + "']").attr('value', ''); + if (j < 6) { + setAddress(i, j + 1, values); + } + } + }); - if (a2) { - $(".autocomplete[name='countryTxt']").addClass('hidden_valid'); + } - $("[name='administrativearea']").parent().load(baseurl + 'list/administrativearea/', { country:a2 }, function() { - if ($("select[name='administrativearea']").children("option").size() > 1) { - $("select[name='administrativearea']").attr('value', '{/literal}{$smarty.request.administrativearea}{literal}'); + function displayNextAddressComponent(i, j, value) + { + var types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'locality', 'sublocality'); + var prev_type = types[i]; + var next_type = types[j]; + var next_list = next_type + '_list'; - $("tr#administrativearea_list").show(); - } else { - $("select[name='administrativearea']").attr('value', ''); + if (j == 3) { + $('tr#locality_text').hide() + $("select[name='localityTxt']").attr('value', ''); + } - $("tr#administrativearea_list").hide(); - } - }); - } else { - $(".autocomplete[name='countryTxt']").removeClass('hidden_valid'); + $("[name='" + next_type + "']").parent().load(baseurl + 'list/' + next_type, { previous:prev_type, value:value }, function() { + $("select[name='" + next_type + "']").attr('value', ''); + if ($("select[name='" + next_type + "']").children("option").size() > 1) { + $("tr#" + next_list).show(); + } else { + $("tr#" + next_list).hide(); + if (j < 6) { + displayNextAddressComponent(i, j + 1, value); + } + } + }); + } - $("select[name='administrativearea']").attr('value', ''); - $("select[name='subadministrativearea']").attr('value', ''); + function changeAddressComponents(type, value) + { + var types = new Array('country', 'administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'locality', 'sublocality'); + var i = 0, j = 0; - $("tr#administrativearea_list").hide(); - $("tr#subadministrativearea_list").hide(); + while (types[i] != type && i < 6) { + ++i; } - } - // when changing administrativearea, open up subadministrativearea choice - function changeAdministrativeArea(id) { - if (id) { - $("[name='subadministrativearea']").parent().load(baseurl + 'list/subadministrativearea/', { administrativearea:id }, function() { - if ($("select[name='subadministrativearea']").children("option").size() > 1) { - $("select[name='subadministrativearea']").attr('value', '{/literal}{$smarty.request.subadministrativearea}{literal}'); - $("tr#subadministrativearea_list").show(); - } else { - $("select[name='subadministrativearea']").attr('value', ''); - $("tr#subadministrativearea_list").hide(); - } - }); - } else { - $("select[name='subadministrativearea']").attr('value', ''); - $("tr#subadministrativearea_list").hide(); + j = i + 1; + while (j < 6) { + $("select[name='" + types[j] + "']").attr('value', ''); + $("tr#" + types[j] + "_list").hide(); + ++j; + } + + if (value != '' && i < 5) { + $("select[name='" + type + "']").attr('value', value); + displayNextAddressComponent(i, i + 1, value); } } @@ -145,15 +175,20 @@ if (nameRealField == name) return null; - // if changing country, might want to open administrativearea choice - if (nameRealField == 'country') + // When changing country or locality, open next address component. + if (nameRealField == 'country' || nameRealField == 'locality') { return function(i) { + nameRealField = name.replace(/Txt$/, ''); if (i.extra[0] < 0) { - cancel_autocomplete('countryTxt', 'country'); + cancel_autocomplete(name, nameRealField); i.extra[1] = ''; } - changeCountry(i.extra[1]); + $("[name='" + nameRealField + "']").parent().load(baseurl + 'list/' + nameRealField, function() { + $("select[name='" + nameRealField + "']").attr('value', i.extra[1]); + }); + changeAddressComponents(nameRealField, i.extra[1]); } + } if (nameRealField == 'school') return function(i) { @@ -204,10 +239,23 @@ $(".autocomplete").change(function() { $(this).removeClass('hidden_valid'); }); - $(".autocomplete[name='countryTxt']").change(function() { changeCountry(''); }); - - changeCountry({/literal}'{$smarty.request.country}'{literal}); - changeAdministrativeArea({/literal}'{$smarty.request.administrativearea}'{literal}); + if ({/literal}'{$smarty.request.country}'{literal} != '') { + $("[name='country']").parent().load(baseurl + 'list/country', function() { + $("select[name='country']").attr('value', {/literal}'{$smarty.request.country}'{literal}); + }); + setAddress(0, 1, new Array({/literal}'{$smarty.request.country}'{literal}, + {/literal}'{$smarty.request.administrative_area_level_1}'{literal}, + {/literal}'{$smarty.request.administrative_area_level_2}'{literal}, + {/literal}'{$smarty.request.administrative_area_level_3}'{literal}, + {/literal}'{$smarty.request.locality}'{literal}, + {/literal}'{$smarty.request.sublocality}'{literal}) + ); + } else { + var types = new Array('administrative_area_level_1', 'administrative_area_level_2', 'administrative_area_level_3', 'locality', 'sublocality'); + for (var i = 0; i < 5; ++i) { + $("tr#" + types[i] + '_list').hide(); + } + } $(".autocomplete[name='schoolTxt']").change(function() { changeSchool(''); }); @@ -235,7 +283,6 @@ }); $("#only_referent").change(function() { changeOnlyReferent(); }); - changeOnlyReferent(); }); /** Regexps to wipe out from search queries */ @@ -404,10 +451,6 @@ function cleanForm(f) { Géographie - Ville - - - Pays {icon name="table" title="Tous les pays"} + + Région, province, état… + + + + + + Département, comté… + + + + + + Canton… + + + + + + Ville + + + + Ville + + + + + + Arrondissement, quartier… + + + +