Skip to content

Commit

Permalink
Merge pull request #8 from CompagnonAgency/fj-update-nextfloor
Browse files Browse the repository at this point in the history
update nextfloor
  • Loading branch information
FalkoJoseph authored May 16, 2024
2 parents 4872f61 + 02e4e70 commit bcc250a
Show file tree
Hide file tree
Showing 28 changed files with 15,250 additions and 1,929 deletions.
111 changes: 97 additions & 14 deletions api/class-controller-locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ public function __construct()
global $wpdb;

// Create tables
$this->create_tables('be');
$this->create_tables('fr');
$this->create_postal_code_tables('be');
$this->create_postal_code_tables('fr');
$this->create_region_tables('fr');

// Populate tables, if empty
$this->populate_tables('be');
$this->populate_tables('fr');
$this->populate_postal_code_tables('be');
$this->populate_postal_code_tables('fr');
$this->populate_region_tables('fr');
}

public function create_tables($country)
public function create_postal_code_tables($country)
{
global $wpdb;

Expand All @@ -44,6 +46,24 @@ public function create_tables($country)
dbDelta($sql);
}

public function create_region_tables($country)
{
global $wpdb;

$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . "regions_" . $country;

$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
code varchar(55) NOT NULL,
name varchar(55) NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}

public function get_locations_from_csv($country)
{
$locations = [];
Expand Down Expand Up @@ -85,7 +105,29 @@ public function get_locations_from_csv($country)
return $locations;
}

public function populate_tables($country)
public function get_regions_from_csv($country)
{
$regions = [];

$file = fopen(plugin_dir_path(__DIR__) . "csv/" . $country . "_regions.csv", "r");

while (!feof($file)) {
$row = fgetcsv($file, 0, ';');

if ($row && $row[1]) {
$regions[] = [
'code' => $row[0],
'name' => $row[1],
];
}
}

fclose($file);

return $regions;
}

public function populate_postal_code_tables($country)
{
global $wpdb;

Expand All @@ -109,6 +151,28 @@ public function populate_tables($country)
}
}

public function populate_region_tables($country)
{
global $wpdb;

$table_name = $wpdb->prefix . "regions_" . $country;
$regions = $wpdb->get_results("SELECT name FROM $table_name LIMIT 1");

if (empty($regions)) {
$regions = $this->get_regions_from_csv($country);

foreach ($regions as $region) {
$wpdb->insert(
$table_name,
[
'code' => $region['code'],
'name' => $region['name'],
]
);
}
}
}

public function locations($param)
{
global $wpdb;
Expand All @@ -117,20 +181,39 @@ public function locations($param)

$country = $param['country'];

error_log(print_r($param['search'], true));
// Get the postal codes and group by postal code
$postal_codes = $GLOBALS['wpdb']->get_results("SELECT * FROM {$wpdb->prefix}locations_{$country} WHERE name LIKE '" . $param['search'] . "%' OR postal_code LIKE '" . $param['search'] . "%' GROUP BY latitude ORDER BY name ASC, postal_code ASC LIMIT 6", OBJECT);

// Write the same but group by latitude
$results = $GLOBALS['wpdb']->get_results("SELECT * FROM {$wpdb->prefix}locations_{$country} WHERE name LIKE '" . $param['search'] . "%' OR postal_code LIKE '%" . $param['search'] . "%' GROUP BY latitude ORDER BY name ASC, postal_code ASC LIMIT 6", OBJECT);
// Get the regions
$regions = $GLOBALS['wpdb']->get_results("SELECT * FROM {$wpdb->prefix}regions_{$country} WHERE name LIKE '" . $param['search'] . "%' OR code LIKE '" . $param['search'] . "%' ORDER BY name ASC, code ASC LIMIT 6", OBJECT);

// Search for mutual postal codes e.g. if the postal code 03190 occurs multiple times, we want to list it as 03190 (Toutes les villes)
$mutual_postal_codes = $GLOBALS['wpdb']->get_results("SELECT postal_code, name, latitude, longitude FROM {$wpdb->prefix}locations_{$country} WHERE postal_code LIKE '" . $param['search'] . "%' GROUP BY postal_code ORDER BY name ASC, postal_code ASC LIMIT 6", OBJECT);

// Merge the postal codes and regions
$locations = [];

foreach ($results as $result) {
if (count($mutual_postal_codes) == 1) {
$locations[] = [
'key' => $mutual_postal_codes[0]->postal_code,
'value' => 'Toutes les villes' . ' (' . $mutual_postal_codes[0]->postal_code . ')',
];
}

foreach ($regions as $region) {
$locations[] = [
'key' => $region->id,
'value' => $region->name . ' (' . $region->code . ')',
];
}

foreach ($postal_codes as $postal_code) {
$locations[] = [
'key' => $result->id,
'value' => $result->name . ' (' . $result->postal_code . ')',
'key' => $postal_code->id,
'value' => $postal_code->name . ' (' . $postal_code->postal_code . ')',
'latLng' => [
'lat' => $result->latitude,
'lng' => $result->longitude,
'lat' => $postal_code->latitude,
'lng' => $postal_code->longitude,
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:typeahead-callback="search_tags"
:typeahead-hide-discard="true"
v-model="store.selectedTags"
:sort-search-results="false"
>
</tags-input>
</div>
Expand Down
2 changes: 1 addition & 1 deletion blocks/sweepbright/estate-energy/estate-energy.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"epc_category": "Score énergétique",
"gas": "Gaz naturel",
"fuel": "Carburant",
"heat_pump": "Pompe à chaud",
"heat_pump": "Pompe à chaleur",
"floor_heating": "Chauffage par le sol",
"solar_panels": "Panneaux solaires",
"central_heating": "Chauffage collectif",
Expand Down
2 changes: 1 addition & 1 deletion blocks/sweepbright/estate-heading/default/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<?php endif; ?>
</p>

<?php if (get_field('price')['buyer_percentage'] || get_field('price')['buyer_fixed_fee']) : ?>
<?php if ((get_field('price')['buyer_percentage'] || get_field('price')['buyer_fixed_fee']) && (get_field('features')['negotiation'] === 'sale')) : ?>
<p class="mt-2 text-sm opacity-75">
<?= WP_Wrapper::get('locale', $component, $args)[WP_Wrapper::lang()]['buyer_label']; ?>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
"kitchen_condition": "Etat de la cuisine",
"bathroom_condition": "État de la salle de bain",
"good": "Bon état",
"poor": "Mauvais état",
"fair": "Rafraîchir",
"poor": "À rénover",
"fair": "À rafraîchir",
"new": "Nouveau",
"mint": "Excellent état",
"home_automation": "Domotique",
Expand All @@ -118,7 +118,7 @@
"display_window": "Fenêtre d'affichage",
"reception_area": "Zone d'accueil",
"waiting_area": "Zone d'attente",
"guesthouse": "Maison d'hôtes",
"guesthouse": "Dépendance",
"attic": "Grenier",
"water_access": "Accès à l'eau",
"utilities_access": "Accès utilitaires",
Expand Down
25 changes: 18 additions & 7 deletions blocks/sweepbright/filter/default/assets/components/Filter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -420,15 +420,21 @@ export default {
if (locations) {
locations.forEach((item) => {
const location = item.slice(0, -1).split(',')
location[1] = parseFloat(location[1])
location[2] = parseFloat(location[2])
locationArr.push({
const locationItem = {
value: location[0],
latLng: {
}
if (location[1] && location[2]) {
locationItem.latLng = {
lat: location[1],
lng: location[2],
},
})
}
}
locationArr.push(locationItem)
})
}
Expand Down Expand Up @@ -535,9 +541,14 @@ export default {
filters.value.forEach((location, index) => {
locations += '['
locations += location.value + ','
locations += location.latLng.lat + ','
locations += location.latLng.lng
locations += location.value
if (location.latLng) {
locations += ','
locations += location.latLng.lat + ','
locations += location.latLng.lng
}
locations += ']'
if (index < filters.value.length - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
:typeahead-callback="search_tags"
:typeahead-hide-discard="true"
v-model="store.selectedTags"
:sort-search-results="false"
>
</tags-input>
</div>
Expand Down
3 changes: 2 additions & 1 deletion blocks/sweepbright/filter/default/dist/main.js

Large diffs are not rendered by default.

This file was deleted.

2 changes: 1 addition & 1 deletion blocks/sweepbright/properties/default/dist/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions blocks/sweepbright/properties/default/dist/main.js

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Loading

0 comments on commit bcc250a

Please sign in to comment.