diff --git a/plugin/AddressList.php b/plugin/AddressList.php index 32cb191df..ab5080070 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -46,6 +46,7 @@ use onOffice\WPlugin\Field\UnknownFieldException; use onOffice\WPlugin\DataView\DataAddressDetailView; use onOffice\WPlugin\Controller\AddressDetailUrl; +use onOffice\WPlugin\ViewFieldModifier\AddressViewFieldModifierTypes; /** * @@ -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(); @@ -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; } @@ -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); @@ -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 @@ -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 */ diff --git a/plugin/Controller/AddressListEnvironment.php b/plugin/Controller/AddressListEnvironment.php index 935fb0325..da6de4e90 100644 --- a/plugin/Controller/AddressListEnvironment.php +++ b/plugin/Controller/AddressListEnvironment.php @@ -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 diff --git a/plugin/Controller/AddressListEnvironmentDefault.php b/plugin/Controller/AddressListEnvironmentDefault.php index 819983c89..ee804f56f 100644 --- a/plugin/Controller/AddressListEnvironmentDefault.php +++ b/plugin/Controller/AddressListEnvironmentDefault.php @@ -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); } /** diff --git a/plugin/DataView/DataListViewAddress.php b/plugin/DataView/DataListViewAddress.php index ef10ced11..3ca794dad 100644 --- a/plugin/DataView/DataListViewAddress.php +++ b/plugin/DataView/DataListViewAddress.php @@ -78,6 +78,9 @@ class DataListViewAddress /** @var bool */ private $_bildWebseite = false; + /** @var bool */ + private $_showMap = false; + /** * * @param int $id @@ -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; } } diff --git a/plugin/DataView/DataListViewFactoryAddress.php b/plugin/DataView/DataListViewFactoryAddress.php index 363d7c4d2..d8de94c61 100644 --- a/plugin/DataView/DataListViewFactoryAddress.php +++ b/plugin/DataView/DataListViewFactoryAddress.php @@ -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; } diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index e23455bd5..c515a56a3 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -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); } diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index 27e909d83..1ac84170b 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -43,7 +43,7 @@ class DatabaseChanges implements DatabaseChangesInterface { /** @var int */ - const MAX_VERSION = 55; + const MAX_VERSION = 56; /** @var WPOptionWrapperBase */ private $_pWpOption; @@ -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 ); } @@ -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;"; diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php b/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php index 354c6ceaf..64fd80feb 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php @@ -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; + } } diff --git a/plugin/Model/InputModel/InputModelDBFactoryConfigAddress.php b/plugin/Model/InputModel/InputModelDBFactoryConfigAddress.php index 0314cb927..92f25f58f 100644 --- a/plugin/Model/InputModel/InputModelDBFactoryConfigAddress.php +++ b/plugin/Model/InputModel/InputModelDBFactoryConfigAddress.php @@ -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', + ], ]; diff --git a/plugin/Record/AddressIdRequestGuard.php b/plugin/Record/AddressIdRequestGuard.php index 00c7eace7..72d355d4f 100644 --- a/plugin/Record/AddressIdRequestGuard.php +++ b/plugin/Record/AddressIdRequestGuard.php @@ -32,6 +32,7 @@ use onOffice\WPlugin\Language; use onOffice\WPlugin\SDKWrapper; use onOffice\WPlugin\Controller\Redirector\AddressRedirector; +use onOffice\WPlugin\AddressList; /** * @@ -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); } @@ -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); @@ -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; @@ -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); - } } diff --git a/plugin/ViewFieldModifier/AddressViewFieldModifierTypeMap.php b/plugin/ViewFieldModifier/AddressViewFieldModifierTypeMap.php new file mode 100644 index 000000000..af5b228f4 --- /dev/null +++ b/plugin/ViewFieldModifier/AddressViewFieldModifierTypeMap.php @@ -0,0 +1,105 @@ +. + * + */ + +namespace onOffice\WPlugin\ViewFieldModifier; + +/** + * + * @url http://www.onoffice.de + * @copyright 2003-2024, onOffice(R) GmbH + * + */ + +class AddressViewFieldModifierTypeMap + implements ViewFieldModifierTypeBase +{ + /** @var array */ + private $_viewFields = []; + + /** + * @param array $viewFields + */ + public function __construct(array $viewFields) + { + $this->_viewFields = $viewFields; + } + + /** + * + * @return array + * + */ + + public function getAPIFields(): array + { + $mapSpecific = [ + 'Vorname', + 'Name', + 'Zusatz1', + 'laengengrad', + 'breitengrad', + ]; + + return $mapSpecific; + } + + + /** + * + * @return array + * + */ + + public function getVisibleFields(): array + { + $mapFields = [ + 'Vorname', + 'Name', + 'Zusatz1', + 'laengengrad', + 'breitengrad', + ]; + + return $this->merge($mapFields, $this->_viewFields); + } + + /** + * @param array $record + * @return array + */ + public function reduceRecord(array $record): array + { + return $record; + } + + /** + * + * @param array $array1 + * @param array $array2 + * @return array + * + */ + + private function merge(array $array1, array $array2): array + { + return array_values(array_unique(array_merge($array1, $array2))); + } +} diff --git a/plugin/ViewFieldModifier/AddressViewFieldModifierTypes.php b/plugin/ViewFieldModifier/AddressViewFieldModifierTypes.php index 799299cc0..9e724ef06 100644 --- a/plugin/ViewFieldModifier/AddressViewFieldModifierTypes.php +++ b/plugin/ViewFieldModifier/AddressViewFieldModifierTypes.php @@ -37,10 +37,14 @@ class AddressViewFieldModifierTypes /** */ const MODIFIER_TYPE_TITLE = 'modifierTypeTitle'; + /** */ + const MODIFIER_TYPE_MAP = 'modifierTypeMap'; + /** @var array */ private $_mapping = [ self::MODIFIER_TYPE_DEFAULT => AddressViewFieldModifierTypeDefault::class, self::MODIFIER_TYPE_TITLE => AddressViewFieldModifierTypeTitle::class, + self::MODIFIER_TYPE_MAP => AddressViewFieldModifierTypeMap::class, ]; diff --git a/templates.dist/address/default.php b/templates.dist/address/default.php index f286116bd..c47913409 100644 --- a/templates.dist/address/default.php +++ b/templates.dist/address/default.php @@ -31,6 +31,11 @@ * */ ?> +getShowMapConfig()) { ?> +