Skip to content

Commit

Permalink
54192 Map for address list with pin display and show/hide functionali…
Browse files Browse the repository at this point in the history
…ty (#960)

* 54192 update map for address list

* 54192 refactor code

* 54192 refactor code

* 54192 update unit test

* 54192 update unit test

* 54192 update config show map

* 54192 refactor code

* 54192 refactor code

* Update onoffice-style.css

added margin to map and height to openstreet address map

* Update default.php

changed class

* 54192 Add conditional rendering for address map based on configuration

---------

Co-authored-by: Frederic Alpers <88546396+fredericalpers@users.noreply.github.com>
Co-authored-by: Helene Neufeld <70378166+miauzjpg@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent 3fa1b9e commit 1d1031f
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 38 deletions.
57 changes: 53 additions & 4 deletions plugin/AddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use onOffice\WPlugin\Field\UnknownFieldException;
use onOffice\WPlugin\DataView\DataAddressDetailView;
use onOffice\WPlugin\Controller\AddressDetailUrl;
use onOffice\WPlugin\ViewFieldModifier\AddressViewFieldModifierTypes;

/**
*
Expand Down Expand Up @@ -243,9 +244,10 @@ public function loadAddresses(int $inputPage = 1)
}

/**
* @param string $modifier
* @return ViewFieldModifierHandler
*/
private function generateRecordModifier(): ViewFieldModifierHandler
private function generateRecordModifier(string $modifier = AddressViewFieldModifierTypes::MODIFIER_TYPE_DEFAULT): ViewFieldModifierHandler
{
$fields = $this->_pDataViewAddress->getFields();

Expand All @@ -261,7 +263,7 @@ private function generateRecordModifier(): ViewFieldModifierHandler
$fields = array_intersect($fields,
array_keys($this->_pEnvironment->getFieldnames()->getFieldList(onOfficeSDK::MODULE_ADDRESS)));

$pAddressFieldModifierHandler = $this->_pEnvironment->getViewFieldModifierHandler($fields);
$pAddressFieldModifierHandler = $this->_pEnvironment->getViewFieldModifierHandler($fields, $modifier);
return $pAddressFieldModifierHandler;
}

Expand Down Expand Up @@ -388,12 +390,13 @@ public function getAddressOverallCount()
}

/**
* @param string $modifier
* @param bool $raw
* @return array
*/
public function getRows(bool $raw = false): array
public function getRows(string $modifier = AddressViewFieldModifierTypes::MODIFIER_TYPE_DEFAULT, bool $raw = false): array
{
$pAddressFieldModifier = $this->generateRecordModifier();
$pAddressFieldModifier = $this->generateRecordModifier($modifier);
return array_map(function($values) use ($pAddressFieldModifier, $raw): ArrayContainer {
$valuesNew = $pAddressFieldModifier->processRecord($values);

Expand Down Expand Up @@ -572,6 +575,28 @@ public function generateImageAlt(int $addressId): string
return $imageAlt;
}

/**
* @param string|null $firstName
* @param string|null $lastName
* @param string|null $company
* @return string
*/
public static function createAddressTitle(string $firstName, string $lastName, string $company): string
{
$parts = [];
if (!empty($firstName)) {
$parts[] = strtolower($firstName);
}
if (!empty($lastName)) {
$parts[] = strtolower($lastName);
}
if (!empty($company)) {
$parts[] = strtolower($company);
}

return implode(' ', $parts);
}

/**
* @param string $addressId
* @return string
Expand Down Expand Up @@ -610,6 +635,30 @@ public function getAddressLink(string $addressId): string
return $fullLink;
}

/**
*
*/
public function resetAddresssIterator()
{
reset($this->_records);
}

/**
* @return mixed
*/
public function getListViewId()
{
return $this->_pDataViewAddress->getId();
}

/**
* @return bool
*/
public function getShowMapConfig(): bool
{
return $this->_pDataViewAddress->getShowMap();
}

/**
* @return array
*/
Expand Down
3 changes: 2 additions & 1 deletion plugin/Controller/AddressListEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public function getDataListViewAddressToAPIParameters(): DataListViewAddressToAP

/**
* @param array $fields
* @param string $modifier
* @return ViewFieldModifierHandler
*/
public function getViewFieldModifierHandler(array $fields): ViewFieldModifierHandler;
public function getViewFieldModifierHandler(array $fields, string $modifier): ViewFieldModifierHandler;

/**
* @return FieldsCollectionBuilderShort
Expand Down
6 changes: 3 additions & 3 deletions plugin/Controller/AddressListEnvironmentDefault.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public function getSDKWrapper(): SDKWrapper

/**
* @param array $fields
* @param string $modified
* @return ViewFieldModifierHandler
*/
public function getViewFieldModifierHandler(array $fields): ViewFieldModifierHandler
public function getViewFieldModifierHandler(array $fields, $modified): ViewFieldModifierHandler
{
return new ViewFieldModifierHandler($fields, onOfficeSDK::MODULE_ADDRESS,
AddressViewFieldModifierTypes::MODIFIER_TYPE_DEFAULT);
return new ViewFieldModifierHandler($fields, onOfficeSDK::MODULE_ADDRESS, $modified);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions plugin/DataView/DataListViewAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class DataListViewAddress
/** @var bool */
private $_bildWebseite = false;

/** @var bool */
private $_showMap = false;

/**
*
* @param int $id
Expand Down Expand Up @@ -195,4 +198,12 @@ public function getBildWebseite(): bool
/** @param bool $bildWebseite */
public function setBildWebseite(bool $bildWebseite)
{ $this->_bildWebseite = $bildWebseite; }

/** @return bool */
public function getShowMap(): bool
{ return (bool) $this->_showMap; }

/** @param bool $showMap */
public function setShowMap(bool $showMap)
{ $this->_showMap = $showMap; }
}
1 change: 1 addition & 0 deletions plugin/DataView/DataListViewFactoryAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function createListViewByRow(array $row): DataViewFilterableFields
$pDataListViewAddress->setHiddenFields($row['hidden']);
$pDataListViewAddress->setConvertInputTextToSelectForField($row['convertInputTextToSelectForField']);
$pDataListViewAddress->setBildWebseite((bool)$row['bildWebseite']);
$pDataListViewAddress->setShowMap((bool)$row['show_map']);

return $pDataListViewAddress;
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/Gui/AdminPageAddressListSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,13 @@ private function addFormModelName()
private function addFormModelTemplate()
{
$pInputModelTemplate = $this->_pFormModelBuilderAddress->createInputModelTemplate('address');
$pInputModelShowMap = $this->_pFormModelBuilderAddress->createInputModelShowMap();
$pFormModelLayoutDesign = new FormModel();
$pFormModelLayoutDesign->setPageSlug($this->getPageSlug());
$pFormModelLayoutDesign->setGroupSlug(self::FORM_VIEW_LAYOUT_DESIGN);
$pFormModelLayoutDesign->setLabel(__('Layout & Design', 'onoffice-for-wp-websites'));
$pFormModelLayoutDesign->addInputModel($pInputModelTemplate);
$pFormModelLayoutDesign->addInputModel($pInputModelShowMap);
$this->addFormModel($pFormModelLayoutDesign);
}

Expand Down
8 changes: 7 additions & 1 deletion plugin/Installer/DatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
class DatabaseChanges implements DatabaseChangesInterface
{
/** @var int */
const MAX_VERSION = 55;
const MAX_VERSION = 56;

/** @var WPOptionWrapperBase */
private $_pWpOption;
Expand Down Expand Up @@ -369,6 +369,11 @@ public function install()
$dbversion = 55;
}

if ($dbversion == 55) {
dbDelta($this->getCreateQueryListViewsAddress());
$dbversion = 56;
}

$this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true );
}

Expand Down Expand Up @@ -723,6 +728,7 @@ private function getCreateQueryListViewsAddress()
`showPhoto` tinyint(1) NOT NULL DEFAULT '0',
`bildWebseite` tinyint(1) NOT NULL DEFAULT '0',
`page_shortcode` tinytext NOT NULL,
`show_map` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`listview_address_id`),
UNIQUE KEY `name` (`name`)
) $charsetCollate;";
Expand Down
19 changes: 19 additions & 0 deletions plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,23 @@ public function getInputModelCustomLabelLanguageSwitch(): InputModelDB
});
return $pInputModel;
}

/**
*
* @return InputModelDB
*
*/

public function createInputModelShowMap()
{
$labelShowMap = __('Show address map', 'onoffice-for-wp-websites');

$pInputModelShowMap = $this->getInputModelDBFactory()->create
(InputModelDBFactory::INPUT_SHOW_MAP, $labelShowMap);
$pInputModelShowMap->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
$pInputModelShowMap->setValue($this->getValue('show_map'));
$pInputModelShowMap->setValuesAvailable(1);

return $pInputModelShowMap;
}
}
4 changes: 4 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactoryConfigAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class InputModelDBFactoryConfigAddress
self::KEY_TABLE => 'oo_plugin_listviews_address',
self::KEY_FIELD => 'bildWebseite',
],
InputModelDBFactory::INPUT_SHOW_MAP => [
self::KEY_TABLE => 'oo_plugin_listviews_address',
self::KEY_FIELD => 'show_map',
],
];


Expand Down
29 changes: 4 additions & 25 deletions plugin/Record/AddressIdRequestGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use onOffice\WPlugin\Language;
use onOffice\WPlugin\SDKWrapper;
use onOffice\WPlugin\Controller\Redirector\AddressRedirector;
use onOffice\WPlugin\AddressList;

/**
*
Expand Down Expand Up @@ -109,7 +110,7 @@ public function addressDetailUrlChecker(int $addressId, AddressRedirector $pRedi
$firstName = $this->_addressData->getValue('Vorname');
$lastName = $this->_addressData->getValue('Name');
$company = $this->_addressData->getValue('Zusatz1');
$addressTitle = $this->createAddressTitle($firstName, $lastName, $company);
$addressTitle = AddressList::createAddressTitle($firstName, $lastName, $company);
$pRedirector->redirectDetailView($addressId, $addressTitle, $pAddressRedirection);
}

Expand All @@ -134,7 +135,7 @@ public function createAddressDetailLinkForSwitchLanguageWPML(string $url, int $a
$firstName = $this->_addressData->getValue('Vorname');
$lastName = $this->_addressData->getValue('Name');
$company = $this->_addressData->getValue('Zusatz1');
$addressDetailTitle = $this->createAddressTitle($firstName, $lastName, $company);
$addressDetailTitle = AddressList::createAddressTitle($firstName, $lastName, $company);
}
}
$detailLinkForWPML = $pAddressDetailUrl->createAddressDetailLink($url, $addressId, $addressDetailTitle, $oldUrl, true);
Expand Down Expand Up @@ -181,7 +182,7 @@ private function getAddressTitleByLocales(array $locales, int $addressId): array
$firstName = $pApiClientAction->getResultRecords()[0]['elements']['Vorname'];
$lastName = $pApiClientAction->getResultRecords()[0]['elements']['Name'];
$company = $pApiClientAction->getResultRecords()[0]['elements']['Zusatz1'];
$addressTitleByLocales[ $key ] = $this->createAddressTitle($firstName, $lastName, $company);
$addressTitleByLocales[ $key ] = AddressList::createAddressTitle($firstName, $lastName, $company);
}

return $addressTitleByLocales;
Expand Down Expand Up @@ -220,26 +221,4 @@ private function addSwitchFilterToLocaleHook(string $locale)
return $locale;
});
}

/**
* @param string|null $firstName
* @param string|null $lastName
* @param string|null $company
* @return string
*/
private function createAddressTitle(string $firstName, string $lastName, string $company): string
{
$parts = [];
if (!empty($firstName)) {
$parts[] = strtolower($firstName);
}
if (!empty($lastName)) {
$parts[] = strtolower($lastName);
}
if (!empty($company)) {
$parts[] = strtolower($company);
}

return implode(' ', $parts);
}
}
Loading

0 comments on commit 1d1031f

Please sign in to comment.