-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- **Added search and sorting support.** - Added optional Google API Server Key setting - **_WARNING:_** This update will break any map fields that are NOT standalone (global) or in a Matrix field.
- Loading branch information
Showing
9 changed files
with
240 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
migrations/m160606_162300_simpleMap_updateFieldStorage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class m160606_162300_simpleMap_updateFieldStorage extends BaseMigration | ||
{ | ||
public function safeUp() | ||
{ | ||
if (!craft()->db->tableExists('simplemap_maps')) | ||
craft()->plugins->getPlugin('simpleMap')->createTables(); | ||
|
||
$fields = craft()->fields->getAllFields(); | ||
|
||
foreach ($fields as $field) | ||
{ | ||
if ($field->type === 'SimpleMap_Map') | ||
$this->_transferData($field, 'content'); | ||
|
||
if ($field->type === 'Matrix') | ||
foreach (craft()->matrix->getBlockTypesByFieldId($field->id) as $blockType) | ||
foreach ($blockType->getFields() as $blockTypeField) | ||
if ($blockTypeField->type == 'SimpleMap_Map') | ||
$this->_transferData($blockTypeField, 'matrixcontent_' . $field->handle, $blockType->handle . '_' . $blockTypeField->handle); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private function _transferData(FieldModel $field, $tableName, $fieldHandle = "") | ||
{ | ||
if (!$fieldHandle) | ||
$fieldHandle = $field->handle; | ||
|
||
$tableData = craft()->db->createCommand() | ||
->select('elementId, locale, field_' . $fieldHandle) | ||
->from($tableName) | ||
->where('field_' . $fieldHandle . ' IS NOT NULL') | ||
->queryAll(); | ||
|
||
foreach ($tableData as $row) { | ||
$record = new SimpleMap_MapRecord; | ||
$record->ownerId = $row['elementId']; | ||
$record->fieldId = $field->id; | ||
$record->ownerLocale = $row['locale']; | ||
|
||
$f = json_decode($row['field_' . $fieldHandle], true); | ||
|
||
$record->setAttribute('lat', $f['lat']); | ||
$record->setAttribute('lng', $f['lng']); | ||
$record->setAttribute('zoom', $f['zoom']); | ||
$record->setAttribute('address', $f['address']); | ||
if ($f !== null && array_key_exists('parts', $f)) | ||
$record->setAttribute('parts', json_encode($f['parts'])); | ||
|
||
$record->save(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Craft; | ||
|
||
class SimpleMapVariable { | ||
|
||
public function latLng ($lat, $lng) | ||
{ | ||
$lat = (float)$lat; | ||
$lng = (float)$lng; | ||
|
||
return compact('lat', 'lng'); | ||
} | ||
|
||
} |