Skip to content

Commit 8f0339c

Browse files
author
James Wigger
authored
Merge pull request #24 from RootStudio/v2.1.0-dev
v2.1.0
2 parents a467ffe + 2e2769a commit 8f0339c

40 files changed

+1012
-264
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
!/perch/addons/apps/jw_locator
1313
!/perch/addons/apps/root_locator
1414

15+
!/perch/addons/fieldtypes
16+
!/perch/addons/fieldtypes/*
17+
18+
!/perch/addons/fieldtypes/locator
19+
!/perch/addons/fieldtypes/locator/*
20+
1521
!/locations/*
1622

1723
!.gitignore

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Perch Locator v2
1+
# Perch Locator v2.1
22

33
Perch Locator is an app to manage locatable resources within Perch CMS. Addresses are Geocoded and can be searched using coordinates or by a valid address to allow users to find places of interest near to them.
44

@@ -56,6 +56,8 @@ CSV Data must include the following columns:
5656

5757
Rows that are missing any of the required fields will not be imported. Those missing recommended fields will be imported but may fail in the geocoding queue.
5858

59+
**v2.1**: You can now include custom fields in the CSV import. Any additional columns that are not listed above will be included in the dynamic fields array to be used in your templates.
60+
5961
---
6062

6163
## Displaying on a map

perch/addons/apps/root_locator/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
if ($CurrentUser->logged_in() && $CurrentUser->has_priv('root_locator')) {
4-
$this->register_app('root_locator', 'Locator', 1, 'Provide location based listings for your site', '2.0.0');
4+
$this->register_app('root_locator', 'Locator', 1, 'Provide location based listings for your site', '2.1.0');
55
$this->require_version('root_locator', '2.8.31');
66
$this->add_create_page('root_locator', 'edit');
77

perch/addons/apps/root_locator/composer.lock

Lines changed: 16 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

perch/addons/apps/root_locator/lib/RootLocator_Addresses.class.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class RootLocator_Addresses extends PerchAPI_Factory
7373

7474
protected $addressDistances = [];
7575

76+
/**
77+
* Return queued addresses by array of IDs
78+
*
79+
* @param array $ids
80+
*
81+
* @return array|bool|SplFixedArray
82+
*/
7683
public function getQueued(array $ids)
7784
{
7885
$sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->pk . ' IN(' . implode(',', $ids) . ');';
@@ -81,6 +88,19 @@ public function getQueued(array $ids)
8188
return $this->return_instances($rows);
8289
}
8390

91+
/**
92+
* Return list of addresses that have been geocoded
93+
*
94+
* @return array|bool|SplFixedArray
95+
*/
96+
public function getCompleted()
97+
{
98+
$sql = 'SELECT * FROM `' . $this->table . '` WHERE `addressLatitude` IS NOT NULL AND `addressLongitude` IS NOT NULL';
99+
$rows = $this->db->get_rows($sql);
100+
101+
return $this->return_instances($rows);
102+
}
103+
84104
/**
85105
* Return results filtered by first character of title column
86106
*

perch/addons/apps/root_locator/lib/RootLocator_Importer.class.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,17 @@ public function import()
9999
$this->addWarning($row, $Lang->get('‘%s’ columns are recommended to prevent geocoding errors.', $warnings));
100100
}
101101

102+
$dynamicFields = $this->getDynamicFields($Addresses->static_fields, $row);
103+
102104
$imported = $Addresses->create([
103-
'addressTitle' => $row['addressTitle'],
104-
'addressBuilding' => $row['addressBuilding'],
105-
'addressStreet' => $row['addressStreet'],
106-
'addressTown' => $row['addressTown'],
107-
'addressRegion' => $row['addressRegion'],
108-
'addressPostcode' => $row['addressPostcode'],
109-
'addressCountry' => $row['addressCountry']
105+
'addressTitle' => $row['addressTitle'],
106+
'addressBuilding' => $row['addressBuilding'],
107+
'addressStreet' => $row['addressStreet'],
108+
'addressTown' => $row['addressTown'],
109+
'addressRegion' => $row['addressRegion'],
110+
'addressPostcode' => $row['addressPostcode'],
111+
'addressCountry' => $row['addressCountry'],
112+
'addressDynamicFields' => PerchUtil::json_safe_encode($dynamicFields)
110113
]);
111114

112115
$imported->index($Template);
@@ -218,6 +221,27 @@ private function getRowWarnings($row)
218221
return false;
219222
}
220223

224+
/**
225+
* Collect dynamic fields from CSV, compared with static fields
226+
*
227+
* @param array $static
228+
* @param array $row
229+
*
230+
* @return array
231+
*/
232+
private function getDynamicFields($static, $row)
233+
{
234+
$dynamicColumns = [];
235+
236+
foreach($row as $key => $value) {
237+
if(!in_array($key, $static)) {
238+
$dynamicColumns[$key] = $value;
239+
}
240+
}
241+
242+
return $dynamicColumns;
243+
}
244+
221245
/**
222246
* Add successful status to results
223247
*

perch/addons/apps/root_locator/lib/vendor/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
// autoload.php @generated by Composer
44

5-
require_once __DIR__ . '/composer' . '/autoload_real.php';
5+
require_once __DIR__ . '/composer/autoload_real.php';
66

77
return ComposerAutoloaderInitdab9da119c295811d6eee5ec2134719a::getLoader();

perch/addons/apps/root_locator/lib/vendor/composer/ClassLoader.php

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
namespace Composer\Autoload;
1414

1515
/**
16-
* ClassLoader implements a PSR-0 class loader
17-
*
18-
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
16+
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
1917
*
2018
* $loader = new \Composer\Autoload\ClassLoader();
2119
*
@@ -39,6 +37,8 @@
3937
*
4038
* @author Fabien Potencier <fabien@symfony.com>
4139
* @author Jordi Boggiano <j.boggiano@seld.be>
40+
* @see http://www.php-fig.org/psr/psr-0/
41+
* @see http://www.php-fig.org/psr/psr-4/
4242
*/
4343
class ClassLoader
4444
{
@@ -53,8 +53,9 @@ class ClassLoader
5353

5454
private $useIncludePath = false;
5555
private $classMap = array();
56-
5756
private $classMapAuthoritative = false;
57+
private $missingClasses = array();
58+
private $apcuPrefix;
5859

5960
public function getPrefixes()
6061
{
@@ -147,7 +148,7 @@ public function add($prefix, $paths, $prepend = false)
147148
* appending or prepending to the ones previously set for this namespace.
148149
*
149150
* @param string $prefix The prefix/namespace, with trailing '\\'
150-
* @param array|string $paths The PSR-0 base directories
151+
* @param array|string $paths The PSR-4 base directories
151152
* @param bool $prepend Whether to prepend the directories
152153
*
153154
* @throws \InvalidArgumentException
@@ -271,6 +272,26 @@ public function isClassMapAuthoritative()
271272
return $this->classMapAuthoritative;
272273
}
273274

275+
/**
276+
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277+
*
278+
* @param string|null $apcuPrefix
279+
*/
280+
public function setApcuPrefix($apcuPrefix)
281+
{
282+
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
283+
}
284+
285+
/**
286+
* The APCu prefix in use, or null if APCu caching is not enabled.
287+
*
288+
* @return string|null
289+
*/
290+
public function getApcuPrefix()
291+
{
292+
return $this->apcuPrefix;
293+
}
294+
274295
/**
275296
* Registers this instance as an autoloader.
276297
*
@@ -313,29 +334,34 @@ public function loadClass($class)
313334
*/
314335
public function findFile($class)
315336
{
316-
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
317-
if ('\\' == $class[0]) {
318-
$class = substr($class, 1);
319-
}
320-
321337
// class map lookup
322338
if (isset($this->classMap[$class])) {
323339
return $this->classMap[$class];
324340
}
325-
if ($this->classMapAuthoritative) {
341+
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
326342
return false;
327343
}
344+
if (null !== $this->apcuPrefix) {
345+
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
346+
if ($hit) {
347+
return $file;
348+
}
349+
}
328350

329351
$file = $this->findFileWithExtension($class, '.php');
330352

331353
// Search for Hack files if we are running on HHVM
332-
if ($file === null && defined('HHVM_VERSION')) {
354+
if (false === $file && defined('HHVM_VERSION')) {
333355
$file = $this->findFileWithExtension($class, '.hh');
334356
}
335357

336-
if ($file === null) {
358+
if (null !== $this->apcuPrefix) {
359+
apcu_add($this->apcuPrefix.$class, $file);
360+
}
361+
362+
if (false === $file) {
337363
// Remember that this class does not exist.
338-
return $this->classMap[$class] = false;
364+
$this->missingClasses[$class] = true;
339365
}
340366

341367
return $file;
@@ -399,6 +425,8 @@ private function findFileWithExtension($class, $ext)
399425
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
400426
return $file;
401427
}
428+
429+
return false;
402430
}
403431
}
404432

perch/addons/apps/root_locator/lib/vendor/composer/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
2+
Copyright (c) 2016 Nils Adermann, Jordi Boggiano
33

44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal

perch/addons/apps/root_locator/lib/vendor/composer/autoload_files.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
$baseDir = dirname(dirname($vendorDir));
77

88
return array(
9-
$vendorDir . '/igorw/get-in/src/get_in.php',
9+
'a16312f9300fed4a097923eacb0ba814' => $vendorDir . '/igorw/get-in/src/get_in.php',
1010
);

0 commit comments

Comments
 (0)