From 5c8e4e00ca804145a79d38c04c74afee67480411 Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Thu, 25 Apr 2024 15:53:35 +0700
Subject: [PATCH 01/33] 47365 revision of the address list template
---
templates.dist/address/default.php | 56 ++++++++++++++++++++++--------
templates.dist/onoffice-style.css | 15 ++++++++
2 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/templates.dist/address/default.php b/templates.dist/address/default.php
index 193684b09..a52ae1b02 100644
--- a/templates.dist/address/default.php
+++ b/templates.dist/address/default.php
@@ -30,19 +30,45 @@
* Default template for address lists
*
*/
-
-/* @var $pAddressList AddressList */
-foreach ($pAddressList->getRows() as $escapedValues) {
- $imageUrl = $escapedValues['imageUrl'];
- unset($escapedValues['imageUrl']);
-
- echo esc_html__('Picture: ', 'onoffice-for-wp-websites'), $imageUrl, ' ';
-
- foreach ($escapedValues as $field => $value) {
- if ($pAddressList->getFieldType($field) === FieldTypes::FIELD_TYPE_BLOB) {
- continue;
- }
- $fieldLabel = $pAddressList->getFieldLabel($field);
- echo $fieldLabel, ': ', (is_array($value) ? implode(', ', array_filter($value)) : $value), ' ';
+?>
+
+ getRows() as $escapedValues) {
+ $imageUrl = $escapedValues['imageUrl'];
+ unset($escapedValues['imageUrl']);
+ ?>
+
+
+ ';
+ }
+ ?>
+
+
+ $value) {
+ if ($pAddressList->getFieldType($field) === FieldTypes::FIELD_TYPE_BLOB) {
+ continue;
+ }
+ if (empty($value)) {
+ continue;
+ }
+ $fieldLabel = $pAddressList->getFieldLabel($field);
+ echo '
' . esc_html($fieldLabel) . '
' . (is_array($value) ? implode(', ', array_filter($value)) : $value) . '
';
+ }
+ ?>
+
+
+
+
+
+
+
+
+
diff --git a/templates.dist/onoffice-style.css b/templates.dist/onoffice-style.css
index 040437a37..7158fe6ca 100644
--- a/templates.dist/onoffice-style.css
+++ b/templates.dist/onoffice-style.css
@@ -270,6 +270,21 @@
width: 100%;
}
+/* address list */
+.oo-address-listframe .oo-address-image {
+ width: 100%;
+ height: auto;
+}
+
+.oo-address-listframe .oo-listtd {
+ word-wrap: break-word;
+}
+
+.oo-address-listframe .oo-listinfotableview {
+ display: flex;
+ flex-wrap: wrap;
+}
+
/* responsive */
@media only screen and (max-width: 991px) {
.oo-listobject, .oo-searchformfield {
From d06e50b42ed4d2cc08f6554dc8516262fe0faec7 Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Mon, 6 May 2024 22:52:32 +0700
Subject: [PATCH 02/33] 47365 update content for image alt & unit test
---
.../DataListViewAddressToAPIParameters.php | 5 +-
plugin/AddressList.php | 119 +++++++++++++++++-
templates.dist/address/default.php | 7 +-
tests/TestClassAddressList.php | 113 ++++++++++++++++-
...lassDataListViewAddressToAPIParameters.php | 6 +-
5 files changed, 240 insertions(+), 10 deletions(-)
diff --git a/plugin/API/DataViewToAPI/DataListViewAddressToAPIParameters.php b/plugin/API/DataViewToAPI/DataListViewAddressToAPIParameters.php
index 4d0bfa6a6..fa60f5e51 100644
--- a/plugin/API/DataViewToAPI/DataListViewAddressToAPIParameters.php
+++ b/plugin/API/DataViewToAPI/DataListViewAddressToAPIParameters.php
@@ -59,10 +59,11 @@ public function __construct(DefaultFilterBuilderListViewAddressFactory $pFilterB
* @param array $fields
* @param DataListViewAddress $pDataListView
* @param int $page
+ * @param bool $raw
* @return array
*/
- public function buildParameters(array $fields, DataListViewAddress $pDataListView, int $page): array
+ public function buildParameters(array $fields, DataListViewAddress $pDataListView, int $page, bool $raw = false): array
{
$pBuilderListViewAddress = $this->_pFilterBuilderFactory->create($pDataListView);
@@ -83,7 +84,7 @@ public function buildParameters(array $fields, DataListViewAddress $pDataListVie
'filter' => $pBuilderListViewAddress->buildFilter(),
'filterid' => $pDataListView->getFilterId(),
'outputlanguage' => Language::getDefault(),
- 'formatoutput' => true,
+ 'formatoutput' => $raw,
);
if ($pDataListView->getShowPhoto()) {
diff --git a/plugin/AddressList.php b/plugin/AddressList.php
index 2a694836d..53b17cba1 100644
--- a/plugin/AddressList.php
+++ b/plugin/AddressList.php
@@ -49,6 +49,54 @@
class AddressList
{
+ /** @var string */
+ const CONTACT_CATEGORY_PRIVATE_CUSTOMER = 'privateCustomer';
+
+ /** @var string */
+ const CONTACT_CATEGORY_BUSINESS_CUSTOMER = 'businessCustomer';
+
+ /** @var string */
+ const CONTACT_CATEGORY_COMPANY = 'company';
+
+ /** @var string */
+ const CONTACT_CATEGORY_OFFICE = 'branch';
+
+ /** @var string */
+ const CONTACT_CATEGORY_DEPARTMMENT = 'department';
+
+ /** @var string */
+ const CONTACT_CATEGORY_MARRIED_COUPLE = 'marriedCouple';
+
+ /** @var string */
+ const CONTACT_CATEGORY_INSTITUTION = 'institution';
+
+ /** @var string */
+ const CONTACT_CATEGORY_ASSOCIATION = 'association';
+
+ /** @var string */
+ const CONTACT_CATEGORY_OWNER_ASSOCIATION = 'communityOfOwners';
+
+ /** @var string */
+ const CONTACT_CATEGORY_JOINT_HEIRS = 'communityOfHeirs';
+
+ /** @var string */
+ const CONTACT_CATEGORY_UMBRELLA_ORGANIZATION = 'umbrellaOrganization';
+
+ /** @var string[] */
+ private $_addressParametersForImageAlt = [
+ 'contactCategory',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'branch',
+ 'communityOfHeirs',
+ 'communityOfOwners',
+ 'umbrellaOrganization',
+ 'association',
+ 'institution',
+ 'department'
+ ];
+
/** @var string[] */
private $_specialContactData = [
'mobile',
@@ -79,6 +127,9 @@ class AddressList
/** @var DataListViewAddress */
private $_pDataViewAddress = null;
+ /** @var array */
+ private $_recordsRaw = [];
+
/**
*
@@ -138,12 +189,21 @@ public function loadAddresses(int $inputPage = 1)
$newPage = $inputPage === 0 ? 1 : $inputPage;
$apiOnlyFields = $pModifier->getAllAPIFields();
- $parameters = $pDataListViewToApi->buildParameters($apiOnlyFields, $this->_pDataViewAddress, $newPage);
+ $parameters = $pDataListViewToApi->buildParameters($apiOnlyFields, $this->_pDataViewAddress, $newPage, true);
$pApiCall = new APIClientActionGeneric
($this->_pEnvironment->getSDKWrapper(), onOfficeSDK::ACTION_ID_READ, 'address');
$pApiCall->setParameters($parameters);
- $pApiCall->addRequestToQueue()->sendRequests();
+ $pApiCall->addRequestToQueue();
+
+ $addressParameterRaws = $pDataListViewToApi->buildParameters($this->_addressParametersForImageAlt,
+ $this->_pDataViewAddress, $newPage);
+
+ $pAddressRawApiCall = clone $pApiCall;
+ $pAddressRawApiCall->setParameters($addressParameterRaws);
+ $pAddressRawApiCall->addRequestToQueue()->sendRequests();
+ $recordsRaw = $pAddressRawApiCall->getResultRecords();
+ $this->_recordsRaw = array_combine(array_column($recordsRaw, 'id'), $recordsRaw);
$records = $pApiCall->getResultRecords();
$this->fillAddressesById($records);
@@ -312,4 +372,59 @@ public function withDataListViewAddress(DataListViewAddress $pDataListViewAddres
$pAddressList->_pDataViewAddress = $pDataListViewAddress;
return $pAddressList;
}
+
+ /**
+ * @param int $addressId
+ *
+ * @return string
+ */
+ public function generateImageAlt(int $addressId): string
+ {
+ $addressRawElements = $this->_recordsRaw[$addressId]['elements'] ?? [];
+ if (empty($addressRawElements)) {
+ return '';
+ }
+
+ $contactCategory = $addressRawElements['contactCategory'];
+
+ switch ($contactCategory) {
+ case AddressList::CONTACT_CATEGORY_ASSOCIATION:
+ $imageAlt = $addressRawElements['association'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_INSTITUTION:
+ $imageAlt = $addressRawElements['institution'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_BUSINESS_CUSTOMER:
+ case AddressList::CONTACT_CATEGORY_PRIVATE_CUSTOMER:
+ $firstName = $addressRawElements['Vorname'] ?? '';
+ $name = $addressRawElements['Name'] ?? '';
+ $imageAlt = trim($firstName . ', ' . $name , ', ');
+ break;
+ case AddressList::CONTACT_CATEGORY_COMPANY:
+ $imageAlt = $addressRawElements['Zusatz1'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_OFFICE:
+ $imageAlt = $addressRawElements['branch'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_DEPARTMMENT:
+ $imageAlt = $addressRawElements['department'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_JOINT_HEIRS:
+ $imageAlt = $addressRawElements['communityOfHeirs'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_MARRIED_COUPLE:
+ $imageAlt = $addressRawElements['Name'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_OWNER_ASSOCIATION:
+ $imageAlt = $addressRawElements['communityOfOwners'] ?? '';
+ break;
+ case AddressList::CONTACT_CATEGORY_UMBRELLA_ORGANIZATION:
+ $imageAlt = $addressRawElements['umbrellaOrganization'] ?? '';
+ break;
+ default:
+ $imageAlt = '';
+ }
+
+ return $imageAlt;
+ }
}
\ No newline at end of file
diff --git a/templates.dist/address/default.php b/templates.dist/address/default.php
index a52ae1b02..4abbde8bf 100644
--- a/templates.dist/address/default.php
+++ b/templates.dist/address/default.php
@@ -34,7 +34,7 @@
getRows() as $escapedValues) {
+ foreach ($pAddressList->getRows() as $addressId => $escapedValues) {
$imageUrl = $escapedValues['imageUrl'];
unset($escapedValues['imageUrl']);
?>
@@ -42,7 +42,8 @@
';
+ $imageAlt = $pAddressList->generateImageAlt($addressId);
+ echo '
';
}
?>
@@ -52,9 +53,11 @@
if ($pAddressList->getFieldType($field) === FieldTypes::FIELD_TYPE_BLOB) {
continue;
}
+
if (empty($value)) {
continue;
}
+
$fieldLabel = $pAddressList->getFieldLabel($field);
echo '
' . esc_html($fieldLabel) . '
' . (is_array($value) ? implode(', ', array_filter($value)) : $value) . '
';
}
diff --git a/tests/TestClassAddressList.php b/tests/TestClassAddressList.php
index efe6a5550..b4cade236 100644
--- a/tests/TestClassAddressList.php
+++ b/tests/TestClassAddressList.php
@@ -41,6 +41,11 @@
use onOffice\WPlugin\Types\FieldTypes;
use onOffice\WPlugin\ViewFieldModifier\ViewFieldModifierHandler;
use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderShort;
+use DI\ContainerBuilder;
+use onOffice\WPlugin\Filter\FilterBuilderInputVariablesFactory;
+use onOffice\WPlugin\Field\CompoundFieldsFilter;
+use onOffice\WPlugin\Filter\DefaultFilterBuilderListViewAddressFactory;
+use onOffice\WPlugin\API\DataViewToAPI\DataListViewAddressToAPIParameters;
use WP_UnitTestCase;
use function json_decode;
@@ -98,10 +103,43 @@ public function prepare()
'formatoutput' => true,
];
+ $addressParametersWithoutFormat = [
+ 'data' => ['Name', 'KdNr', 'Vorname'],
+ 'listoffset' => 0,
+ 'listlimit' => 5,
+ 'sortby' => "",
+ 'sortorder' => "",
+ 'filter' => [],
+ 'filterid' => 0,
+ 'outputlanguage' => "ENG",
+ 'formatoutput' => true,
+ ];
+
+ $responseRaw = $this->getResponseGetRowsRaw();
+ $addressParametersWithFormat = [
+ 'data' => ['contactCategory', 'Vorname', 'Name', 'Zusatz1', 'branch', 'communityOfHeirs', 'communityOfOwners', 'umbrellaOrganization', 'association', 'institution', 'department'],
+ 'listoffset' => 0,
+ 'listlimit' => 5,
+ 'sortby' => "",
+ 'sortorder' => "",
+ 'filter' => [],
+ 'filterid' => 0,
+ 'outputlanguage' => "ENG",
+ 'formatoutput' => false,
+ ];
+
$pSDKWrapper->addResponseByParameters
(onOfficeSDK::ACTION_ID_READ, 'address', '', $parameters, null, $response);
$pSDKWrapper->addResponseByParameters
- (onOfficeSDK::ACTION_ID_READ, 'address', '', [], null, $response);
+ (onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithoutFormat, null, $response);
+ $addressParametersWithoutFormat['data'][] = 'imageUrl';
+ $pSDKWrapper->addResponseByParameters
+ (onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithoutFormat, null, $response);
+ $pSDKWrapper->addResponseByParameters
+ (onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithFormat, null, $responseRaw);
+ $addressParametersWithFormat['data'][] = 'imageUrl';
+ $pSDKWrapper->addResponseByParameters
+ (onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithFormat, null, $responseRaw);
$pMockViewFieldModifierHandler = $this->getMockBuilder(ViewFieldModifierHandler::class)
->setMethods(['processRecord', 'getAllAPIFields'])
@@ -138,12 +176,24 @@ public function prepare()
$pMockOutputFields->method('getVisibleFilterableFields')
->will($this->returnValue(['KdNr' => 4, 'Vorname' => null, 'Name' => 'Stefansson']));
+ $pContainerBuilder = new ContainerBuilder();
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $pContainer = $pContainerBuilder->build();
+ $pFieldsCollectionBuilderShort = $pContainer->get(FieldsCollectionBuilderShort::class);
+ $pFilterBuilderFactory = $pContainer->get(FilterBuilderInputVariablesFactory::class);
+ $pCompoundFieldsFilter = $pContainer->get(CompoundFieldsFilter::class);
+ $pFactory = $this->getMockBuilder(DefaultFilterBuilderListViewAddressFactory::class)
+ ->setConstructorArgs([$pFieldsCollectionBuilderShort, $pCompoundFieldsFilter, $pFilterBuilderFactory])
+ ->getMock();
+ $pDataListViewAddressToAPIParameters = new DataListViewAddressToAPIParameters($pFactory);
+
$pMockConfig = $this->getMockBuilder(AddressListEnvironment::class)->getMock();
$pMockConfig->method('getSDKWrapper')->will($this->returnValue($pSDKWrapper));
$pMockConfig->method('getViewFieldModifierHandler')
->will($this->returnValue($pMockViewFieldModifierHandler));
$pMockConfig->method('getFieldnames')->will($this->returnValue($pMockFieldnames));
$pMockConfig->method('getOutputFields')->will($this->returnValue($pMockOutputFields));
+ $pMockConfig->method('getDataListViewAddressToAPIParameters')->will($this->returnValue($pDataListViewAddressToAPIParameters));
$pFieldsCollectionBuilderMock = $this->getMockBuilder(FieldsCollectionBuilderShort::class)
->setConstructorArgs([new Container()])
@@ -401,4 +451,65 @@ private function getResponseGetRows()
return json_decode($responseStr, true);
}
+
+ private function getResponseGetRowsRaw()
+ {
+ $responseStr = '
+ {
+ "actionid": "urn:onoffice-de-ns:smart:2.5:smartml:action:read",
+ "resourceid": "",
+ "resourcetype": "address",
+ "cacheable": true,
+ "identifier": "",
+ "data": {
+ "meta": {
+ "cntabsolute": null
+ },
+ "records": [
+ {
+ "id": 13,
+ "type": "address",
+ "elements": {
+ "id": 13,
+ "contactCategory": "branch",
+ "Vorname": "David",
+ "Name": "Joe",
+ "Zusatz1": "AST Company",
+ "branch": "AST1 Office",
+ "communityOfHeirs": "AST Community",
+ "communityOfOwners": "AST community",
+ "umbrellaOrganization": "AST Organization",
+ "association": "AST",
+ "institution": "AST",
+ "department": "Department"
+ }
+ },
+ {
+ "id": 37,
+ "type": "address",
+ "elements": {
+ "id": 37,
+ "contactCategory": "institution",
+ "Vorname": "David",
+ "Name": "Joe",
+ "Zusatz1": "AST Company",
+ "branch": "AST1 Office",
+ "communityOfHeirs": "AST Community",
+ "communityOfOwners": "AST community",
+ "umbrellaOrganization": "AST Organization",
+ "association": "AST",
+ "institution": "AST",
+ "department": "Department"
+ }
+ }
+ ]
+ },
+ "status": {
+ "errorcode": 0,
+ "message": "OK"
+ }
+ }';
+
+ return json_decode($responseStr, true);
+ }
}
diff --git a/tests/TestClassDataListViewAddressToAPIParameters.php b/tests/TestClassDataListViewAddressToAPIParameters.php
index 79421d73e..5038f5ec6 100644
--- a/tests/TestClassDataListViewAddressToAPIParameters.php
+++ b/tests/TestClassDataListViewAddressToAPIParameters.php
@@ -74,7 +74,7 @@ public function testBuildParameters()
'filter' => $this->_filter,
'filterid' => 12,
'outputlanguage' => 'ENG',
- 'formatoutput' => true,
+ 'formatoutput' => false,
];
$this->assertEquals($expectedResult, $result);
@@ -100,7 +100,7 @@ public function testBuildParametersImage()
'filter' => $this->_filter,
'filterid' => 12,
'outputlanguage' => 'ENG',
- 'formatoutput' => true,
+ 'formatoutput' => false,
];
$this->assertEquals($expectedResult, $result);
@@ -168,7 +168,7 @@ public function testBuildParametersWithPageGreaterThanOne()
'filter' => $this->_filter,
'filterid' => 12,
'outputlanguage' => 'ENG',
- 'formatoutput' => true,
+ 'formatoutput' => false,
];
$this->assertEquals($expectedResult, $result);
From 07d82dde7817fde091bfa80d26282471a7563804 Mon Sep 17 00:00:00 2001
From: yeneastgate
Date: Thu, 16 May 2024 14:12:29 +0700
Subject: [PATCH 03/33] 47941 add address detail page
---
css/admin.css | 3 +
plugin.php | 2 +
plugin/Controller/AdminViewController.php | 26 +-
.../DetailViewPostSaveController.php | 78 ++-
plugin/Controller/RewriteRuleBuilder.php | 24 +-
plugin/DataView/DataAddressDetailView.php | 129 +++++
.../DataView/DataAddressDetailViewHandler.php | 110 ++++
plugin/DataView/DataListViewAddress.php | 2 +-
plugin/DataView/DataViewAddress.php | 43 ++
plugin/Gui/AdminPageAddress.php | 249 ++++++++
plugin/Gui/AdminPageAddressDetail.php | 547 ++++++++++++++++++
plugin/Gui/AdminPageAddressList.php | 82 +--
plugin/Gui/AdminPageAddressListSettings.php | 16 +
.../Gui/AdminPageEstateListSettingsBase.php | 7 +
plugin/Gui/AdminPageSettingsBase.php | 7 -
.../FormModelBuilderAddressDetailSettings.php | 314 ++++++++++
...putModelOptionFactoryAddressDetailView.php | 104 ++++
.../InputFieldTemplateListRenderer.php | 1 +
plugin/Types/ImageTypes.php | 11 +
tests/TestClassDataAddressDetailView.php | 86 +++
.../TestClassDataAddressDetailViewHandler.php | 133 +++++
...sFormModelBuilderAddressDetailSettings.php | 199 +++++++
tests/TestClassImageTypes.php | 21 +
23 files changed, 2101 insertions(+), 93 deletions(-)
create mode 100644 plugin/DataView/DataAddressDetailView.php
create mode 100644 plugin/DataView/DataAddressDetailViewHandler.php
create mode 100644 plugin/DataView/DataViewAddress.php
create mode 100644 plugin/Gui/AdminPageAddress.php
create mode 100644 plugin/Gui/AdminPageAddressDetail.php
create mode 100644 plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
create mode 100644 plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
create mode 100644 tests/TestClassDataAddressDetailView.php
create mode 100644 tests/TestClassDataAddressDetailViewHandler.php
create mode 100644 tests/TestClassFormModelBuilderAddressDetailSettings.php
diff --git a/css/admin.css b/css/admin.css
index 9153698b7..e019d7ce5 100644
--- a/css/admin.css
+++ b/css/admin.css
@@ -287,6 +287,7 @@ div[data-name^=oopluginfieldconfigformdefaultsvalues-value].multiselect > input.
#onoffice-form-search-address{
display: flex;
float: right;
+ margin-top: -33px;
}
#onoffice-form-search-form {
display: flex;
@@ -754,10 +755,12 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
width: 100%;
}
+ .oo-poststuff-address-detail .viewusage,
.oo-poststuff-estate-detail .viewusage {
width: 100%;
}
+ .oo-poststuff-address-detail .block-publish,
.oo-poststuff-estate-detail .block-publish,
.oo-poststuff-similar-estate .block-publish {
margin-top: 0;
diff --git a/plugin.php b/plugin.php
index 590b913cc..04f9a94f7 100644
--- a/plugin.php
+++ b/plugin.php
@@ -171,6 +171,8 @@
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
+ $pRewriteRuleBuilder->addCustomRewriteTagsAddressDetail();
+ $pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
});
// This hook [wp] is one effective place to perform any high-level filtering or validation,
diff --git a/plugin/Controller/AdminViewController.php b/plugin/Controller/AdminViewController.php
index 4c1de1a52..a18af97cb 100644
--- a/plugin/Controller/AdminViewController.php
+++ b/plugin/Controller/AdminViewController.php
@@ -43,6 +43,7 @@
use onOffice\WPlugin\Types\FieldsCollection;
use onOffice\WPlugin\Utility\__String;
use onOffice\WPlugin\WP\ListTableBulkActionsHandler;
+use onOffice\WPlugin\Gui\AdminPageAddress;
use Parsedown;
use HTMLPurifier_Config;
use HTMLPurifier;
@@ -93,6 +94,9 @@ class AdminViewController
/** @var AdminPageFormSettingsMain */
private $_pAdminPageFormSettings = null;
+ /** @var AdminPageAddress */
+ private $_pAdminPageAddresses = null;
+
/** */
const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
@@ -127,6 +131,13 @@ public function onInit()
if ($pSelectedSubPage instanceof AdminPageAjax) {
$this->_ajaxHooks['onoffice_page_'.$this->_pageSlug.'-estates'] = $pSelectedSubPage;
}
+
+ $this->_pAdminPageAddresses = new AdminPageAddress($this->_pageSlug);
+ $pSelectedSubPageForAddress = $this->_pAdminPageAddresses->getSelectedAdminPage();
+
+ if ($pSelectedSubPageForAddress instanceof AdminPageAjax) {
+ $this->_ajaxHooks['onoffice_page_'.$this->_pageSlug.'-addresses'] = $pSelectedSubPageForAddress;
+ }
}
@@ -167,11 +178,16 @@ public function register_menu()
__( 'Getting started', 'onoffice-for-wp-websites' ),
$roleMainPage, $this->_pageSlug );
- $pAdminPageAddresses = new AdminPageAddressList($this->_pageSlug);
- $hookAddresses = add_submenu_page( $this->_pageSlug, __('Addresses', 'onoffice-for-wp-websites'), __('Addresses', 'onoffice-for-wp-websites'),
- $roleAddress, $this->_pageSlug.'-addresses', array($pAdminPageAddresses, 'render'));
- add_action('load-'.$hookAddresses, [$pAdminPageAddresses, 'handleAdminNotices']);
- add_action('current_screen', [$pAdminPageAddresses, 'preOutput']);
+ // Addresses
+ $hookAddresses = add_submenu_page( $this->_pageSlug, __('Addresses', 'onoffice-for-wp-websites'),
+ __('Addresses', 'onoffice-for-wp-websites'), $roleAddress,
+ $this->_pageSlug.'-addresses', array($this->_pAdminPageAddresses, 'render'));
+ add_action('load-'.$hookAddresses, [$this->_pAdminPageAddresses, 'handleAdminNotices']);
+ $pSelectedSubPageForAddress = $this->_pAdminPageAddresses->getSelectedAdminPage();
+ if ($pSelectedSubPageForAddress instanceof AdminPageAjax) {
+ add_action( 'load-'.$hookAddresses, array($pSelectedSubPageForAddress, 'checkForms'));
+ }
+ add_action('current_screen', [$this->_pAdminPageAddresses, 'preOutput']);
// Estates
$hookEstates = add_submenu_page( $this->_pageSlug, __('Estates', 'onoffice-for-wp-websites'),
diff --git a/plugin/Controller/DetailViewPostSaveController.php b/plugin/Controller/DetailViewPostSaveController.php
index ec094480e..cf5aa9847 100644
--- a/plugin/Controller/DetailViewPostSaveController.php
+++ b/plugin/Controller/DetailViewPostSaveController.php
@@ -29,6 +29,7 @@
use onOffice\WPlugin\Record\RecordManagerReadListViewEstate;
use onOffice\WPlugin\Record\RecordManagerReadListViewAddress;
use onOffice\WPlugin\Record\RecordManagerReadForm;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
use WP_Post;
@@ -104,26 +105,40 @@ public function onSavePost($postId) {
if (!$isRevision) {
$pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class);
$pDetailView = $pDataDetailViewHandler->getDetailView();
+ $pDataAddressDetailViewHandler = $this->_pContainer->get(DataAddressDetailViewHandler::class);
+ $pAddressDetailView = $pDataAddressDetailViewHandler->getAddressDetailView();
$detailViewName = $pDetailView->getName();
+ $addressDetailViewName = $pAddressDetailView->getName();
$postContent = $pPost->post_content;
$postType = $pPost->post_type;
$metaKeys = get_post_meta($postId, '', true);
$viewContained = $this->postContainsViewName($postContent, $detailViewName);
+ $viewContainedAddressDetail = $this->postContainsViewName($postContent, $addressDetailViewName, 'oo_address');
$viewContainedCustomField = false;
$hasOtherShortcodeInPostContent = false;
+ $viewContainedAddressDetailCustomField = false;
+ $hasOtherAddressDetailShortcodeInPostContent = false;
if (!$viewContained && !empty($postContent) && $this->checkOtherShortcodeInPostContent($postContent, $detailViewName)) {
$hasOtherShortcodeInPostContent = true;
}
+ if (!$viewContainedAddressDetail && !empty($postContent) && $this->checkOtherShortcodeInPostContent($postContent, $addressDetailViewName, 'oo_address')) {
+ $hasOtherAddressDetailShortcodeInPostContent = true;
+ }
+
foreach ($metaKeys as $metaKey) {
$viewContainedMetaKey = $this->postContainsViewName($metaKey[0], $detailViewName);
if ($viewContainedMetaKey) {
$viewContainedCustomField = true;
}
+ $viewAddressDetailContainedMetaKey = $this->postContainsViewName($metaKey[0], $addressDetailViewName, 'oo_address');
+ if ($viewAddressDetailContainedMetaKey) {
+ $viewContainedAddressDetailCustomField = true;
+ }
}
if (($viewContained) || ($viewContainedCustomField && $viewContained) || ($viewContainedCustomField && $hasOtherShortcodeInPostContent == false)) {
@@ -146,6 +161,28 @@ public function onSavePost($postId) {
flush_rewrite_rules();
}
}
+
+ if (($viewContainedAddressDetail) || ($viewContainedAddressDetailCustomField && $hasOtherAddressDetailShortcodeInPostContent == false)) {
+ if ($postType == 'page') {
+ $pAddressDetailView->setPageId((int) $postId);
+ $pAddressDetailView->addToPageIdsHaveDetailShortCode((int) $postId);
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesAddressDetail();
+ flush_rewrite_rules();
+ }
+ } elseif ($pAddressDetailView->getPageId() !== 0) {
+ $postRevisions = wp_get_post_revisions($postId);
+ $detailInPreviousRev = array_key_exists($pAddressDetailView->getPageId(), $postRevisions);
+
+ if ($detailInPreviousRev || $pAddressDetailView->getPageId() === $postId) {
+ $pAddressDetailView->setPageId(0);
+ $pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesAddressDetail();
+ flush_rewrite_rules();
+ }
+ }
+
$this->addPageUseShortCode($pPost);
$listView = $this->getListView();
$listViewAddress = $this->getListViewAddress();
@@ -209,9 +246,13 @@ public function onMoveTrash() {
$posts = $_GET['post'];
if ( isset( $posts ) ) {
$pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class);
+ $pDataAddressDetailViewHandler = $this->_pContainer->get(DataAddressDetailViewHandler::class);
$pDetailView = $pDataDetailViewHandler->getDetailView();
$detailPageIds = $pDetailView->getPageIdsHaveDetailShortCode();
+ $pAddressDetailView = $pDataAddressDetailViewHandler->getAddressDetailView();
+ $addressDetailPageIds = $pAddressDetailView->getPageIdsHaveDetailShortCode();
$hasDetailPost = false;
+ $hasAddressDetailPost = false;
if ( ! is_array( $posts ) ) {
$posts = [ $posts ];
}
@@ -220,17 +261,31 @@ public function onMoveTrash() {
$pDetailView->removeFromPageIdsHaveDetailShortCode( (int) $postId );
$hasDetailPost = true;
}
+ if (in_array($postId, $addressDetailPageIds)) {
+ $pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
+ $hasAddressDetailPost = true;
+ }
$pPost = get_post( $postId );
$this->deletePageUseShortCode( $pPost );
}
if ( $hasDetailPost ) {
- if ( empty( $pDetailView->getPageIdsHaveDetailShortCode() ) ) {
- $pDetailView->setPageId( 0 );
- } elseif ( in_array( $pDetailView->getPageId(), $posts ) ) {
- $firstDetailPageId = min( array_keys( $detailPageIds ) );
- $pDetailView->setPageId( (int) $detailPageIds[ $firstDetailPageId ] );
+ if (empty($pDetailView->getPageIdsHaveDetailShortCode())) {
+ $pDetailView->setPageId(0);
+ } elseif (in_array($pDetailView->getPageId(), $posts)) {
+ $firstDetailPageId = min(array_keys($detailPageIds));
+ $pDetailView->setPageId((int) $detailPageIds[$firstDetailPageId]);
}
- $pDataDetailViewHandler->saveDetailView( $pDetailView );
+ $pDataDetailViewHandler->saveDetailView($pDetailView);
+ flush_rewrite_rules();
+ }
+ if ( $hasAddressDetailPost ) {
+ if (empty($pAddressDetailView->getPageIdsHaveDetailShortCode())) {
+ $pAddressDetailView->setPageId(0);
+ } elseif (in_array($pAddressDetailView->getPageId(), $posts)) {
+ $firstDetailPageId = min(array_keys( $addressDetailPageIds ));
+ $pAddressDetailView->setPageId((int) $addressDetailPageIds[$firstDetailPageId]);
+ }
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
flush_rewrite_rules();
}
}
@@ -311,13 +366,14 @@ private function getListForm()
*
* @param string $post
* @param string $viewName
+ * @param string $tagShortcode
* @return bool
*
*/
- private function postContainsViewName($post, $viewName) {
+ private function postContainsViewName(string $post, string $viewName, string $tagShortcode = 'oo_estate') {
$matches = array();
- $regex = get_shortcode_regex(array('oo_estate'));
+ $regex = get_shortcode_regex(array($tagShortcode));
preg_match_all('/'.$regex.'/ism', $post, $matches);
$detailviewCode = $this->generateDetailViewCode($viewName);
@@ -338,18 +394,18 @@ private function postContainsViewName($post, $viewName) {
return false;
}
-
/**
*
* @param string $post
* @param string $viewName
+ * @param string $tagShortcode
* @return bool
*
*/
- private function checkOtherShortcodeInPostContent($post, $viewName) {
+ private function checkOtherShortcodeInPostContent(string $post, string $viewName, string $tagShortcode = 'oo_estate') {
$matches = array();
- $regex = get_shortcode_regex(array('oo_estate'));
+ $regex = get_shortcode_regex(array($tagShortcode));
preg_match_all('/' . $regex . '/ism', $post, $matches);
$detailviewCode = $this->generateDetailViewCode($viewName);
diff --git a/plugin/Controller/RewriteRuleBuilder.php b/plugin/Controller/RewriteRuleBuilder.php
index 4df42660a..98a2928a7 100644
--- a/plugin/Controller/RewriteRuleBuilder.php
+++ b/plugin/Controller/RewriteRuleBuilder.php
@@ -25,6 +25,7 @@
use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\WP\WPPageWrapper;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
class RewriteRuleBuilder
{
@@ -34,16 +35,21 @@ class RewriteRuleBuilder
/** @var WPPageWrapper */
private $_pWPPageWrapper;
+ /** @var DataAddressDetailViewHandler */
+ private $_pDataAddressDetailViewHandler;
+
/**
* @param DataDetailViewHandler $pDataDetailViewHandler
* @param WPPageWrapper $pWPPageWrapper
*/
public function __construct(
DataDetailViewHandler $pDataDetailViewHandler,
- WPPageWrapper $pWPPageWrapper)
+ WPPageWrapper $pWPPageWrapper,
+ DataAddressDetailViewHandler $pDataAddressDetailViewHandler)
{
$this->_pDataDetailViewHandler = $pDataDetailViewHandler;
$this->_pWPPageWrapper = $pWPPageWrapper;
+ $this->_pDataAddressDetailViewHandler = $pDataAddressDetailViewHandler;
}
public function addCustomRewriteTags()
@@ -70,4 +76,20 @@ public function addDynamicRewriteRules()
'index.php?pagename=' . urlencode( $pageName ) . '&view=$matches[1]&estate_id=$matches[2]', 'top' );
}
}
+
+ public function addCustomRewriteTagsAddressDetail()
+ {
+ add_rewrite_tag('%address_id%', '([^&]+)');
+ add_rewrite_tag('%view%', '([^&]+)');
+ }
+
+ public function addDynamicRewriteRulesForAddressDetail()
+ {
+ $detailPageIds = $this->_pDataAddressDetailViewHandler->getAddressDetailView()->getPageIdsHaveDetailShortCode();
+ foreach ( $detailPageIds as $detailPageId ) {
+ $pageName = $this->_pWPPageWrapper->getPageUriByPageId( $detailPageId );
+ add_rewrite_rule( '^(' . preg_quote( $pageName ) . ')/([0-9]+)(-([^$]+)?)?/?$',
+ 'index.php?pagename=' . urlencode( $pageName ) . '&view=$matches[1]&address_id=$matches[2]', 'top' );
+ }
+ }
}
\ No newline at end of file
diff --git a/plugin/DataView/DataAddressDetailView.php b/plugin/DataView/DataAddressDetailView.php
new file mode 100644
index 000000000..dd91464ef
--- /dev/null
+++ b/plugin/DataView/DataAddressDetailView.php
@@ -0,0 +1,129 @@
+.
+ *
+ */
+
+declare(strict_types=1);
+
+namespace onOffice\WPlugin\DataView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class DataAddressDetailView
+ implements DataViewAddress
+{
+ /** */
+ const FIELDS = 'fields';
+
+ /** */
+ const TEMPLATE = 'template';
+
+ /** */
+ const PICTURES = 'pictures';
+
+ /** */
+ const FIELD_CUSTOM_LABEL = 'oo_plugin_fieldconfig_address_translated_labels';
+
+ /** @var string[] */
+ private $_fields = [
+ 'Anrede',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'Email',
+ 'Telefon1',
+ 'Telefax1',
+ ];
+
+ /** @var string[] */
+ private $_pictureTypes = [];
+
+ /** @var string */
+ private $_template = '';
+
+ /** @var int */
+ private $_pageId = 0;
+
+ /** @var array */
+ private $_pageIdsHaveDetailShortCode = [];
+
+ /** @var array */
+ private $_customLabel = [];
+
+ /** @return int */
+ public function getPageId(): int
+ { return $this->_pageId; }
+
+ /** @param int $pageId */
+ public function setPageId(int $pageId)
+ { $this->_pageId = $pageId; }
+
+ /** @return string */
+ public function getName(): string
+ { return 'detail'; }
+
+ /** @return string[] */
+ public function getFields(): array
+ { return $this->_fields; }
+
+ /** @return array */
+ public function getPictureTypes(): array
+ { return $this->_pictureTypes; }
+
+ /** @return string */
+ public function getTemplate(): string
+ { return $this->_template; }
+
+ /** @param array $fields */
+ public function setFields(array $fields)
+ { $this->_fields = $fields; }
+
+ /** @param array $pictureTypes */
+ public function setPictureTypes(array $pictureTypes)
+ { $this->_pictureTypes = $pictureTypes; }
+
+ /** @param string $template */
+ public function setTemplate(string $template)
+ { $this->_template = $template; }
+
+ /** @return array */
+ public function getPageIdsHaveDetailShortCode(): array
+ { return $this->_pageIdsHaveDetailShortCode; }
+
+ /** @param int $pageId */
+ public function addToPageIdsHaveDetailShortCode(int $pageId)
+ { $this->_pageIdsHaveDetailShortCode[$pageId] = $pageId; }
+
+ /** @param int $pageId */
+ public function removeFromPageIdsHaveDetailShortCode(int $pageId)
+ { unset($this->_pageIdsHaveDetailShortCode[$pageId]); }
+
+ /** @return array */
+ public function getCustomLabels()
+ { return $this->_customLabel; }
+
+ /** @param array $customLabel */
+ public function setCustomLabels(array $customLabel)
+ { $this->_customLabel = $customLabel; }
+}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
new file mode 100644
index 000000000..b8f81255d
--- /dev/null
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -0,0 +1,110 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\DataView;
+
+use onOffice\WPlugin\WP\WPOptionWrapperBase;
+use onOffice\WPlugin\WP\WPOptionWrapperDefault;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class DataAddressDetailViewHandler
+{
+ /** */
+ const DEFAULT_ADDRESS_VIEW_OPTION_KEY = 'onoffice-default-address-view';
+
+ /** @var WPOptionWrapperBase */
+ private $_pWPOptionWrapper;
+
+
+ /**
+ * @param WPOptionWrapperBase $pWPOptionWrapper
+ */
+ public function __construct(WPOptionWrapperBase $pWPOptionWrapper = null)
+ {
+ $this->_pWPOptionWrapper = $pWPOptionWrapper ?? new WPOptionWrapperDefault();
+ }
+
+
+ /**
+ *
+ * @return DataAddressDetailView
+ *
+ */
+
+ public function getAddressDetailView(): DataAddressDetailView
+ {
+ $optionKey = self::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+ $pAlternate = new DataAddressDetailView();
+ $pResult = $this->_pWPOptionWrapper->getOption($optionKey, $pAlternate);
+
+ if ($pResult == null) {
+ $pResult = $pAlternate;
+ }
+
+ return $pResult;
+ }
+
+
+ /**
+ *
+ * @param DataAddressDetailView $pDataAddressDetailView
+ *
+ */
+
+ public function saveAddressDetailView(DataAddressDetailView $pDataAddressDetailView)
+ {
+ $pWpOptionsWrapper = $this->_pWPOptionWrapper;
+ $viewOptionKey = self::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+
+ if ($pWpOptionsWrapper->getOption($viewOptionKey) !== false) {
+ $pWpOptionsWrapper->updateOption($viewOptionKey, $pDataAddressDetailView);
+ } else {
+ $pWpOptionsWrapper->addOption($viewOptionKey, $pDataAddressDetailView);
+ }
+ }
+
+
+ /**
+ *
+ * @param array $row
+ * @return DataAddressDetailView
+ *
+ */
+
+ public function createAddressDetailViewByValues(array $row): DataAddressDetailView
+ {
+ $pDataAddressDetailView = $this->getAddressDetailView();
+ $pDataAddressDetailView->setTemplate($row[DataAddressDetailView::TEMPLATE] ?? '');
+ $pDataAddressDetailView->setFields($row[DataAddressDetailView::FIELDS] ?? []);
+ $pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
+ $pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
+
+ return $pDataAddressDetailView;
+ }
+}
\ No newline at end of file
diff --git a/plugin/DataView/DataListViewAddress.php b/plugin/DataView/DataListViewAddress.php
index ca46167be..18c5925ff 100644
--- a/plugin/DataView/DataListViewAddress.php
+++ b/plugin/DataView/DataListViewAddress.php
@@ -34,7 +34,7 @@
*/
class DataListViewAddress
- implements DataViewFilterableFields, ViewProperty
+ implements DataViewFilterableFields, ViewProperty, DataViewAddress
{
/** */
const FIELDS = 'fields';
diff --git a/plugin/DataView/DataViewAddress.php b/plugin/DataView/DataViewAddress.php
new file mode 100644
index 000000000..af0865a80
--- /dev/null
+++ b/plugin/DataView/DataViewAddress.php
@@ -0,0 +1,43 @@
+.
+ *
+ */
+
+declare(strict_types=1);
+
+namespace onOffice\WPlugin\DataView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+interface DataViewAddress
+{
+ /** @return array */
+ public function getFields(): array;
+
+ /** @return string */
+ public function getTemplate(): string;
+
+ /** @return string */
+ public function getName(): string;
+}
diff --git a/plugin/Gui/AdminPageAddress.php b/plugin/Gui/AdminPageAddress.php
new file mode 100644
index 000000000..1773a6317
--- /dev/null
+++ b/plugin/Gui/AdminPageAddress.php
@@ -0,0 +1,249 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Gui;
+
+use DI\ContainerBuilder;
+use onOffice\WPlugin\Controller\UserCapabilities;
+use onOffice\WPlugin\Form\BulkDeleteRecord;
+use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
+use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
+use const ONOFFICE_DI_CONFIG_PATH;
+use function __;
+use function add_action;
+use function add_filter;
+use function add_query_arg;
+use function admin_url;
+use function check_admin_referer;
+use Exception;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class AdminPageAddress
+ extends AdminPage
+{
+ /** */
+ const PAGE_ADDRESS_LIST = 'list';
+
+ /** */
+ const PAGE_ADDRESS_DETAIL = 'detail';
+
+ /** @var string[] */
+ private $_subPageClassByTab = array(
+ self::PAGE_ADDRESS_LIST => AdminPageAddressList::class,
+ self::PAGE_ADDRESS_DETAIL => AdminPageAddressDetail::class,
+ );
+
+ /** */
+ const PARAM_TAB = 'tab';
+
+ /** @var array */
+ private $_tabs = array();
+
+ /** @var AdminPage */
+ private $_pSelectedTab = null;
+
+ /**
+ * @param string $pageSlug
+ * @throws Exception
+ */
+
+ public function __construct($pageSlug)
+ {
+ $this->_tabs = array(
+ self::PAGE_ADDRESS_LIST => __('Address Views', 'onoffice-for-wp-websites'),
+ self::PAGE_ADDRESS_DETAIL => __('Detail View', 'onoffice-for-wp-websites'),
+ );
+
+ parent::__construct($pageSlug);
+
+ $selectedTab = $this->getSelectedTab();
+ $this->_pSelectedTab = $this->getAdminPageForTab($selectedTab);
+ }
+
+ /**
+ *
+ * @return string
+ *
+ */
+
+ private function getSelectedTab()
+ {
+ $selectedTab = $this->getDefaultTab();
+ $getParamTab = filter_input(INPUT_GET, self::PARAM_TAB);
+ $postParamTab = filter_input(INPUT_POST, self::PARAM_TAB);
+ if (!is_null($getParamTab)) {
+ $selectedTab = $getParamTab;
+ } elseif (!is_null($postParamTab)) {
+ $selectedTab = $postParamTab;
+ }
+
+ return $selectedTab;
+ }
+
+
+ /**
+ *
+ * @param string $tab
+ * @return AdminPage
+ *
+ */
+
+ private function getAdminPageForTab(string $tab)
+ {
+ if (!isset($this->_subPageClassByTab[$tab])) {
+ $tab = self::PAGE_ADDRESS_LIST;
+ }
+
+ $className = $this->_subPageClassByTab[$tab];
+ $pAdminPage = new $className($this->getPageSlug());
+
+ return $pAdminPage;
+ }
+
+
+ /**
+ *
+ */
+
+ public function renderContent()
+ {
+ $selectedTab = $this->getSelectedTab();
+ $defaultTab = $this->getDefaultTab();
+ $this->_pSelectedTab->generatePageMainTitle(__('Addresses', 'onoffice-for-wp-websites'));
+
+ echo '';
+ $adminUrl = admin_url('admin.php?page=onoffice-addresses');
+
+ foreach ($this->_tabs as $index => $label)
+ {
+ $newAdminUrl = ($index != $defaultTab) ? add_query_arg('tab', $index, $adminUrl) : $adminUrl;
+ $class = ($index === $selectedTab) ? ' nav-tab-active' : '';
+ echo ''.esc_html($label).' ';
+ }
+ echo ' ';
+ echo $this->_pSelectedTab->renderContent();
+ }
+
+ /**
+ *
+ * @return string
+ *
+ */
+
+ private function getDefaultTab()
+ {
+ return self::PAGE_ADDRESS_LIST;
+ }
+
+
+ /**
+ *
+ */
+
+ public function handleAdminNotices()
+ {
+ $this->_pSelectedTab->handleAdminNotices();
+ $itemsDeleted = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_NUMBER_INT);
+
+ if ($itemsDeleted !== null && $itemsDeleted !== false) {
+ add_action('admin_notices', function() use ($itemsDeleted) {
+ $pHandler = new AdminNoticeHandlerListViewDeletion();
+ echo $pHandler->handleListView($itemsDeleted);
+ });
+ }
+ }
+
+
+ /**
+ *
+ */
+
+ public function preOutput()
+ {
+ $this->_pSelectedTab->preOutput();
+
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $pDI = $pContainerBuilder->build();
+ $pClosureDeleteAddress = function(string $redirectTo, Table\WP\ListTable $pTable, array $recordIds) use ($pDI): string {
+ /* @var $pBulkDeleteRecord BulkDeleteRecord */
+ $pBulkDeleteRecord = $pDI->get(BulkDeleteRecord::class);
+ /* @var $pRecordManagerDelete RecordManagerDeleteListViewAddress */
+ $pRecordManagerDelete = $pDI->get(RecordManagerDeleteListViewAddress::class);
+ if (in_array($pTable->current_action(), ['delete', 'bulk_delete'])) {
+ check_admin_referer('bulk-'.$pTable->getArgs()['plural']);
+ $itemsDeleted = $pBulkDeleteRecord->delete
+ ($pRecordManagerDelete, UserCapabilities::RULE_EDIT_VIEW_ADDRESS, $recordIds);
+ $redirectTo = add_query_arg(['delete' => $itemsDeleted],
+ admin_url('admin.php?page=onoffice-addresses'));
+ }
+ return $redirectTo;
+ };
+
+ add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDeleteAddress, 10, 3);
+
+ $pClosureDuplicateAddress = function (string $redirectTo, Table\WP\ListTable $pTable) use ($pDI): string {
+ if (in_array($pTable->current_action(), ['duplicate', 'bulk_duplicate'])) {
+ check_admin_referer('bulk-' . $pTable->getArgs()['plural']);
+ if (!(isset($_GET['listViewId']))) {
+ wp_die('No List Views for duplicating!');
+ }
+
+ /* @var $pRecordManagerDuplicateListViewAddress RecordManagerDuplicateListViewAddress */
+ $pRecordManagerDuplicateListViewAddress = $pDI->get(RecordManagerDuplicateListViewAddress::class);
+ $listViewRootId = $_GET['listViewId'];
+ $pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
+ }
+ return $redirectTo;
+ };
+
+ add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDuplicateAddress, 10, 3);
+
+ parent::preOutput();
+ }
+
+ /**
+ *
+ * @return AdminPage
+ *
+ */
+
+ public function getSelectedAdminPage()
+ {
+ return $this->_pSelectedTab;
+ }
+
+
+ /**
+ *
+ */
+
+ public function doExtraEnqueues()
+ {
+ $this->_pSelectedTab->doExtraEnqueues();
+ }
+}
diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php
new file mode 100644
index 000000000..5d5aaa45a
--- /dev/null
+++ b/plugin/Gui/AdminPageAddressDetail.php
@@ -0,0 +1,547 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Gui;
+
+use DI\DependencyException;
+use DI\NotFoundException;
+use Exception;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Controller\Exception\UnknownModuleException;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\FormModel;
+use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings;
+use onOffice\WPlugin\Model\InputModelBase;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Model\InputModelOptionAdapterArray;
+use onOffice\WPlugin\Renderer\InputModelRenderer;
+use onOffice\WPlugin\Types\FieldsCollection;
+use function __;
+use function add_action;
+use function do_accordion_sections;
+use function do_action;
+use function do_meta_boxes;
+use function do_settings_sections;
+use function esc_attr;
+use function esc_html;
+use function esc_html__;
+use function get_current_screen;
+use function plugin_dir_url;
+use function wp_die;
+use function wp_enqueue_script;
+use function wp_nonce_field;
+use function wp_register_script;
+use function wp_verify_nonce;
+use const ONOFFICE_PLUGIN_DIR;
+use onOffice\WPlugin\Controller\AddressListEnvironmentDefault;
+use onOffice\WPlugin\Language;
+use onOffice\WPlugin\Field\UnknownFieldException;
+
+/**
+ *
+ */
+
+class AdminPageAddressDetail
+ extends AdminPageAjax
+{
+ /** */
+ const FORM_VIEW_LAYOUT_DESIGN = 'viewlayoutdesign';
+
+ /** */
+ const FORM_VIEW_PICTURE_TYPES = 'viewpicturetypes';
+
+ /** */
+ const FORM_VIEW_SORTABLE_FIELDS_CONFIG = 'viewSortableFieldsConfig';
+
+ /** */
+ const FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG = 'viewSearchFieldForFieldListsConfig';
+
+ /** */
+ const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
+
+ /** */
+ const VIEW_LEAVE_WITHOUT_SAVING_TEXT = 'view_leave_without_saving_text';
+
+ /** */
+ const CUSTOM_LABELS = 'customlabels';
+
+ /**
+ *
+ */
+
+ public function renderContent()
+ {
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'true' ) {
+ echo ''
+ . esc_html__( 'The address detail view has been saved.', 'onoffice-for-wp-websites' )
+ . '
';
+ }
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the address detail view.', 'onoffice-for-wp-websites' )
+ . '
';
+ }
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pAddressDataView = $pDataAddressDetailViewHandler->getAddressDetailView();
+
+ do_action('add_meta_boxes', get_current_screen()->id, null);
+ $this->generateMetaBoxes();
+
+ /* @var $pRenderer InputModelRenderer */
+ $pRenderer = $this->getContainer()->get(InputModelRenderer::class);
+ $pFormViewSortableFields = $this->getFormModelByGroupSlug(self::FORM_VIEW_SORTABLE_FIELDS_CONFIG);
+ $pFormViewSearchFieldForFieldLists = $this->getFormModelByGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
+
+ echo '';
+ }
+
+
+ /**
+ *
+ * @param string $subTitle
+ *
+ */
+
+ public function generatePageMainTitle($subTitle)
+ {
+ echo ''.esc_html__('onOffice', 'onoffice-for-wp-websites');
+ echo ' › ' . esc_html( $subTitle );
+ echo ' › '.esc_html__('Detail View', 'onoffice-for-wp-websites');
+ echo ' ';
+ echo '';
+ }
+
+
+ /**
+ *
+ */
+
+ private function generateMetaBoxes()
+ {
+ $pFormPictureTypes = $this->getFormModelByGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
+ $this->createMetaBoxByForm($pFormPictureTypes, 'side');
+
+ $pFormLayoutDesign = $this->getFormModelByGroupSlug(self::FORM_VIEW_LAYOUT_DESIGN);
+ $this->createMetaBoxByForm($pFormLayoutDesign, 'normal');
+ }
+
+ /**
+ * @return void
+ */
+ protected function generateAccordionBoxes()
+ {
+ $fieldNames = array_keys($this->readFieldnamesByContent(onOfficeSDK::MODULE_ADDRESS));
+
+ foreach ($fieldNames as $category) {
+ $slug = $this->generateGroupSlugByModuleCategory(onOfficeSDK::MODULE_ADDRESS, $category);
+ $pFormFieldsConfig = $this->getFormModelByGroupSlug($slug);
+ if (!is_null($pFormFieldsConfig))
+ {
+ $this->createMetaBoxByForm($pFormFieldsConfig, 'contactperson');
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ protected function buildForms()
+ {
+ $pFormModelBuilder = $this->getContainer()->get(FormModelBuilderAddressDetailSettings::class);
+ $pFormModel = $pFormModelBuilder->generate($this->getPageSlug());
+ $this->addFormModel($pFormModel);
+
+ $pInputModelTemplate = $pFormModelBuilder->createInputModelTemplate();
+ $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);
+ $this->addFormModel($pFormModelLayoutDesign);
+
+ $pInputModelPictureTypes = $pFormModelBuilder->createInputModelPictureTypes();
+ $pFormModelPictureTypes = new FormModel();
+ $pFormModelPictureTypes->setPageSlug($this->getPageSlug());
+ $pFormModelPictureTypes->setGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
+ $pFormModelPictureTypes->setLabel(__('Photo Types', 'onoffice-for-wp-websites'));
+ $pFormModelPictureTypes->addInputModel($pInputModelPictureTypes);
+ $this->addFormModel($pFormModelPictureTypes);
+
+ $pEnvironment = new AddressListEnvironmentDefault();
+ $pBuilderShort = $pEnvironment->getFieldsCollectionBuilderShort();
+ $pFieldsCollection = new FieldsCollection();
+ $pBuilderShort->addFieldsAddressEstate($pFieldsCollection);
+ $fieldNames = $this->readFieldnamesByContent(onOfficeSDK::MODULE_ADDRESS, $pFieldsCollection);
+ $this->addFieldsConfiguration(onOfficeSDK::MODULE_ADDRESS,
+ self::FORM_VIEW_SORTABLE_FIELDS_CONFIG, $pFormModelBuilder, $fieldNames);
+ $this->addSearchFieldForFieldLists(onOfficeSDK::MODULE_ADDRESS, $pFormModelBuilder);
+ }
+
+ /**
+ *
+ */
+ public function save_form() {
+ $this->buildForms();
+ $action = filter_input( INPUT_POST, 'action' );
+ $nonce = filter_input( INPUT_POST, 'nonce' );
+
+ if ( ! wp_verify_nonce( $nonce, $action ) ) {
+ wp_die();
+ }
+
+ $values = (object) $this->transformPostValues();
+
+ $pInputModelDBAdapterArray = new InputModelOptionAdapterArray();
+
+ foreach ( $this->getFormModels() as $pFormModel ) {
+ foreach ( $pFormModel->getInputModel() as $pInputModel ) {
+ if ( $pInputModel instanceof InputModelOption ) {
+ $identifier = $pInputModel->getIdentifier();
+
+ $value = isset( $values->$identifier ) ? $values->$identifier : null;
+ $pInputModel->setValue( $value );
+ $pInputModelDBAdapterArray->addInputModelOption( $pInputModel );
+ }
+ }
+ }
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $valuesPrefixless = $pInputModelDBAdapterArray->generateValuesArray();
+ $valuesPrefixless = $this->saveField($valuesPrefixless, $values);
+ $pDataDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues( $valuesPrefixless );
+ $success = true;
+
+ try {
+ $pDataAddressDetailViewHandler->saveAddressDetailView( $pDataDetailView );
+ } catch ( Exception $pEx ) {
+ $success = false;
+ }
+
+ $tabQuery = '&tab=' . AdminPageAddress::PAGE_ADDRESS_DETAIL;
+ $statusQuery = $success ? '&saved=true' : '&saved=false';
+
+ wp_redirect( admin_url( 'admin.php?page=onoffice-addresses' . $tabQuery . $statusQuery ) );
+
+ die();
+ }
+
+ /**
+ *
+ */
+ public function doExtraEnqueues()
+ {
+ wp_register_script('admin-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/admin.min.js',
+ array('jquery'), '', true);
+
+ wp_enqueue_script('admin-js');
+ wp_enqueue_script('postbox');
+ wp_register_script( 'oo-copy-shortcode',
+ plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . 'dist/onoffice-copycode.min.js',
+ [ 'jquery' ], '', true );
+ wp_enqueue_script( 'oo-copy-shortcode' );
+ wp_register_script('onoffice-custom-form-label-js',
+ plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true);
+ wp_enqueue_script('onoffice-custom-form-label-js');
+ $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php';
+ wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath));
+ wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath));
+ wp_enqueue_script('onoffice-multiselect');
+ wp_enqueue_style('onoffice-multiselect');
+
+ wp_register_script('oo-unsaved-changes-message', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-unsaved-changes-message.min.js',
+ ['jquery'], '', true);
+ wp_enqueue_script('oo-unsaved-changes-message');
+ }
+
+ /**
+ *
+ */
+ public function handleAdminNotices()
+ {
+ add_action('admin_notices', array($this, 'addAdminNoticeWrapper'));
+ }
+
+ /**
+ * rest will be added via js
+ */
+ public function addAdminNoticeWrapper()
+ {
+ echo '
';
+ }
+
+ /**
+ * @return array
+ */
+ public function getEnqueueData(): array
+ {
+ return array(
+ AdminPageAddress::PARAM_TAB => AdminPageAddress::PAGE_ADDRESS_DETAIL,
+ self::ENQUEUE_DATA_MERGE => array(AdminPageAddress::PARAM_TAB),
+ self::VIEW_UNSAVED_CHANGES_MESSAGE => __('Your changes have not been saved yet! Do you want to leave the page without saving?', 'onoffice-for-wp-websites'),
+ self::VIEW_LEAVE_WITHOUT_SAVING_TEXT => __('Leave without saving', 'onoffice-for-wp-websites'),
+ self::CUSTOM_LABELS => $this->readCustomLabels(),
+ 'label_custom_label' => __('Custom Label: %s', 'onoffice-for-wp-websites')
+ );
+ }
+
+ /**
+ * @param string $module
+ * @param string $groupSlug
+ * @param FormModelBuilderAddressDetailSettings $pFormModelBuilder
+ * @param array $fieldNames
+ * @return void
+ * @throws DependencyException
+ * @throws ExceptionInputModelMissingField
+ * @throws NotFoundException
+ */
+ private function addFieldsConfiguration(string $module, string $groupSlug, FormModelBuilderAddressDetailSettings $pFormModelBuilder,
+ array $fieldNames)
+ {
+ foreach ($fieldNames as $category => $fields) {
+ $slug = $this->generateGroupSlugByModuleCategory($module, $category);
+ $pInputModelFieldsConfig = $pFormModelBuilder->createButtonModelFieldsConfigByCategory
+ ($slug, $fields, $category);
+ $pFormModelFieldsConfig = new FormModel();
+ $pFormModelFieldsConfig->setPageSlug($this->getPageSlug());
+ $pFormModelFieldsConfig->setGroupSlug($slug);
+ $pFormModelFieldsConfig->setLabel($category);
+ $pFormModelFieldsConfig->addInputModel($pInputModelFieldsConfig);
+ $this->addFormModel($pFormModelFieldsConfig);
+ }
+
+ $pInputModelSortableFields = $pFormModelBuilder->createSortableFieldList($module,
+ InputModelBase::HTML_TYPE_COMPLEX_SORTABLE_DETAIL_LIST);
+ $pFormModelSortableFields = new FormModel();
+ $pFormModelSortableFields->setPageSlug($this->getPageSlug());
+ $pFormModelSortableFields->setGroupSlug($groupSlug);
+ $pFormModelSortableFields->addInputModel($pInputModelSortableFields);
+ $this->addFormModel($pFormModelSortableFields);
+ }
+
+ /**
+ * @param InputModelRenderer $pRenderer
+ * @param $pFormViewSearchFieldForFieldLists
+ * @return void
+ * @throws Exception
+ */
+
+ private function renderSearchFieldForFieldLists(InputModelRenderer $pRenderer, $pFormViewSearchFieldForFieldLists)
+ {
+ echo '';
+ echo '
' . __( 'Field list search', 'onoffice-for-wp-websites' ) . ' ';
+ echo '
';
+ $pRenderer->buildForAjax($pFormViewSearchFieldForFieldLists);
+ echo '
';
+ echo '
';
+ }
+
+ /**
+ * @param string $module
+ * @param FormModelBuilderAddressDetailSettings $pFormModelBuilder
+ * @param string $htmlType
+ * @return void
+ * @throws ExceptionInputModelMissingField
+ */
+
+ private function addSearchFieldForFieldLists(string $module, FormModelBuilderAddressDetailSettings $pFormModelBuilder, string $htmlType = InputModelBase::HTML_SEARCH_FIELD_FOR_FIELD_LISTS)
+ {
+ $pInputModelSearchFieldForFieldLists = $pFormModelBuilder->createSearchFieldForFieldLists($module, $htmlType);
+
+ $pFormModelFieldsConfig = new FormModel();
+ $pFormModelFieldsConfig->setPageSlug($this->getPageSlug());
+ $pFormModelFieldsConfig->setGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
+ $pFormModelFieldsConfig->addInputModel($pInputModelSearchFieldForFieldLists);
+ $this->addFormModel($pFormModelFieldsConfig);
+ }
+
+ /**
+ *
+ * @param string $module
+ * @param string $category
+ * @return string
+ *
+ */
+
+ protected function generateGroupSlugByModuleCategory($module, $category)
+ {
+ return $module.'/'.$category;
+ }
+
+ /**
+ *
+ * @return FieldsCollection
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws UnknownFieldException
+ */
+
+ private function buildFieldsCollectionForCurrentAddress(): FieldsCollection
+ {
+ $pAddressListEnvironmentDefault = new AddressListEnvironmentDefault();
+ $pFieldsCollectionBuilder = $pAddressListEnvironmentDefault->getFieldsCollectionBuilderShort();
+ $pDefaultFieldsCollection = new FieldsCollection();
+ $pFieldsCollectionBuilder->addFieldsAddressEstate($pDefaultFieldsCollection);
+
+ foreach ($pDefaultFieldsCollection->getAllFields() as $pField) {
+ if (!in_array($pField->getModule(), [onOfficeSDK::MODULE_ADDRESS], true)) {
+ $pDefaultFieldsCollection->removeFieldByModuleAndName
+ ($pField->getModule(), $pField->getName());
+ }
+
+ }
+
+ return $pDefaultFieldsCollection;
+ }
+
+ /**
+ * @return array
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws UnknownFieldException
+ */
+ private function readCustomLabels(): array
+ {
+ $result = [];
+ $pDataDetailViewHandler = new DataAddressDetailViewHandler();
+ $dataAddressDetailView = $pDataDetailViewHandler->getAddressDetailView();
+ $pLanguage = $this->getContainer()->get(Language::class);
+
+ foreach ($this->buildFieldsCollectionForCurrentAddress()->getAllFields() as $pField) {
+ $valuesByLocale = $dataAddressDetailView->getCustomLabels();
+ $currentLocale = $pLanguage->getLocale();
+ $valuesByLocale = $valuesByLocale[$pField->getName()] ?? '';
+
+ if (isset($valuesByLocale[$currentLocale])) {
+ $valuesByLocale['native'] = $valuesByLocale[$currentLocale];
+ unset($valuesByLocale[$currentLocale]);
+ }
+ $result[$pField->getName()] = $valuesByLocale;
+ }
+
+ return $result;
+ }
+
+ /**
+ * @param array $valuesPrefixless
+ * @param $values
+ * @return array
+ */
+ private function saveField(array $valuesPrefixless, $values)
+ {
+ $data = [];
+ $customLabel = (array) ($values->{'customlabel-lang'});
+
+ foreach ($customLabel as $key => $value) {
+ $data[$key] = $this->addLocaleToModelForField($value);
+ }
+
+ $valuesPrefixless['oo_plugin_fieldconfig_address_translated_labels'] = $data;
+
+ return $valuesPrefixless;
+ }
+
+ /**
+ * @param $value
+ * @return array|mixed
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function addLocaleToModelForField($value)
+ {
+ $pLanguage = $this->getContainer()->get( Language::class );
+
+ foreach ($value as $locale => $values) {
+ $value = (array) $value;
+ if ($locale === 'native') {
+ $value[$pLanguage->getLocale()] = $values;
+ unset($value['native']);
+ }
+ }
+
+ return $value;
+ }
+}
diff --git a/plugin/Gui/AdminPageAddressList.php b/plugin/Gui/AdminPageAddressList.php
index c27e4acba..edcad9ad4 100644
--- a/plugin/Gui/AdminPageAddressList.php
+++ b/plugin/Gui/AdminPageAddressList.php
@@ -21,20 +21,10 @@
namespace onOffice\WPlugin\Gui;
-use DI\ContainerBuilder;
-use onOffice\WPlugin\Controller\UserCapabilities;
-use onOffice\WPlugin\Form\BulkDeleteRecord;
use onOffice\WPlugin\Gui\Table\AddressListTable;
-use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
-use onOffice\WPlugin\Record\RecordManagerDeleteListViewEstate;
-use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
-use const ONOFFICE_DI_CONFIG_PATH;
use function __;
-use function add_action;
use function add_filter;
-use function add_query_arg;
use function admin_url;
-use function check_admin_referer;
use function esc_html__;
use function add_screen_option;
@@ -58,7 +48,6 @@ class AdminPageAddressList
public function renderContent()
{
- $this->generatePageMainTitle(__('Addresses', 'onoffice-for-wp-websites'));
$this->_pAddressListTable->prepare_items();
$page = 'onoffice-addresses';
$buttonSearch = __('Search Addresses', 'onoffice-for-wp-websites');
@@ -87,30 +76,15 @@ public function generatePageMainTitle($subTitle)
echo ' › ' . esc_html( $subTitle );
}
- echo '';
+ echo ' › '.esc_html__('List Views', 'onoffice-for-wp-websites');
$newLink = admin_url('admin.php?page=onoffice-editlistviewaddress');
+
+ echo '';
echo ''.esc_html__('Add New', 'onoffice-for-wp-websites').' ';
echo '';
}
- /**
- *
- */
-
- public function handleAdminNotices()
- {
- $itemsDeleted = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_NUMBER_INT);
-
- if ($itemsDeleted !== null && $itemsDeleted !== false) {
- add_action('admin_notices', function() use ($itemsDeleted) {
- $pHandler = new AdminNoticeHandlerListViewDeletion();
- echo $pHandler->handleListView($itemsDeleted);
- });
- }
- }
-
-
/**
*
*/
@@ -124,45 +98,7 @@ public function preOutput()
add_screen_option( 'per_page', array('option' => 'onoffice_address_listview_per_page') );
$this->_pAddressListTable = new AddressListTable();
- $pContainerBuilder = new ContainerBuilder;
- $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
- $pDI = $pContainerBuilder->build();
- $pClosureDeleteAddress = function(string $redirectTo, Table\WP\ListTable $pTable, array $recordIds)
- use ($pDI): string
- {
- /* @var $pBulkDeleteRecord BulkDeleteRecord */
- $pBulkDeleteRecord = $pDI->get(BulkDeleteRecord::class);
- /* @var $pRecordManagerDelete RecordManagerDeleteListViewEstate */
- $pRecordManagerDelete = $pDI->get(RecordManagerDeleteListViewAddress::class);
- if (in_array($pTable->current_action(), ['delete', 'bulk_delete'])) {
- check_admin_referer('bulk-'.$pTable->getArgs()['plural']);
- $itemsDeleted = $pBulkDeleteRecord->delete
- ($pRecordManagerDelete, UserCapabilities::RULE_EDIT_VIEW_ADDRESS, $recordIds);
- $redirectTo = add_query_arg(['delete' => $itemsDeleted],
- admin_url('admin.php?page=onoffice-addresses'));
- }
- return $redirectTo;
- };
-
- add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDeleteAddress, 10, 3);
-
- $pClosureDuplicateAddress = function (string $redirectTo, Table\WP\ListTable $pTable)
- use ($pDI): string {
- if (in_array($pTable->current_action(), ['duplicate', 'bulk_duplicate'])) {
- check_admin_referer('bulk-' . $pTable->getArgs()['plural']);
- if (!(isset($_GET['listViewId']))) {
- wp_die('No List Views for duplicating!');
- }
-
- /* @var $pRecordManagerDuplicateListViewAddress RecordManagerDuplicateListViewAddress */
- $pRecordManagerDuplicateListViewAddress = $pDI->get(RecordManagerDuplicateListViewAddress::class);
- $listViewRootId = $_GET['listViewId'];
- $pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
- }
- return $redirectTo;
- };
-
- add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDuplicateAddress, 10, 3);
+
add_filter('handle_bulk_actions-table-onoffice_page_onoffice-addresses', function(): Table\WP\ListTable {
return $this->_pAddressListTable;
});
@@ -172,6 +108,16 @@ public function preOutput()
public function doExtraEnqueues()
{
+ $translation = array(
+ 'confirmdialog' => __('Are you sure you want to delete the selected items?', 'onoffice-for-wp-websites'),
+ );
+
+ wp_register_script('onoffice-bulk-actions', plugins_url('/dist/onoffice-bulk-actions.min.js',
+ ONOFFICE_PLUGIN_DIR.'/index.php'), array('jquery'));
+
+ wp_localize_script('onoffice-bulk-actions', 'onoffice_table_settings', $translation);
+ wp_enqueue_script('onoffice-bulk-actions');
+
wp_register_script( 'oo-copy-shortcode',
plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . '/dist/onoffice-copycode.min.js',
[ 'jquery' ], '', true );
diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php
index 1e9952dd8..a73f5059a 100644
--- a/plugin/Gui/AdminPageAddressListSettings.php
+++ b/plugin/Gui/AdminPageAddressListSettings.php
@@ -40,6 +40,7 @@
use onOffice\WPlugin\Types\FieldsCollection;
use function __;
use function wp_enqueue_script;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -77,6 +78,13 @@ public function renderContent()
. esc_html__( 'There was a problem saving the address. The Name field cannot be empty.', 'onoffice-for-wp-websites' )
. ' ';
}
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo '
'
+ . esc_html__( 'There was a problem saving the view. Please make '
+ . 'sure the name of the view is unique, even across all address list types.',
+ 'onoffice-for-wp-websites' )
+ . '
';
+ }
parent::renderContent();
}
@@ -253,6 +261,14 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null)
{
$type = RecordManagerFactory::TYPE_ADDRESS;
$result = false;
+ $pDummyAddressDetailView = new DataAddressDetailView();
+
+ if ($row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS]['name'] === $pDummyAddressDetailView->getName()) {
+ // false / null
+ $pResult->result = false;
+ $pResult->record_id = null;
+ return;
+ }
if (array_key_exists('name', $row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS])) {
$row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS]['name'] = $this->sanitizeShortcodeName(
diff --git a/plugin/Gui/AdminPageEstateListSettingsBase.php b/plugin/Gui/AdminPageEstateListSettingsBase.php
index a57103c7d..6b9841dea 100644
--- a/plugin/Gui/AdminPageEstateListSettingsBase.php
+++ b/plugin/Gui/AdminPageEstateListSettingsBase.php
@@ -72,6 +72,13 @@ public function renderContent()
. esc_html__( 'There was a problem saving the list. The Name field cannot be empty.', 'onoffice-for-wp-websites' )
. '
';
}
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo '
'
+ . esc_html__( 'There was a problem saving the view. Please make '
+ . 'sure the name of the view is unique, even across all estate list types.',
+ 'onoffice-for-wp-websites' )
+ . '
';
+ }
parent::renderContent();
}
diff --git a/plugin/Gui/AdminPageSettingsBase.php b/plugin/Gui/AdminPageSettingsBase.php
index a4133e291..330d78efe 100644
--- a/plugin/Gui/AdminPageSettingsBase.php
+++ b/plugin/Gui/AdminPageSettingsBase.php
@@ -154,13 +154,6 @@ public function renderContent()
. esc_html__( 'The view has been saved.', 'onoffice-for-wp-websites' )
. '
';
}
- if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
- echo ''
- . esc_html__( 'There was a problem saving the view. Please make '
- . 'sure the name of the view is unique, even across all estate list types.',
- 'onoffice-for-wp-websites' )
- . '
';
- }
do_action( 'add_meta_boxes', get_current_screen()->id, null );
$this->generateMetaBoxes();
diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
new file mode 100644
index 000000000..72aef5cec
--- /dev/null
+++ b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
@@ -0,0 +1,314 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Model\FormModelBuilder;
+
+use function __;
+use DI\NotFoundException;
+use DI\DependencyException;
+use onOffice\WPlugin\Fieldnames;
+use onOffice\WPlugin\Model\FormModel;
+use onOffice\WPlugin\Types\ImageTypes;
+use onOffice\WPlugin\Model\InputModelBase;
+use onOffice\WPlugin\DataView\DataDetailView;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\Model\InputModel\InputModelDBFactory;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\InputModel\InputModelOptionFactoryAddressDetailView;
+use onOffice\WPlugin\Model\InputModelDB;
+use onOffice\WPlugin\WP\InstalledLanguageReader;
+use onOffice\WPlugin\Model\InputModelBuilder\InputModelBuilderCustomLabel;
+use DI\ContainerBuilder;
+use DI\Container;
+use onOffice\WPlugin\Types\Field;
+use Exception;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ * This class must not use InputModelOption!
+ *
+ */
+
+class FormModelBuilderAddressDetailSettings
+ extends FormModelBuilder
+{
+ /** @var InputModelOptionFactoryAddressDetailView */
+ private $_pInputModelAddressDetailFactory = null;
+
+ /** @var DataAddressDetailView */
+ private $_pDataAddressDetail = null;
+
+ /** @var Container */
+ private $_pContainer;
+
+ /**
+ * @param Container|null $pContainer
+ * @param Fieldnames|null $pFieldnames
+ * @throws Exception
+ */
+
+ public function __construct(Container $pContainer = null, Fieldnames $pFieldnames = null)
+ {
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $this->_pContainer = $pContainer ?? $pContainerBuilder->build();
+
+ $pFieldsCollection = new FieldsCollection();
+ $pFieldnames = $pFieldnames ?? new Fieldnames($pFieldsCollection);
+ $pFieldnames->loadLanguage();
+ $this->setFieldnames($pFieldnames);
+ }
+
+ /**
+ * @param string $pageSlug
+ * @return FormModel
+ */
+
+ public function generate(string $pageSlug): FormModel
+ {
+ $this->_pInputModelAddressDetailFactory = new InputModelOptionFactoryAddressDetailView($pageSlug);
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler;
+ $this->_pDataAddressDetail = $pDataAddressDetailViewHandler->getAddressDetailView();
+
+ $pFormModel = new FormModel();
+ $pFormModel->setLabel(__('Address Detail View', 'onoffice-for-wp-websites'));
+ $pFormModel->setGroupSlug('onoffice-address-detail-settings-main');
+ $pFormModel->setPageSlug($pageSlug);
+
+ return $pFormModel;
+ }
+
+ /**
+ * @param string $category
+ * @param array $fieldNames
+ * @param string $categoryLabel
+ * @return InputModelOption
+ */
+
+ public function createInputModelFieldsConfigByCategory($category, $fieldNames, $categoryLabel): InputModelOption
+ {
+ $pInputModelFieldsConfig = new InputModelOption
+ (null, $category, null, InputModelDBFactory::INPUT_FIELD_CONFIG);
+ $pInputModelFieldsConfig->setIsMulti(true);
+
+ $pInputModelFieldsConfig->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX_BUTTON);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNames);
+ $pInputModelFieldsConfig->setId($category);
+ $pInputModelFieldsConfig->setLabel($categoryLabel);
+ $fields = $this->getValue(DataDetailView::FIELDS);
+
+ if (null == $fields)
+ {
+ $fields = array();
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param $module
+ * @param string $htmlType
+ * @return InputModelOption
+ * @throws DependencyException
+ * @throws ExceptionInputModelMissingField
+ * @throws NotFoundException
+ */
+ public function createSortableFieldList($module, string $htmlType): InputModelOption
+ {
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FIELD_CONFIG, null, true);
+
+ $fields = $this->_pDataAddressDetail->getFields();
+ $fieldNames = $this->getFieldnames()->getFieldList($module);
+
+ $fieldNamesArray = [];
+ $pFieldsCollectionUsedFields = new FieldsCollection;
+
+ foreach ($fieldNames as $name => $pField) {
+ $pFields = Field::createByRow($name, $pField);
+ $fieldNamesArray[$pFields->getName()] = $pFields->getAsRow();
+ $pFieldsCollectionUsedFields->addField($pFields);
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+ $pInputModelFieldsConfig->setHtmlType($htmlType);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNamesArray);
+ $pInputModelFieldsConfig->addReferencedInputModel($this->getInputModelCustomLabel($pFieldsCollectionUsedFields));
+ $pInputModelFieldsConfig->addReferencedInputModel($this->getInputModelCustomLabelLanguageSwitch());
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param string $field
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelTemplate(string $field = InputModelOptionFactoryAddressDetailView::INPUT_TEMPLATE)
+ {
+ $labelTemplate = __('Template', 'onoffice-for-wp-websites');
+ $pInputModelTemplate = $this->_pInputModelAddressDetailFactory->create($field, $labelTemplate);
+ $pInputModelTemplate->setHtmlType(InputModelBase::HTML_TYPE_TEMPLATE_LIST);
+ $pInputModelTemplate->setValuesAvailable($this->readTemplatePaths('address'));
+ $pInputModelTemplate->setValue($this->getTemplateValueByField($field));
+
+ return $pInputModelTemplate;
+ }
+
+
+ /**
+ * @param string $field
+ * @return string
+ */
+
+ private function getTemplateValueByField(string $field): string
+ {
+ switch ($field) {
+ case InputModelOptionFactoryAddressDetailView::INPUT_TEMPLATE:
+ return $this->_pDataAddressDetail->getTemplate();
+ default:
+ return '';
+ }
+ }
+
+ /**
+ *
+ * @param string $category
+ * @param array $fieldNames
+ * @param string $categoryLabel
+ * @return InputModelOption
+ *
+ */
+
+ public function createButtonModelFieldsConfigByCategory($category, $fieldNames, $categoryLabel)
+ {
+ $pInputModelFieldsConfig = new InputModelOption
+ (null, $category, null, InputModelDBFactory::INPUT_FIELD_CONFIG);
+ $pInputModelFieldsConfig->setIsMulti(true);
+
+ $pInputModelFieldsConfig->setHtmlType(InputModelBase::HTML_TYPE_BUTTON_FIELD);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNames);
+ $pInputModelFieldsConfig->setId($category);
+ $pInputModelFieldsConfig->setLabel($categoryLabel);
+ $fields = $this->getValue(DataDetailView::FIELDS);
+
+ if ($fields == null) {
+ $fields = array_merge($this->_pDataAddressDetail->getFields());
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ *
+ * @return InputModelOption
+ *
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createInputModelPictureTypes(): InputModelOption
+ {
+ $allPictureTypes = ImageTypes::getImageTypesForAddress();
+
+ $pInputModelPictureTypes = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_PICTURE_TYPE, null, true);
+ $pInputModelPictureTypes->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+ $pInputModelPictureTypes->setValuesAvailable($allPictureTypes);
+ $pictureTypes = $this->_pDataAddressDetail->getPictureTypes();
+
+ if ($pictureTypes == null) {
+ $pictureTypes = array();
+ }
+
+ $pInputModelPictureTypes->setValue($pictureTypes);
+
+ return $pInputModelPictureTypes;
+ }
+
+ /**
+ * @param $module
+ * @param string $htmlType
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createSearchFieldForFieldLists($module, string $htmlType): InputModelOption
+ {
+ $fields = [];
+
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FIELD_CONFIG, null, true);
+ $fields = $this->_pDataAddressDetail->getFields();
+
+ $fieldNames = $this->getFieldnames()->getFieldList($module);
+
+ $pInputModelFieldsConfig->setHtmlType($htmlType);
+ $pInputModelFieldsConfig->setValuesAvailable($this->groupByContent($fieldNames));
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param FieldsCollection $pFieldsCollection
+ * @return InputModelDB
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function getInputModelCustomLabel(FieldsCollection $pFieldsCollection): InputModelDB
+ {
+ $pInputModelBuilder = $this->_pContainer->get(InputModelBuilderCustomLabel::class);
+
+ return $pInputModelBuilder->createInputModelCustomLabel($pFieldsCollection, $this->getValue('customlabel', []));
+ }
+
+ /**
+ * @return InputModelDB
+ */
+ public function getInputModelCustomLabelLanguageSwitch(): InputModelDB
+ {
+ $pInputModel = new InputModelDB('customlabel_newlang',
+ __('Add custom label language', 'onoffice-for-wp-websites'));
+ $pInputModel->setTable('language-custom-label');
+ $pInputModel->setField('language');
+
+ $pLanguageReader = new InstalledLanguageReader;
+ $languages = ['' => __('Choose Language', 'onoffice-for-wp-websites')]
+ + $pLanguageReader->readAvailableLanguageNamesUsingNativeName();
+ $pInputModel->setValuesAvailable(array_diff_key($languages, [get_locale() => []]));
+ $pInputModel->setValueCallback(function (InputModelDB $pInputModel) {
+ $pInputModel->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
+ $pInputModel->setLabel(__('Add custom label language', 'onoffice-for-wp-websites'));
+ });
+
+ return $pInputModel;
+ }
+}
diff --git a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
new file mode 100644
index 000000000..b3dd6d873
--- /dev/null
+++ b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
@@ -0,0 +1,104 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Model\InputModel;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\InputModelOption;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class InputModelOptionFactoryAddressDetailView
+{
+
+ /** */
+ const INPUT_TEMPLATE = 'template';
+
+ /** */
+ const INPUT_FIELD_CONFIG = DataAddressDetailView::FIELDS;
+
+ /** */
+ const INPUT_PICTURE_TYPE = DataAddressDetailView::PICTURES;
+
+ /** */
+ const KEY_TYPE = 'type';
+
+ /** @var string */
+ private $_optionGroup = null;
+
+
+ /** @var array */
+ private $_inputConfig = [
+ self::INPUT_FIELD_CONFIG => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_PICTURE_TYPE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_TEMPLATE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ]
+ ];
+
+
+ /**
+ *
+ * @param string $optionGroup
+ *
+ */
+
+ public function __construct(string $optionGroup)
+ {
+ $this->_optionGroup = $optionGroup;
+ }
+
+
+ /**
+ *
+ * @param string $name
+ * @param string $label
+ * @param bool $multi
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ *
+ */
+
+ public function create(string $name, $label, bool $multi = false): InputModelOption
+ {
+ if (!isset($this->_inputConfig[$name])) {
+ throw new ExceptionInputModelMissingField($name);
+ }
+
+ $config = $this->_inputConfig[$name];
+ $type = $config[self::KEY_TYPE];
+
+ $pInstance = new InputModelOption($this->_optionGroup, $name, $label, $type);
+ $pInstance->setIsMulti($multi);
+
+ return $pInstance;
+ }
+}
diff --git a/plugin/Renderer/InputFieldTemplateListRenderer.php b/plugin/Renderer/InputFieldTemplateListRenderer.php
index 715abbc7a..6c64c9b54 100644
--- a/plugin/Renderer/InputFieldTemplateListRenderer.php
+++ b/plugin/Renderer/InputFieldTemplateListRenderer.php
@@ -34,6 +34,7 @@ class InputFieldTemplateListRenderer
{
const TEMPLATE_DEFAULT_LIST = [
'onoffice-editlistviewaddress' => 'default.php',
+ 'onoffice-addresses' => 'default_detail.php',
'onoffice-editlistview' => 'default.php',
'onoffice-editunitlist' => 'default_units.php',
'onoffice-estates' => [
diff --git a/plugin/Types/ImageTypes.php b/plugin/Types/ImageTypes.php
index 426604686..0f061031c 100644
--- a/plugin/Types/ImageTypes.php
+++ b/plugin/Types/ImageTypes.php
@@ -32,6 +32,7 @@ class ImageTypes
const PANORAMA = 'Panorama';
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
+ const PASSPORTPHOTO = 'PassportPhoto';
const IMAGE_TYPES = [
self::TITLE,
@@ -67,4 +68,14 @@ public static function getAllImageTypesTranslated(): array
self::ENERGY_PASS_RANGE => __('Energy-Pass Range', 'onoffice-for-wp-websites'),
];
}
+
+ /**
+ * @return array
+ */
+ public static function getImageTypesForAddress(): array
+ {
+ return [
+ self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
+ ];
+ }
}
diff --git a/tests/TestClassDataAddressDetailView.php b/tests/TestClassDataAddressDetailView.php
new file mode 100644
index 000000000..9fbdffe2d
--- /dev/null
+++ b/tests/TestClassDataAddressDetailView.php
@@ -0,0 +1,86 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use WP_UnitTestCase;
+
+class TestClassDataAddressDetailView
+ extends WP_UnitTestCase
+{
+ /** */
+ const DEFAULT_FIELDS = [
+ 'Anrede',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'Email',
+ 'Telefon1',
+ 'Telefax1',
+ ];
+
+ /**
+ *
+ */
+ public function testDefaultValues()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+
+ $this->assertEquals(self::DEFAULT_FIELDS, $pDataAddressDetailView->getFields());
+ $this->assertEquals('detail', $pDataAddressDetailView->getName());
+ $this->assertEquals(0, $pDataAddressDetailView->getPageId());
+ $this->assertEquals([], $pDataAddressDetailView->getPictureTypes());
+ $this->assertEquals('', $pDataAddressDetailView->getTemplate());
+ $this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $this->assertEquals([], $pDataAddressDetailView->getCustomLabels());
+ }
+
+ /**
+ *
+ */
+ public function testGetterSetter()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+
+ $pDataAddressDetailView->setFields(['testaddressfield1', 'testaddressfield2']);
+ $this->assertEquals(['testaddressfield1', 'testaddressfield2'],
+ $pDataAddressDetailView->getFields());
+ $pDataAddressDetailView->setFields(['testfield1', 'testfield2']);
+ $this->assertEquals(['testfield1', 'testfield2'], $pDataAddressDetailView->getFields());
+ $pDataAddressDetailView->setPageId(12);
+ $this->assertEquals(12, $pDataAddressDetailView->getPageId());
+ $pDataAddressDetailView->setPictureTypes(['testpicturetype1', 'testpicturetype2']);
+ $this->assertEquals(['testpicturetype1', 'testpicturetype2'],
+ $pDataAddressDetailView->getPictureTypes());
+ $pDataAddressDetailView->setTemplate('/test/template1.test');
+ $this->assertEquals('/test/template1.test', $pDataAddressDetailView->getTemplate());
+
+ $pDataAddressDetailView->addToPageIdsHaveDetailShortCode(14);
+ $this->assertEquals([14 => 14], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $pDataAddressDetailView->removeFromPageIdsHaveDetailShortCode(14);
+ $this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $pDataAddressDetailView->setCustomLabels(['field1']);
+ $this->assertEquals(['field1'], $pDataAddressDetailView->getCustomLabels());
+ }
+}
diff --git a/tests/TestClassDataAddressDetailViewHandler.php b/tests/TestClassDataAddressDetailViewHandler.php
new file mode 100644
index 000000000..6c12da083
--- /dev/null
+++ b/tests/TestClassDataAddressDetailViewHandler.php
@@ -0,0 +1,133 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Types\ImageTypes;
+use onOffice\WPlugin\WP\WPOptionWrapperTest;
+use WP_UnitTestCase;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class TestClassDataAddressDetailViewHandler
+ extends WP_UnitTestCase
+{
+ /** */
+ const VALUES_BY_ROW = [
+ 'template' => '/test/template.php',
+ 'fields' => [
+ 'Objektnr_extern',
+ 'wohnflaeche',
+ 'kaufpreis',
+ ],
+ 'pictures' => [
+ ImageTypes::PASSPORTPHOTO,
+ ],
+ 'oo_plugin_fieldconfig_address_translated_labels' => ['field']
+ ];
+
+ /**
+ *
+ */
+
+ public function testCreateAddressDetailViewByValues()
+ {
+ $row = self::VALUES_BY_ROW;
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pDataAddressDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues($row);
+ $this->assertEquals($row['template'], $pDataAddressDetailView->getTemplate());
+ $this->assertEquals($row['fields'], $pDataAddressDetailView->getFields());
+ $this->assertEquals($row['pictures'], $pDataAddressDetailView->getPictureTypes());
+ $this->assertEquals($row['oo_plugin_fieldconfig_address_translated_labels'], $pDataAddressDetailView->getCustomLabels());
+ }
+
+
+ /**
+ *
+ */
+
+ public function testCreateEmptyDetailViewByValues()
+ {
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pDataAddressDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues([]);
+
+ $this->assertEquals($pDataAddressDetailView->getTemplate(), '');
+ $this->assertEquals($pDataAddressDetailView->getFields(), []);
+ $this->assertEquals($pDataAddressDetailView->getPictureTypes(), []);
+ $this->assertEquals($pDataAddressDetailView->getName(), 'detail');
+ $this->assertEquals($pDataAddressDetailView->getPageId(), 0);
+ $this->assertEquals($pDataAddressDetailView->getPageIdsHaveDetailShortCode(), []);
+ }
+
+
+ /**
+ *
+ */
+
+ public function testGetAddressDetailView()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+ $pDataAddressDetailView->setPageId(1337);
+
+ $pWPOptionsWrapper = new WPOptionWrapperTest();
+ $pWPOptionsWrapper->addOption(DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY, $pDataAddressDetailView);
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWPOptionsWrapper);
+
+ $this->assertEquals($pDataAddressDetailView, $pDataAddressDetailViewHandler->getAddressDetailView());
+
+ $pWPOptionsWrapper->deleteOption(DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY);
+
+ // if not set, return a new instance
+ $this->assertEquals(new DataAddressDetailView(), $pDataAddressDetailViewHandler->getAddressDetailView());
+ }
+
+
+ /**
+ *
+ */
+
+ public function testSaveAddressDetailView()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+ $pDataAddressDetailView->setPageId(1337);
+ $optionsKey = DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+ $pWPOptionsWrapper = new WPOptionWrapperTest();
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWPOptionsWrapper);
+ $pDataAddressDetailViewHandler->saveAddressDetailView(clone $pDataAddressDetailView);
+ $this->assertEquals($pDataAddressDetailView, $pWPOptionsWrapper->getOption($optionsKey));
+
+ // test if overwriting works
+ $pDataAddressDetailView->setPageId(1339);
+ $pDataAddressDetailViewHandler->saveAddressDetailView(clone $pDataAddressDetailView);
+ $this->assertEquals($pDataAddressDetailView, $pWPOptionsWrapper->getOption($optionsKey));
+ }
+}
diff --git a/tests/TestClassFormModelBuilderAddressDetailSettings.php b/tests/TestClassFormModelBuilderAddressDetailSettings.php
new file mode 100644
index 000000000..1d7773fa7
--- /dev/null
+++ b/tests/TestClassFormModelBuilderAddressDetailSettings.php
@@ -0,0 +1,199 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use DI\Container;
+use WP_UnitTestCase;
+use DI\ContainerBuilder;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Fieldnames;
+use onOffice\WPlugin\Model\InputModelDB;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\WPlugin\Field\FieldnamesEnvironmentTest;
+use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings;
+
+class TestClassFormModelBuilderAddressDetailSettings
+ extends WP_UnitTestCase
+{
+ /** @var Container */
+ private $_pContainer;
+
+ /** @var Fieldnames */
+ private $_pFieldnames = null;
+
+ /** @var FieldnamesEnvironmentTest */
+ private $_pFieldnamesEnvironment = null;
+
+ /** @var FormModelBuilderAddressDetailSettings */
+ private $_pFormModelBuilderAddressDetailSettings;
+
+ /**
+ * @before
+ */
+ public function prepare()
+ {
+ $this->_pFieldnamesEnvironment = new FieldnamesEnvironmentTest();
+ $fieldParameters = [
+ 'labels' => true,
+ 'showContent' => true,
+ 'showTable' => true,
+ 'language' => 'ENG',
+ 'modules' => ['address', 'estate'],
+ 'realDataTypes' => true,
+ ];
+ $pSDKWrapperMocker = $this->_pFieldnamesEnvironment->getSDKWrapper();
+ $responseGetFields = json_decode
+ (file_get_contents(__DIR__ . '/resources/ApiResponseGetFields.json'), true);
+ /* @var $pSDKWrapperMocker SDKWrapperMocker */
+ $pSDKWrapperMocker->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'fields', '', $fieldParameters, null, $responseGetFields);
+ $this->_pFieldnames = new Fieldnames(new FieldsCollection(), false, $this->_pFieldnamesEnvironment);
+
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $this->_pContainer = $pContainerBuilder->build();
+
+ $this->_pFormModelBuilderAddressDetailSettings = new FormModelBuilderAddressDetailSettings($this->_pContainer, $this->_pFieldnames);
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::__construct
+ */
+
+ public function testConstruct()
+ {
+ $pInstance = $this->_pFormModelBuilderAddressDetailSettings;
+ $this->assertInstanceOf(FormModelBuilderAddressDetailSettings::class, $pInstance);
+ }
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSortableFieldList
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabel
+ */
+ public function testCreateSortableFieldList()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSortableFieldList('address', 'complexSortableDetailList');
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'complexSortableDetailList');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSearchFieldForFieldLists
+ */
+ public function testCreateSearchFieldForFieldLists()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSearchFieldForFieldLists('address', 'searchFieldForFieldLists');
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'searchFieldForFieldLists');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelPictureTypes
+ */
+ public function testCreateInputModelPictureTypes()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getValue'])
+ ->getMock();
+ $pInstance->generate('test');
+
+ $pInputModelDB = $pInstance->createInputModelPictureTypes();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'checkbox');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::CreateInputModelTemplate
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getTemplateValueByField
+ */
+ public function testCreateInputModelTemplate()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getValue', 'readTemplatePaths'])
+ ->getMock();
+ $pInstance->expects($this->exactly(1))
+ ->method('readTemplatePaths');
+ $pInstance->generate('test');
+
+ $pInputModelDB = $pInstance->createInputModelTemplate();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'templateList');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelFieldsConfigByCategory
+ */
+ public function testCreateInputModelFieldsConfigByCategory()
+ {
+ $inputModel = $this->_pFormModelBuilderAddressDetailSettings->createInputModelFieldsConfigByCategory('1', ['field1'], 'label');
+ $this->assertEquals('label', $inputModel->getLabel());
+ $this->assertEquals('1', $inputModel->getId());
+ $this->assertEquals(['field1'], $inputModel->getValuesAvailable());
+ $this->assertInstanceOf(InputModelOption::class, $inputModel);
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabelLanguageSwitch
+ */
+ public function testGetInputModelCustomLabelLanguageSwitch()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['readAvailableLanguageNamesUsingNativeName'])
+ ->getMock();
+
+ $inputModel = $pInstance->getInputModelCustomLabelLanguageSwitch();
+ $this->assertInstanceOf(InputModelDB::class, $inputModel);
+ $this->assertEquals('Add custom label language', $inputModel->getLabel());
+ $this->assertEquals('language-custom-label', $inputModel->getTable());
+ $this->assertEquals('language', $inputModel->getField());
+
+ $values = $inputModel->getValuesAvailable();
+
+ $this->assertContains('Choose Language', $values);
+ $this->assertNotContains(get_locale(), $values);
+ }
+
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::generate
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createButtonModelFieldsConfigByCategory
+ */
+ public function testCreateButtonModelFieldsConfigByCategory()
+ {
+ $this->_pFormModelBuilderAddressDetailSettings->generate('test');
+ $inputModel = $this->_pFormModelBuilderAddressDetailSettings->createButtonModelFieldsConfigByCategory('1', ['field1'], 'label');
+ $this->assertEquals('label', $inputModel->getLabel());
+ $this->assertEquals('1', $inputModel->getId());
+ $this->assertEquals(['field1'], $inputModel->getValuesAvailable());
+ $this->assertInstanceOf(InputModelOption::class, $inputModel);
+ }
+}
diff --git a/tests/TestClassImageTypes.php b/tests/TestClassImageTypes.php
index 9abd48f74..3ef024d5b 100644
--- a/tests/TestClassImageTypes.php
+++ b/tests/TestClassImageTypes.php
@@ -60,6 +60,27 @@ public function testGetAllImageTypesTranslated()
$pReflection = new ReflectionClass(ImageTypes::class);
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
+ unset($nameConstants['PASSPORTPHOTO']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}
+
+
+ /**
+ *
+ */
+
+ public function testGetImageTypesForAddress()
+ {
+ $pReflection = new ReflectionClass(ImageTypes::class);
+ $nameConstants = $pReflection->getConstants();
+ unset($nameConstants['TITLE']);
+ unset($nameConstants['PHOTO']);
+ unset($nameConstants['PHOTO_BIG']);
+ unset($nameConstants['PANORAMA']);
+ unset($nameConstants['GROUNDPLAN']);
+ unset($nameConstants['LOCATION_MAP']);
+ unset($nameConstants['ENERGY_PASS_RANGE']);
+ unset($nameConstants['IMAGE_TYPES']);
+ $this->assertEqualSets($nameConstants, array_keys(ImageTypes::getImageTypesForAddress()));
+ }
}
From 88e59098611cc7c456f93dbd9191a6226b795b20 Mon Sep 17 00:00:00 2001
From: yeneastgate
Date: Thu, 16 May 2024 14:43:55 +0700
Subject: [PATCH 04/33] 47941 update unit test
---
.../DetailViewPostSaveController.php | 4 +-
plugin/Installer/Installer.php | 2 +
.../TestClassDetailViewPostSaveController.php | 57 ++++++++++++++++++-
3 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/plugin/Controller/DetailViewPostSaveController.php b/plugin/Controller/DetailViewPostSaveController.php
index cf5aa9847..757ad9b28 100644
--- a/plugin/Controller/DetailViewPostSaveController.php
+++ b/plugin/Controller/DetailViewPostSaveController.php
@@ -167,7 +167,7 @@ public function onSavePost($postId) {
$pAddressDetailView->setPageId((int) $postId);
$pAddressDetailView->addToPageIdsHaveDetailShortCode((int) $postId);
$pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
- $this->_pRewriteRuleBuilder->addDynamicRewriteRulesAddressDetail();
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
flush_rewrite_rules();
}
} elseif ($pAddressDetailView->getPageId() !== 0) {
@@ -178,7 +178,7 @@ public function onSavePost($postId) {
$pAddressDetailView->setPageId(0);
$pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
$pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
- $this->_pRewriteRuleBuilder->addDynamicRewriteRulesAddressDetail();
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
flush_rewrite_rules();
}
}
diff --git a/plugin/Installer/Installer.php b/plugin/Installer/Installer.php
index 738cb367d..784d975c8 100644
--- a/plugin/Installer/Installer.php
+++ b/plugin/Installer/Installer.php
@@ -51,6 +51,8 @@ static public function install()
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
+ $pRewriteRuleBuilder->addCustomRewriteTagsAddressDetail();
+ $pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
self::flushRules();
}
diff --git a/tests/TestClassDetailViewPostSaveController.php b/tests/TestClassDetailViewPostSaveController.php
index b75d0c2b1..691c324c8 100644
--- a/tests/TestClassDetailViewPostSaveController.php
+++ b/tests/TestClassDetailViewPostSaveController.php
@@ -31,6 +31,8 @@
use onOffice\WPlugin\WP\WPOptionWrapperTest;
use onOffice\WPlugin\WP\WPPageWrapper;
use WP_UnitTestCase;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -62,6 +64,15 @@ class TestClassDetailViewPostSaveController extends WP_UnitTestCase
*/
private $_pWPPageWrapper;
+ /**
+ * @var DataAddressDetailViewHandler
+ */
+ private $_pDataAddressDetailViewHandler;
+
+ /**
+ * @var DataAddressDetailView
+ */
+ private $_pDataAddressDetailView;
/**
* @before
@@ -75,13 +86,16 @@ public function prepare()
$this->_pDataDetailViewHandler = new DataDetailViewHandler($pWpOption);
$this->_pDataDetailView = $this->_pDataDetailViewHandler->getDetailView();
$this->_pDataDetailViewHandler->saveDetailView($this->_pDataDetailView);
+ $this->_pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWpOption);
+ $this->_pDataAddressDetailView = $this->_pDataAddressDetailViewHandler->getAddressDetailView();
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView($this->_pDataAddressDetailView);
$this->_pWPPageWrapper = $this->getMockBuilder( WPPageWrapper::class )
->setMethods( [ 'getPageUriByPageId' ] )
->getMock();
$pSubject = new RewriteRuleBuilder( $this->_pDataDetailViewHandler,
- $this->_pWPPageWrapper );
+ $this->_pWPPageWrapper, $this->_pDataAddressDetailViewHandler );
$pDbChanges = new DatabaseChanges($pWpOption, $wpdb);
@@ -99,6 +113,9 @@ public function testReturnNullForTrashStatus()
$this->_pDataDetailView->setPageId( 13 );
$this->_pDataDetailViewHandler->saveDetailView( $this->_pDataDetailView );
+ $this->_pDataAddressDetailView->setPageId( 14 );
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView( $this->_pDataAddressDetailView );
+
$pWPPost = self::factory()->post->create_and_get( [
'post_author' => 1,
'post_content' => '[oo_estate view="detail"]',
@@ -107,7 +124,16 @@ public function testReturnNullForTrashStatus()
'post_status' => 'trash',
] );
+ $pWPPostForAddressDetail = self::factory()->post->create_and_get( [
+ 'post_author' => 1,
+ 'post_content' => '[oo_address view="detail"]',
+ 'post_title' => 'Details',
+ 'post_type' => 'page',
+ 'post_status' => 'trash',
+ ] );
+
$this->assertNull( $this->_pDetailViewPostSaveController->onSavePost( $pWPPost->ID ) );
+ $this->assertNull( $this->_pDetailViewPostSaveController->onSavePost( $pWPPostForAddressDetail->ID ) );
}
@@ -169,4 +195,33 @@ public function testShortCodeInMetaKey()
$detailViewOptions = get_option( DataDetailViewHandler::DEFAULT_VIEW_OPTION_KEY );
$this->assertEquals( $pWPPost->ID, $detailViewOptions->getPageId() );
}
+
+
+ /**
+ *
+ */
+
+ public function testAddreeDetailShortCodeInMetaKey()
+ {
+ $this->_pDataAddressDetailView->setPageId( 14 );
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView( $this->_pDataAddressDetailView );
+
+ $pWPPostForAddressDetail = self::factory()->post->create_and_get( [
+ 'post_author' => 1,
+ 'post_content' => '[oo_address view="detail"]',
+ 'post_title' => 'Test Post',
+ 'post_type' => 'page',
+ ] );
+
+ add_post_meta( $pWPPostForAddressDetail->ID, 'view', '[oo_address view="detail"]' );
+
+ $this->_pWPPageWrapper->method( 'getPageUriByPageId' )
+ ->with( $pWPPostForAddressDetail->ID )
+ ->willReturn( 'test-post' );
+
+ $this->_pDetailViewPostSaveController->onSavePost( $pWPPostForAddressDetail->ID );
+
+ $addressDetailViewOptions = get_option( DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY );
+ $this->assertEquals( $pWPPostForAddressDetail->ID, $addressDetailViewOptions->getPageId() );
+ }
}
\ No newline at end of file
From ea46e52708a389445fa0fe1686a08d43a9231b15 Mon Sep 17 00:00:00 2001
From: yeneastgate
Date: Thu, 16 May 2024 15:10:41 +0700
Subject: [PATCH 05/33] 47941 update unit test
---
plugin.php | 2 +-
plugin/Controller/RewriteRuleBuilder.php | 2 +-
plugin/Installer/Installer.php | 2 +-
...putModelOptionFactoryAddressDetailView.php | 73 +++++++++++++++++++
tests/TestClassRewriteRuleBuilder.php | 55 ++++++++++++++
5 files changed, 131 insertions(+), 3 deletions(-)
create mode 100644 tests/TestClassInputModelOptionFactoryAddressDetailView.php
diff --git a/plugin.php b/plugin.php
index 04f9a94f7..cb70a2cd7 100644
--- a/plugin.php
+++ b/plugin.php
@@ -171,7 +171,7 @@
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
- $pRewriteRuleBuilder->addCustomRewriteTagsAddressDetail();
+ $pRewriteRuleBuilder->addCustomRewriteTagsForAddressDetail();
$pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
});
diff --git a/plugin/Controller/RewriteRuleBuilder.php b/plugin/Controller/RewriteRuleBuilder.php
index 98a2928a7..e9908eec5 100644
--- a/plugin/Controller/RewriteRuleBuilder.php
+++ b/plugin/Controller/RewriteRuleBuilder.php
@@ -77,7 +77,7 @@ public function addDynamicRewriteRules()
}
}
- public function addCustomRewriteTagsAddressDetail()
+ public function addCustomRewriteTagsForAddressDetail()
{
add_rewrite_tag('%address_id%', '([^&]+)');
add_rewrite_tag('%view%', '([^&]+)');
diff --git a/plugin/Installer/Installer.php b/plugin/Installer/Installer.php
index 784d975c8..faffba436 100644
--- a/plugin/Installer/Installer.php
+++ b/plugin/Installer/Installer.php
@@ -51,7 +51,7 @@ static public function install()
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
- $pRewriteRuleBuilder->addCustomRewriteTagsAddressDetail();
+ $pRewriteRuleBuilder->addCustomRewriteTagsForAddressDetail();
$pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
self::flushRules();
}
diff --git a/tests/TestClassInputModelOptionFactoryAddressDetailView.php b/tests/TestClassInputModelOptionFactoryAddressDetailView.php
new file mode 100644
index 000000000..f4c91f4d9
--- /dev/null
+++ b/tests/TestClassInputModelOptionFactoryAddressDetailView.php
@@ -0,0 +1,73 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use WP_UnitTestCase;
+use onOffice\WPlugin\Model\InputModel\InputModelOptionFactoryAddressDetailView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class TestClassInputModelOptionFactoryAddressDetailView
+ extends WP_UnitTestCase
+{
+
+ /** @var string */
+ private $_optionGroup = 'onoffice';
+
+ /**
+ *
+ */
+
+ public function testConstruct()
+ {
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $this->assertInstanceOf(InputModelOptionFactoryAddressDetailView::class,
+ $pInputModelOptionFactoryAddressDetailView);
+ }
+
+ public function testCreate()
+ {
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $label = 'Label Test';
+ $pInputModelOption = $pInputModelOptionFactoryAddressDetailView->create('fields', $label);
+
+ $this->assertEquals($pInputModelOption->getOptionGroup(), 'onoffice');
+ $this->assertEquals($pInputModelOption->getName(), 'fields');
+ $this->assertEquals($pInputModelOption->getDescriptionTextHTML(), null);
+ $this->assertEquals($pInputModelOption->getDescriptionRadioTextHTML(), []);
+ }
+
+ public function testNoNameCreate()
+ {
+ $this->expectException(ExceptionInputModelMissingField::class);
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $label = 'Label Test';
+ $pInputModelOptionFactoryAddressDetailView->create('test', $label);
+ }
+}
diff --git a/tests/TestClassRewriteRuleBuilder.php b/tests/TestClassRewriteRuleBuilder.php
index 0f2e26c67..1726c31f3 100644
--- a/tests/TestClassRewriteRuleBuilder.php
+++ b/tests/TestClassRewriteRuleBuilder.php
@@ -31,6 +31,8 @@
use onOffice\WPlugin\DataView\DataDetailView;
use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\WP\WPPageWrapper;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -121,4 +123,57 @@ public function testAddDynamicRewriteRules()
'index.php?pagename=test_parent%2Ftest-post&view=$matches[1]&estate_id=$matches[2]'
], $wp_rewrite->extra_rules_top);
}
+
+ public function testAddCustomRewriteTagsForAddressDetail()
+ {
+ global $wp_rewrite;
+ $wp_rewrite->rewritecode = [];
+ $wp_rewrite->rewritereplace = [];
+ $pSubject = $this->_pContainer->get(RewriteRuleBuilder::class);
+ $pSubject->addCustomRewriteTagsForAddressDetail();
+ $this->assertSame('%address_id%', $wp_rewrite->rewritecode[0]);
+ $this->assertSame('([^&]+)', $wp_rewrite->rewritereplace[0]);
+
+ $this->assertSame('%view%', $wp_rewrite->rewritecode[1]);
+ $this->assertSame('([^&]+)', $wp_rewrite->rewritereplace[1]);
+ }
+
+ /**
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ public function testAddDynamicRewriteRulesForAddressDetail()
+ {
+ global $wp_rewrite;
+ $wp_rewrite->extra_rules_top = [];
+
+ $pDataAddressDetailViewHandler = $this->getMockBuilder(DataAddressDetailViewHandler::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getAddressDetailView'])
+ ->getMock();
+
+ $pDataAdressDetailView = new DataAddressDetailView;
+ $pDataAdressDetailView->addToPageIdsHaveDetailShortCode(13);
+ $pDataAdressDetailView->setPageId(13);
+ $pDataAddressDetailViewHandler->expects($this->once())
+ ->method('getAddressDetailView')
+ ->willReturn($pDataAdressDetailView);
+
+ $pWPPageWrapper = $this->getMockBuilder(WPPageWrapper::class)
+ ->setMethods(['getPageUriByPageId'])
+ ->getMock();
+ $pWPPageWrapper->method('getPageUriByPageId')
+ ->with(13)
+ ->willReturn('test_parent/test-post');
+
+ $this->_pContainer->set(DataAddressDetailViewHandler::class, $pDataAddressDetailViewHandler);
+ $this->_pContainer->set(WPPageWrapper::class, $pWPPageWrapper);
+
+ $pSubject = $this->_pContainer->get(RewriteRuleBuilder::class);
+ $pSubject->addDynamicRewriteRulesForAddressDetail();
+ $this->assertSame([
+ '^(test_parent/test\-post)/([0-9]+)(-([^$]+)?)?/?$' =>
+ 'index.php?pagename=test_parent%2Ftest-post&view=$matches[1]&address_id=$matches[2]'
+ ], $wp_rewrite->extra_rules_top);
+ }
}
\ No newline at end of file
From c6870b62bdd0f9e7a66f8802d1ce0ab1133ec97a Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Mon, 20 May 2024 17:40:21 +0700
Subject: [PATCH 06/33] 47944 add form selection
---
css/admin.css | 3 +
plugin.php | 2 +
plugin/Controller/AdminViewController.php | 26 +-
.../DetailViewPostSaveController.php | 78 ++-
plugin/Controller/RewriteRuleBuilder.php | 24 +-
plugin/DataView/DataAddressDetailView.php | 142 +++++
.../DataView/DataAddressDetailViewHandler.php | 111 ++++
plugin/DataView/DataListViewAddress.php | 2 +-
plugin/DataView/DataViewAddress.php | 43 ++
plugin/Gui/AdminPageAddress.php | 252 ++++++++
plugin/Gui/AdminPageAddressDetail.php | 549 ++++++++++++++++++
plugin/Gui/AdminPageAddressList.php | 82 +--
plugin/Gui/AdminPageAddressListSettings.php | 16 +
.../Gui/AdminPageEstateListSettingsBase.php | 7 +
plugin/Gui/AdminPageSettingsBase.php | 7 -
plugin/Installer/Installer.php | 2 +
.../FormModelBuilderAddressDetailSettings.php | 365 ++++++++++++
...putModelOptionFactoryAddressDetailView.php | 110 ++++
.../InputFieldTemplateListRenderer.php | 1 +
plugin/Types/ImageTypes.php | 11 +
tests/TestClassDataAddressDetailView.php | 86 +++
.../TestClassDataAddressDetailViewHandler.php | 133 +++++
.../TestClassDetailViewPostSaveController.php | 57 +-
...sFormModelBuilderAddressDetailSettings.php | 247 ++++++++
tests/TestClassImageTypes.php | 21 +
...putModelOptionFactoryAddressDetailView.php | 73 +++
tests/TestClassRewriteRuleBuilder.php | 55 ++
27 files changed, 2411 insertions(+), 94 deletions(-)
create mode 100644 plugin/DataView/DataAddressDetailView.php
create mode 100644 plugin/DataView/DataAddressDetailViewHandler.php
create mode 100644 plugin/DataView/DataViewAddress.php
create mode 100644 plugin/Gui/AdminPageAddress.php
create mode 100644 plugin/Gui/AdminPageAddressDetail.php
create mode 100644 plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
create mode 100644 plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
create mode 100644 tests/TestClassDataAddressDetailView.php
create mode 100644 tests/TestClassDataAddressDetailViewHandler.php
create mode 100644 tests/TestClassFormModelBuilderAddressDetailSettings.php
create mode 100644 tests/TestClassInputModelOptionFactoryAddressDetailView.php
diff --git a/css/admin.css b/css/admin.css
index 9616884e1..61b84e08b 100644
--- a/css/admin.css
+++ b/css/admin.css
@@ -287,6 +287,7 @@ div[data-name^=oopluginfieldconfigformdefaultsvalues-value].multiselect > input.
#onoffice-form-search-address{
display: flex;
float: right;
+ margin-top: -33px;
}
#onoffice-form-search-form {
display: flex;
@@ -816,10 +817,12 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
width: 100%;
}
+ .oo-poststuff-address-detail .viewusage,
.oo-poststuff-estate-detail .viewusage {
width: 100%;
}
+ .oo-poststuff-address-detail .block-publish,
.oo-poststuff-estate-detail .block-publish,
.oo-poststuff-similar-estate .block-publish {
margin-top: 0;
diff --git a/plugin.php b/plugin.php
index 590b913cc..cb70a2cd7 100644
--- a/plugin.php
+++ b/plugin.php
@@ -171,6 +171,8 @@
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
+ $pRewriteRuleBuilder->addCustomRewriteTagsForAddressDetail();
+ $pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
});
// This hook [wp] is one effective place to perform any high-level filtering or validation,
diff --git a/plugin/Controller/AdminViewController.php b/plugin/Controller/AdminViewController.php
index 31f2407ed..7acb94a81 100644
--- a/plugin/Controller/AdminViewController.php
+++ b/plugin/Controller/AdminViewController.php
@@ -43,6 +43,7 @@
use onOffice\WPlugin\Utility\__String;
use onOffice\WPlugin\WP\WPPluginChecker;
use onOffice\WPlugin\WP\ListTableBulkActionsHandler;
+use onOffice\WPlugin\Gui\AdminPageAddress;
use Parsedown;
use HTMLPurifier_Config;
use HTMLPurifier;
@@ -93,6 +94,9 @@ class AdminViewController
/** @var AdminPageFormSettingsMain */
private $_pAdminPageFormSettings = null;
+ /** @var AdminPageAddress */
+ private $_pAdminPageAddresses = null;
+
/** */
const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
@@ -127,6 +131,13 @@ public function onInit()
if ($pSelectedSubPage instanceof AdminPageAjax) {
$this->_ajaxHooks['onoffice_page_'.$this->_pageSlug.'-estates'] = $pSelectedSubPage;
}
+
+ $this->_pAdminPageAddresses = new AdminPageAddress($this->_pageSlug);
+ $pSelectedSubPageForAddress = $this->_pAdminPageAddresses->getSelectedAdminPage();
+
+ if ($pSelectedSubPageForAddress instanceof AdminPageAjax) {
+ $this->_ajaxHooks['onoffice_page_'.$this->_pageSlug.'-addresses'] = $pSelectedSubPageForAddress;
+ }
}
@@ -167,11 +178,16 @@ public function register_menu()
__( 'Getting started', 'onoffice-for-wp-websites' ),
$roleMainPage, $this->_pageSlug );
- $pAdminPageAddresses = new AdminPageAddressList($this->_pageSlug);
- $hookAddresses = add_submenu_page( $this->_pageSlug, __('Addresses', 'onoffice-for-wp-websites'), __('Addresses', 'onoffice-for-wp-websites'),
- $roleAddress, $this->_pageSlug.'-addresses', array($pAdminPageAddresses, 'render'));
- add_action('load-'.$hookAddresses, [$pAdminPageAddresses, 'handleAdminNotices']);
- add_action('current_screen', [$pAdminPageAddresses, 'preOutput']);
+ // Addresses
+ $hookAddresses = add_submenu_page( $this->_pageSlug, __('Addresses', 'onoffice-for-wp-websites'),
+ __('Addresses', 'onoffice-for-wp-websites'), $roleAddress,
+ $this->_pageSlug.'-addresses', array($this->_pAdminPageAddresses, 'render'));
+ add_action('load-'.$hookAddresses, [$this->_pAdminPageAddresses, 'handleAdminNotices']);
+ $pSelectedSubPageForAddress = $this->_pAdminPageAddresses->getSelectedAdminPage();
+ if ($pSelectedSubPageForAddress instanceof AdminPageAjax) {
+ add_action( 'load-'.$hookAddresses, array($pSelectedSubPageForAddress, 'checkForms'));
+ }
+ add_action('current_screen', [$this->_pAdminPageAddresses, 'preOutput']);
// Estates
$hookEstates = add_submenu_page( $this->_pageSlug, __('Estates', 'onoffice-for-wp-websites'),
diff --git a/plugin/Controller/DetailViewPostSaveController.php b/plugin/Controller/DetailViewPostSaveController.php
index ec094480e..757ad9b28 100644
--- a/plugin/Controller/DetailViewPostSaveController.php
+++ b/plugin/Controller/DetailViewPostSaveController.php
@@ -29,6 +29,7 @@
use onOffice\WPlugin\Record\RecordManagerReadListViewEstate;
use onOffice\WPlugin\Record\RecordManagerReadListViewAddress;
use onOffice\WPlugin\Record\RecordManagerReadForm;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
use WP_Post;
@@ -104,26 +105,40 @@ public function onSavePost($postId) {
if (!$isRevision) {
$pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class);
$pDetailView = $pDataDetailViewHandler->getDetailView();
+ $pDataAddressDetailViewHandler = $this->_pContainer->get(DataAddressDetailViewHandler::class);
+ $pAddressDetailView = $pDataAddressDetailViewHandler->getAddressDetailView();
$detailViewName = $pDetailView->getName();
+ $addressDetailViewName = $pAddressDetailView->getName();
$postContent = $pPost->post_content;
$postType = $pPost->post_type;
$metaKeys = get_post_meta($postId, '', true);
$viewContained = $this->postContainsViewName($postContent, $detailViewName);
+ $viewContainedAddressDetail = $this->postContainsViewName($postContent, $addressDetailViewName, 'oo_address');
$viewContainedCustomField = false;
$hasOtherShortcodeInPostContent = false;
+ $viewContainedAddressDetailCustomField = false;
+ $hasOtherAddressDetailShortcodeInPostContent = false;
if (!$viewContained && !empty($postContent) && $this->checkOtherShortcodeInPostContent($postContent, $detailViewName)) {
$hasOtherShortcodeInPostContent = true;
}
+ if (!$viewContainedAddressDetail && !empty($postContent) && $this->checkOtherShortcodeInPostContent($postContent, $addressDetailViewName, 'oo_address')) {
+ $hasOtherAddressDetailShortcodeInPostContent = true;
+ }
+
foreach ($metaKeys as $metaKey) {
$viewContainedMetaKey = $this->postContainsViewName($metaKey[0], $detailViewName);
if ($viewContainedMetaKey) {
$viewContainedCustomField = true;
}
+ $viewAddressDetailContainedMetaKey = $this->postContainsViewName($metaKey[0], $addressDetailViewName, 'oo_address');
+ if ($viewAddressDetailContainedMetaKey) {
+ $viewContainedAddressDetailCustomField = true;
+ }
}
if (($viewContained) || ($viewContainedCustomField && $viewContained) || ($viewContainedCustomField && $hasOtherShortcodeInPostContent == false)) {
@@ -146,6 +161,28 @@ public function onSavePost($postId) {
flush_rewrite_rules();
}
}
+
+ if (($viewContainedAddressDetail) || ($viewContainedAddressDetailCustomField && $hasOtherAddressDetailShortcodeInPostContent == false)) {
+ if ($postType == 'page') {
+ $pAddressDetailView->setPageId((int) $postId);
+ $pAddressDetailView->addToPageIdsHaveDetailShortCode((int) $postId);
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
+ flush_rewrite_rules();
+ }
+ } elseif ($pAddressDetailView->getPageId() !== 0) {
+ $postRevisions = wp_get_post_revisions($postId);
+ $detailInPreviousRev = array_key_exists($pAddressDetailView->getPageId(), $postRevisions);
+
+ if ($detailInPreviousRev || $pAddressDetailView->getPageId() === $postId) {
+ $pAddressDetailView->setPageId(0);
+ $pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
+ flush_rewrite_rules();
+ }
+ }
+
$this->addPageUseShortCode($pPost);
$listView = $this->getListView();
$listViewAddress = $this->getListViewAddress();
@@ -209,9 +246,13 @@ public function onMoveTrash() {
$posts = $_GET['post'];
if ( isset( $posts ) ) {
$pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class);
+ $pDataAddressDetailViewHandler = $this->_pContainer->get(DataAddressDetailViewHandler::class);
$pDetailView = $pDataDetailViewHandler->getDetailView();
$detailPageIds = $pDetailView->getPageIdsHaveDetailShortCode();
+ $pAddressDetailView = $pDataAddressDetailViewHandler->getAddressDetailView();
+ $addressDetailPageIds = $pAddressDetailView->getPageIdsHaveDetailShortCode();
$hasDetailPost = false;
+ $hasAddressDetailPost = false;
if ( ! is_array( $posts ) ) {
$posts = [ $posts ];
}
@@ -220,17 +261,31 @@ public function onMoveTrash() {
$pDetailView->removeFromPageIdsHaveDetailShortCode( (int) $postId );
$hasDetailPost = true;
}
+ if (in_array($postId, $addressDetailPageIds)) {
+ $pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
+ $hasAddressDetailPost = true;
+ }
$pPost = get_post( $postId );
$this->deletePageUseShortCode( $pPost );
}
if ( $hasDetailPost ) {
- if ( empty( $pDetailView->getPageIdsHaveDetailShortCode() ) ) {
- $pDetailView->setPageId( 0 );
- } elseif ( in_array( $pDetailView->getPageId(), $posts ) ) {
- $firstDetailPageId = min( array_keys( $detailPageIds ) );
- $pDetailView->setPageId( (int) $detailPageIds[ $firstDetailPageId ] );
+ if (empty($pDetailView->getPageIdsHaveDetailShortCode())) {
+ $pDetailView->setPageId(0);
+ } elseif (in_array($pDetailView->getPageId(), $posts)) {
+ $firstDetailPageId = min(array_keys($detailPageIds));
+ $pDetailView->setPageId((int) $detailPageIds[$firstDetailPageId]);
}
- $pDataDetailViewHandler->saveDetailView( $pDetailView );
+ $pDataDetailViewHandler->saveDetailView($pDetailView);
+ flush_rewrite_rules();
+ }
+ if ( $hasAddressDetailPost ) {
+ if (empty($pAddressDetailView->getPageIdsHaveDetailShortCode())) {
+ $pAddressDetailView->setPageId(0);
+ } elseif (in_array($pAddressDetailView->getPageId(), $posts)) {
+ $firstDetailPageId = min(array_keys( $addressDetailPageIds ));
+ $pAddressDetailView->setPageId((int) $addressDetailPageIds[$firstDetailPageId]);
+ }
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
flush_rewrite_rules();
}
}
@@ -311,13 +366,14 @@ private function getListForm()
*
* @param string $post
* @param string $viewName
+ * @param string $tagShortcode
* @return bool
*
*/
- private function postContainsViewName($post, $viewName) {
+ private function postContainsViewName(string $post, string $viewName, string $tagShortcode = 'oo_estate') {
$matches = array();
- $regex = get_shortcode_regex(array('oo_estate'));
+ $regex = get_shortcode_regex(array($tagShortcode));
preg_match_all('/'.$regex.'/ism', $post, $matches);
$detailviewCode = $this->generateDetailViewCode($viewName);
@@ -338,18 +394,18 @@ private function postContainsViewName($post, $viewName) {
return false;
}
-
/**
*
* @param string $post
* @param string $viewName
+ * @param string $tagShortcode
* @return bool
*
*/
- private function checkOtherShortcodeInPostContent($post, $viewName) {
+ private function checkOtherShortcodeInPostContent(string $post, string $viewName, string $tagShortcode = 'oo_estate') {
$matches = array();
- $regex = get_shortcode_regex(array('oo_estate'));
+ $regex = get_shortcode_regex(array($tagShortcode));
preg_match_all('/' . $regex . '/ism', $post, $matches);
$detailviewCode = $this->generateDetailViewCode($viewName);
diff --git a/plugin/Controller/RewriteRuleBuilder.php b/plugin/Controller/RewriteRuleBuilder.php
index 4df42660a..e9908eec5 100644
--- a/plugin/Controller/RewriteRuleBuilder.php
+++ b/plugin/Controller/RewriteRuleBuilder.php
@@ -25,6 +25,7 @@
use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\WP\WPPageWrapper;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
class RewriteRuleBuilder
{
@@ -34,16 +35,21 @@ class RewriteRuleBuilder
/** @var WPPageWrapper */
private $_pWPPageWrapper;
+ /** @var DataAddressDetailViewHandler */
+ private $_pDataAddressDetailViewHandler;
+
/**
* @param DataDetailViewHandler $pDataDetailViewHandler
* @param WPPageWrapper $pWPPageWrapper
*/
public function __construct(
DataDetailViewHandler $pDataDetailViewHandler,
- WPPageWrapper $pWPPageWrapper)
+ WPPageWrapper $pWPPageWrapper,
+ DataAddressDetailViewHandler $pDataAddressDetailViewHandler)
{
$this->_pDataDetailViewHandler = $pDataDetailViewHandler;
$this->_pWPPageWrapper = $pWPPageWrapper;
+ $this->_pDataAddressDetailViewHandler = $pDataAddressDetailViewHandler;
}
public function addCustomRewriteTags()
@@ -70,4 +76,20 @@ public function addDynamicRewriteRules()
'index.php?pagename=' . urlencode( $pageName ) . '&view=$matches[1]&estate_id=$matches[2]', 'top' );
}
}
+
+ public function addCustomRewriteTagsForAddressDetail()
+ {
+ add_rewrite_tag('%address_id%', '([^&]+)');
+ add_rewrite_tag('%view%', '([^&]+)');
+ }
+
+ public function addDynamicRewriteRulesForAddressDetail()
+ {
+ $detailPageIds = $this->_pDataAddressDetailViewHandler->getAddressDetailView()->getPageIdsHaveDetailShortCode();
+ foreach ( $detailPageIds as $detailPageId ) {
+ $pageName = $this->_pWPPageWrapper->getPageUriByPageId( $detailPageId );
+ add_rewrite_rule( '^(' . preg_quote( $pageName ) . ')/([0-9]+)(-([^$]+)?)?/?$',
+ 'index.php?pagename=' . urlencode( $pageName ) . '&view=$matches[1]&address_id=$matches[2]', 'top' );
+ }
+ }
}
\ No newline at end of file
diff --git a/plugin/DataView/DataAddressDetailView.php b/plugin/DataView/DataAddressDetailView.php
new file mode 100644
index 000000000..2df8500b1
--- /dev/null
+++ b/plugin/DataView/DataAddressDetailView.php
@@ -0,0 +1,142 @@
+.
+ *
+ */
+
+declare(strict_types=1);
+
+namespace onOffice\WPlugin\DataView;
+
+use onOffice\SDK\onOfficeSDK;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class DataAddressDetailView
+ implements DataViewAddress
+{
+ /** */
+ const FIELDS = 'fields';
+
+ /** */
+ const TEMPLATE = 'template';
+
+ /** */
+ const PICTURES = 'pictures';
+
+ /** */
+ const FIELD_CUSTOM_LABEL = 'oo_plugin_fieldconfig_address_translated_labels';
+
+ /** @var string[] */
+ private $_fields = [
+ 'Anrede',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'Email',
+ 'Telefon1',
+ 'Telefax1',
+ ];
+
+ /** @var string[] */
+ private $_pictureTypes = [];
+
+ /** @var string */
+ private $_template = '';
+
+ /** @var int */
+ private $_pageId = 0;
+
+ /** @var array */
+ private $_pageIdsHaveDetailShortCode = [];
+
+ /** @var array */
+ private $_customLabel = [];
+
+ /** @var string */
+ private $_shortCodeForm = '';
+
+ /** @return int */
+ public function getPageId(): int
+ { return $this->_pageId; }
+
+ /** @param int $pageId */
+ public function setPageId(int $pageId)
+ { $this->_pageId = $pageId; }
+
+ /** @return string */
+ public function getName(): string
+ { return 'detail'; }
+
+ /** @return string[] */
+ public function getFields(): array
+ { return $this->_fields; }
+
+ /** @return array */
+ public function getPictureTypes(): array
+ { return $this->_pictureTypes; }
+
+ /** @return string */
+ public function getTemplate(): string
+ { return $this->_template; }
+
+ /** @param array $fields */
+ public function setFields(array $fields)
+ { $this->_fields = $fields; }
+
+ /** @param array $pictureTypes */
+ public function setPictureTypes(array $pictureTypes)
+ { $this->_pictureTypes = $pictureTypes; }
+
+ /** @param string $template */
+ public function setTemplate(string $template)
+ { $this->_template = $template; }
+
+ /** @return string */
+ public function getShortCodeForm(): string
+ { return $this->_shortCodeForm; }
+
+ /** @param string $shortCodeForm */
+ public function setShortCodeForm(string $shortCodeForm)
+ { $this->_shortCodeForm = $shortCodeForm; }
+
+ /** @return array */
+ public function getPageIdsHaveDetailShortCode(): array
+ { return $this->_pageIdsHaveDetailShortCode; }
+
+ /** @param int $pageId */
+ public function addToPageIdsHaveDetailShortCode(int $pageId)
+ { $this->_pageIdsHaveDetailShortCode[$pageId] = $pageId; }
+
+ /** @param int $pageId */
+ public function removeFromPageIdsHaveDetailShortCode(int $pageId)
+ { unset($this->_pageIdsHaveDetailShortCode[$pageId]); }
+
+ /** @return array */
+ public function getCustomLabels()
+ { return $this->_customLabel; }
+
+ /** @param array $customLabel */
+ public function setCustomLabels(array $customLabel)
+ { $this->_customLabel = $customLabel; }
+}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
new file mode 100644
index 000000000..c2ab5b80c
--- /dev/null
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -0,0 +1,111 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\DataView;
+
+use onOffice\WPlugin\WP\WPOptionWrapperBase;
+use onOffice\WPlugin\WP\WPOptionWrapperDefault;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class DataAddressDetailViewHandler
+{
+ /** */
+ const DEFAULT_ADDRESS_VIEW_OPTION_KEY = 'onoffice-default-address-view';
+
+ /** @var WPOptionWrapperBase */
+ private $_pWPOptionWrapper;
+
+
+ /**
+ * @param WPOptionWrapperBase $pWPOptionWrapper
+ */
+ public function __construct(WPOptionWrapperBase $pWPOptionWrapper = null)
+ {
+ $this->_pWPOptionWrapper = $pWPOptionWrapper ?? new WPOptionWrapperDefault();
+ }
+
+
+ /**
+ *
+ * @return DataAddressDetailView
+ *
+ */
+
+ public function getAddressDetailView(): DataAddressDetailView
+ {
+ $optionKey = self::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+ $pAlternate = new DataAddressDetailView();
+ $pResult = $this->_pWPOptionWrapper->getOption($optionKey, $pAlternate);
+
+ if ($pResult == null) {
+ $pResult = $pAlternate;
+ }
+
+ return $pResult;
+ }
+
+
+ /**
+ *
+ * @param DataAddressDetailView $pDataAddressDetailView
+ *
+ */
+
+ public function saveAddressDetailView(DataAddressDetailView $pDataAddressDetailView)
+ {
+ $pWpOptionsWrapper = $this->_pWPOptionWrapper;
+ $viewOptionKey = self::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+
+ if ($pWpOptionsWrapper->getOption($viewOptionKey) !== false) {
+ $pWpOptionsWrapper->updateOption($viewOptionKey, $pDataAddressDetailView);
+ } else {
+ $pWpOptionsWrapper->addOption($viewOptionKey, $pDataAddressDetailView);
+ }
+ }
+
+
+ /**
+ *
+ * @param array $row
+ * @return DataAddressDetailView
+ *
+ */
+
+ public function createAddressDetailViewByValues(array $row): DataAddressDetailView
+ {
+ $pDataAddressDetailView = $this->getAddressDetailView();
+ $pDataAddressDetailView->setTemplate($row[DataAddressDetailView::TEMPLATE] ?? '');
+ $pDataAddressDetailView->setFields($row[DataAddressDetailView::FIELDS] ?? []);
+ $pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
+ $pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
+ $pDataAddressDetailView->setShortCodeForm($row['shortcodeform'] ?? '');
+
+ return $pDataAddressDetailView;
+ }
+}
\ No newline at end of file
diff --git a/plugin/DataView/DataListViewAddress.php b/plugin/DataView/DataListViewAddress.php
index ca46167be..18c5925ff 100644
--- a/plugin/DataView/DataListViewAddress.php
+++ b/plugin/DataView/DataListViewAddress.php
@@ -34,7 +34,7 @@
*/
class DataListViewAddress
- implements DataViewFilterableFields, ViewProperty
+ implements DataViewFilterableFields, ViewProperty, DataViewAddress
{
/** */
const FIELDS = 'fields';
diff --git a/plugin/DataView/DataViewAddress.php b/plugin/DataView/DataViewAddress.php
new file mode 100644
index 000000000..af0865a80
--- /dev/null
+++ b/plugin/DataView/DataViewAddress.php
@@ -0,0 +1,43 @@
+.
+ *
+ */
+
+declare(strict_types=1);
+
+namespace onOffice\WPlugin\DataView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+interface DataViewAddress
+{
+ /** @return array */
+ public function getFields(): array;
+
+ /** @return string */
+ public function getTemplate(): string;
+
+ /** @return string */
+ public function getName(): string;
+}
diff --git a/plugin/Gui/AdminPageAddress.php b/plugin/Gui/AdminPageAddress.php
new file mode 100644
index 000000000..c9c88a5f2
--- /dev/null
+++ b/plugin/Gui/AdminPageAddress.php
@@ -0,0 +1,252 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Gui;
+
+use DI\ContainerBuilder;
+use onOffice\WPlugin\Controller\UserCapabilities;
+use onOffice\WPlugin\Form\BulkDeleteRecord;
+use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
+use onOffice\WPlugin\Record\RecordManagerDeleteListViewEstate;
+use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
+use const ONOFFICE_DI_CONFIG_PATH;
+use function __;
+use function add_action;
+use function add_filter;
+use function add_query_arg;
+use function admin_url;
+use function check_admin_referer;
+use function esc_html__;
+use function add_screen_option;
+use Exception;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class AdminPageAddress
+ extends AdminPage
+{
+ /** */
+ const PAGE_ADDRESS_LIST = 'list';
+
+ /** */
+ const PAGE_ADDRESS_DETAIL = 'detail';
+
+ /** @var string[] */
+ private $_subPageClassByTab = array(
+ self::PAGE_ADDRESS_LIST => AdminPageAddressList::class,
+ self::PAGE_ADDRESS_DETAIL => AdminPageAddressDetail::class,
+ );
+
+ /** */
+ const PARAM_TAB = 'tab';
+
+ /** @var array */
+ private $_tabs = array();
+
+ /** @var AdminPage */
+ private $_pSelectedTab = null;
+
+ /**
+ * @param string $pageSlug
+ * @throws Exception
+ */
+
+ public function __construct($pageSlug)
+ {
+ $this->_tabs = array(
+ self::PAGE_ADDRESS_LIST => __('Address Views', 'onoffice-for-wp-websites'),
+ self::PAGE_ADDRESS_DETAIL => __('Detail View', 'onoffice-for-wp-websites'),
+ );
+
+ parent::__construct($pageSlug);
+
+ $selectedTab = $this->getSelectedTab();
+ $this->_pSelectedTab = $this->getAdminPageForTab($selectedTab);
+ }
+
+ /**
+ *
+ * @return string
+ *
+ */
+
+ private function getSelectedTab()
+ {
+ $selectedTab = $this->getDefaultTab();
+ $getParamTab = filter_input(INPUT_GET, self::PARAM_TAB);
+ $postParamTab = filter_input(INPUT_POST, self::PARAM_TAB);
+ if (!is_null($getParamTab)) {
+ $selectedTab = $getParamTab;
+ } elseif (!is_null($postParamTab)) {
+ $selectedTab = $postParamTab;
+ }
+
+ return $selectedTab;
+ }
+
+
+ /**
+ *
+ * @param string $tab
+ * @return AdminPage
+ *
+ */
+
+ private function getAdminPageForTab(string $tab)
+ {
+ if (!isset($this->_subPageClassByTab[$tab])) {
+ $tab = self::PAGE_ADDRESS_LIST;
+ }
+
+ $className = $this->_subPageClassByTab[$tab];
+ $pAdminPage = new $className($this->getPageSlug());
+
+ return $pAdminPage;
+ }
+
+
+ /**
+ *
+ */
+
+ public function renderContent()
+ {
+ $selectedTab = $this->getSelectedTab();
+ $defaultTab = $this->getDefaultTab();
+ $this->_pSelectedTab->generatePageMainTitle(__('Addresses', 'onoffice-for-wp-websites'));
+
+ echo '';
+ $adminUrl = admin_url('admin.php?page=onoffice-addresses');
+
+ foreach ($this->_tabs as $index => $label)
+ {
+ $newAdminUrl = ($index != $defaultTab) ? add_query_arg('tab', $index, $adminUrl) : $adminUrl;
+ $class = ($index === $selectedTab) ? ' nav-tab-active' : '';
+ echo ''.esc_html($label).' ';
+ }
+ echo ' ';
+ echo $this->_pSelectedTab->renderContent();
+ }
+
+ /**
+ *
+ * @return string
+ *
+ */
+
+ private function getDefaultTab()
+ {
+ return self::PAGE_ADDRESS_LIST;
+ }
+
+
+ /**
+ *
+ */
+
+ public function handleAdminNotices()
+ {
+ $this->_pSelectedTab->handleAdminNotices();
+ $itemsDeleted = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_NUMBER_INT);
+
+ if ($itemsDeleted !== null && $itemsDeleted !== false) {
+ add_action('admin_notices', function() use ($itemsDeleted) {
+ $pHandler = new AdminNoticeHandlerListViewDeletion();
+ echo $pHandler->handleListView($itemsDeleted);
+ });
+ }
+ }
+
+
+ /**
+ *
+ */
+
+ public function preOutput()
+ {
+ $this->_pSelectedTab->preOutput();
+
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $pDI = $pContainerBuilder->build();
+ $pClosureDeleteAddress = function(string $redirectTo, Table\WP\ListTable $pTable, array $recordIds) use ($pDI): string {
+ /* @var $pBulkDeleteRecord BulkDeleteRecord */
+ $pBulkDeleteRecord = $pDI->get(BulkDeleteRecord::class);
+ /* @var $pRecordManagerDelete RecordManagerDeleteListViewAddress */
+ $pRecordManagerDelete = $pDI->get(RecordManagerDeleteListViewAddress::class);
+ if (in_array($pTable->current_action(), ['delete', 'bulk_delete'])) {
+ check_admin_referer('bulk-'.$pTable->getArgs()['plural']);
+ $itemsDeleted = $pBulkDeleteRecord->delete
+ ($pRecordManagerDelete, UserCapabilities::RULE_EDIT_VIEW_ADDRESS, $recordIds);
+ $redirectTo = add_query_arg(['delete' => $itemsDeleted],
+ admin_url('admin.php?page=onoffice-addresses'));
+ }
+ return $redirectTo;
+ };
+
+ add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDeleteAddress, 10, 3);
+
+ $pClosureDuplicateAddress = function (string $redirectTo, Table\WP\ListTable $pTable) use ($pDI): string {
+ if (in_array($pTable->current_action(), ['duplicate', 'bulk_duplicate'])) {
+ check_admin_referer('bulk-' . $pTable->getArgs()['plural']);
+ if (!(isset($_GET['listViewId']))) {
+ wp_die('No List Views for duplicating!');
+ }
+
+ /* @var $pRecordManagerDuplicateListViewAddress RecordManagerDuplicateListViewAddress */
+ $pRecordManagerDuplicateListViewAddress = $pDI->get(RecordManagerDuplicateListViewAddress::class);
+ $listViewRootId = $_GET['listViewId'];
+ $pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
+ }
+ return $redirectTo;
+ };
+
+ add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDuplicateAddress, 10, 3);
+
+ parent::preOutput();
+ }
+
+ /**
+ *
+ * @return AdminPage
+ *
+ */
+
+ public function getSelectedAdminPage()
+ {
+ return $this->_pSelectedTab;
+ }
+
+
+ /**
+ *
+ */
+
+ public function doExtraEnqueues()
+ {
+ $this->_pSelectedTab->doExtraEnqueues();
+ }
+}
diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php
new file mode 100644
index 000000000..aaa289bbd
--- /dev/null
+++ b/plugin/Gui/AdminPageAddressDetail.php
@@ -0,0 +1,549 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Gui;
+
+use DI\DependencyException;
+use DI\NotFoundException;
+use Exception;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\FormModel;
+use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings;
+use onOffice\WPlugin\Model\InputModelBase;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Model\InputModelOptionAdapterArray;
+use onOffice\WPlugin\Renderer\InputModelRenderer;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\WPlugin\Controller\AddressListEnvironmentDefault;
+use onOffice\WPlugin\Language;
+use onOffice\WPlugin\Field\UnknownFieldException;
+use function __;
+use function add_action;
+use function do_accordion_sections;
+use function do_action;
+use function do_meta_boxes;
+use function do_settings_sections;
+use function esc_attr;
+use function esc_html;
+use function esc_html__;
+use function get_current_screen;
+use function plugin_dir_url;
+use function wp_die;
+use function wp_enqueue_script;
+use function wp_nonce_field;
+use function wp_register_script;
+use function wp_verify_nonce;
+use const ONOFFICE_PLUGIN_DIR;
+
+/**
+ *
+ */
+
+class AdminPageAddressDetail
+ extends AdminPageAjax
+{
+ /** */
+ const FORM_VIEW_LAYOUT_DESIGN = 'viewlayoutdesign';
+
+ /** */
+ const FORM_VIEW_PICTURE_TYPES = 'viewpicturetypes';
+
+ /** */
+ const FORM_VIEW_SORTABLE_FIELDS_CONFIG = 'viewSortableFieldsConfig';
+
+ /** */
+ const FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG = 'viewSearchFieldForFieldListsConfig';
+
+ /** */
+ const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
+
+ /** */
+ const VIEW_LEAVE_WITHOUT_SAVING_TEXT = 'view_leave_without_saving_text';
+
+ /** */
+ const CUSTOM_LABELS = 'customlabels';
+
+ /**
+ *
+ * @throws Exception
+ */
+
+ public function renderContent()
+ {
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'true' ) {
+ echo ''
+ . esc_html__( 'The address detail view has been saved.', 'onoffice-for-wp-websites' )
+ . '
';
+ }
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the address detail view.', 'onoffice-for-wp-websites' )
+ . '
';
+ }
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pAddressDataView = $pDataAddressDetailViewHandler->getAddressDetailView();
+
+ do_action('add_meta_boxes', get_current_screen()->id, null);
+ $this->generateMetaBoxes();
+
+ /* @var $pRenderer InputModelRenderer */
+ $pRenderer = $this->getContainer()->get(InputModelRenderer::class);
+ $pFormViewSortableFields = $this->getFormModelByGroupSlug(self::FORM_VIEW_SORTABLE_FIELDS_CONFIG);
+ $pFormViewSearchFieldForFieldLists = $this->getFormModelByGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
+
+ echo '';
+ }
+
+
+ /**
+ *
+ * @param string $subTitle
+ *
+ */
+
+ public function generatePageMainTitle($subTitle)
+ {
+ echo ''.esc_html__('onOffice', 'onoffice-for-wp-websites');
+ echo ' › ' . esc_html( $subTitle );
+ echo ' › '.esc_html__('Detail View', 'onoffice-for-wp-websites');
+ echo ' ';
+ echo '';
+ }
+
+
+ /**
+ *
+ */
+
+ private function generateMetaBoxes()
+ {
+ $pFormPictureTypes = $this->getFormModelByGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
+ $this->createMetaBoxByForm($pFormPictureTypes, 'side');
+
+ $pFormLayoutDesign = $this->getFormModelByGroupSlug(self::FORM_VIEW_LAYOUT_DESIGN);
+ $this->createMetaBoxByForm($pFormLayoutDesign, 'normal');
+ }
+
+ /**
+ * @return void
+ */
+ protected function generateAccordionBoxes()
+ {
+ $fieldNames = array_keys($this->readFieldnamesByContent(onOfficeSDK::MODULE_ADDRESS));
+
+ foreach ($fieldNames as $category) {
+ $slug = $this->generateGroupSlugByModuleCategory(onOfficeSDK::MODULE_ADDRESS, $category);
+ $pFormFieldsConfig = $this->getFormModelByGroupSlug($slug);
+ if (!is_null($pFormFieldsConfig))
+ {
+ $this->createMetaBoxByForm($pFormFieldsConfig, 'contactperson');
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ protected function buildForms()
+ {
+ $pFormModelBuilder = $this->getContainer()->get(FormModelBuilderAddressDetailSettings::class);
+ $pFormModel = $pFormModelBuilder->generate($this->getPageSlug());
+ $this->addFormModel($pFormModel);
+
+ $pInputModelTemplate = $pFormModelBuilder->createInputModelTemplate();
+ $pInputModelShortCodeForm = $pFormModelBuilder->createInputModelShortCodeForm();
+ $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($pInputModelShortCodeForm);
+ $this->addFormModel($pFormModelLayoutDesign);
+
+ $pInputModelPictureTypes = $pFormModelBuilder->createInputModelPictureTypes();
+ $pFormModelPictureTypes = new FormModel();
+ $pFormModelPictureTypes->setPageSlug($this->getPageSlug());
+ $pFormModelPictureTypes->setGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
+ $pFormModelPictureTypes->setLabel(__('Photo Types', 'onoffice-for-wp-websites'));
+ $pFormModelPictureTypes->addInputModel($pInputModelPictureTypes);
+ $this->addFormModel($pFormModelPictureTypes);
+
+ $pEnvironment = new AddressListEnvironmentDefault();
+ $pBuilderShort = $pEnvironment->getFieldsCollectionBuilderShort();
+ $pFieldsCollection = new FieldsCollection();
+ $pBuilderShort->addFieldsAddressEstate($pFieldsCollection);
+ $fieldNames = $this->readFieldnamesByContent(onOfficeSDK::MODULE_ADDRESS, $pFieldsCollection);
+ $this->addFieldsConfiguration(onOfficeSDK::MODULE_ADDRESS,
+ self::FORM_VIEW_SORTABLE_FIELDS_CONFIG, $pFormModelBuilder, $fieldNames);
+ $this->addSearchFieldForFieldLists(onOfficeSDK::MODULE_ADDRESS, $pFormModelBuilder);
+ }
+
+ /**
+ *
+ */
+ public function save_form() {
+ $this->buildForms();
+ $action = filter_input( INPUT_POST, 'action' );
+ $nonce = filter_input( INPUT_POST, 'nonce' );
+
+ if ( ! wp_verify_nonce( $nonce, $action ) ) {
+ wp_die();
+ }
+
+ $values = (object) $this->transformPostValues();
+
+ $pInputModelDBAdapterArray = new InputModelOptionAdapterArray();
+
+ foreach ( $this->getFormModels() as $pFormModel ) {
+ foreach ( $pFormModel->getInputModel() as $pInputModel ) {
+ if ( $pInputModel instanceof InputModelOption ) {
+ $identifier = $pInputModel->getIdentifier();
+
+ $value = isset( $values->$identifier ) ? $values->$identifier : null;
+ $pInputModel->setValue( $value );
+ $pInputModelDBAdapterArray->addInputModelOption( $pInputModel );
+ }
+ }
+ }
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $valuesPrefixless = $pInputModelDBAdapterArray->generateValuesArray();
+ $valuesPrefixless = $this->saveField($valuesPrefixless, $values);
+ $pDataDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues( $valuesPrefixless );
+ $success = true;
+
+ try {
+ $pDataAddressDetailViewHandler->saveAddressDetailView( $pDataDetailView );
+ } catch ( Exception $pEx ) {
+ $success = false;
+ }
+
+ $tabQuery = '&tab=' . AdminPageAddress::PAGE_ADDRESS_DETAIL;
+ $statusQuery = $success ? '&saved=true' : '&saved=false';
+
+ wp_redirect( admin_url( 'admin.php?page=onoffice-addresses' . $tabQuery . $statusQuery ) );
+
+ die();
+ }
+
+ /**
+ *
+ */
+ public function doExtraEnqueues()
+ {
+ wp_register_script('admin-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/admin.min.js',
+ array('jquery'), '', true);
+
+ wp_enqueue_script('admin-js');
+ wp_enqueue_script('postbox');
+ wp_register_script( 'oo-copy-shortcode',
+ plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . 'dist/onoffice-copycode.min.js',
+ [ 'jquery' ], '', true );
+ wp_enqueue_script( 'oo-copy-shortcode' );
+ wp_register_script('onoffice-custom-form-label-js',
+ plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true);
+ wp_enqueue_script('onoffice-custom-form-label-js');
+ $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php';
+ wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath));
+ wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath));
+ wp_enqueue_script('onoffice-multiselect');
+ wp_enqueue_style('onoffice-multiselect');
+
+ wp_register_script('oo-unsaved-changes-message', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-unsaved-changes-message.min.js',
+ ['jquery'], '', true);
+ wp_enqueue_script('oo-unsaved-changes-message');
+ }
+
+ /**
+ *
+ */
+ public function handleAdminNotices()
+ {
+ add_action('admin_notices', array($this, 'addAdminNoticeWrapper'));
+ }
+
+ /**
+ * rest will be added via js
+ */
+ public function addAdminNoticeWrapper()
+ {
+ echo '
';
+ }
+
+ /**
+ * @return array
+ */
+ public function getEnqueueData(): array
+ {
+ return array(
+ AdminPageAddress::PARAM_TAB => AdminPageAddress::PAGE_ADDRESS_DETAIL,
+ self::ENQUEUE_DATA_MERGE => array(AdminPageAddress::PARAM_TAB),
+ self::VIEW_UNSAVED_CHANGES_MESSAGE => __('Your changes have not been saved yet! Do you want to leave the page without saving?', 'onoffice-for-wp-websites'),
+ self::VIEW_LEAVE_WITHOUT_SAVING_TEXT => __('Leave without saving', 'onoffice-for-wp-websites'),
+ self::CUSTOM_LABELS => $this->readCustomLabels(),
+ 'label_custom_label' => __('Custom Label: %s', 'onoffice-for-wp-websites')
+ );
+ }
+
+ /**
+ * @param string $module
+ * @param string $groupSlug
+ * @param FormModelBuilderAddressDetailSettings $pFormModelBuilder
+ * @param array $fieldNames
+ * @return void
+ * @throws DependencyException
+ * @throws ExceptionInputModelMissingField
+ * @throws NotFoundException
+ */
+ private function addFieldsConfiguration(string $module, string $groupSlug, FormModelBuilderAddressDetailSettings $pFormModelBuilder,
+ array $fieldNames)
+ {
+ foreach ($fieldNames as $category => $fields) {
+ $slug = $this->generateGroupSlugByModuleCategory($module, $category);
+ $pInputModelFieldsConfig = $pFormModelBuilder->createButtonModelFieldsConfigByCategory
+ ($slug, $fields, $category);
+ $pFormModelFieldsConfig = new FormModel();
+ $pFormModelFieldsConfig->setPageSlug($this->getPageSlug());
+ $pFormModelFieldsConfig->setGroupSlug($slug);
+ $pFormModelFieldsConfig->setLabel($category);
+ $pFormModelFieldsConfig->addInputModel($pInputModelFieldsConfig);
+ $this->addFormModel($pFormModelFieldsConfig);
+ }
+
+ $pInputModelSortableFields = $pFormModelBuilder->createSortableFieldList($module,
+ InputModelBase::HTML_TYPE_COMPLEX_SORTABLE_DETAIL_LIST);
+ $pFormModelSortableFields = new FormModel();
+ $pFormModelSortableFields->setPageSlug($this->getPageSlug());
+ $pFormModelSortableFields->setGroupSlug($groupSlug);
+ $pFormModelSortableFields->addInputModel($pInputModelSortableFields);
+ $this->addFormModel($pFormModelSortableFields);
+ }
+
+ /**
+ * @param InputModelRenderer $pRenderer
+ * @param $pFormViewSearchFieldForFieldLists
+ * @return void
+ * @throws Exception
+ */
+
+ private function renderSearchFieldForFieldLists(InputModelRenderer $pRenderer, $pFormViewSearchFieldForFieldLists)
+ {
+ echo '';
+ echo '
' . __( 'Field list search', 'onoffice-for-wp-websites' ) . ' ';
+ echo '
';
+ $pRenderer->buildForAjax($pFormViewSearchFieldForFieldLists);
+ echo '
';
+ echo '
';
+ }
+
+ /**
+ * @param string $module
+ * @param FormModelBuilderAddressDetailSettings $pFormModelBuilder
+ * @param string $htmlType
+ * @return void
+ * @throws ExceptionInputModelMissingField
+ */
+
+ private function addSearchFieldForFieldLists(string $module, FormModelBuilderAddressDetailSettings $pFormModelBuilder, string $htmlType = InputModelBase::HTML_SEARCH_FIELD_FOR_FIELD_LISTS)
+ {
+ $pInputModelSearchFieldForFieldLists = $pFormModelBuilder->createSearchFieldForFieldLists($module, $htmlType);
+
+ $pFormModelFieldsConfig = new FormModel();
+ $pFormModelFieldsConfig->setPageSlug($this->getPageSlug());
+ $pFormModelFieldsConfig->setGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
+ $pFormModelFieldsConfig->addInputModel($pInputModelSearchFieldForFieldLists);
+ $this->addFormModel($pFormModelFieldsConfig);
+ }
+
+ /**
+ *
+ * @param string $module
+ * @param string $category
+ * @return string
+ *
+ */
+
+ protected function generateGroupSlugByModuleCategory($module, $category): string
+ {
+ return $module.'/'.$category;
+ }
+
+ /**
+ *
+ * @return FieldsCollection
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws UnknownFieldException
+ */
+
+ private function buildFieldsCollectionForCurrentAddress(): FieldsCollection
+ {
+ $pAddressListEnvironmentDefault = new AddressListEnvironmentDefault();
+ $pFieldsCollectionBuilder = $pAddressListEnvironmentDefault->getFieldsCollectionBuilderShort();
+ $pDefaultFieldsCollection = new FieldsCollection();
+ $pFieldsCollectionBuilder->addFieldsAddressEstate($pDefaultFieldsCollection);
+
+ foreach ($pDefaultFieldsCollection->getAllFields() as $pField) {
+ if (!in_array($pField->getModule(), [onOfficeSDK::MODULE_ADDRESS], true)) {
+ $pDefaultFieldsCollection->removeFieldByModuleAndName
+ ($pField->getModule(), $pField->getName());
+ }
+
+ }
+
+ return $pDefaultFieldsCollection;
+ }
+
+ /**
+ * @return array
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws UnknownFieldException
+ */
+ private function readCustomLabels(): array
+ {
+ $result = [];
+ $pDataDetailViewHandler = new DataAddressDetailViewHandler();
+ $dataAddressDetailView = $pDataDetailViewHandler->getAddressDetailView();
+ $pLanguage = $this->getContainer()->get(Language::class);
+
+ foreach ($this->buildFieldsCollectionForCurrentAddress()->getAllFields() as $pField) {
+ $valuesByLocale = $dataAddressDetailView->getCustomLabels();
+ $currentLocale = $pLanguage->getLocale();
+ $valuesByLocale = $valuesByLocale[$pField->getName()] ?? '';
+
+ if (isset($valuesByLocale[$currentLocale])) {
+ $valuesByLocale['native'] = $valuesByLocale[$currentLocale];
+ unset($valuesByLocale[$currentLocale]);
+ }
+ $result[$pField->getName()] = $valuesByLocale;
+ }
+
+ return $result;
+ }
+
+ /**
+ * @param array $valuesPrefixless
+ * @param $values
+ * @return array
+ */
+ private function saveField(array $valuesPrefixless, $values): array
+ {
+ $data = [];
+ $customLabel = (array) ($values->{'customlabel-lang'});
+
+ foreach ($customLabel as $key => $value) {
+ $data[$key] = $this->addLocaleToModelForField($value);
+ }
+
+ $valuesPrefixless['oo_plugin_fieldconfig_address_translated_labels'] = $data;
+
+ return $valuesPrefixless;
+ }
+
+ /**
+ * @param $value
+ * @return array|mixed
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function addLocaleToModelForField($value)
+ {
+ $pLanguage = $this->getContainer()->get( Language::class );
+
+ foreach ($value as $locale => $values) {
+ $value = (array) $value;
+ if ($locale === 'native') {
+ $value[$pLanguage->getLocale()] = $values;
+ unset($value['native']);
+ }
+ }
+
+ return $value;
+ }
+}
diff --git a/plugin/Gui/AdminPageAddressList.php b/plugin/Gui/AdminPageAddressList.php
index c27e4acba..edcad9ad4 100644
--- a/plugin/Gui/AdminPageAddressList.php
+++ b/plugin/Gui/AdminPageAddressList.php
@@ -21,20 +21,10 @@
namespace onOffice\WPlugin\Gui;
-use DI\ContainerBuilder;
-use onOffice\WPlugin\Controller\UserCapabilities;
-use onOffice\WPlugin\Form\BulkDeleteRecord;
use onOffice\WPlugin\Gui\Table\AddressListTable;
-use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
-use onOffice\WPlugin\Record\RecordManagerDeleteListViewEstate;
-use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
-use const ONOFFICE_DI_CONFIG_PATH;
use function __;
-use function add_action;
use function add_filter;
-use function add_query_arg;
use function admin_url;
-use function check_admin_referer;
use function esc_html__;
use function add_screen_option;
@@ -58,7 +48,6 @@ class AdminPageAddressList
public function renderContent()
{
- $this->generatePageMainTitle(__('Addresses', 'onoffice-for-wp-websites'));
$this->_pAddressListTable->prepare_items();
$page = 'onoffice-addresses';
$buttonSearch = __('Search Addresses', 'onoffice-for-wp-websites');
@@ -87,30 +76,15 @@ public function generatePageMainTitle($subTitle)
echo ' › ' . esc_html( $subTitle );
}
- echo '';
+ echo ' › '.esc_html__('List Views', 'onoffice-for-wp-websites');
$newLink = admin_url('admin.php?page=onoffice-editlistviewaddress');
+
+ echo '';
echo ''.esc_html__('Add New', 'onoffice-for-wp-websites').' ';
echo '';
}
- /**
- *
- */
-
- public function handleAdminNotices()
- {
- $itemsDeleted = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_NUMBER_INT);
-
- if ($itemsDeleted !== null && $itemsDeleted !== false) {
- add_action('admin_notices', function() use ($itemsDeleted) {
- $pHandler = new AdminNoticeHandlerListViewDeletion();
- echo $pHandler->handleListView($itemsDeleted);
- });
- }
- }
-
-
/**
*
*/
@@ -124,45 +98,7 @@ public function preOutput()
add_screen_option( 'per_page', array('option' => 'onoffice_address_listview_per_page') );
$this->_pAddressListTable = new AddressListTable();
- $pContainerBuilder = new ContainerBuilder;
- $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
- $pDI = $pContainerBuilder->build();
- $pClosureDeleteAddress = function(string $redirectTo, Table\WP\ListTable $pTable, array $recordIds)
- use ($pDI): string
- {
- /* @var $pBulkDeleteRecord BulkDeleteRecord */
- $pBulkDeleteRecord = $pDI->get(BulkDeleteRecord::class);
- /* @var $pRecordManagerDelete RecordManagerDeleteListViewEstate */
- $pRecordManagerDelete = $pDI->get(RecordManagerDeleteListViewAddress::class);
- if (in_array($pTable->current_action(), ['delete', 'bulk_delete'])) {
- check_admin_referer('bulk-'.$pTable->getArgs()['plural']);
- $itemsDeleted = $pBulkDeleteRecord->delete
- ($pRecordManagerDelete, UserCapabilities::RULE_EDIT_VIEW_ADDRESS, $recordIds);
- $redirectTo = add_query_arg(['delete' => $itemsDeleted],
- admin_url('admin.php?page=onoffice-addresses'));
- }
- return $redirectTo;
- };
-
- add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDeleteAddress, 10, 3);
-
- $pClosureDuplicateAddress = function (string $redirectTo, Table\WP\ListTable $pTable)
- use ($pDI): string {
- if (in_array($pTable->current_action(), ['duplicate', 'bulk_duplicate'])) {
- check_admin_referer('bulk-' . $pTable->getArgs()['plural']);
- if (!(isset($_GET['listViewId']))) {
- wp_die('No List Views for duplicating!');
- }
-
- /* @var $pRecordManagerDuplicateListViewAddress RecordManagerDuplicateListViewAddress */
- $pRecordManagerDuplicateListViewAddress = $pDI->get(RecordManagerDuplicateListViewAddress::class);
- $listViewRootId = $_GET['listViewId'];
- $pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
- }
- return $redirectTo;
- };
-
- add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDuplicateAddress, 10, 3);
+
add_filter('handle_bulk_actions-table-onoffice_page_onoffice-addresses', function(): Table\WP\ListTable {
return $this->_pAddressListTable;
});
@@ -172,6 +108,16 @@ public function preOutput()
public function doExtraEnqueues()
{
+ $translation = array(
+ 'confirmdialog' => __('Are you sure you want to delete the selected items?', 'onoffice-for-wp-websites'),
+ );
+
+ wp_register_script('onoffice-bulk-actions', plugins_url('/dist/onoffice-bulk-actions.min.js',
+ ONOFFICE_PLUGIN_DIR.'/index.php'), array('jquery'));
+
+ wp_localize_script('onoffice-bulk-actions', 'onoffice_table_settings', $translation);
+ wp_enqueue_script('onoffice-bulk-actions');
+
wp_register_script( 'oo-copy-shortcode',
plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . '/dist/onoffice-copycode.min.js',
[ 'jquery' ], '', true );
diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php
index 1e9952dd8..a73f5059a 100644
--- a/plugin/Gui/AdminPageAddressListSettings.php
+++ b/plugin/Gui/AdminPageAddressListSettings.php
@@ -40,6 +40,7 @@
use onOffice\WPlugin\Types\FieldsCollection;
use function __;
use function wp_enqueue_script;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -77,6 +78,13 @@ public function renderContent()
. esc_html__( 'There was a problem saving the address. The Name field cannot be empty.', 'onoffice-for-wp-websites' )
. '
';
}
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the view. Please make '
+ . 'sure the name of the view is unique, even across all address list types.',
+ 'onoffice-for-wp-websites' )
+ . '
';
+ }
parent::renderContent();
}
@@ -253,6 +261,14 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null)
{
$type = RecordManagerFactory::TYPE_ADDRESS;
$result = false;
+ $pDummyAddressDetailView = new DataAddressDetailView();
+
+ if ($row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS]['name'] === $pDummyAddressDetailView->getName()) {
+ // false / null
+ $pResult->result = false;
+ $pResult->record_id = null;
+ return;
+ }
if (array_key_exists('name', $row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS])) {
$row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS]['name'] = $this->sanitizeShortcodeName(
diff --git a/plugin/Gui/AdminPageEstateListSettingsBase.php b/plugin/Gui/AdminPageEstateListSettingsBase.php
index a57103c7d..6b9841dea 100644
--- a/plugin/Gui/AdminPageEstateListSettingsBase.php
+++ b/plugin/Gui/AdminPageEstateListSettingsBase.php
@@ -72,6 +72,13 @@ public function renderContent()
. esc_html__( 'There was a problem saving the list. The Name field cannot be empty.', 'onoffice-for-wp-websites' )
. ' ';
}
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the view. Please make '
+ . 'sure the name of the view is unique, even across all estate list types.',
+ 'onoffice-for-wp-websites' )
+ . '
';
+ }
parent::renderContent();
}
diff --git a/plugin/Gui/AdminPageSettingsBase.php b/plugin/Gui/AdminPageSettingsBase.php
index a4133e291..330d78efe 100644
--- a/plugin/Gui/AdminPageSettingsBase.php
+++ b/plugin/Gui/AdminPageSettingsBase.php
@@ -154,13 +154,6 @@ public function renderContent()
. esc_html__( 'The view has been saved.', 'onoffice-for-wp-websites' )
. ' ';
}
- if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
- echo ''
- . esc_html__( 'There was a problem saving the view. Please make '
- . 'sure the name of the view is unique, even across all estate list types.',
- 'onoffice-for-wp-websites' )
- . '
';
- }
do_action( 'add_meta_boxes', get_current_screen()->id, null );
$this->generateMetaBoxes();
diff --git a/plugin/Installer/Installer.php b/plugin/Installer/Installer.php
index e472eeea7..cd60b4838 100644
--- a/plugin/Installer/Installer.php
+++ b/plugin/Installer/Installer.php
@@ -51,6 +51,8 @@ static public function install()
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
+ $pRewriteRuleBuilder->addCustomRewriteTagsForAddressDetail();
+ $pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
self::flushRules();
}
diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
new file mode 100644
index 000000000..4ee6e4024
--- /dev/null
+++ b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
@@ -0,0 +1,365 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Model\FormModelBuilder;
+
+use function __;
+use DI\NotFoundException;
+use DI\DependencyException;
+use onOffice\WPlugin\Fieldnames;
+use onOffice\WPlugin\Model\FormModel;
+use onOffice\WPlugin\Types\ImageTypes;
+use onOffice\WPlugin\Model\InputModelBase;
+use onOffice\WPlugin\DataView\DataDetailView;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Utility\__String;
+use onOffice\WPlugin\DataView\DataListView;
+use onOffice\WPlugin\Record\RecordManagerReadForm;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\Model\InputModel\InputModelDBFactory;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\InputModel\InputModelOptionFactoryAddressDetailView;
+use onOffice\WPlugin\Model\InputModelDB;
+use onOffice\WPlugin\WP\InstalledLanguageReader;
+use onOffice\WPlugin\Model\InputModelBuilder\InputModelBuilderCustomLabel;
+use DI\ContainerBuilder;
+use DI\Container;
+use onOffice\WPlugin\Types\Field;
+use Exception;
+use onOffice\WPlugin\Controller\Exception\UnknownModuleException;
+use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorReadAddress;
+use onOffice\WPlugin\DataFormConfiguration\UnknownFormException;
+use onOffice\WPlugin\Record\RecordManagerReadListViewEstate;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ * This class must not use InputModelOption!
+ *
+ */
+
+class FormModelBuilderAddressDetailSettings
+ extends FormModelBuilder
+{
+ /** @var InputModelOptionFactoryAddressDetailView */
+ private $_pInputModelAddressDetailFactory = null;
+
+ /** @var DataAddressDetailView */
+ private $_pDataAddressDetail = null;
+
+ /** @var Container */
+ private $_pContainer;
+
+ /**
+ * @param Container|null $pContainer
+ * @param Fieldnames|null $pFieldnames
+ * @throws Exception
+ */
+
+ public function __construct(Container $pContainer = null, Fieldnames $pFieldnames = null)
+ {
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $this->_pContainer = $pContainer ?? $pContainerBuilder->build();
+
+ $pFieldsCollection = new FieldsCollection();
+ $pFieldnames = $pFieldnames ?? new Fieldnames($pFieldsCollection);
+ $pFieldnames->loadLanguage();
+ $this->setFieldnames($pFieldnames);
+ }
+
+ /**
+ * @param string $pageSlug
+ * @return FormModel
+ */
+
+ public function generate(string $pageSlug): FormModel
+ {
+ $this->_pInputModelAddressDetailFactory = new InputModelOptionFactoryAddressDetailView($pageSlug);
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler;
+ $this->_pDataAddressDetail = $pDataAddressDetailViewHandler->getAddressDetailView();
+
+ $pFormModel = new FormModel();
+ $pFormModel->setLabel(__('Address Detail View', 'onoffice-for-wp-websites'));
+ $pFormModel->setGroupSlug('onoffice-address-detail-settings-main');
+ $pFormModel->setPageSlug($pageSlug);
+
+ return $pFormModel;
+ }
+
+ /**
+ * @param string $category
+ * @param array $fieldNames
+ * @param string $categoryLabel
+ * @return InputModelOption
+ */
+
+ public function createInputModelFieldsConfigByCategory($category, $fieldNames, $categoryLabel): InputModelOption
+ {
+ $pInputModelFieldsConfig = new InputModelOption
+ (null, $category, null, InputModelDBFactory::INPUT_FIELD_CONFIG);
+ $pInputModelFieldsConfig->setIsMulti(true);
+
+ $pInputModelFieldsConfig->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX_BUTTON);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNames);
+ $pInputModelFieldsConfig->setId($category);
+ $pInputModelFieldsConfig->setLabel($categoryLabel);
+ $fields = $this->getValue(DataDetailView::FIELDS);
+
+ if (null == $fields)
+ {
+ $fields = array();
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param $module
+ * @param string $htmlType
+ * @return InputModelOption
+ * @throws DependencyException
+ * @throws ExceptionInputModelMissingField
+ * @throws NotFoundException
+ */
+ public function createSortableFieldList($module, string $htmlType): InputModelOption
+ {
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FIELD_CONFIG, null, true);
+
+ $fields = $this->_pDataAddressDetail->getFields();
+ $fieldNames = $this->getFieldnames()->getFieldList($module);
+
+ $fieldNamesArray = [];
+ $pFieldsCollectionUsedFields = new FieldsCollection;
+
+ foreach ($fieldNames as $name => $pField) {
+ $pFields = Field::createByRow($name, $pField);
+ $fieldNamesArray[$pFields->getName()] = $pFields->getAsRow();
+ $pFieldsCollectionUsedFields->addField($pFields);
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+ $pInputModelFieldsConfig->setHtmlType($htmlType);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNamesArray);
+ $pInputModelFieldsConfig->addReferencedInputModel($this->getInputModelCustomLabel($pFieldsCollectionUsedFields));
+ $pInputModelFieldsConfig->addReferencedInputModel($this->getInputModelCustomLabelLanguageSwitch());
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param string $field
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelTemplate(string $field = InputModelOptionFactoryAddressDetailView::INPUT_TEMPLATE)
+ {
+ $labelTemplate = __('Template', 'onoffice-for-wp-websites');
+ $pInputModelTemplate = $this->_pInputModelAddressDetailFactory->create($field, $labelTemplate);
+ $pInputModelTemplate->setHtmlType(InputModelBase::HTML_TYPE_TEMPLATE_LIST);
+ $pInputModelTemplate->setValuesAvailable($this->readTemplatePaths('address'));
+ $pInputModelTemplate->setValue($this->getTemplateValueByField($field));
+
+ return $pInputModelTemplate;
+ }
+
+
+ /**
+ * @param string $field
+ * @return string
+ */
+
+ private function getTemplateValueByField(string $field): string
+ {
+ switch ($field) {
+ case InputModelOptionFactoryAddressDetailView::INPUT_TEMPLATE:
+ return $this->_pDataAddressDetail->getTemplate();
+ default:
+ return '';
+ }
+ }
+
+ /**
+ *
+ * @param string $category
+ * @param array $fieldNames
+ * @param string $categoryLabel
+ * @return InputModelOption
+ *
+ */
+
+ public function createButtonModelFieldsConfigByCategory($category, $fieldNames, $categoryLabel)
+ {
+ $pInputModelFieldsConfig = new InputModelOption
+ (null, $category, null, InputModelDBFactory::INPUT_FIELD_CONFIG);
+ $pInputModelFieldsConfig->setIsMulti(true);
+
+ $pInputModelFieldsConfig->setHtmlType(InputModelBase::HTML_TYPE_BUTTON_FIELD);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNames);
+ $pInputModelFieldsConfig->setId($category);
+ $pInputModelFieldsConfig->setLabel($categoryLabel);
+ $fields = $this->getValue(DataDetailView::FIELDS);
+
+ if ($fields == null) {
+ $fields = array_merge($this->_pDataAddressDetail->getFields());
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ *
+ * @return InputModelOption
+ *
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createInputModelPictureTypes(): InputModelOption
+ {
+ $allPictureTypes = ImageTypes::getImageTypesForAddress();
+
+ $pInputModelPictureTypes = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_PICTURE_TYPE, null, true);
+ $pInputModelPictureTypes->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+ $pInputModelPictureTypes->setValuesAvailable($allPictureTypes);
+ $pictureTypes = $this->_pDataAddressDetail->getPictureTypes();
+
+ if ($pictureTypes == null) {
+ $pictureTypes = array();
+ }
+
+ $pInputModelPictureTypes->setValue($pictureTypes);
+
+ return $pInputModelPictureTypes;
+ }
+
+ /**
+ * @param $module
+ * @param string $htmlType
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createSearchFieldForFieldLists($module, string $htmlType): InputModelOption
+ {
+ $fields = [];
+
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FIELD_CONFIG, null, true);
+ $fields = $this->_pDataAddressDetail->getFields();
+
+ $fieldNames = $this->getFieldnames()->getFieldList($module);
+
+ $pInputModelFieldsConfig->setHtmlType($htmlType);
+ $pInputModelFieldsConfig->setValuesAvailable($this->groupByContent($fieldNames));
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param FieldsCollection $pFieldsCollection
+ * @return InputModelDB
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function getInputModelCustomLabel(FieldsCollection $pFieldsCollection): InputModelDB
+ {
+ $pInputModelBuilder = $this->_pContainer->get(InputModelBuilderCustomLabel::class);
+
+ return $pInputModelBuilder->createInputModelCustomLabel($pFieldsCollection, $this->getValue('customlabel', []));
+ }
+
+ /**
+ * @return InputModelDB
+ */
+ public function getInputModelCustomLabelLanguageSwitch(): InputModelDB
+ {
+ $pInputModel = new InputModelDB('customlabel_newlang',
+ __('Add custom label language', 'onoffice-for-wp-websites'));
+ $pInputModel->setTable('language-custom-label');
+ $pInputModel->setField('language');
+
+ $pLanguageReader = new InstalledLanguageReader;
+ $languages = ['' => __('Choose Language', 'onoffice-for-wp-websites')]
+ + $pLanguageReader->readAvailableLanguageNamesUsingNativeName();
+ $pInputModel->setValuesAvailable(array_diff_key($languages, [get_locale() => []]));
+ $pInputModel->setValueCallback(function (InputModelDB $pInputModel) {
+ $pInputModel->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
+ $pInputModel->setLabel(__('Add custom label language', 'onoffice-for-wp-websites'));
+ });
+
+ return $pInputModel;
+ }
+
+ /**
+ *
+ * @return InputModelOption
+ *
+ * @throws UnknownFormException
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createInputModelShortCodeForm()
+ {
+ $labelShortCodeForm = __('Select Contact Form', 'onoffice-for-wp-websites');
+ $pInputModelShortCodeForm = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHORT_CODE_FORM, $labelShortCodeForm);
+ $pInputModelShortCodeForm->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
+ $nameShortCodeForms = array('' => __('No Contact Form', 'onoffice-for-wp-websites')) + $this->readNameShortCodeForm();
+ $pInputModelShortCodeForm->setValuesAvailable($nameShortCodeForms);
+
+ $pInputModelShortCodeForm->setValue($this->_pDataAddressDetail->getShortCodeForm());
+
+ return $pInputModelShortCodeForm;
+ }
+
+ /**
+ *
+ * @return array
+ *
+ * @throws UnknownFormException
+ */
+
+ private function readNameShortCodeForm(): array
+ {
+ $recordManagerReadForm = $this->_pContainer->get(RecordManagerReadForm::class);
+ $allRecordsForm = $recordManagerReadForm->getAllRecords();
+ $shortCodeForm = array();
+
+ foreach ($allRecordsForm as $value) {
+ $form_name = __String::getNew($value->name);
+ $shortCodeForm[$value->name] = '[oo_form form="' . esc_html($form_name) . '"]';
+ }
+
+ return $shortCodeForm;
+ }
+}
diff --git a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
new file mode 100644
index 000000000..cd0c238b1
--- /dev/null
+++ b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
@@ -0,0 +1,110 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Model\InputModel;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\InputModelOption;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class InputModelOptionFactoryAddressDetailView
+{
+
+ /** */
+ const INPUT_TEMPLATE = 'template';
+
+ /** */
+ const INPUT_FIELD_CONFIG = DataAddressDetailView::FIELDS;
+
+ /** */
+ const INPUT_PICTURE_TYPE = DataAddressDetailView::PICTURES;
+
+ /** */
+ const INPUT_SHORT_CODE_FORM = 'shortcodeform';
+
+ /** */
+ const KEY_TYPE = 'type';
+
+ /** @var string */
+ private $_optionGroup = null;
+
+
+ /** @var array */
+ private $_inputConfig = [
+ self::INPUT_FIELD_CONFIG => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_PICTURE_TYPE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_TEMPLATE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_SHORT_CODE_FORM => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ ];
+
+
+ /**
+ *
+ * @param string $optionGroup
+ *
+ */
+
+ public function __construct(string $optionGroup)
+ {
+ $this->_optionGroup = $optionGroup;
+ }
+
+
+ /**
+ *
+ * @param string $name
+ * @param string $label
+ * @param bool $multi
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ *
+ */
+
+ public function create(string $name, $label, bool $multi = false): InputModelOption
+ {
+ if (!isset($this->_inputConfig[$name])) {
+ throw new ExceptionInputModelMissingField($name);
+ }
+
+ $config = $this->_inputConfig[$name];
+ $type = $config[self::KEY_TYPE];
+
+ $pInstance = new InputModelOption($this->_optionGroup, $name, $label, $type);
+ $pInstance->setIsMulti($multi);
+
+ return $pInstance;
+ }
+}
diff --git a/plugin/Renderer/InputFieldTemplateListRenderer.php b/plugin/Renderer/InputFieldTemplateListRenderer.php
index 715abbc7a..6c64c9b54 100644
--- a/plugin/Renderer/InputFieldTemplateListRenderer.php
+++ b/plugin/Renderer/InputFieldTemplateListRenderer.php
@@ -34,6 +34,7 @@ class InputFieldTemplateListRenderer
{
const TEMPLATE_DEFAULT_LIST = [
'onoffice-editlistviewaddress' => 'default.php',
+ 'onoffice-addresses' => 'default_detail.php',
'onoffice-editlistview' => 'default.php',
'onoffice-editunitlist' => 'default_units.php',
'onoffice-estates' => [
diff --git a/plugin/Types/ImageTypes.php b/plugin/Types/ImageTypes.php
index 426604686..0f061031c 100644
--- a/plugin/Types/ImageTypes.php
+++ b/plugin/Types/ImageTypes.php
@@ -32,6 +32,7 @@ class ImageTypes
const PANORAMA = 'Panorama';
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
+ const PASSPORTPHOTO = 'PassportPhoto';
const IMAGE_TYPES = [
self::TITLE,
@@ -67,4 +68,14 @@ public static function getAllImageTypesTranslated(): array
self::ENERGY_PASS_RANGE => __('Energy-Pass Range', 'onoffice-for-wp-websites'),
];
}
+
+ /**
+ * @return array
+ */
+ public static function getImageTypesForAddress(): array
+ {
+ return [
+ self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
+ ];
+ }
}
diff --git a/tests/TestClassDataAddressDetailView.php b/tests/TestClassDataAddressDetailView.php
new file mode 100644
index 000000000..9fbdffe2d
--- /dev/null
+++ b/tests/TestClassDataAddressDetailView.php
@@ -0,0 +1,86 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use WP_UnitTestCase;
+
+class TestClassDataAddressDetailView
+ extends WP_UnitTestCase
+{
+ /** */
+ const DEFAULT_FIELDS = [
+ 'Anrede',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'Email',
+ 'Telefon1',
+ 'Telefax1',
+ ];
+
+ /**
+ *
+ */
+ public function testDefaultValues()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+
+ $this->assertEquals(self::DEFAULT_FIELDS, $pDataAddressDetailView->getFields());
+ $this->assertEquals('detail', $pDataAddressDetailView->getName());
+ $this->assertEquals(0, $pDataAddressDetailView->getPageId());
+ $this->assertEquals([], $pDataAddressDetailView->getPictureTypes());
+ $this->assertEquals('', $pDataAddressDetailView->getTemplate());
+ $this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $this->assertEquals([], $pDataAddressDetailView->getCustomLabels());
+ }
+
+ /**
+ *
+ */
+ public function testGetterSetter()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+
+ $pDataAddressDetailView->setFields(['testaddressfield1', 'testaddressfield2']);
+ $this->assertEquals(['testaddressfield1', 'testaddressfield2'],
+ $pDataAddressDetailView->getFields());
+ $pDataAddressDetailView->setFields(['testfield1', 'testfield2']);
+ $this->assertEquals(['testfield1', 'testfield2'], $pDataAddressDetailView->getFields());
+ $pDataAddressDetailView->setPageId(12);
+ $this->assertEquals(12, $pDataAddressDetailView->getPageId());
+ $pDataAddressDetailView->setPictureTypes(['testpicturetype1', 'testpicturetype2']);
+ $this->assertEquals(['testpicturetype1', 'testpicturetype2'],
+ $pDataAddressDetailView->getPictureTypes());
+ $pDataAddressDetailView->setTemplate('/test/template1.test');
+ $this->assertEquals('/test/template1.test', $pDataAddressDetailView->getTemplate());
+
+ $pDataAddressDetailView->addToPageIdsHaveDetailShortCode(14);
+ $this->assertEquals([14 => 14], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $pDataAddressDetailView->removeFromPageIdsHaveDetailShortCode(14);
+ $this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $pDataAddressDetailView->setCustomLabels(['field1']);
+ $this->assertEquals(['field1'], $pDataAddressDetailView->getCustomLabels());
+ }
+}
diff --git a/tests/TestClassDataAddressDetailViewHandler.php b/tests/TestClassDataAddressDetailViewHandler.php
new file mode 100644
index 000000000..6c12da083
--- /dev/null
+++ b/tests/TestClassDataAddressDetailViewHandler.php
@@ -0,0 +1,133 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Types\ImageTypes;
+use onOffice\WPlugin\WP\WPOptionWrapperTest;
+use WP_UnitTestCase;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class TestClassDataAddressDetailViewHandler
+ extends WP_UnitTestCase
+{
+ /** */
+ const VALUES_BY_ROW = [
+ 'template' => '/test/template.php',
+ 'fields' => [
+ 'Objektnr_extern',
+ 'wohnflaeche',
+ 'kaufpreis',
+ ],
+ 'pictures' => [
+ ImageTypes::PASSPORTPHOTO,
+ ],
+ 'oo_plugin_fieldconfig_address_translated_labels' => ['field']
+ ];
+
+ /**
+ *
+ */
+
+ public function testCreateAddressDetailViewByValues()
+ {
+ $row = self::VALUES_BY_ROW;
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pDataAddressDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues($row);
+ $this->assertEquals($row['template'], $pDataAddressDetailView->getTemplate());
+ $this->assertEquals($row['fields'], $pDataAddressDetailView->getFields());
+ $this->assertEquals($row['pictures'], $pDataAddressDetailView->getPictureTypes());
+ $this->assertEquals($row['oo_plugin_fieldconfig_address_translated_labels'], $pDataAddressDetailView->getCustomLabels());
+ }
+
+
+ /**
+ *
+ */
+
+ public function testCreateEmptyDetailViewByValues()
+ {
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pDataAddressDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues([]);
+
+ $this->assertEquals($pDataAddressDetailView->getTemplate(), '');
+ $this->assertEquals($pDataAddressDetailView->getFields(), []);
+ $this->assertEquals($pDataAddressDetailView->getPictureTypes(), []);
+ $this->assertEquals($pDataAddressDetailView->getName(), 'detail');
+ $this->assertEquals($pDataAddressDetailView->getPageId(), 0);
+ $this->assertEquals($pDataAddressDetailView->getPageIdsHaveDetailShortCode(), []);
+ }
+
+
+ /**
+ *
+ */
+
+ public function testGetAddressDetailView()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+ $pDataAddressDetailView->setPageId(1337);
+
+ $pWPOptionsWrapper = new WPOptionWrapperTest();
+ $pWPOptionsWrapper->addOption(DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY, $pDataAddressDetailView);
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWPOptionsWrapper);
+
+ $this->assertEquals($pDataAddressDetailView, $pDataAddressDetailViewHandler->getAddressDetailView());
+
+ $pWPOptionsWrapper->deleteOption(DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY);
+
+ // if not set, return a new instance
+ $this->assertEquals(new DataAddressDetailView(), $pDataAddressDetailViewHandler->getAddressDetailView());
+ }
+
+
+ /**
+ *
+ */
+
+ public function testSaveAddressDetailView()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+ $pDataAddressDetailView->setPageId(1337);
+ $optionsKey = DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+ $pWPOptionsWrapper = new WPOptionWrapperTest();
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWPOptionsWrapper);
+ $pDataAddressDetailViewHandler->saveAddressDetailView(clone $pDataAddressDetailView);
+ $this->assertEquals($pDataAddressDetailView, $pWPOptionsWrapper->getOption($optionsKey));
+
+ // test if overwriting works
+ $pDataAddressDetailView->setPageId(1339);
+ $pDataAddressDetailViewHandler->saveAddressDetailView(clone $pDataAddressDetailView);
+ $this->assertEquals($pDataAddressDetailView, $pWPOptionsWrapper->getOption($optionsKey));
+ }
+}
diff --git a/tests/TestClassDetailViewPostSaveController.php b/tests/TestClassDetailViewPostSaveController.php
index b75d0c2b1..691c324c8 100644
--- a/tests/TestClassDetailViewPostSaveController.php
+++ b/tests/TestClassDetailViewPostSaveController.php
@@ -31,6 +31,8 @@
use onOffice\WPlugin\WP\WPOptionWrapperTest;
use onOffice\WPlugin\WP\WPPageWrapper;
use WP_UnitTestCase;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -62,6 +64,15 @@ class TestClassDetailViewPostSaveController extends WP_UnitTestCase
*/
private $_pWPPageWrapper;
+ /**
+ * @var DataAddressDetailViewHandler
+ */
+ private $_pDataAddressDetailViewHandler;
+
+ /**
+ * @var DataAddressDetailView
+ */
+ private $_pDataAddressDetailView;
/**
* @before
@@ -75,13 +86,16 @@ public function prepare()
$this->_pDataDetailViewHandler = new DataDetailViewHandler($pWpOption);
$this->_pDataDetailView = $this->_pDataDetailViewHandler->getDetailView();
$this->_pDataDetailViewHandler->saveDetailView($this->_pDataDetailView);
+ $this->_pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWpOption);
+ $this->_pDataAddressDetailView = $this->_pDataAddressDetailViewHandler->getAddressDetailView();
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView($this->_pDataAddressDetailView);
$this->_pWPPageWrapper = $this->getMockBuilder( WPPageWrapper::class )
->setMethods( [ 'getPageUriByPageId' ] )
->getMock();
$pSubject = new RewriteRuleBuilder( $this->_pDataDetailViewHandler,
- $this->_pWPPageWrapper );
+ $this->_pWPPageWrapper, $this->_pDataAddressDetailViewHandler );
$pDbChanges = new DatabaseChanges($pWpOption, $wpdb);
@@ -99,6 +113,9 @@ public function testReturnNullForTrashStatus()
$this->_pDataDetailView->setPageId( 13 );
$this->_pDataDetailViewHandler->saveDetailView( $this->_pDataDetailView );
+ $this->_pDataAddressDetailView->setPageId( 14 );
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView( $this->_pDataAddressDetailView );
+
$pWPPost = self::factory()->post->create_and_get( [
'post_author' => 1,
'post_content' => '[oo_estate view="detail"]',
@@ -107,7 +124,16 @@ public function testReturnNullForTrashStatus()
'post_status' => 'trash',
] );
+ $pWPPostForAddressDetail = self::factory()->post->create_and_get( [
+ 'post_author' => 1,
+ 'post_content' => '[oo_address view="detail"]',
+ 'post_title' => 'Details',
+ 'post_type' => 'page',
+ 'post_status' => 'trash',
+ ] );
+
$this->assertNull( $this->_pDetailViewPostSaveController->onSavePost( $pWPPost->ID ) );
+ $this->assertNull( $this->_pDetailViewPostSaveController->onSavePost( $pWPPostForAddressDetail->ID ) );
}
@@ -169,4 +195,33 @@ public function testShortCodeInMetaKey()
$detailViewOptions = get_option( DataDetailViewHandler::DEFAULT_VIEW_OPTION_KEY );
$this->assertEquals( $pWPPost->ID, $detailViewOptions->getPageId() );
}
+
+
+ /**
+ *
+ */
+
+ public function testAddreeDetailShortCodeInMetaKey()
+ {
+ $this->_pDataAddressDetailView->setPageId( 14 );
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView( $this->_pDataAddressDetailView );
+
+ $pWPPostForAddressDetail = self::factory()->post->create_and_get( [
+ 'post_author' => 1,
+ 'post_content' => '[oo_address view="detail"]',
+ 'post_title' => 'Test Post',
+ 'post_type' => 'page',
+ ] );
+
+ add_post_meta( $pWPPostForAddressDetail->ID, 'view', '[oo_address view="detail"]' );
+
+ $this->_pWPPageWrapper->method( 'getPageUriByPageId' )
+ ->with( $pWPPostForAddressDetail->ID )
+ ->willReturn( 'test-post' );
+
+ $this->_pDetailViewPostSaveController->onSavePost( $pWPPostForAddressDetail->ID );
+
+ $addressDetailViewOptions = get_option( DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY );
+ $this->assertEquals( $pWPPostForAddressDetail->ID, $addressDetailViewOptions->getPageId() );
+ }
}
\ No newline at end of file
diff --git a/tests/TestClassFormModelBuilderAddressDetailSettings.php b/tests/TestClassFormModelBuilderAddressDetailSettings.php
new file mode 100644
index 000000000..f6dec0a85
--- /dev/null
+++ b/tests/TestClassFormModelBuilderAddressDetailSettings.php
@@ -0,0 +1,247 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use DI\Container;
+use onOffice\WPlugin\Form;
+use onOffice\WPlugin\Record\RecordManagerReadForm;
+use WP_UnitTestCase;
+use DI\ContainerBuilder;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Fieldnames;
+use onOffice\WPlugin\Model\InputModelDB;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\WPlugin\Field\FieldnamesEnvironmentTest;
+use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings;
+
+class TestClassFormModelBuilderAddressDetailSettings
+ extends WP_UnitTestCase
+{
+ /** @var Container */
+ private $_pContainer;
+
+ /** @var Fieldnames */
+ private $_pFieldnames = null;
+
+ /** @var FieldnamesEnvironmentTest */
+ private $_pFieldnamesEnvironment = null;
+
+ /** @var FormModelBuilderAddressDetailSettings */
+ private $_pFormModelBuilderAddressDetailSettings;
+
+ private $_pDataTest;
+
+ /**
+ * @before
+ */
+ public function prepare()
+ {
+ $this->_pFieldnamesEnvironment = new FieldnamesEnvironmentTest();
+ $fieldParameters = [
+ 'labels' => true,
+ 'showContent' => true,
+ 'showTable' => true,
+ 'language' => 'ENG',
+ 'modules' => ['address', 'estate'],
+ 'realDataTypes' => true,
+ ];
+ $pSDKWrapperMocker = $this->_pFieldnamesEnvironment->getSDKWrapper();
+ $responseGetFields = json_decode
+ (file_get_contents(__DIR__ . '/resources/ApiResponseGetFields.json'), true);
+ /* @var $pSDKWrapperMocker SDKWrapperMocker */
+ $pSDKWrapperMocker->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'fields', '', $fieldParameters, null, $responseGetFields);
+ $this->_pFieldnames = new Fieldnames(new FieldsCollection(), false, $this->_pFieldnamesEnvironment);
+
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $this->_pContainer = $pContainerBuilder->build();
+
+ $pRecordManagerReadForm = $this->getMockBuilder(RecordManagerReadForm::class)->getMock();
+ $expectedObject = [(object) $this->getBaseRow(1, Form::TYPE_CONTACT)];
+ $pRecordManagerReadForm->method('getAllRecords')->willReturn($expectedObject);
+ $this->_pContainer->set(RecordManagerReadForm::class, $pRecordManagerReadForm);
+
+ $this->_pFormModelBuilderAddressDetailSettings = new FormModelBuilderAddressDetailSettings($this->_pContainer, $this->_pFieldnames);
+ }
+
+ /**
+ * @param int $formId
+ * @param string $formType
+ *
+ * @return array
+ */
+ private function getBaseRow(int $formId, string $formType): array
+ {
+ return [
+ 'form_id' => $formId,
+ 'name' => 'testForm'.$formId,
+ 'form_type' => $formType,
+ 'template' => 'testtemplate.php',
+ 'recipient' => 'test@my-onoffice.com',
+ 'subject' => 'A Subject',
+ 'createaddress' => '1',
+ 'limitresults' => '30',
+ 'checkduplicates' => '1',
+ 'pages' => '3',
+ 'captcha' => '1',
+ 'newsletter' => '1',
+ 'availableOptions' => '1',
+ 'show_estate_context' => '0',
+ 'contact_type' => '',
+ 'default_recipient' => 'default@my-onoffice.com'
+ ];
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::__construct
+ */
+
+ public function testConstruct()
+ {
+ $pInstance = $this->_pFormModelBuilderAddressDetailSettings;
+ $this->assertInstanceOf(FormModelBuilderAddressDetailSettings::class, $pInstance);
+ }
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSortableFieldList
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabel
+ */
+ public function testCreateSortableFieldList()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSortableFieldList('address', 'complexSortableDetailList');
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'complexSortableDetailList');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSearchFieldForFieldLists
+ */
+ public function testCreateSearchFieldForFieldLists()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSearchFieldForFieldLists('address', 'searchFieldForFieldLists');
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'searchFieldForFieldLists');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelPictureTypes
+ */
+ public function testCreateInputModelPictureTypes()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getValue'])
+ ->getMock();
+ $pInstance->generate('test');
+
+ $pInputModelDB = $pInstance->createInputModelPictureTypes();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'checkbox');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::CreateInputModelTemplate
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getTemplateValueByField
+ */
+ public function testCreateInputModelTemplate()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getValue', 'readTemplatePaths'])
+ ->getMock();
+ $pInstance->expects($this->exactly(1))
+ ->method('readTemplatePaths');
+ $pInstance->generate('test');
+
+ $pInputModelDB = $pInstance->createInputModelTemplate();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'templateList');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelFieldsConfigByCategory
+ */
+ public function testCreateInputModelFieldsConfigByCategory()
+ {
+ $inputModel = $this->_pFormModelBuilderAddressDetailSettings->createInputModelFieldsConfigByCategory('1', ['field1'], 'label');
+ $this->assertEquals('label', $inputModel->getLabel());
+ $this->assertEquals('1', $inputModel->getId());
+ $this->assertEquals(['field1'], $inputModel->getValuesAvailable());
+ $this->assertInstanceOf(InputModelOption::class, $inputModel);
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabelLanguageSwitch
+ */
+ public function testGetInputModelCustomLabelLanguageSwitch()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['readAvailableLanguageNamesUsingNativeName'])
+ ->getMock();
+
+ $inputModel = $pInstance->getInputModelCustomLabelLanguageSwitch();
+ $this->assertInstanceOf(InputModelDB::class, $inputModel);
+ $this->assertEquals('Add custom label language', $inputModel->getLabel());
+ $this->assertEquals('language-custom-label', $inputModel->getTable());
+ $this->assertEquals('language', $inputModel->getField());
+
+ $values = $inputModel->getValuesAvailable();
+
+ $this->assertContains('Choose Language', $values);
+ $this->assertNotContains(get_locale(), $values);
+ }
+
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::generate
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createButtonModelFieldsConfigByCategory
+ */
+ public function testCreateButtonModelFieldsConfigByCategory()
+ {
+ $this->_pFormModelBuilderAddressDetailSettings->generate('test');
+ $inputModel = $this->_pFormModelBuilderAddressDetailSettings->createButtonModelFieldsConfigByCategory('1', ['field1'], 'label');
+ $this->assertEquals('label', $inputModel->getLabel());
+ $this->assertEquals('1', $inputModel->getId());
+ $this->assertEquals(['field1'], $inputModel->getValuesAvailable());
+ $this->assertInstanceOf(InputModelOption::class, $inputModel);
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShortCodeForm
+ */
+ public function testCreateInputModelShortCodeForm1()
+ {
+ $this->_pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelDB = $this->_pFormModelBuilderAddressDetailSettings->createInputModelShortCodeForm();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'select');
+ $this->assertEquals(2, count($pInputModelDB->getValuesAvailable()));
+ }
+}
diff --git a/tests/TestClassImageTypes.php b/tests/TestClassImageTypes.php
index 9abd48f74..3ef024d5b 100644
--- a/tests/TestClassImageTypes.php
+++ b/tests/TestClassImageTypes.php
@@ -60,6 +60,27 @@ public function testGetAllImageTypesTranslated()
$pReflection = new ReflectionClass(ImageTypes::class);
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
+ unset($nameConstants['PASSPORTPHOTO']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}
+
+
+ /**
+ *
+ */
+
+ public function testGetImageTypesForAddress()
+ {
+ $pReflection = new ReflectionClass(ImageTypes::class);
+ $nameConstants = $pReflection->getConstants();
+ unset($nameConstants['TITLE']);
+ unset($nameConstants['PHOTO']);
+ unset($nameConstants['PHOTO_BIG']);
+ unset($nameConstants['PANORAMA']);
+ unset($nameConstants['GROUNDPLAN']);
+ unset($nameConstants['LOCATION_MAP']);
+ unset($nameConstants['ENERGY_PASS_RANGE']);
+ unset($nameConstants['IMAGE_TYPES']);
+ $this->assertEqualSets($nameConstants, array_keys(ImageTypes::getImageTypesForAddress()));
+ }
}
diff --git a/tests/TestClassInputModelOptionFactoryAddressDetailView.php b/tests/TestClassInputModelOptionFactoryAddressDetailView.php
new file mode 100644
index 000000000..f4c91f4d9
--- /dev/null
+++ b/tests/TestClassInputModelOptionFactoryAddressDetailView.php
@@ -0,0 +1,73 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use WP_UnitTestCase;
+use onOffice\WPlugin\Model\InputModel\InputModelOptionFactoryAddressDetailView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class TestClassInputModelOptionFactoryAddressDetailView
+ extends WP_UnitTestCase
+{
+
+ /** @var string */
+ private $_optionGroup = 'onoffice';
+
+ /**
+ *
+ */
+
+ public function testConstruct()
+ {
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $this->assertInstanceOf(InputModelOptionFactoryAddressDetailView::class,
+ $pInputModelOptionFactoryAddressDetailView);
+ }
+
+ public function testCreate()
+ {
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $label = 'Label Test';
+ $pInputModelOption = $pInputModelOptionFactoryAddressDetailView->create('fields', $label);
+
+ $this->assertEquals($pInputModelOption->getOptionGroup(), 'onoffice');
+ $this->assertEquals($pInputModelOption->getName(), 'fields');
+ $this->assertEquals($pInputModelOption->getDescriptionTextHTML(), null);
+ $this->assertEquals($pInputModelOption->getDescriptionRadioTextHTML(), []);
+ }
+
+ public function testNoNameCreate()
+ {
+ $this->expectException(ExceptionInputModelMissingField::class);
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $label = 'Label Test';
+ $pInputModelOptionFactoryAddressDetailView->create('test', $label);
+ }
+}
diff --git a/tests/TestClassRewriteRuleBuilder.php b/tests/TestClassRewriteRuleBuilder.php
index 0f2e26c67..1726c31f3 100644
--- a/tests/TestClassRewriteRuleBuilder.php
+++ b/tests/TestClassRewriteRuleBuilder.php
@@ -31,6 +31,8 @@
use onOffice\WPlugin\DataView\DataDetailView;
use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\WP\WPPageWrapper;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -121,4 +123,57 @@ public function testAddDynamicRewriteRules()
'index.php?pagename=test_parent%2Ftest-post&view=$matches[1]&estate_id=$matches[2]'
], $wp_rewrite->extra_rules_top);
}
+
+ public function testAddCustomRewriteTagsForAddressDetail()
+ {
+ global $wp_rewrite;
+ $wp_rewrite->rewritecode = [];
+ $wp_rewrite->rewritereplace = [];
+ $pSubject = $this->_pContainer->get(RewriteRuleBuilder::class);
+ $pSubject->addCustomRewriteTagsForAddressDetail();
+ $this->assertSame('%address_id%', $wp_rewrite->rewritecode[0]);
+ $this->assertSame('([^&]+)', $wp_rewrite->rewritereplace[0]);
+
+ $this->assertSame('%view%', $wp_rewrite->rewritecode[1]);
+ $this->assertSame('([^&]+)', $wp_rewrite->rewritereplace[1]);
+ }
+
+ /**
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ public function testAddDynamicRewriteRulesForAddressDetail()
+ {
+ global $wp_rewrite;
+ $wp_rewrite->extra_rules_top = [];
+
+ $pDataAddressDetailViewHandler = $this->getMockBuilder(DataAddressDetailViewHandler::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getAddressDetailView'])
+ ->getMock();
+
+ $pDataAdressDetailView = new DataAddressDetailView;
+ $pDataAdressDetailView->addToPageIdsHaveDetailShortCode(13);
+ $pDataAdressDetailView->setPageId(13);
+ $pDataAddressDetailViewHandler->expects($this->once())
+ ->method('getAddressDetailView')
+ ->willReturn($pDataAdressDetailView);
+
+ $pWPPageWrapper = $this->getMockBuilder(WPPageWrapper::class)
+ ->setMethods(['getPageUriByPageId'])
+ ->getMock();
+ $pWPPageWrapper->method('getPageUriByPageId')
+ ->with(13)
+ ->willReturn('test_parent/test-post');
+
+ $this->_pContainer->set(DataAddressDetailViewHandler::class, $pDataAddressDetailViewHandler);
+ $this->_pContainer->set(WPPageWrapper::class, $pWPPageWrapper);
+
+ $pSubject = $this->_pContainer->get(RewriteRuleBuilder::class);
+ $pSubject->addDynamicRewriteRulesForAddressDetail();
+ $this->assertSame([
+ '^(test_parent/test\-post)/([0-9]+)(-([^$]+)?)?/?$' =>
+ 'index.php?pagename=test_parent%2Ftest-post&view=$matches[1]&address_id=$matches[2]'
+ ], $wp_rewrite->extra_rules_top);
+ }
}
\ No newline at end of file
From b8a022038224c5e6a71c80911e00deea9155d729 Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Wed, 29 May 2024 13:36:58 +0700
Subject: [PATCH 07/33] 47945 update config show estate
---
css/admin.css | 3 +
dist/checkbox.min.js | 2 +-
js/checkbox.js | 28 +
plugin.php | 2 +
plugin/Controller/AdminViewController.php | 26 +-
.../DetailViewPostSaveController.php | 78 ++-
plugin/Controller/RewriteRuleBuilder.php | 24 +-
plugin/DataView/DataAddressDetailView.php | 268 ++++++++
.../DataView/DataAddressDetailViewHandler.php | 118 ++++
plugin/DataView/DataListViewAddress.php | 2 +-
plugin/DataView/DataViewAddress.php | 43 ++
plugin/Gui/AdminPageAddress.php | 249 +++++++
plugin/Gui/AdminPageAddressDetail.php | 635 ++++++++++++++++++
plugin/Gui/AdminPageAddressList.php | 82 +--
plugin/Gui/AdminPageAddressListSettings.php | 16 +
.../Gui/AdminPageEstateListSettingsBase.php | 7 +
plugin/Gui/AdminPageSettingsBase.php | 7 -
plugin/Installer/Installer.php | 2 +
.../FormModelBuilderAddressDetailSettings.php | 482 +++++++++++++
...putModelOptionFactoryAddressDetailView.php | 152 +++++
.../InputFieldTemplateListRenderer.php | 1 +
plugin/Types/ImageTypes.php | 11 +
tests/TestClassDataAddressDetailView.php | 91 +++
.../TestClassDataAddressDetailViewHandler.php | 133 ++++
.../TestClassDetailViewPostSaveController.php | 57 +-
...sFormModelBuilderAddressDetailSettings.php | 199 ++++++
tests/TestClassImageTypes.php | 21 +
...putModelOptionFactoryAddressDetailView.php | 73 ++
tests/TestClassRewriteRuleBuilder.php | 55 ++
29 files changed, 2772 insertions(+), 95 deletions(-)
create mode 100644 plugin/DataView/DataAddressDetailView.php
create mode 100644 plugin/DataView/DataAddressDetailViewHandler.php
create mode 100644 plugin/DataView/DataViewAddress.php
create mode 100644 plugin/Gui/AdminPageAddress.php
create mode 100644 plugin/Gui/AdminPageAddressDetail.php
create mode 100644 plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
create mode 100644 plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
create mode 100644 tests/TestClassDataAddressDetailView.php
create mode 100644 tests/TestClassDataAddressDetailViewHandler.php
create mode 100644 tests/TestClassFormModelBuilderAddressDetailSettings.php
create mode 100644 tests/TestClassInputModelOptionFactoryAddressDetailView.php
diff --git a/css/admin.css b/css/admin.css
index 9616884e1..61b84e08b 100644
--- a/css/admin.css
+++ b/css/admin.css
@@ -287,6 +287,7 @@ div[data-name^=oopluginfieldconfigformdefaultsvalues-value].multiselect > input.
#onoffice-form-search-address{
display: flex;
float: right;
+ margin-top: -33px;
}
#onoffice-form-search-form {
display: flex;
@@ -816,10 +817,12 @@ body #post-head-content p.wp-clearfix:nth-child(1) {
width: 100%;
}
+ .oo-poststuff-address-detail .viewusage,
.oo-poststuff-estate-detail .viewusage {
width: 100%;
}
+ .oo-poststuff-address-detail .block-publish,
.oo-poststuff-estate-detail .block-publish,
.oo-poststuff-similar-estate .block-publish {
margin-top: 0;
diff --git a/dist/checkbox.min.js b/dist/checkbox.min.js
index 541010b49..b29aaa010 100644
--- a/dist/checkbox.min.js
+++ b/dist/checkbox.min.js
@@ -1 +1 @@
-var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){var isChosen=receiverElement[0].classList.contains("chosen-select");if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked");if(isChosen){receiverElement.trigger("chosen:updated")}}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled");if(isChosen){receiverElement.trigger("chosen:updated")}}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
+var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name=onoffice-showLinkEstates]":[{element:"select[name=onoffice-referenceEstates]",invert:false},{element:"select[name=onoffice-filterId]",invert:false},{element:"input[name=onoffice-recordsPerPage]",invert:false},{element:"input[name=onoffice-showEstatesStatus]",invert:false},{element:"input[name=onoffice-showPriceOnRequest]",invert:false},{element:"input[name=onoffice-showMap]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){var isChosen=receiverElement[0].classList.contains("chosen-select");if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked");if(isChosen){receiverElement.trigger("chosen:updated")}}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled");if(isChosen){receiverElement.trigger("chosen:updated")}}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
diff --git a/js/checkbox.js b/js/checkbox.js
index 87dc07492..4217cae35 100644
--- a/js/checkbox.js
+++ b/js/checkbox.js
@@ -44,6 +44,34 @@ onOffice.checkboxAdmin = function() {
element: "input[name=oopluginforms-recipient]",
invert: true
}
+ ],
+
+ // view: address detail view
+ "input[name=onoffice-showLinkEstates]": [
+ {
+ element: "select[name=onoffice-referenceEstates]",
+ invert: false
+ },
+ {
+ element: "select[name=onoffice-filterId]",
+ invert: false
+ },
+ {
+ element: "input[name=onoffice-recordsPerPage]",
+ invert: false
+ },
+ {
+ element: "input[name=onoffice-showEstatesStatus]",
+ invert: false
+ },
+ {
+ element: "input[name=onoffice-showPriceOnRequest]",
+ invert: false
+ },
+ {
+ element: "input[name=onoffice-showMap]",
+ invert: false
+ },
]
};
};
diff --git a/plugin.php b/plugin.php
index 590b913cc..cb70a2cd7 100644
--- a/plugin.php
+++ b/plugin.php
@@ -171,6 +171,8 @@
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
+ $pRewriteRuleBuilder->addCustomRewriteTagsForAddressDetail();
+ $pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
});
// This hook [wp] is one effective place to perform any high-level filtering or validation,
diff --git a/plugin/Controller/AdminViewController.php b/plugin/Controller/AdminViewController.php
index 31f2407ed..7acb94a81 100644
--- a/plugin/Controller/AdminViewController.php
+++ b/plugin/Controller/AdminViewController.php
@@ -43,6 +43,7 @@
use onOffice\WPlugin\Utility\__String;
use onOffice\WPlugin\WP\WPPluginChecker;
use onOffice\WPlugin\WP\ListTableBulkActionsHandler;
+use onOffice\WPlugin\Gui\AdminPageAddress;
use Parsedown;
use HTMLPurifier_Config;
use HTMLPurifier;
@@ -93,6 +94,9 @@ class AdminViewController
/** @var AdminPageFormSettingsMain */
private $_pAdminPageFormSettings = null;
+ /** @var AdminPageAddress */
+ private $_pAdminPageAddresses = null;
+
/** */
const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
@@ -127,6 +131,13 @@ public function onInit()
if ($pSelectedSubPage instanceof AdminPageAjax) {
$this->_ajaxHooks['onoffice_page_'.$this->_pageSlug.'-estates'] = $pSelectedSubPage;
}
+
+ $this->_pAdminPageAddresses = new AdminPageAddress($this->_pageSlug);
+ $pSelectedSubPageForAddress = $this->_pAdminPageAddresses->getSelectedAdminPage();
+
+ if ($pSelectedSubPageForAddress instanceof AdminPageAjax) {
+ $this->_ajaxHooks['onoffice_page_'.$this->_pageSlug.'-addresses'] = $pSelectedSubPageForAddress;
+ }
}
@@ -167,11 +178,16 @@ public function register_menu()
__( 'Getting started', 'onoffice-for-wp-websites' ),
$roleMainPage, $this->_pageSlug );
- $pAdminPageAddresses = new AdminPageAddressList($this->_pageSlug);
- $hookAddresses = add_submenu_page( $this->_pageSlug, __('Addresses', 'onoffice-for-wp-websites'), __('Addresses', 'onoffice-for-wp-websites'),
- $roleAddress, $this->_pageSlug.'-addresses', array($pAdminPageAddresses, 'render'));
- add_action('load-'.$hookAddresses, [$pAdminPageAddresses, 'handleAdminNotices']);
- add_action('current_screen', [$pAdminPageAddresses, 'preOutput']);
+ // Addresses
+ $hookAddresses = add_submenu_page( $this->_pageSlug, __('Addresses', 'onoffice-for-wp-websites'),
+ __('Addresses', 'onoffice-for-wp-websites'), $roleAddress,
+ $this->_pageSlug.'-addresses', array($this->_pAdminPageAddresses, 'render'));
+ add_action('load-'.$hookAddresses, [$this->_pAdminPageAddresses, 'handleAdminNotices']);
+ $pSelectedSubPageForAddress = $this->_pAdminPageAddresses->getSelectedAdminPage();
+ if ($pSelectedSubPageForAddress instanceof AdminPageAjax) {
+ add_action( 'load-'.$hookAddresses, array($pSelectedSubPageForAddress, 'checkForms'));
+ }
+ add_action('current_screen', [$this->_pAdminPageAddresses, 'preOutput']);
// Estates
$hookEstates = add_submenu_page( $this->_pageSlug, __('Estates', 'onoffice-for-wp-websites'),
diff --git a/plugin/Controller/DetailViewPostSaveController.php b/plugin/Controller/DetailViewPostSaveController.php
index ec094480e..757ad9b28 100644
--- a/plugin/Controller/DetailViewPostSaveController.php
+++ b/plugin/Controller/DetailViewPostSaveController.php
@@ -29,6 +29,7 @@
use onOffice\WPlugin\Record\RecordManagerReadListViewEstate;
use onOffice\WPlugin\Record\RecordManagerReadListViewAddress;
use onOffice\WPlugin\Record\RecordManagerReadForm;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
use WP_Post;
@@ -104,26 +105,40 @@ public function onSavePost($postId) {
if (!$isRevision) {
$pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class);
$pDetailView = $pDataDetailViewHandler->getDetailView();
+ $pDataAddressDetailViewHandler = $this->_pContainer->get(DataAddressDetailViewHandler::class);
+ $pAddressDetailView = $pDataAddressDetailViewHandler->getAddressDetailView();
$detailViewName = $pDetailView->getName();
+ $addressDetailViewName = $pAddressDetailView->getName();
$postContent = $pPost->post_content;
$postType = $pPost->post_type;
$metaKeys = get_post_meta($postId, '', true);
$viewContained = $this->postContainsViewName($postContent, $detailViewName);
+ $viewContainedAddressDetail = $this->postContainsViewName($postContent, $addressDetailViewName, 'oo_address');
$viewContainedCustomField = false;
$hasOtherShortcodeInPostContent = false;
+ $viewContainedAddressDetailCustomField = false;
+ $hasOtherAddressDetailShortcodeInPostContent = false;
if (!$viewContained && !empty($postContent) && $this->checkOtherShortcodeInPostContent($postContent, $detailViewName)) {
$hasOtherShortcodeInPostContent = true;
}
+ if (!$viewContainedAddressDetail && !empty($postContent) && $this->checkOtherShortcodeInPostContent($postContent, $addressDetailViewName, 'oo_address')) {
+ $hasOtherAddressDetailShortcodeInPostContent = true;
+ }
+
foreach ($metaKeys as $metaKey) {
$viewContainedMetaKey = $this->postContainsViewName($metaKey[0], $detailViewName);
if ($viewContainedMetaKey) {
$viewContainedCustomField = true;
}
+ $viewAddressDetailContainedMetaKey = $this->postContainsViewName($metaKey[0], $addressDetailViewName, 'oo_address');
+ if ($viewAddressDetailContainedMetaKey) {
+ $viewContainedAddressDetailCustomField = true;
+ }
}
if (($viewContained) || ($viewContainedCustomField && $viewContained) || ($viewContainedCustomField && $hasOtherShortcodeInPostContent == false)) {
@@ -146,6 +161,28 @@ public function onSavePost($postId) {
flush_rewrite_rules();
}
}
+
+ if (($viewContainedAddressDetail) || ($viewContainedAddressDetailCustomField && $hasOtherAddressDetailShortcodeInPostContent == false)) {
+ if ($postType == 'page') {
+ $pAddressDetailView->setPageId((int) $postId);
+ $pAddressDetailView->addToPageIdsHaveDetailShortCode((int) $postId);
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
+ flush_rewrite_rules();
+ }
+ } elseif ($pAddressDetailView->getPageId() !== 0) {
+ $postRevisions = wp_get_post_revisions($postId);
+ $detailInPreviousRev = array_key_exists($pAddressDetailView->getPageId(), $postRevisions);
+
+ if ($detailInPreviousRev || $pAddressDetailView->getPageId() === $postId) {
+ $pAddressDetailView->setPageId(0);
+ $pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
+ $this->_pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
+ flush_rewrite_rules();
+ }
+ }
+
$this->addPageUseShortCode($pPost);
$listView = $this->getListView();
$listViewAddress = $this->getListViewAddress();
@@ -209,9 +246,13 @@ public function onMoveTrash() {
$posts = $_GET['post'];
if ( isset( $posts ) ) {
$pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class);
+ $pDataAddressDetailViewHandler = $this->_pContainer->get(DataAddressDetailViewHandler::class);
$pDetailView = $pDataDetailViewHandler->getDetailView();
$detailPageIds = $pDetailView->getPageIdsHaveDetailShortCode();
+ $pAddressDetailView = $pDataAddressDetailViewHandler->getAddressDetailView();
+ $addressDetailPageIds = $pAddressDetailView->getPageIdsHaveDetailShortCode();
$hasDetailPost = false;
+ $hasAddressDetailPost = false;
if ( ! is_array( $posts ) ) {
$posts = [ $posts ];
}
@@ -220,17 +261,31 @@ public function onMoveTrash() {
$pDetailView->removeFromPageIdsHaveDetailShortCode( (int) $postId );
$hasDetailPost = true;
}
+ if (in_array($postId, $addressDetailPageIds)) {
+ $pAddressDetailView->removeFromPageIdsHaveDetailShortCode((int) $postId);
+ $hasAddressDetailPost = true;
+ }
$pPost = get_post( $postId );
$this->deletePageUseShortCode( $pPost );
}
if ( $hasDetailPost ) {
- if ( empty( $pDetailView->getPageIdsHaveDetailShortCode() ) ) {
- $pDetailView->setPageId( 0 );
- } elseif ( in_array( $pDetailView->getPageId(), $posts ) ) {
- $firstDetailPageId = min( array_keys( $detailPageIds ) );
- $pDetailView->setPageId( (int) $detailPageIds[ $firstDetailPageId ] );
+ if (empty($pDetailView->getPageIdsHaveDetailShortCode())) {
+ $pDetailView->setPageId(0);
+ } elseif (in_array($pDetailView->getPageId(), $posts)) {
+ $firstDetailPageId = min(array_keys($detailPageIds));
+ $pDetailView->setPageId((int) $detailPageIds[$firstDetailPageId]);
}
- $pDataDetailViewHandler->saveDetailView( $pDetailView );
+ $pDataDetailViewHandler->saveDetailView($pDetailView);
+ flush_rewrite_rules();
+ }
+ if ( $hasAddressDetailPost ) {
+ if (empty($pAddressDetailView->getPageIdsHaveDetailShortCode())) {
+ $pAddressDetailView->setPageId(0);
+ } elseif (in_array($pAddressDetailView->getPageId(), $posts)) {
+ $firstDetailPageId = min(array_keys( $addressDetailPageIds ));
+ $pAddressDetailView->setPageId((int) $addressDetailPageIds[$firstDetailPageId]);
+ }
+ $pDataAddressDetailViewHandler->saveAddressDetailView($pAddressDetailView);
flush_rewrite_rules();
}
}
@@ -311,13 +366,14 @@ private function getListForm()
*
* @param string $post
* @param string $viewName
+ * @param string $tagShortcode
* @return bool
*
*/
- private function postContainsViewName($post, $viewName) {
+ private function postContainsViewName(string $post, string $viewName, string $tagShortcode = 'oo_estate') {
$matches = array();
- $regex = get_shortcode_regex(array('oo_estate'));
+ $regex = get_shortcode_regex(array($tagShortcode));
preg_match_all('/'.$regex.'/ism', $post, $matches);
$detailviewCode = $this->generateDetailViewCode($viewName);
@@ -338,18 +394,18 @@ private function postContainsViewName($post, $viewName) {
return false;
}
-
/**
*
* @param string $post
* @param string $viewName
+ * @param string $tagShortcode
* @return bool
*
*/
- private function checkOtherShortcodeInPostContent($post, $viewName) {
+ private function checkOtherShortcodeInPostContent(string $post, string $viewName, string $tagShortcode = 'oo_estate') {
$matches = array();
- $regex = get_shortcode_regex(array('oo_estate'));
+ $regex = get_shortcode_regex(array($tagShortcode));
preg_match_all('/' . $regex . '/ism', $post, $matches);
$detailviewCode = $this->generateDetailViewCode($viewName);
diff --git a/plugin/Controller/RewriteRuleBuilder.php b/plugin/Controller/RewriteRuleBuilder.php
index 4df42660a..e9908eec5 100644
--- a/plugin/Controller/RewriteRuleBuilder.php
+++ b/plugin/Controller/RewriteRuleBuilder.php
@@ -25,6 +25,7 @@
use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\WP\WPPageWrapper;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
class RewriteRuleBuilder
{
@@ -34,16 +35,21 @@ class RewriteRuleBuilder
/** @var WPPageWrapper */
private $_pWPPageWrapper;
+ /** @var DataAddressDetailViewHandler */
+ private $_pDataAddressDetailViewHandler;
+
/**
* @param DataDetailViewHandler $pDataDetailViewHandler
* @param WPPageWrapper $pWPPageWrapper
*/
public function __construct(
DataDetailViewHandler $pDataDetailViewHandler,
- WPPageWrapper $pWPPageWrapper)
+ WPPageWrapper $pWPPageWrapper,
+ DataAddressDetailViewHandler $pDataAddressDetailViewHandler)
{
$this->_pDataDetailViewHandler = $pDataDetailViewHandler;
$this->_pWPPageWrapper = $pWPPageWrapper;
+ $this->_pDataAddressDetailViewHandler = $pDataAddressDetailViewHandler;
}
public function addCustomRewriteTags()
@@ -70,4 +76,20 @@ public function addDynamicRewriteRules()
'index.php?pagename=' . urlencode( $pageName ) . '&view=$matches[1]&estate_id=$matches[2]', 'top' );
}
}
+
+ public function addCustomRewriteTagsForAddressDetail()
+ {
+ add_rewrite_tag('%address_id%', '([^&]+)');
+ add_rewrite_tag('%view%', '([^&]+)');
+ }
+
+ public function addDynamicRewriteRulesForAddressDetail()
+ {
+ $detailPageIds = $this->_pDataAddressDetailViewHandler->getAddressDetailView()->getPageIdsHaveDetailShortCode();
+ foreach ( $detailPageIds as $detailPageId ) {
+ $pageName = $this->_pWPPageWrapper->getPageUriByPageId( $detailPageId );
+ add_rewrite_rule( '^(' . preg_quote( $pageName ) . ')/([0-9]+)(-([^$]+)?)?/?$',
+ 'index.php?pagename=' . urlencode( $pageName ) . '&view=$matches[1]&address_id=$matches[2]', 'top' );
+ }
+ }
}
\ No newline at end of file
diff --git a/plugin/DataView/DataAddressDetailView.php b/plugin/DataView/DataAddressDetailView.php
new file mode 100644
index 000000000..a17443029
--- /dev/null
+++ b/plugin/DataView/DataAddressDetailView.php
@@ -0,0 +1,268 @@
+.
+ *
+ */
+
+declare(strict_types=1);
+
+namespace onOffice\WPlugin\DataView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class DataAddressDetailView
+ implements DataViewAddress
+{
+ /** */
+ const FIELDS = 'fields';
+
+ /** */
+ const ESTATE_FIELDS = 'estateFields';
+
+ /** */
+ const TEMPLATE = 'template';
+
+ /** */
+ const PICTURES = 'pictures';
+
+ /** */
+ const SHOW_ESTATES_STATUS = 'showEstatesStatus';
+
+ /** */
+ const SHOW_LINK_ESTATES = 'showLinkEstates';
+
+ /** */
+ const REFERENCE_ESTATES = 'referenceEstates';
+
+ /** */
+ const INPUT_FILTERID = 'filterId';
+
+ /** */
+ const RECORDS_PER_PAGE = 'recordsPerPage';
+
+ /** */
+ const SHOW_PRICE_ON_REQUEST = 'showPriceOnRequest';
+
+ /** */
+ const SHOW_ESTATES_MAP = 'showMap';
+
+ /** */
+ const FIELD_CUSTOM_LABEL = 'oo_plugin_fieldconfig_address_translated_labels';
+
+ /** @var string[] */
+ private $_fields = [
+ 'Anrede',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'Email',
+ 'Telefon1',
+ 'Telefax1',
+ ];
+
+ /** @var string[] */
+ private $_estateFields = [
+ 'objekttitel',
+ 'objektart',
+ 'objekttyp',
+ 'vermarktungsart',
+ 'plz',
+ 'ort',
+ 'objektnr_extern',
+ 'wohnflaeche',
+ 'grundstuecksflaeche',
+ 'nutzflaeche',
+ 'anzahl_zimmer',
+ 'anzahl_badezimmer',
+ 'kaufpreis',
+ 'kaltmiete',
+ 'objektbeschreibung',
+ 'lage',
+ 'ausstatt_beschr',
+ 'sonstige_angaben',
+ 'baujahr',
+ 'endenergiebedarf',
+ 'energieverbrauchskennwert',
+ 'energieausweistyp',
+ 'energieausweis_gueltig_bis',
+ 'energyClass',
+ 'aussen_courtage',
+ 'kaution',
+ ];
+
+ /** @var string[] */
+ private $_pictureTypes = [];
+
+ /** @var string */
+ private $_template = '';
+
+ /** @var int */
+ private $_pageId = 0;
+
+ /** @var array */
+ private $_pageIdsHaveDetailShortCode = [];
+
+ /** @var array */
+ private $_customLabel = [];
+
+ /** @var int */
+ private $_showEstateStatus = 0;
+
+ /** @var int */
+ private $_showLinkEstates = 0;
+
+ /** @var string */
+ private $_showReferenceEstates = '0';
+
+ /** @var int */
+ private $_filter = '';
+
+ /** @var int */
+ private $_numberRecordsPerPage = 5;
+
+ /** @var int */
+ private $_showPriceOnRequest = 0;
+
+ /** @var int */
+ private $_showEstatesMap = 0;
+
+ /** @return int */
+ public function getPageId(): int
+ { return $this->_pageId; }
+
+ /** @param int $pageId */
+ public function setPageId(int $pageId)
+ { $this->_pageId = $pageId; }
+
+ /** @return string */
+ public function getName(): string
+ { return 'detail'; }
+
+ /** @return string[] */
+ public function getFields(): array
+ { return $this->_fields; }
+
+ /** @return string[] */
+ public function getEstateFields(): array
+ { return $this->_estateFields; }
+
+ /** @param array $estateFields */
+ public function setEstateFields(array $estateFields)
+ { $this->_estateFields = $estateFields; }
+
+ /** @return array */
+ public function getPictureTypes(): array
+ { return $this->_pictureTypes; }
+
+ /** @return string */
+ public function getTemplate(): string
+ { return $this->_template; }
+
+ /** @param array $fields */
+ public function setFields(array $fields)
+ { $this->_fields = $fields; }
+
+ /** @param array $pictureTypes */
+ public function setPictureTypes(array $pictureTypes)
+ { $this->_pictureTypes = $pictureTypes; }
+
+ /** @param string $template */
+ public function setTemplate(string $template)
+ { $this->_template = $template; }
+
+ /** @return array */
+ public function getPageIdsHaveDetailShortCode(): array
+ { return $this->_pageIdsHaveDetailShortCode; }
+
+ /** @param int $pageId */
+ public function addToPageIdsHaveDetailShortCode(int $pageId)
+ { $this->_pageIdsHaveDetailShortCode[$pageId] = $pageId; }
+
+ /** @param int $pageId */
+ public function removeFromPageIdsHaveDetailShortCode(int $pageId)
+ { unset($this->_pageIdsHaveDetailShortCode[$pageId]); }
+
+ /** @return array */
+ public function getCustomLabels()
+ { return $this->_customLabel; }
+
+ /** @param array $customLabel */
+ public function setCustomLabels(array $customLabel)
+ { $this->_customLabel = $customLabel; }
+
+ /** @return int */
+ public function getShowEstateStatus(): int
+ { return $this->_showEstateStatus;}
+
+ /** @param int $estateStatus */
+ public function setShowEstateStatus(int $estateStatus)
+ { $this->_showEstateStatus = $estateStatus; }
+
+ /** @return int */
+ public function getShowLinkEstates(): int
+ { return $this->_showLinkEstates; }
+
+ /** @param int $showLinkEstates */
+ public function setShowLinkEstates(int $showLinkEstates)
+ { $this->_showLinkEstates = $showLinkEstates; }
+
+ /** @return string */
+ public function getShowReferenceEstate(): string
+ { return $this->_showReferenceEstates; }
+
+ /** @param string $referenceEstate */
+ public function setShowReferenceEstate(string $referenceEstate)
+ { $this->_showReferenceEstates = $referenceEstate; }
+
+ /** @return string */
+ public function getFilter(): string
+ { return $this->_filter; }
+
+ /** @param string $filter */
+ public function setFilter(string $filter)
+ { $this->_filter = $filter; }
+
+ /** @return int */
+ public function getRecordsPerPage(): int
+ { return $this->_numberRecordsPerPage; }
+
+ /** @param int $numberRecords */
+ public function setRecordsPerPage(int $numberRecords)
+ { $this->_numberRecordsPerPage = $numberRecords; }
+
+ /** @return int */
+ public function getShowPriceOnRequest(): int
+ { return $this->_showPriceOnRequest; }
+
+ /** @param int $showPriceOnRequest */
+ public function setShowPriceOnRequest(int $showPriceOnRequest)
+ { $this->_showPriceOnRequest = $showPriceOnRequest; }
+
+ /** @return int */
+ public function getShowEstateMap(): int
+ { return $this->_showEstatesMap; }
+
+ /** @param int $showEstatesMap */
+ public function setShowEstateMap(int $showEstatesMap)
+ { $this->_showEstatesMap = $showEstatesMap; }
+}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
new file mode 100644
index 000000000..27fac18d9
--- /dev/null
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -0,0 +1,118 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\DataView;
+
+use onOffice\WPlugin\WP\WPOptionWrapperBase;
+use onOffice\WPlugin\WP\WPOptionWrapperDefault;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class DataAddressDetailViewHandler
+{
+ /** */
+ const DEFAULT_ADDRESS_VIEW_OPTION_KEY = 'onoffice-default-address-view';
+
+ /** @var WPOptionWrapperBase */
+ private $_pWPOptionWrapper;
+
+
+ /**
+ * @param WPOptionWrapperBase $pWPOptionWrapper
+ */
+ public function __construct(WPOptionWrapperBase $pWPOptionWrapper = null)
+ {
+ $this->_pWPOptionWrapper = $pWPOptionWrapper ?? new WPOptionWrapperDefault();
+ }
+
+
+ /**
+ *
+ * @return DataAddressDetailView
+ *
+ */
+
+ public function getAddressDetailView(): DataAddressDetailView
+ {
+ $optionKey = self::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+ $pAlternate = new DataAddressDetailView();
+ $pResult = $this->_pWPOptionWrapper->getOption($optionKey, $pAlternate);
+
+ if ($pResult == null) {
+ $pResult = $pAlternate;
+ }
+
+ return $pResult;
+ }
+
+
+ /**
+ *
+ * @param DataAddressDetailView $pDataAddressDetailView
+ *
+ */
+
+ public function saveAddressDetailView(DataAddressDetailView $pDataAddressDetailView)
+ {
+ $pWpOptionsWrapper = $this->_pWPOptionWrapper;
+ $viewOptionKey = self::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+
+ if ($pWpOptionsWrapper->getOption($viewOptionKey) !== false) {
+ $pWpOptionsWrapper->updateOption($viewOptionKey, $pDataAddressDetailView);
+ } else {
+ $pWpOptionsWrapper->addOption($viewOptionKey, $pDataAddressDetailView);
+ }
+ }
+
+
+ /**
+ *
+ * @param array $row
+ * @return DataAddressDetailView
+ *
+ */
+
+ public function createAddressDetailViewByValues(array $row): DataAddressDetailView
+ {
+ $pDataAddressDetailView = $this->getAddressDetailView();
+ $pDataAddressDetailView->setTemplate($row[DataAddressDetailView::TEMPLATE] ?? '');
+ $pDataAddressDetailView->setFields($row[DataAddressDetailView::FIELDS] ?? []);
+ $pDataAddressDetailView->setEstateFields($row[DataAddressDetailView::ESTATE_FIELDS] ?? []);
+ $pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
+ $pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
+ $pDataAddressDetailView->setShowEstateStatus($row[DataAddressDetailView::SHOW_ESTATES_STATUS] ?? 0);
+ $pDataAddressDetailView->setShowLinkEstates($row[DataAddressDetailView::SHOW_LINK_ESTATES] ?? 0);
+ $pDataAddressDetailView->setShowReferenceEstate($row[DataAddressDetailView::REFERENCE_ESTATES] ?? '0');
+ $pDataAddressDetailView->setFilter($row[DataAddressDetailView::INPUT_FILTERID] ?? '');
+ $pDataAddressDetailView->setRecordsPerPage($row[DataAddressDetailView::RECORDS_PER_PAGE] ?? 0);
+ $pDataAddressDetailView->setShowPriceOnRequest($row[DataAddressDetailView::SHOW_PRICE_ON_REQUEST] ?? 0);
+ $pDataAddressDetailView->setShowEstateMap($row[DataAddressDetailView::SHOW_ESTATES_MAP] ?? 0);
+
+ return $pDataAddressDetailView;
+ }
+}
\ No newline at end of file
diff --git a/plugin/DataView/DataListViewAddress.php b/plugin/DataView/DataListViewAddress.php
index ca46167be..18c5925ff 100644
--- a/plugin/DataView/DataListViewAddress.php
+++ b/plugin/DataView/DataListViewAddress.php
@@ -34,7 +34,7 @@
*/
class DataListViewAddress
- implements DataViewFilterableFields, ViewProperty
+ implements DataViewFilterableFields, ViewProperty, DataViewAddress
{
/** */
const FIELDS = 'fields';
diff --git a/plugin/DataView/DataViewAddress.php b/plugin/DataView/DataViewAddress.php
new file mode 100644
index 000000000..af0865a80
--- /dev/null
+++ b/plugin/DataView/DataViewAddress.php
@@ -0,0 +1,43 @@
+.
+ *
+ */
+
+declare(strict_types=1);
+
+namespace onOffice\WPlugin\DataView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+interface DataViewAddress
+{
+ /** @return array */
+ public function getFields(): array;
+
+ /** @return string */
+ public function getTemplate(): string;
+
+ /** @return string */
+ public function getName(): string;
+}
diff --git a/plugin/Gui/AdminPageAddress.php b/plugin/Gui/AdminPageAddress.php
new file mode 100644
index 000000000..1773a6317
--- /dev/null
+++ b/plugin/Gui/AdminPageAddress.php
@@ -0,0 +1,249 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Gui;
+
+use DI\ContainerBuilder;
+use onOffice\WPlugin\Controller\UserCapabilities;
+use onOffice\WPlugin\Form\BulkDeleteRecord;
+use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
+use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
+use const ONOFFICE_DI_CONFIG_PATH;
+use function __;
+use function add_action;
+use function add_filter;
+use function add_query_arg;
+use function admin_url;
+use function check_admin_referer;
+use Exception;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class AdminPageAddress
+ extends AdminPage
+{
+ /** */
+ const PAGE_ADDRESS_LIST = 'list';
+
+ /** */
+ const PAGE_ADDRESS_DETAIL = 'detail';
+
+ /** @var string[] */
+ private $_subPageClassByTab = array(
+ self::PAGE_ADDRESS_LIST => AdminPageAddressList::class,
+ self::PAGE_ADDRESS_DETAIL => AdminPageAddressDetail::class,
+ );
+
+ /** */
+ const PARAM_TAB = 'tab';
+
+ /** @var array */
+ private $_tabs = array();
+
+ /** @var AdminPage */
+ private $_pSelectedTab = null;
+
+ /**
+ * @param string $pageSlug
+ * @throws Exception
+ */
+
+ public function __construct($pageSlug)
+ {
+ $this->_tabs = array(
+ self::PAGE_ADDRESS_LIST => __('Address Views', 'onoffice-for-wp-websites'),
+ self::PAGE_ADDRESS_DETAIL => __('Detail View', 'onoffice-for-wp-websites'),
+ );
+
+ parent::__construct($pageSlug);
+
+ $selectedTab = $this->getSelectedTab();
+ $this->_pSelectedTab = $this->getAdminPageForTab($selectedTab);
+ }
+
+ /**
+ *
+ * @return string
+ *
+ */
+
+ private function getSelectedTab()
+ {
+ $selectedTab = $this->getDefaultTab();
+ $getParamTab = filter_input(INPUT_GET, self::PARAM_TAB);
+ $postParamTab = filter_input(INPUT_POST, self::PARAM_TAB);
+ if (!is_null($getParamTab)) {
+ $selectedTab = $getParamTab;
+ } elseif (!is_null($postParamTab)) {
+ $selectedTab = $postParamTab;
+ }
+
+ return $selectedTab;
+ }
+
+
+ /**
+ *
+ * @param string $tab
+ * @return AdminPage
+ *
+ */
+
+ private function getAdminPageForTab(string $tab)
+ {
+ if (!isset($this->_subPageClassByTab[$tab])) {
+ $tab = self::PAGE_ADDRESS_LIST;
+ }
+
+ $className = $this->_subPageClassByTab[$tab];
+ $pAdminPage = new $className($this->getPageSlug());
+
+ return $pAdminPage;
+ }
+
+
+ /**
+ *
+ */
+
+ public function renderContent()
+ {
+ $selectedTab = $this->getSelectedTab();
+ $defaultTab = $this->getDefaultTab();
+ $this->_pSelectedTab->generatePageMainTitle(__('Addresses', 'onoffice-for-wp-websites'));
+
+ echo '';
+ $adminUrl = admin_url('admin.php?page=onoffice-addresses');
+
+ foreach ($this->_tabs as $index => $label)
+ {
+ $newAdminUrl = ($index != $defaultTab) ? add_query_arg('tab', $index, $adminUrl) : $adminUrl;
+ $class = ($index === $selectedTab) ? ' nav-tab-active' : '';
+ echo ''.esc_html($label).' ';
+ }
+ echo ' ';
+ echo $this->_pSelectedTab->renderContent();
+ }
+
+ /**
+ *
+ * @return string
+ *
+ */
+
+ private function getDefaultTab()
+ {
+ return self::PAGE_ADDRESS_LIST;
+ }
+
+
+ /**
+ *
+ */
+
+ public function handleAdminNotices()
+ {
+ $this->_pSelectedTab->handleAdminNotices();
+ $itemsDeleted = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_NUMBER_INT);
+
+ if ($itemsDeleted !== null && $itemsDeleted !== false) {
+ add_action('admin_notices', function() use ($itemsDeleted) {
+ $pHandler = new AdminNoticeHandlerListViewDeletion();
+ echo $pHandler->handleListView($itemsDeleted);
+ });
+ }
+ }
+
+
+ /**
+ *
+ */
+
+ public function preOutput()
+ {
+ $this->_pSelectedTab->preOutput();
+
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $pDI = $pContainerBuilder->build();
+ $pClosureDeleteAddress = function(string $redirectTo, Table\WP\ListTable $pTable, array $recordIds) use ($pDI): string {
+ /* @var $pBulkDeleteRecord BulkDeleteRecord */
+ $pBulkDeleteRecord = $pDI->get(BulkDeleteRecord::class);
+ /* @var $pRecordManagerDelete RecordManagerDeleteListViewAddress */
+ $pRecordManagerDelete = $pDI->get(RecordManagerDeleteListViewAddress::class);
+ if (in_array($pTable->current_action(), ['delete', 'bulk_delete'])) {
+ check_admin_referer('bulk-'.$pTable->getArgs()['plural']);
+ $itemsDeleted = $pBulkDeleteRecord->delete
+ ($pRecordManagerDelete, UserCapabilities::RULE_EDIT_VIEW_ADDRESS, $recordIds);
+ $redirectTo = add_query_arg(['delete' => $itemsDeleted],
+ admin_url('admin.php?page=onoffice-addresses'));
+ }
+ return $redirectTo;
+ };
+
+ add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDeleteAddress, 10, 3);
+
+ $pClosureDuplicateAddress = function (string $redirectTo, Table\WP\ListTable $pTable) use ($pDI): string {
+ if (in_array($pTable->current_action(), ['duplicate', 'bulk_duplicate'])) {
+ check_admin_referer('bulk-' . $pTable->getArgs()['plural']);
+ if (!(isset($_GET['listViewId']))) {
+ wp_die('No List Views for duplicating!');
+ }
+
+ /* @var $pRecordManagerDuplicateListViewAddress RecordManagerDuplicateListViewAddress */
+ $pRecordManagerDuplicateListViewAddress = $pDI->get(RecordManagerDuplicateListViewAddress::class);
+ $listViewRootId = $_GET['listViewId'];
+ $pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
+ }
+ return $redirectTo;
+ };
+
+ add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDuplicateAddress, 10, 3);
+
+ parent::preOutput();
+ }
+
+ /**
+ *
+ * @return AdminPage
+ *
+ */
+
+ public function getSelectedAdminPage()
+ {
+ return $this->_pSelectedTab;
+ }
+
+
+ /**
+ *
+ */
+
+ public function doExtraEnqueues()
+ {
+ $this->_pSelectedTab->doExtraEnqueues();
+ }
+}
diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php
new file mode 100644
index 000000000..8dab48401
--- /dev/null
+++ b/plugin/Gui/AdminPageAddressDetail.php
@@ -0,0 +1,635 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Gui;
+
+use DI\DependencyException;
+use DI\NotFoundException;
+use Exception;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Controller\Exception\UnknownModuleException;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\FormModel;
+use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings;
+use onOffice\WPlugin\Model\InputModelBase;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Model\InputModelOptionAdapterArray;
+use onOffice\WPlugin\Renderer\InputModelRenderer;
+use onOffice\WPlugin\Types\FieldsCollection;
+use function __;
+use function add_action;
+use function do_accordion_sections;
+use function do_action;
+use function do_meta_boxes;
+use function do_settings_sections;
+use function esc_attr;
+use function esc_html;
+use function esc_html__;
+use function get_current_screen;
+use function plugin_dir_url;
+use function wp_die;
+use function wp_enqueue_script;
+use function wp_nonce_field;
+use function wp_register_script;
+use function wp_verify_nonce;
+use const ONOFFICE_PLUGIN_DIR;
+use onOffice\WPlugin\Controller\AddressListEnvironmentDefault;
+use onOffice\WPlugin\Language;
+use onOffice\WPlugin\Field\UnknownFieldException;
+
+/**
+ *
+ */
+
+class AdminPageAddressDetail
+ extends AdminPageAjax
+{
+ /** */
+ const FORM_VIEW_LAYOUT_DESIGN = 'viewlayoutdesign';
+
+ /** */
+ const FORM_VIEW_PICTURE_TYPES = 'viewpicturetypes';
+
+ /** */
+ const FORM_VIEW_SORTABLE_FIELDS_CONFIG = 'viewSortableFieldsConfig';
+
+ /** */
+ const FORM_VIEW_CONTACT_DATA_FIELDS = 'viewcontactdatafields';
+
+ /** */
+ const FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG = 'viewSearchFieldForFieldListsConfig';
+
+ /** */
+ const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
+
+ /** */
+ const VIEW_LEAVE_WITHOUT_SAVING_TEXT = 'view_leave_without_saving_text';
+
+ /** */
+ const CUSTOM_LABELS = 'customlabels';
+
+ /** */
+ const FORM_VIEW_ESTATE_CONFIG = 'viewEstatesConfig';
+
+ /**
+ *
+ */
+
+ public function renderContent()
+ {
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'true' ) {
+ echo ''
+ . esc_html__( 'The address detail view has been saved.', 'onoffice-for-wp-websites' )
+ . '
';
+ }
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the address detail view.', 'onoffice-for-wp-websites' )
+ . '
';
+ }
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pAddressDataView = $pDataAddressDetailViewHandler->getAddressDetailView();
+
+ do_action('add_meta_boxes', get_current_screen()->id, null);
+ $this->generateMetaBoxes();
+
+ /* @var $pRenderer InputModelRenderer */
+ $pRenderer = $this->getContainer()->get(InputModelRenderer::class);
+ $pFormViewSortableFields = $this->getFormModelByGroupSlug(self::FORM_VIEW_SORTABLE_FIELDS_CONFIG);
+ $pFormViewSearchFieldForFieldLists = $this->getFormModelByGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
+ $pFormViewSortableContactFields = $this->getFormModelByGroupSlug(self::FORM_VIEW_CONTACT_DATA_FIELDS);
+
+ echo '';
+ }
+
+
+ /**
+ *
+ * @param string $subTitle
+ *
+ */
+
+ public function generatePageMainTitle($subTitle)
+ {
+ echo ''.esc_html__('onOffice', 'onoffice-for-wp-websites');
+ echo ' › ' . esc_html( $subTitle );
+ echo ' › '.esc_html__('Detail View', 'onoffice-for-wp-websites');
+ echo ' ';
+ echo '';
+ }
+
+
+ /**
+ *
+ */
+
+ private function generateMetaBoxes()
+ {
+ $pFormPictureTypes = $this->getFormModelByGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
+ $this->createMetaBoxByForm($pFormPictureTypes, 'side');
+
+ $pFormLayoutDesign = $this->getFormModelByGroupSlug(self::FORM_VIEW_LAYOUT_DESIGN);
+ $this->createMetaBoxByForm($pFormLayoutDesign, 'normal');
+
+ $pFormEstateConfig = $this->getFormModelByGroupSlug(self::FORM_VIEW_ESTATE_CONFIG);
+ $this->createMetaBoxByForm($pFormEstateConfig, 'side');
+ }
+
+ /**
+ * @return void
+ */
+ protected function generateAccordionBoxes()
+ {
+ $fieldNames = array_keys($this->readFieldnamesByContent(onOfficeSDK::MODULE_ADDRESS));
+
+ foreach ($fieldNames as $category) {
+ $slug = $this->generateGroupSlugByModuleCategory(onOfficeSDK::MODULE_ADDRESS, $category);
+ $pFormFieldsConfig = $this->getFormModelByGroupSlug($slug);
+ if (!is_null($pFormFieldsConfig))
+ {
+ $this->createMetaBoxByForm($pFormFieldsConfig, 'contactperson');
+ }
+ }
+ }
+
+ protected function generateAccordionBoxesForEstateFields()
+ {
+ $fieldNames = array_keys($this->readFieldnamesByContent(onOfficeSDK::MODULE_ESTATE));
+
+ foreach ($fieldNames as $category) {
+ $slug = $this->generateGroupSlugByModuleCategory(onOfficeSDK::MODULE_ESTATE, $category);
+ $pFormFieldsConfig = $this->getFormModelByGroupSlug($slug);
+ if (!is_null($pFormFieldsConfig))
+ {
+ $this->createMetaBoxByForm($pFormFieldsConfig, 'estatedata');
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ protected function buildForms()
+ {
+ $pFormModelBuilder = $this->getContainer()->get(FormModelBuilderAddressDetailSettings::class);
+ $pFormModel = $pFormModelBuilder->generate($this->getPageSlug());
+ $this->addFormModel($pFormModel);
+
+ $pInputModelTemplate = $pFormModelBuilder->createInputModelTemplate();
+ $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);
+ $this->addFormModel($pFormModelLayoutDesign);
+
+ $pInputModelPictureTypes = $pFormModelBuilder->createInputModelPictureTypes();
+ $pFormModelPictureTypes = new FormModel();
+ $pFormModelPictureTypes->setPageSlug($this->getPageSlug());
+ $pFormModelPictureTypes->setGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
+ $pFormModelPictureTypes->setLabel(__('Photo Types', 'onoffice-for-wp-websites'));
+ $pFormModelPictureTypes->addInputModel($pInputModelPictureTypes);
+ $this->addFormModel($pFormModelPictureTypes);
+
+ $pInputModelLinkEstates = $pFormModelBuilder->createInputModelShowLinkEstates();
+ $pInputModelEstatesStatus = $pFormModelBuilder->createInputModelShowEstatesStatus();
+ $pInputModelListReferenceEstates = $pFormModelBuilder->createInputModelShowReferenceEstates();
+ $pInputModelFilters = $pFormModelBuilder->createInputModelFilter();
+ $pInputModelRecordsPerPage = $pFormModelBuilder->createInputModelRecordsPerPage();
+ $pInputModelPriceOnRequest = $pFormModelBuilder->createInputModelShowPriceOnRequest();
+ $pInputModelEstateMap = $pFormModelBuilder->createInputModelShowMap();
+ $pFormModelEstates = new FormModel();
+ $pFormModelEstates->setPageSlug($this->getPageSlug());
+ $pFormModelEstates->setGroupSlug(self::FORM_VIEW_ESTATE_CONFIG);
+ $pFormModelEstates->setLabel(__('Estates', 'onoffice-for-wp-websites'));
+ $pFormModelEstates->addInputModel($pInputModelLinkEstates);
+ $pFormModelEstates->addInputModel($pInputModelListReferenceEstates);
+ $pFormModelEstates->addInputModel($pInputModelFilters);
+ $pFormModelEstates->addInputModel($pInputModelRecordsPerPage);
+ $pFormModelEstates->addInputModel($pInputModelEstatesStatus);
+ $pFormModelEstates->addInputModel($pInputModelPriceOnRequest);
+ $pFormModelEstates->addInputModel($pInputModelEstateMap);
+ $this->addFormModel($pFormModelEstates);
+
+ $pEnvironment = new AddressListEnvironmentDefault();
+ $pBuilderShort = $pEnvironment->getFieldsCollectionBuilderShort();
+ $pFieldsCollection = new FieldsCollection();
+ $pBuilderShort->addFieldsAddressEstate($pFieldsCollection);
+ $fieldNames = $this->readFieldnamesByContent(onOfficeSDK::MODULE_ADDRESS, $pFieldsCollection);
+ $fieldNamesForEstate = $this->readFieldnamesByContent(onOfficeSDK::MODULE_ESTATE, $pFieldsCollection);
+ $this->addFieldsConfiguration(onOfficeSDK::MODULE_ADDRESS,
+ self::FORM_VIEW_CONTACT_DATA_FIELDS, $pFormModelBuilder, $fieldNames);
+ $this->addSearchFieldForFieldLists([onOfficeSDK::MODULE_ADDRESS, onOfficeSDK::MODULE_ESTATE], $pFormModelBuilder);
+ $this->addFieldsConfiguration(onOfficeSDK::MODULE_ESTATE,
+ self::FORM_VIEW_SORTABLE_FIELDS_CONFIG, $pFormModelBuilder, $fieldNamesForEstate);
+ }
+
+ /**
+ *
+ */
+ public function save_form() {
+ $this->buildForms();
+ $action = filter_input( INPUT_POST, 'action' );
+ $nonce = filter_input( INPUT_POST, 'nonce' );
+
+ if ( ! wp_verify_nonce( $nonce, $action ) ) {
+ wp_die();
+ }
+
+ $values = (object) $this->transformPostValues();
+
+ $pInputModelDBAdapterArray = new InputModelOptionAdapterArray();
+
+ foreach ( $this->getFormModels() as $pFormModel ) {
+ foreach ( $pFormModel->getInputModel() as $pInputModel ) {
+ if ( $pInputModel instanceof InputModelOption ) {
+ $identifier = $pInputModel->getIdentifier();
+
+ $value = isset( $values->$identifier ) ? $values->$identifier : null;
+ $pInputModel->setValue( $value );
+ $pInputModelDBAdapterArray->addInputModelOption( $pInputModel );
+ }
+ }
+ }
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $valuesPrefixless = $pInputModelDBAdapterArray->generateValuesArray();
+ $valuesPrefixless = $this->setRecordsPerPage($valuesPrefixless);
+ $valuesPrefixless = $this->saveField($valuesPrefixless, $values);
+ $pDataDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues( $valuesPrefixless );
+ $success = true;
+
+ try {
+ $pDataAddressDetailViewHandler->saveAddressDetailView( $pDataDetailView );
+ } catch ( Exception $pEx ) {
+ $success = false;
+ }
+
+ $tabQuery = '&tab=' . AdminPageAddress::PAGE_ADDRESS_DETAIL;
+ $statusQuery = $success ? '&saved=true' : '&saved=false';
+
+ wp_redirect( admin_url( 'admin.php?page=onoffice-addresses' . $tabQuery . $statusQuery ) );
+
+ die();
+ }
+
+ /**
+ *
+ */
+ public function doExtraEnqueues()
+ {
+ wp_register_script('admin-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/admin.min.js',
+ array('jquery'), '', true);
+ wp_register_script('checkbox', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/checkbox.min.js',
+ array('jquery'), '', true);
+
+ wp_enqueue_script('admin-js');
+ wp_enqueue_script('checkbox');
+ wp_enqueue_script('postbox');
+ wp_register_script( 'oo-copy-shortcode',
+ plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . 'dist/onoffice-copycode.min.js',
+ [ 'jquery' ], '', true );
+ wp_enqueue_script( 'oo-copy-shortcode' );
+ wp_register_script('onoffice-custom-form-label-js',
+ plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true);
+ wp_enqueue_script('onoffice-custom-form-label-js');
+ $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php';
+ wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath));
+ wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath));
+ wp_enqueue_script('onoffice-multiselect');
+ wp_enqueue_style('onoffice-multiselect');
+
+ wp_register_script('oo-unsaved-changes-message', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-unsaved-changes-message.min.js',
+ ['jquery'], '', true);
+ wp_enqueue_script('oo-unsaved-changes-message');
+ }
+
+ /**
+ *
+ */
+ public function handleAdminNotices()
+ {
+ add_action('admin_notices', array($this, 'addAdminNoticeWrapper'));
+ }
+
+ /**
+ * rest will be added via js
+ */
+ public function addAdminNoticeWrapper()
+ {
+ echo '
';
+ }
+
+ /**
+ * @return array
+ */
+ public function getEnqueueData(): array
+ {
+ return array(
+ AdminPageAddress::PARAM_TAB => AdminPageAddress::PAGE_ADDRESS_DETAIL,
+ self::ENQUEUE_DATA_MERGE => array(AdminPageAddress::PARAM_TAB),
+ self::VIEW_UNSAVED_CHANGES_MESSAGE => __('Your changes have not been saved yet! Do you want to leave the page without saving?', 'onoffice-for-wp-websites'),
+ self::VIEW_LEAVE_WITHOUT_SAVING_TEXT => __('Leave without saving', 'onoffice-for-wp-websites'),
+ self::CUSTOM_LABELS => $this->readCustomLabels(),
+ 'label_custom_label' => __('Custom Label: %s', 'onoffice-for-wp-websites')
+ );
+ }
+
+ /**
+ * @param string $module
+ * @param string $groupSlug
+ * @param FormModelBuilderAddressDetailSettings $pFormModelBuilder
+ * @param array $fieldNames
+ * @return void
+ * @throws DependencyException
+ * @throws ExceptionInputModelMissingField
+ * @throws NotFoundException
+ */
+ private function addFieldsConfiguration(string $module, string $groupSlug, FormModelBuilderAddressDetailSettings $pFormModelBuilder,
+ array $fieldNames)
+ {
+ foreach ($fieldNames as $category => $fields) {
+ $slug = $this->generateGroupSlugByModuleCategory($module, $category);
+ $pInputModelFieldsConfig = $pFormModelBuilder->createButtonModelFieldsConfigByCategory
+ ($slug, $fields, $category);
+ $pInputModelFieldsConfig->setSpecialDivId(self::getSpecialDivId($module));
+ $pFormModelFieldsConfig = new FormModel();
+ $pFormModelFieldsConfig->setPageSlug($this->getPageSlug());
+ $pFormModelFieldsConfig->setGroupSlug($slug);
+ $pFormModelFieldsConfig->setLabel($category);
+ $pFormModelFieldsConfig->addInputModel($pInputModelFieldsConfig);
+ $this->addFormModel($pFormModelFieldsConfig);
+ }
+
+ $pInputModelSortableFields = $pFormModelBuilder->createSortableFieldList($module,
+ InputModelBase::HTML_TYPE_COMPLEX_SORTABLE_DETAIL_LIST);
+ $pFormModelSortableFields = new FormModel();
+ $pFormModelSortableFields->setPageSlug($this->getPageSlug());
+ $pFormModelSortableFields->setGroupSlug($groupSlug);
+ $pFormModelSortableFields->addInputModel($pInputModelSortableFields);
+ $this->addFormModel($pFormModelSortableFields);
+ }
+
+ /**
+ * @param InputModelRenderer $pRenderer
+ * @param $pFormViewSearchFieldForFieldLists
+ * @return void
+ * @throws Exception
+ */
+
+ private function renderSearchFieldForFieldLists(InputModelRenderer $pRenderer, $pFormViewSearchFieldForFieldLists)
+ {
+ echo '';
+ echo '
' . __( 'Field list search', 'onoffice-for-wp-websites' ) . ' ';
+ echo '
';
+ $pRenderer->buildForAjax($pFormViewSearchFieldForFieldLists);
+ echo '
';
+ echo '
';
+ }
+
+ /**
+ * @param array $module
+ * @param FormModelBuilderAddressDetailSettings $pFormModelBuilder
+ * @param string $htmlType
+ * @return void
+ * @throws ExceptionInputModelMissingField
+ */
+
+ private function addSearchFieldForFieldLists(array $module, FormModelBuilderAddressDetailSettings $pFormModelBuilder, string $htmlType = InputModelBase::HTML_SEARCH_FIELD_FOR_FIELD_LISTS)
+ {
+ $pInputModelSearchFieldForFieldLists = $pFormModelBuilder->createSearchFieldForFieldLists($module, $htmlType);
+
+ $pFormModelFieldsConfig = new FormModel();
+ $pFormModelFieldsConfig->setPageSlug($this->getPageSlug());
+ $pFormModelFieldsConfig->setGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
+ $pFormModelFieldsConfig->addInputModel($pInputModelSearchFieldForFieldLists);
+ $this->addFormModel($pFormModelFieldsConfig);
+ }
+
+ /**
+ *
+ * @param string $module
+ * @param string $category
+ * @return string
+ *
+ */
+
+ protected function generateGroupSlugByModuleCategory($module, $category)
+ {
+ return $module.'/'.$category;
+ }
+
+ /**
+ *
+ * @return FieldsCollection
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws UnknownFieldException
+ */
+
+ private function buildFieldsCollectionForCurrentAddress(): FieldsCollection
+ {
+ $pAddressListEnvironmentDefault = new AddressListEnvironmentDefault();
+ $pFieldsCollectionBuilder = $pAddressListEnvironmentDefault->getFieldsCollectionBuilderShort();
+ $pDefaultFieldsCollection = new FieldsCollection();
+ $pFieldsCollectionBuilder->addFieldsAddressEstate($pDefaultFieldsCollection);
+
+ foreach ($pDefaultFieldsCollection->getAllFields() as $pField) {
+ if (!in_array($pField->getModule(), [onOfficeSDK::MODULE_ADDRESS, onOfficeSDK::MODULE_ESTATE], true)) {
+ $pDefaultFieldsCollection->removeFieldByModuleAndName
+ ($pField->getModule(), $pField->getName());
+ }
+
+ }
+
+ return $pDefaultFieldsCollection;
+ }
+
+ /**
+ * @return array
+ * @throws DependencyException
+ * @throws NotFoundException
+ * @throws UnknownFieldException
+ */
+ private function readCustomLabels(): array
+ {
+ $result = [];
+ $pDataDetailViewHandler = new DataAddressDetailViewHandler();
+ $dataAddressDetailView = $pDataDetailViewHandler->getAddressDetailView();
+ $pLanguage = $this->getContainer()->get(Language::class);
+
+ foreach ($this->buildFieldsCollectionForCurrentAddress()->getAllFields() as $pField) {
+ $valuesByLocale = $dataAddressDetailView->getCustomLabels();
+ $currentLocale = $pLanguage->getLocale();
+ $valuesByLocale = $valuesByLocale[$pField->getName()] ?? '';
+
+ if (isset($valuesByLocale[$currentLocale])) {
+ $valuesByLocale['native'] = $valuesByLocale[$currentLocale];
+ unset($valuesByLocale[$currentLocale]);
+ }
+ $result[$pField->getName()] = $valuesByLocale;
+ }
+
+ return $result;
+ }
+
+ /**
+ * @param array $valuesPrefixless
+ * @param $values
+ * @return array
+ */
+ private function saveField(array $valuesPrefixless, $values)
+ {
+ $data = [];
+ $customLabel = (array) ($values->{'customlabel-lang'});
+
+ foreach ($customLabel as $key => $value) {
+ $data[$key] = $this->addLocaleToModelForField($value);
+ }
+
+ $valuesPrefixless['oo_plugin_fieldconfig_address_translated_labels'] = $data;
+
+ return $valuesPrefixless;
+ }
+
+ /**
+ * @param $value
+ * @return array|mixed
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function addLocaleToModelForField($value)
+ {
+ $pLanguage = $this->getContainer()->get( Language::class );
+
+ foreach ($value as $locale => $values) {
+ $value = (array) $value;
+ if ($locale === 'native') {
+ $value[$pLanguage->getLocale()] = $values;
+ unset($value['native']);
+ }
+ }
+
+ return $value;
+ }
+
+
+ /**
+ * @param array $row
+ *
+ * @return array
+ */
+ private function setRecordsPerPage(array $row): array
+ {
+ $recordsPerPage = (int)$row['recordsPerPage'];
+ $row['recordsPerPage'] = $recordsPerPage > 0 ? $recordsPerPage : 20;
+ return $row;
+ }
+
+ /**
+ * @param string $module
+ * @return string
+ */
+ private static function getSpecialDivId($module)
+ {
+ return 'actionFor'.$module;
+ }
+}
diff --git a/plugin/Gui/AdminPageAddressList.php b/plugin/Gui/AdminPageAddressList.php
index c27e4acba..edcad9ad4 100644
--- a/plugin/Gui/AdminPageAddressList.php
+++ b/plugin/Gui/AdminPageAddressList.php
@@ -21,20 +21,10 @@
namespace onOffice\WPlugin\Gui;
-use DI\ContainerBuilder;
-use onOffice\WPlugin\Controller\UserCapabilities;
-use onOffice\WPlugin\Form\BulkDeleteRecord;
use onOffice\WPlugin\Gui\Table\AddressListTable;
-use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
-use onOffice\WPlugin\Record\RecordManagerDeleteListViewEstate;
-use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
-use const ONOFFICE_DI_CONFIG_PATH;
use function __;
-use function add_action;
use function add_filter;
-use function add_query_arg;
use function admin_url;
-use function check_admin_referer;
use function esc_html__;
use function add_screen_option;
@@ -58,7 +48,6 @@ class AdminPageAddressList
public function renderContent()
{
- $this->generatePageMainTitle(__('Addresses', 'onoffice-for-wp-websites'));
$this->_pAddressListTable->prepare_items();
$page = 'onoffice-addresses';
$buttonSearch = __('Search Addresses', 'onoffice-for-wp-websites');
@@ -87,30 +76,15 @@ public function generatePageMainTitle($subTitle)
echo ' › ' . esc_html( $subTitle );
}
- echo '';
+ echo ' › '.esc_html__('List Views', 'onoffice-for-wp-websites');
$newLink = admin_url('admin.php?page=onoffice-editlistviewaddress');
+
+ echo '';
echo ''.esc_html__('Add New', 'onoffice-for-wp-websites').' ';
echo '';
}
- /**
- *
- */
-
- public function handleAdminNotices()
- {
- $itemsDeleted = filter_input(INPUT_GET, 'delete', FILTER_SANITIZE_NUMBER_INT);
-
- if ($itemsDeleted !== null && $itemsDeleted !== false) {
- add_action('admin_notices', function() use ($itemsDeleted) {
- $pHandler = new AdminNoticeHandlerListViewDeletion();
- echo $pHandler->handleListView($itemsDeleted);
- });
- }
- }
-
-
/**
*
*/
@@ -124,45 +98,7 @@ public function preOutput()
add_screen_option( 'per_page', array('option' => 'onoffice_address_listview_per_page') );
$this->_pAddressListTable = new AddressListTable();
- $pContainerBuilder = new ContainerBuilder;
- $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
- $pDI = $pContainerBuilder->build();
- $pClosureDeleteAddress = function(string $redirectTo, Table\WP\ListTable $pTable, array $recordIds)
- use ($pDI): string
- {
- /* @var $pBulkDeleteRecord BulkDeleteRecord */
- $pBulkDeleteRecord = $pDI->get(BulkDeleteRecord::class);
- /* @var $pRecordManagerDelete RecordManagerDeleteListViewEstate */
- $pRecordManagerDelete = $pDI->get(RecordManagerDeleteListViewAddress::class);
- if (in_array($pTable->current_action(), ['delete', 'bulk_delete'])) {
- check_admin_referer('bulk-'.$pTable->getArgs()['plural']);
- $itemsDeleted = $pBulkDeleteRecord->delete
- ($pRecordManagerDelete, UserCapabilities::RULE_EDIT_VIEW_ADDRESS, $recordIds);
- $redirectTo = add_query_arg(['delete' => $itemsDeleted],
- admin_url('admin.php?page=onoffice-addresses'));
- }
- return $redirectTo;
- };
-
- add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDeleteAddress, 10, 3);
-
- $pClosureDuplicateAddress = function (string $redirectTo, Table\WP\ListTable $pTable)
- use ($pDI): string {
- if (in_array($pTable->current_action(), ['duplicate', 'bulk_duplicate'])) {
- check_admin_referer('bulk-' . $pTable->getArgs()['plural']);
- if (!(isset($_GET['listViewId']))) {
- wp_die('No List Views for duplicating!');
- }
-
- /* @var $pRecordManagerDuplicateListViewAddress RecordManagerDuplicateListViewAddress */
- $pRecordManagerDuplicateListViewAddress = $pDI->get(RecordManagerDuplicateListViewAddress::class);
- $listViewRootId = $_GET['listViewId'];
- $pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
- }
- return $redirectTo;
- };
-
- add_filter('handle_bulk_actions-onoffice_page_onoffice-addresses', $pClosureDuplicateAddress, 10, 3);
+
add_filter('handle_bulk_actions-table-onoffice_page_onoffice-addresses', function(): Table\WP\ListTable {
return $this->_pAddressListTable;
});
@@ -172,6 +108,16 @@ public function preOutput()
public function doExtraEnqueues()
{
+ $translation = array(
+ 'confirmdialog' => __('Are you sure you want to delete the selected items?', 'onoffice-for-wp-websites'),
+ );
+
+ wp_register_script('onoffice-bulk-actions', plugins_url('/dist/onoffice-bulk-actions.min.js',
+ ONOFFICE_PLUGIN_DIR.'/index.php'), array('jquery'));
+
+ wp_localize_script('onoffice-bulk-actions', 'onoffice_table_settings', $translation);
+ wp_enqueue_script('onoffice-bulk-actions');
+
wp_register_script( 'oo-copy-shortcode',
plugin_dir_url( ONOFFICE_PLUGIN_DIR . '/index.php' ) . '/dist/onoffice-copycode.min.js',
[ 'jquery' ], '', true );
diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php
index 1e9952dd8..a73f5059a 100644
--- a/plugin/Gui/AdminPageAddressListSettings.php
+++ b/plugin/Gui/AdminPageAddressListSettings.php
@@ -40,6 +40,7 @@
use onOffice\WPlugin\Types\FieldsCollection;
use function __;
use function wp_enqueue_script;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -77,6 +78,13 @@ public function renderContent()
. esc_html__( 'There was a problem saving the address. The Name field cannot be empty.', 'onoffice-for-wp-websites' )
. ' ';
}
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the view. Please make '
+ . 'sure the name of the view is unique, even across all address list types.',
+ 'onoffice-for-wp-websites' )
+ . '
';
+ }
parent::renderContent();
}
@@ -253,6 +261,14 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null)
{
$type = RecordManagerFactory::TYPE_ADDRESS;
$result = false;
+ $pDummyAddressDetailView = new DataAddressDetailView();
+
+ if ($row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS]['name'] === $pDummyAddressDetailView->getName()) {
+ // false / null
+ $pResult->result = false;
+ $pResult->record_id = null;
+ return;
+ }
if (array_key_exists('name', $row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS])) {
$row[RecordManager::TABLENAME_LIST_VIEW_ADDRESS]['name'] = $this->sanitizeShortcodeName(
diff --git a/plugin/Gui/AdminPageEstateListSettingsBase.php b/plugin/Gui/AdminPageEstateListSettingsBase.php
index a57103c7d..6b9841dea 100644
--- a/plugin/Gui/AdminPageEstateListSettingsBase.php
+++ b/plugin/Gui/AdminPageEstateListSettingsBase.php
@@ -72,6 +72,13 @@ public function renderContent()
. esc_html__( 'There was a problem saving the list. The Name field cannot be empty.', 'onoffice-for-wp-websites' )
. ' ';
}
+ if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
+ echo ''
+ . esc_html__( 'There was a problem saving the view. Please make '
+ . 'sure the name of the view is unique, even across all estate list types.',
+ 'onoffice-for-wp-websites' )
+ . '
';
+ }
parent::renderContent();
}
diff --git a/plugin/Gui/AdminPageSettingsBase.php b/plugin/Gui/AdminPageSettingsBase.php
index a4133e291..330d78efe 100644
--- a/plugin/Gui/AdminPageSettingsBase.php
+++ b/plugin/Gui/AdminPageSettingsBase.php
@@ -154,13 +154,6 @@ public function renderContent()
. esc_html__( 'The view has been saved.', 'onoffice-for-wp-websites' )
. ' ';
}
- if ( isset( $_GET['saved'] ) && $_GET['saved'] === 'false' ) {
- echo ''
- . esc_html__( 'There was a problem saving the view. Please make '
- . 'sure the name of the view is unique, even across all estate list types.',
- 'onoffice-for-wp-websites' )
- . '
';
- }
do_action( 'add_meta_boxes', get_current_screen()->id, null );
$this->generateMetaBoxes();
diff --git a/plugin/Installer/Installer.php b/plugin/Installer/Installer.php
index e472eeea7..cd60b4838 100644
--- a/plugin/Installer/Installer.php
+++ b/plugin/Installer/Installer.php
@@ -51,6 +51,8 @@ static public function install()
$pRewriteRuleBuilder->addCustomRewriteTags();
$pRewriteRuleBuilder->addStaticRewriteRules();
$pRewriteRuleBuilder->addDynamicRewriteRules();
+ $pRewriteRuleBuilder->addCustomRewriteTagsForAddressDetail();
+ $pRewriteRuleBuilder->addDynamicRewriteRulesForAddressDetail();
self::flushRules();
}
diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
new file mode 100644
index 000000000..ba9bca24b
--- /dev/null
+++ b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
@@ -0,0 +1,482 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Model\FormModelBuilder;
+
+use function __;
+use DI\NotFoundException;
+use DI\DependencyException;
+use onOffice\WPlugin\Fieldnames;
+use onOffice\WPlugin\Model\FormModel;
+use onOffice\WPlugin\Types\ImageTypes;
+use onOffice\WPlugin\Model\InputModelBase;
+use onOffice\WPlugin\DataView\DataDetailView;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\Model\InputModel\InputModelDBFactory;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\InputModel\InputModelOptionFactoryAddressDetailView;
+use onOffice\WPlugin\Model\InputModelDB;
+use onOffice\WPlugin\WP\InstalledLanguageReader;
+use onOffice\WPlugin\Model\InputModelBuilder\InputModelBuilderCustomLabel;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Controller\Exception\UnknownModuleException;
+use onOffice\WPlugin\DataView\DataListView;
+use DI\ContainerBuilder;
+use DI\Container;
+use onOffice\WPlugin\Types\Field;
+use Exception;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ * This class must not use InputModelOption!
+ *
+ */
+
+class FormModelBuilderAddressDetailSettings
+ extends FormModelBuilder
+{
+ /** @var InputModelOptionFactoryAddressDetailView */
+ private $_pInputModelAddressDetailFactory = null;
+
+ /** @var DataAddressDetailView */
+ private $_pDataAddressDetail = null;
+
+ /** @var Container */
+ private $_pContainer;
+
+ /**
+ * @param Container|null $pContainer
+ * @param Fieldnames|null $pFieldnames
+ * @throws Exception
+ */
+
+ public function __construct(Container $pContainer = null, Fieldnames $pFieldnames = null)
+ {
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $this->_pContainer = $pContainer ?? $pContainerBuilder->build();
+
+ $pFieldsCollection = new FieldsCollection();
+ $pFieldnames = $pFieldnames ?? new Fieldnames($pFieldsCollection);
+ $pFieldnames->loadLanguage();
+ $this->setFieldnames($pFieldnames);
+ }
+
+ /**
+ * @param string $pageSlug
+ * @return FormModel
+ */
+
+ public function generate(string $pageSlug): FormModel
+ {
+ $this->_pInputModelAddressDetailFactory = new InputModelOptionFactoryAddressDetailView($pageSlug);
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler;
+ $this->_pDataAddressDetail = $pDataAddressDetailViewHandler->getAddressDetailView();
+
+ $pFormModel = new FormModel();
+ $pFormModel->setLabel(__('Address Detail View', 'onoffice-for-wp-websites'));
+ $pFormModel->setGroupSlug('onoffice-address-detail-settings-main');
+ $pFormModel->setPageSlug($pageSlug);
+
+ return $pFormModel;
+ }
+
+ /**
+ * @param string $category
+ * @param array $fieldNames
+ * @param string $categoryLabel
+ * @return InputModelOption
+ */
+
+ public function createInputModelFieldsConfigByCategory($category, $fieldNames, $categoryLabel): InputModelOption
+ {
+ $pInputModelFieldsConfig = new InputModelOption
+ (null, $category, null, InputModelDBFactory::INPUT_FIELD_CONFIG);
+ $pInputModelFieldsConfig->setIsMulti(true);
+
+ $pInputModelFieldsConfig->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX_BUTTON);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNames);
+ $pInputModelFieldsConfig->setId($category);
+ $pInputModelFieldsConfig->setLabel($categoryLabel);
+ $fields = $this->getValue(DataDetailView::FIELDS);
+
+ if (null == $fields)
+ {
+ $fields = array();
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param $module
+ * @param string $htmlType
+ * @return InputModelOption
+ * @throws DependencyException
+ * @throws ExceptionInputModelMissingField
+ * @throws NotFoundException
+ */
+ public function createSortableFieldList($module, string $htmlType): InputModelOption
+ {
+ $fields = [];
+
+ if ($module == onOfficeSDK::MODULE_ADDRESS) {
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FIELD_CONFIG, null, true);
+ $fields = $this->_pDataAddressDetail->getFields();
+ } elseif ($module == onOfficeSDK::MODULE_ESTATE) {
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_ESTATE_FIELD_CONFIG, null, true);
+ $fields = $this->_pDataAddressDetail->getEstateFields();
+ } else {
+ throw new UnknownModuleException();
+ }
+
+ $fieldNames = $this->getFieldnames()->getFieldList($module);
+
+ $fieldNamesArray = [];
+ $pFieldsCollectionUsedFields = new FieldsCollection;
+
+ foreach ($fieldNames as $name => $pField) {
+ $pFields = Field::createByRow($name, $pField);
+ $fieldNamesArray[$pFields->getName()] = $pFields->getAsRow();
+ $pFieldsCollectionUsedFields->addField($pFields);
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+ $pInputModelFieldsConfig->setHtmlType($htmlType);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNamesArray);
+ $pInputModelFieldsConfig->addReferencedInputModel($this->getInputModelCustomLabel($pFieldsCollectionUsedFields));
+ $pInputModelFieldsConfig->addReferencedInputModel($this->getInputModelCustomLabelLanguageSwitch());
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param string $field
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelTemplate(string $field = InputModelOptionFactoryAddressDetailView::INPUT_TEMPLATE)
+ {
+ $labelTemplate = __('Template', 'onoffice-for-wp-websites');
+ $pInputModelTemplate = $this->_pInputModelAddressDetailFactory->create($field, $labelTemplate);
+ $pInputModelTemplate->setHtmlType(InputModelBase::HTML_TYPE_TEMPLATE_LIST);
+ $pInputModelTemplate->setValuesAvailable($this->readTemplatePaths('address'));
+ $pInputModelTemplate->setValue($this->getTemplateValueByField($field));
+
+ return $pInputModelTemplate;
+ }
+
+
+ /**
+ * @param string $field
+ * @return string
+ */
+
+ private function getTemplateValueByField(string $field): string
+ {
+ switch ($field) {
+ case InputModelOptionFactoryAddressDetailView::INPUT_TEMPLATE:
+ return $this->_pDataAddressDetail->getTemplate();
+ default:
+ return '';
+ }
+ }
+
+ /**
+ *
+ * @param string $category
+ * @param array $fieldNames
+ * @param string $categoryLabel
+ * @return InputModelOption
+ *
+ */
+
+ public function createButtonModelFieldsConfigByCategory($category, $fieldNames, $categoryLabel)
+ {
+ $pInputModelFieldsConfig = new InputModelOption
+ (null, $category, null, InputModelDBFactory::INPUT_FIELD_CONFIG);
+ $pInputModelFieldsConfig->setIsMulti(true);
+
+ $pInputModelFieldsConfig->setHtmlType(InputModelBase::HTML_TYPE_BUTTON_FIELD);
+ $pInputModelFieldsConfig->setValuesAvailable($fieldNames);
+ $pInputModelFieldsConfig->setId($category);
+ $pInputModelFieldsConfig->setLabel($categoryLabel);
+ $fields = $this->getValue(DataDetailView::FIELDS);
+
+ if ($fields == null) {
+ $fields = array_merge($this->_pDataAddressDetail->getFields());
+ }
+
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ *
+ * @return InputModelOption
+ *
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createInputModelPictureTypes(): InputModelOption
+ {
+ $allPictureTypes = ImageTypes::getImageTypesForAddress();
+
+ $pInputModelPictureTypes = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_PICTURE_TYPE, null, true);
+ $pInputModelPictureTypes->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+ $pInputModelPictureTypes->setValuesAvailable($allPictureTypes);
+ $pictureTypes = $this->_pDataAddressDetail->getPictureTypes();
+
+ if ($pictureTypes == null) {
+ $pictureTypes = array();
+ }
+
+ $pInputModelPictureTypes->setValue($pictureTypes);
+
+ return $pInputModelPictureTypes;
+ }
+
+ /**
+ * @param $module
+ * @param string $htmlType
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+
+ public function createSearchFieldForFieldLists($module, string $htmlType): InputModelOption
+ {
+ $fields = [];
+
+ $pInputModelFieldsConfig = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FIELD_CONFIG, null, true);
+ $fields = $this->_pDataAddressDetail->getFields();
+ $fieldNames = [];
+
+ if (is_array($module)) {
+ foreach ($module as $submodule) {
+ $newFields = $this->getFieldnames()->getFieldList($submodule);
+ $fieldNames = array_merge($fieldNames, $newFields);
+ }
+ }
+
+ foreach ($fieldNames as $key => $pField) {
+ $action = $pField['module'] === onOfficeSDK::MODULE_ADDRESS ? onOfficeSDK::MODULE_ADDRESS : onOfficeSDK::MODULE_ESTATE;
+ $fieldNames[$key]['action'] = $action;
+ }
+
+ $fields = array_merge($this->_pDataAddressDetail->getFields(), $this->_pDataAddressDetail->getEstateFields()) ?? [];
+ $pInputModelFieldsConfig->setHtmlType($htmlType);
+ $pInputModelFieldsConfig->setValuesAvailable($this->groupByContent($fieldNames));
+ $pInputModelFieldsConfig->setValue($fields);
+
+ return $pInputModelFieldsConfig;
+ }
+
+ /**
+ * @param FieldsCollection $pFieldsCollection
+ * @return InputModelDB
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ private function getInputModelCustomLabel(FieldsCollection $pFieldsCollection): InputModelDB
+ {
+ $pInputModelBuilder = $this->_pContainer->get(InputModelBuilderCustomLabel::class);
+
+ return $pInputModelBuilder->createInputModelCustomLabel($pFieldsCollection, $this->getValue('customlabel', []));
+ }
+
+ /**
+ * @return InputModelDB
+ */
+ public function getInputModelCustomLabelLanguageSwitch(): InputModelDB
+ {
+ $pInputModel = new InputModelDB('customlabel_newlang',
+ __('Add custom label language', 'onoffice-for-wp-websites'));
+ $pInputModel->setTable('language-custom-label');
+ $pInputModel->setField('language');
+
+ $pLanguageReader = new InstalledLanguageReader;
+ $languages = ['' => __('Choose Language', 'onoffice-for-wp-websites')]
+ + $pLanguageReader->readAvailableLanguageNamesUsingNativeName();
+ $pInputModel->setValuesAvailable(array_diff_key($languages, [get_locale() => []]));
+ $pInputModel->setValueCallback(function (InputModelDB $pInputModel) {
+ $pInputModel->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
+ $pInputModel->setLabel(__('Add custom label language', 'onoffice-for-wp-websites'));
+ });
+
+ return $pInputModel;
+ }
+
+ /**
+ * @return array
+ */
+ static public function getListViewReferenceEstates(): array
+ {
+ return array(
+ DataListView::HIDE_REFERENCE_ESTATE => __( 'Hide reference estates', 'onoffice-for-wp-websites' ),
+ DataListView::SHOW_REFERENCE_ESTATE => __( 'Show reference estates (alongside others)', 'onoffice-for-wp-websites' ),
+ DataListView::SHOW_ONLY_REFERENCE_ESTATE => __( 'Show only reference estates (filter out all others)', 'onoffice-for-wp-websites' ),
+ );
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelShowLinkEstates(): InputModelOption
+ {
+ $labelShowStatus = __('Show Linked Estates', 'onoffice-for-wp-websites');
+
+ $pInputModelShowStatus = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_LINK_ESTATES, $labelShowStatus);
+ $pInputModelShowStatus->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+
+ $showEstateStatus = $this->_pDataAddressDetail->getShowLinkEstates();
+
+ $pInputModelShowStatus->setValue($showEstateStatus);
+ $pInputModelShowStatus->setValuesAvailable(1);
+
+ return $pInputModelShowStatus;
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelShowEstatesStatus(): InputModelOption
+ {
+ $labelShowStatus = __('Show Estates Status', 'onoffice-for-wp-websites');
+
+ $pInputModelShowStatus = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_ESTATES_STATUS, $labelShowStatus);
+ $pInputModelShowStatus->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+
+ $showEstateStatus = $this->_pDataAddressDetail->getShowEstateStatus();
+
+ $pInputModelShowStatus->setValue($showEstateStatus);
+ $pInputModelShowStatus->setValuesAvailable(1);
+
+ return $pInputModelShowStatus;
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelShowReferenceEstates(): InputModelOption
+ {
+ $labelShowReferenceEstate = __('Reference estates', 'onoffice-for-wp-websites');
+
+ $pInputModelShowReferenceEstate = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_REFERENCE_ESTATE, $labelShowReferenceEstate);
+ $pInputModelShowReferenceEstate->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
+
+ $showReferenceEstate = $this->_pDataAddressDetail->getShowReferenceEstate();
+
+ $pInputModelShowReferenceEstate->setValue($showReferenceEstate);
+ $pInputModelShowReferenceEstate->setValuesAvailable(self::getListViewReferenceEstates());
+
+ return $pInputModelShowReferenceEstate;
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelFilter(): InputModelOption
+ {
+ $labelFilterName = __('Filter', 'onoffice-for-wp-websites');
+ $pInputModelFilterName = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_FILTERID, $labelFilterName);
+ $pInputModelFilterName->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
+
+ $availableFilters = array(0 => '') + $this->readFilters(onOfficeSDK::MODULE_ESTATE);
+ $filterIdSelected = $this->_pDataAddressDetail->getFilter();
+
+ $pInputModelFilterName->setValuesAvailable($availableFilters);
+ $pInputModelFilterName->setValue($filterIdSelected);
+
+ return $pInputModelFilterName;
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelRecordsPerPage(): InputModelOption
+ {
+ $labelRecordsPerPage = __('Estates per page', 'onoffice-for-wp-websites');
+ $pInputModelRecordsPerPage = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_RECORDS_PER_PAGE, $labelRecordsPerPage);
+ $pInputModelRecordsPerPage->setHtmlType(InputModelBase::HTML_TYPE_NUMBER);
+ $pInputModelRecordsPerPage->setValue($this->_pDataAddressDetail->getRecordsPerPage());
+ $pInputModelRecordsPerPage->setMaxValueHtml(500);
+ $pInputModelRecordsPerPage->setHintHtml(__('You can show up to 500 per page.', 'onoffice-for-wp-websites'));
+
+ return $pInputModelRecordsPerPage;
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelShowPriceOnRequest(): InputModelOption
+ {
+ $labelShowPriceOnRequest = __('Show price on request', 'onoffice-for-wp-websites');
+
+ $pInputModelShowPriceOnRequest = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_PRICE_ON_REQUEST, $labelShowPriceOnRequest);
+ $pInputModelShowPriceOnRequest->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+ $pInputModelShowPriceOnRequest->setValue($this->_pDataAddressDetail->getShowPriceOnRequest());
+ $pInputModelShowPriceOnRequest->setValuesAvailable(1);
+
+ return $pInputModelShowPriceOnRequest;
+ }
+
+ /**
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ */
+ public function createInputModelShowMap(): InputModelOption
+ {
+ $labelShowMap = __('Show estate map', 'onoffice-for-wp-websites');
+
+ $pInputModelShowMap = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_MAP, $labelShowMap);
+ $pInputModelShowMap->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+ $pInputModelShowMap->setValue($this->_pDataAddressDetail->getShowEstateMap() ?? true);
+ $pInputModelShowMap->setValuesAvailable(1);
+
+ return $pInputModelShowMap;
+ }
+}
diff --git a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
new file mode 100644
index 000000000..35a7e4da1
--- /dev/null
+++ b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
@@ -0,0 +1,152 @@
+.
+ *
+ */
+
+namespace onOffice\WPlugin\Model\InputModel;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use onOffice\WPlugin\Model\InputModelOption;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class InputModelOptionFactoryAddressDetailView
+{
+
+ /** */
+ const INPUT_TEMPLATE = 'template';
+
+ /** */
+ const INPUT_FIELD_CONFIG = DataAddressDetailView::FIELDS;
+
+ /** */
+ const INPUT_ESTATE_FIELD_CONFIG = DataAddressDetailView::ESTATE_FIELDS;
+
+ /** */
+ const INPUT_PICTURE_TYPE = DataAddressDetailView::PICTURES;
+
+ /** @var string */
+ const INPUT_SHOW_ESTATES_STATUS = 'showEstatesStatus';
+
+ /** @var string */
+ const INPUT_SHOW_LINK_ESTATES = 'showLinkEstates';
+
+ /** @var string */
+ const INPUT_SHOW_REFERENCE_ESTATE = 'referenceEstates';
+
+ /** @var string */
+ const INPUT_FILTERID = 'filterId';
+
+ /** @var string */
+ const INPUT_RECORDS_PER_PAGE = 'recordsPerPage';
+
+ /** @var string */
+ const INPUT_SHOW_PRICE_ON_REQUEST = 'showPriceOnRequest';
+
+ /** @var string */
+ const INPUT_SHOW_MAP = 'showMap';
+
+ /** */
+ const KEY_TYPE = 'type';
+
+ /** @var string */
+ private $_optionGroup = null;
+
+
+ /** @var array */
+ private $_inputConfig = [
+ self::INPUT_FIELD_CONFIG => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_PICTURE_TYPE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_TEMPLATE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_ESTATE_FIELD_CONFIG => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_SHOW_LINK_ESTATES => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ ],
+ self::INPUT_SHOW_ESTATES_STATUS => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ ],
+ self::INPUT_SHOW_REFERENCE_ESTATE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ ],
+ self::INPUT_FILTERID => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_RECORDS_PER_PAGE => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ ],
+ self::INPUT_SHOW_PRICE_ON_REQUEST => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ ],
+ self::INPUT_SHOW_MAP => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ ],
+ ];
+
+
+ /**
+ *
+ * @param string $optionGroup
+ *
+ */
+
+ public function __construct(string $optionGroup)
+ {
+ $this->_optionGroup = $optionGroup;
+ }
+
+
+ /**
+ *
+ * @param string $name
+ * @param string $label
+ * @param bool $multi
+ * @return InputModelOption
+ * @throws ExceptionInputModelMissingField
+ *
+ */
+
+ public function create(string $name, $label, bool $multi = false): InputModelOption
+ {
+ if (!isset($this->_inputConfig[$name])) {
+ throw new ExceptionInputModelMissingField($name);
+ }
+
+ $config = $this->_inputConfig[$name];
+ $type = $config[self::KEY_TYPE];
+
+ $pInstance = new InputModelOption($this->_optionGroup, $name, $label, $type);
+ $pInstance->setIsMulti($multi);
+
+ return $pInstance;
+ }
+}
diff --git a/plugin/Renderer/InputFieldTemplateListRenderer.php b/plugin/Renderer/InputFieldTemplateListRenderer.php
index 715abbc7a..6c64c9b54 100644
--- a/plugin/Renderer/InputFieldTemplateListRenderer.php
+++ b/plugin/Renderer/InputFieldTemplateListRenderer.php
@@ -34,6 +34,7 @@ class InputFieldTemplateListRenderer
{
const TEMPLATE_DEFAULT_LIST = [
'onoffice-editlistviewaddress' => 'default.php',
+ 'onoffice-addresses' => 'default_detail.php',
'onoffice-editlistview' => 'default.php',
'onoffice-editunitlist' => 'default_units.php',
'onoffice-estates' => [
diff --git a/plugin/Types/ImageTypes.php b/plugin/Types/ImageTypes.php
index 426604686..0f061031c 100644
--- a/plugin/Types/ImageTypes.php
+++ b/plugin/Types/ImageTypes.php
@@ -32,6 +32,7 @@ class ImageTypes
const PANORAMA = 'Panorama';
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
+ const PASSPORTPHOTO = 'PassportPhoto';
const IMAGE_TYPES = [
self::TITLE,
@@ -67,4 +68,14 @@ public static function getAllImageTypesTranslated(): array
self::ENERGY_PASS_RANGE => __('Energy-Pass Range', 'onoffice-for-wp-websites'),
];
}
+
+ /**
+ * @return array
+ */
+ public static function getImageTypesForAddress(): array
+ {
+ return [
+ self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
+ ];
+ }
}
diff --git a/tests/TestClassDataAddressDetailView.php b/tests/TestClassDataAddressDetailView.php
new file mode 100644
index 000000000..db5a77292
--- /dev/null
+++ b/tests/TestClassDataAddressDetailView.php
@@ -0,0 +1,91 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use WP_UnitTestCase;
+
+class TestClassDataAddressDetailView
+ extends WP_UnitTestCase
+{
+ /** */
+ const DEFAULT_FIELDS = [
+ 'Anrede',
+ 'Vorname',
+ 'Name',
+ 'Zusatz1',
+ 'Email',
+ 'Telefon1',
+ 'Telefax1',
+ ];
+
+ /**
+ *
+ */
+ public function testDefaultValues()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+
+ $this->assertEquals(self::DEFAULT_FIELDS, $pDataAddressDetailView->getFields());
+ $this->assertEquals('detail', $pDataAddressDetailView->getName());
+ $this->assertEquals(0, $pDataAddressDetailView->getPageId());
+ $this->assertEquals([], $pDataAddressDetailView->getPictureTypes());
+ $this->assertEquals('', $pDataAddressDetailView->getTemplate());
+ $this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $this->assertEquals([], $pDataAddressDetailView->getCustomLabels());
+ }
+
+ /**
+ *
+ */
+ public function testGetterSetter()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+
+ $pDataAddressDetailView->setFields(['testaddressfield1', 'testaddressfield2']);
+ $this->assertEquals(['testaddressfield1', 'testaddressfield2'],
+ $pDataAddressDetailView->getFields());
+ $pDataAddressDetailView->setFields(['testfield1', 'testfield2']);
+ $this->assertEquals(['testfield1', 'testfield2'], $pDataAddressDetailView->getFields());
+ $pDataAddressDetailView->setPageId(12);
+ $this->assertEquals(12, $pDataAddressDetailView->getPageId());
+ $pDataAddressDetailView->setPictureTypes(['testpicturetype1', 'testpicturetype2']);
+ $this->assertEquals(['testpicturetype1', 'testpicturetype2'],
+ $pDataAddressDetailView->getPictureTypes());
+ $pDataAddressDetailView->setTemplate('/test/template1.test');
+ $this->assertEquals('/test/template1.test', $pDataAddressDetailView->getTemplate());
+
+ $pDataAddressDetailView->addToPageIdsHaveDetailShortCode(14);
+ $this->assertEquals([14 => 14], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $pDataAddressDetailView->removeFromPageIdsHaveDetailShortCode(14);
+ $this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
+ $pDataAddressDetailView->setCustomLabels(['field1']);
+ $this->assertEquals(['field1'], $pDataAddressDetailView->getCustomLabels());
+ $pDataAddressDetailView->setShowPriceOnRequest(1);
+ $this->assertEquals(1, $pDataAddressDetailView->getShowPriceOnRequest());
+ $pDataAddressDetailView->setShowEstateMap(1);
+ $this->assertEquals(1, $pDataAddressDetailView->getShowEstateMap());
+ $pDataAddressDetailView->setShowReferenceEstates('');
+ }
+}
diff --git a/tests/TestClassDataAddressDetailViewHandler.php b/tests/TestClassDataAddressDetailViewHandler.php
new file mode 100644
index 000000000..6c12da083
--- /dev/null
+++ b/tests/TestClassDataAddressDetailViewHandler.php
@@ -0,0 +1,133 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use onOffice\WPlugin\DataView\DataAddressDetailView;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\Types\ImageTypes;
+use onOffice\WPlugin\WP\WPOptionWrapperTest;
+use WP_UnitTestCase;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class TestClassDataAddressDetailViewHandler
+ extends WP_UnitTestCase
+{
+ /** */
+ const VALUES_BY_ROW = [
+ 'template' => '/test/template.php',
+ 'fields' => [
+ 'Objektnr_extern',
+ 'wohnflaeche',
+ 'kaufpreis',
+ ],
+ 'pictures' => [
+ ImageTypes::PASSPORTPHOTO,
+ ],
+ 'oo_plugin_fieldconfig_address_translated_labels' => ['field']
+ ];
+
+ /**
+ *
+ */
+
+ public function testCreateAddressDetailViewByValues()
+ {
+ $row = self::VALUES_BY_ROW;
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pDataAddressDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues($row);
+ $this->assertEquals($row['template'], $pDataAddressDetailView->getTemplate());
+ $this->assertEquals($row['fields'], $pDataAddressDetailView->getFields());
+ $this->assertEquals($row['pictures'], $pDataAddressDetailView->getPictureTypes());
+ $this->assertEquals($row['oo_plugin_fieldconfig_address_translated_labels'], $pDataAddressDetailView->getCustomLabels());
+ }
+
+
+ /**
+ *
+ */
+
+ public function testCreateEmptyDetailViewByValues()
+ {
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
+ $pDataAddressDetailView = $pDataAddressDetailViewHandler->createAddressDetailViewByValues([]);
+
+ $this->assertEquals($pDataAddressDetailView->getTemplate(), '');
+ $this->assertEquals($pDataAddressDetailView->getFields(), []);
+ $this->assertEquals($pDataAddressDetailView->getPictureTypes(), []);
+ $this->assertEquals($pDataAddressDetailView->getName(), 'detail');
+ $this->assertEquals($pDataAddressDetailView->getPageId(), 0);
+ $this->assertEquals($pDataAddressDetailView->getPageIdsHaveDetailShortCode(), []);
+ }
+
+
+ /**
+ *
+ */
+
+ public function testGetAddressDetailView()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+ $pDataAddressDetailView->setPageId(1337);
+
+ $pWPOptionsWrapper = new WPOptionWrapperTest();
+ $pWPOptionsWrapper->addOption(DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY, $pDataAddressDetailView);
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWPOptionsWrapper);
+
+ $this->assertEquals($pDataAddressDetailView, $pDataAddressDetailViewHandler->getAddressDetailView());
+
+ $pWPOptionsWrapper->deleteOption(DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY);
+
+ // if not set, return a new instance
+ $this->assertEquals(new DataAddressDetailView(), $pDataAddressDetailViewHandler->getAddressDetailView());
+ }
+
+
+ /**
+ *
+ */
+
+ public function testSaveAddressDetailView()
+ {
+ $pDataAddressDetailView = new DataAddressDetailView();
+ $pDataAddressDetailView->setPageId(1337);
+ $optionsKey = DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY;
+ $pWPOptionsWrapper = new WPOptionWrapperTest();
+
+ $pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWPOptionsWrapper);
+ $pDataAddressDetailViewHandler->saveAddressDetailView(clone $pDataAddressDetailView);
+ $this->assertEquals($pDataAddressDetailView, $pWPOptionsWrapper->getOption($optionsKey));
+
+ // test if overwriting works
+ $pDataAddressDetailView->setPageId(1339);
+ $pDataAddressDetailViewHandler->saveAddressDetailView(clone $pDataAddressDetailView);
+ $this->assertEquals($pDataAddressDetailView, $pWPOptionsWrapper->getOption($optionsKey));
+ }
+}
diff --git a/tests/TestClassDetailViewPostSaveController.php b/tests/TestClassDetailViewPostSaveController.php
index b75d0c2b1..691c324c8 100644
--- a/tests/TestClassDetailViewPostSaveController.php
+++ b/tests/TestClassDetailViewPostSaveController.php
@@ -31,6 +31,8 @@
use onOffice\WPlugin\WP\WPOptionWrapperTest;
use onOffice\WPlugin\WP\WPPageWrapper;
use WP_UnitTestCase;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -62,6 +64,15 @@ class TestClassDetailViewPostSaveController extends WP_UnitTestCase
*/
private $_pWPPageWrapper;
+ /**
+ * @var DataAddressDetailViewHandler
+ */
+ private $_pDataAddressDetailViewHandler;
+
+ /**
+ * @var DataAddressDetailView
+ */
+ private $_pDataAddressDetailView;
/**
* @before
@@ -75,13 +86,16 @@ public function prepare()
$this->_pDataDetailViewHandler = new DataDetailViewHandler($pWpOption);
$this->_pDataDetailView = $this->_pDataDetailViewHandler->getDetailView();
$this->_pDataDetailViewHandler->saveDetailView($this->_pDataDetailView);
+ $this->_pDataAddressDetailViewHandler = new DataAddressDetailViewHandler($pWpOption);
+ $this->_pDataAddressDetailView = $this->_pDataAddressDetailViewHandler->getAddressDetailView();
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView($this->_pDataAddressDetailView);
$this->_pWPPageWrapper = $this->getMockBuilder( WPPageWrapper::class )
->setMethods( [ 'getPageUriByPageId' ] )
->getMock();
$pSubject = new RewriteRuleBuilder( $this->_pDataDetailViewHandler,
- $this->_pWPPageWrapper );
+ $this->_pWPPageWrapper, $this->_pDataAddressDetailViewHandler );
$pDbChanges = new DatabaseChanges($pWpOption, $wpdb);
@@ -99,6 +113,9 @@ public function testReturnNullForTrashStatus()
$this->_pDataDetailView->setPageId( 13 );
$this->_pDataDetailViewHandler->saveDetailView( $this->_pDataDetailView );
+ $this->_pDataAddressDetailView->setPageId( 14 );
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView( $this->_pDataAddressDetailView );
+
$pWPPost = self::factory()->post->create_and_get( [
'post_author' => 1,
'post_content' => '[oo_estate view="detail"]',
@@ -107,7 +124,16 @@ public function testReturnNullForTrashStatus()
'post_status' => 'trash',
] );
+ $pWPPostForAddressDetail = self::factory()->post->create_and_get( [
+ 'post_author' => 1,
+ 'post_content' => '[oo_address view="detail"]',
+ 'post_title' => 'Details',
+ 'post_type' => 'page',
+ 'post_status' => 'trash',
+ ] );
+
$this->assertNull( $this->_pDetailViewPostSaveController->onSavePost( $pWPPost->ID ) );
+ $this->assertNull( $this->_pDetailViewPostSaveController->onSavePost( $pWPPostForAddressDetail->ID ) );
}
@@ -169,4 +195,33 @@ public function testShortCodeInMetaKey()
$detailViewOptions = get_option( DataDetailViewHandler::DEFAULT_VIEW_OPTION_KEY );
$this->assertEquals( $pWPPost->ID, $detailViewOptions->getPageId() );
}
+
+
+ /**
+ *
+ */
+
+ public function testAddreeDetailShortCodeInMetaKey()
+ {
+ $this->_pDataAddressDetailView->setPageId( 14 );
+ $this->_pDataAddressDetailViewHandler->saveAddressDetailView( $this->_pDataAddressDetailView );
+
+ $pWPPostForAddressDetail = self::factory()->post->create_and_get( [
+ 'post_author' => 1,
+ 'post_content' => '[oo_address view="detail"]',
+ 'post_title' => 'Test Post',
+ 'post_type' => 'page',
+ ] );
+
+ add_post_meta( $pWPPostForAddressDetail->ID, 'view', '[oo_address view="detail"]' );
+
+ $this->_pWPPageWrapper->method( 'getPageUriByPageId' )
+ ->with( $pWPPostForAddressDetail->ID )
+ ->willReturn( 'test-post' );
+
+ $this->_pDetailViewPostSaveController->onSavePost( $pWPPostForAddressDetail->ID );
+
+ $addressDetailViewOptions = get_option( DataAddressDetailViewHandler::DEFAULT_ADDRESS_VIEW_OPTION_KEY );
+ $this->assertEquals( $pWPPostForAddressDetail->ID, $addressDetailViewOptions->getPageId() );
+ }
}
\ No newline at end of file
diff --git a/tests/TestClassFormModelBuilderAddressDetailSettings.php b/tests/TestClassFormModelBuilderAddressDetailSettings.php
new file mode 100644
index 000000000..1d7773fa7
--- /dev/null
+++ b/tests/TestClassFormModelBuilderAddressDetailSettings.php
@@ -0,0 +1,199 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+
+use DI\Container;
+use WP_UnitTestCase;
+use DI\ContainerBuilder;
+use onOffice\SDK\onOfficeSDK;
+use onOffice\WPlugin\Fieldnames;
+use onOffice\WPlugin\Model\InputModelDB;
+use onOffice\WPlugin\Model\InputModelOption;
+use onOffice\WPlugin\Types\FieldsCollection;
+use onOffice\WPlugin\Field\FieldnamesEnvironmentTest;
+use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings;
+
+class TestClassFormModelBuilderAddressDetailSettings
+ extends WP_UnitTestCase
+{
+ /** @var Container */
+ private $_pContainer;
+
+ /** @var Fieldnames */
+ private $_pFieldnames = null;
+
+ /** @var FieldnamesEnvironmentTest */
+ private $_pFieldnamesEnvironment = null;
+
+ /** @var FormModelBuilderAddressDetailSettings */
+ private $_pFormModelBuilderAddressDetailSettings;
+
+ /**
+ * @before
+ */
+ public function prepare()
+ {
+ $this->_pFieldnamesEnvironment = new FieldnamesEnvironmentTest();
+ $fieldParameters = [
+ 'labels' => true,
+ 'showContent' => true,
+ 'showTable' => true,
+ 'language' => 'ENG',
+ 'modules' => ['address', 'estate'],
+ 'realDataTypes' => true,
+ ];
+ $pSDKWrapperMocker = $this->_pFieldnamesEnvironment->getSDKWrapper();
+ $responseGetFields = json_decode
+ (file_get_contents(__DIR__ . '/resources/ApiResponseGetFields.json'), true);
+ /* @var $pSDKWrapperMocker SDKWrapperMocker */
+ $pSDKWrapperMocker->addResponseByParameters(onOfficeSDK::ACTION_ID_GET, 'fields', '', $fieldParameters, null, $responseGetFields);
+ $this->_pFieldnames = new Fieldnames(new FieldsCollection(), false, $this->_pFieldnamesEnvironment);
+
+ $pContainerBuilder = new ContainerBuilder;
+ $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
+ $this->_pContainer = $pContainerBuilder->build();
+
+ $this->_pFormModelBuilderAddressDetailSettings = new FormModelBuilderAddressDetailSettings($this->_pContainer, $this->_pFieldnames);
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::__construct
+ */
+
+ public function testConstruct()
+ {
+ $pInstance = $this->_pFormModelBuilderAddressDetailSettings;
+ $this->assertInstanceOf(FormModelBuilderAddressDetailSettings::class, $pInstance);
+ }
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSortableFieldList
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabel
+ */
+ public function testCreateSortableFieldList()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSortableFieldList('address', 'complexSortableDetailList');
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'complexSortableDetailList');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSearchFieldForFieldLists
+ */
+ public function testCreateSearchFieldForFieldLists()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSearchFieldForFieldLists('address', 'searchFieldForFieldLists');
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'searchFieldForFieldLists');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelPictureTypes
+ */
+ public function testCreateInputModelPictureTypes()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getValue'])
+ ->getMock();
+ $pInstance->generate('test');
+
+ $pInputModelDB = $pInstance->createInputModelPictureTypes();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'checkbox');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::CreateInputModelTemplate
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getTemplateValueByField
+ */
+ public function testCreateInputModelTemplate()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getValue', 'readTemplatePaths'])
+ ->getMock();
+ $pInstance->expects($this->exactly(1))
+ ->method('readTemplatePaths');
+ $pInstance->generate('test');
+
+ $pInputModelDB = $pInstance->createInputModelTemplate();
+ $this->assertEquals($pInputModelDB->getHtmlType(), 'templateList');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelFieldsConfigByCategory
+ */
+ public function testCreateInputModelFieldsConfigByCategory()
+ {
+ $inputModel = $this->_pFormModelBuilderAddressDetailSettings->createInputModelFieldsConfigByCategory('1', ['field1'], 'label');
+ $this->assertEquals('label', $inputModel->getLabel());
+ $this->assertEquals('1', $inputModel->getId());
+ $this->assertEquals(['field1'], $inputModel->getValuesAvailable());
+ $this->assertInstanceOf(InputModelOption::class, $inputModel);
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabelLanguageSwitch
+ */
+ public function testGetInputModelCustomLabelLanguageSwitch()
+ {
+ $pInstance = $this->getMockBuilder(FormModelBuilderAddressDetailSettings::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['readAvailableLanguageNamesUsingNativeName'])
+ ->getMock();
+
+ $inputModel = $pInstance->getInputModelCustomLabelLanguageSwitch();
+ $this->assertInstanceOf(InputModelDB::class, $inputModel);
+ $this->assertEquals('Add custom label language', $inputModel->getLabel());
+ $this->assertEquals('language-custom-label', $inputModel->getTable());
+ $this->assertEquals('language', $inputModel->getField());
+
+ $values = $inputModel->getValuesAvailable();
+
+ $this->assertContains('Choose Language', $values);
+ $this->assertNotContains(get_locale(), $values);
+ }
+
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::generate
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createButtonModelFieldsConfigByCategory
+ */
+ public function testCreateButtonModelFieldsConfigByCategory()
+ {
+ $this->_pFormModelBuilderAddressDetailSettings->generate('test');
+ $inputModel = $this->_pFormModelBuilderAddressDetailSettings->createButtonModelFieldsConfigByCategory('1', ['field1'], 'label');
+ $this->assertEquals('label', $inputModel->getLabel());
+ $this->assertEquals('1', $inputModel->getId());
+ $this->assertEquals(['field1'], $inputModel->getValuesAvailable());
+ $this->assertInstanceOf(InputModelOption::class, $inputModel);
+ }
+}
diff --git a/tests/TestClassImageTypes.php b/tests/TestClassImageTypes.php
index 9abd48f74..3ef024d5b 100644
--- a/tests/TestClassImageTypes.php
+++ b/tests/TestClassImageTypes.php
@@ -60,6 +60,27 @@ public function testGetAllImageTypesTranslated()
$pReflection = new ReflectionClass(ImageTypes::class);
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
+ unset($nameConstants['PASSPORTPHOTO']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}
+
+
+ /**
+ *
+ */
+
+ public function testGetImageTypesForAddress()
+ {
+ $pReflection = new ReflectionClass(ImageTypes::class);
+ $nameConstants = $pReflection->getConstants();
+ unset($nameConstants['TITLE']);
+ unset($nameConstants['PHOTO']);
+ unset($nameConstants['PHOTO_BIG']);
+ unset($nameConstants['PANORAMA']);
+ unset($nameConstants['GROUNDPLAN']);
+ unset($nameConstants['LOCATION_MAP']);
+ unset($nameConstants['ENERGY_PASS_RANGE']);
+ unset($nameConstants['IMAGE_TYPES']);
+ $this->assertEqualSets($nameConstants, array_keys(ImageTypes::getImageTypesForAddress()));
+ }
}
diff --git a/tests/TestClassInputModelOptionFactoryAddressDetailView.php b/tests/TestClassInputModelOptionFactoryAddressDetailView.php
new file mode 100644
index 000000000..f4c91f4d9
--- /dev/null
+++ b/tests/TestClassInputModelOptionFactoryAddressDetailView.php
@@ -0,0 +1,73 @@
+.
+ *
+ */
+
+declare (strict_types=1);
+
+namespace onOffice\tests;
+use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
+use WP_UnitTestCase;
+use onOffice\WPlugin\Model\InputModel\InputModelOptionFactoryAddressDetailView;
+
+/**
+ *
+ * @url http://www.onoffice.de
+ * @copyright 2003-2024, onOffice(R) GmbH
+ *
+ */
+
+class TestClassInputModelOptionFactoryAddressDetailView
+ extends WP_UnitTestCase
+{
+
+ /** @var string */
+ private $_optionGroup = 'onoffice';
+
+ /**
+ *
+ */
+
+ public function testConstruct()
+ {
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $this->assertInstanceOf(InputModelOptionFactoryAddressDetailView::class,
+ $pInputModelOptionFactoryAddressDetailView);
+ }
+
+ public function testCreate()
+ {
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $label = 'Label Test';
+ $pInputModelOption = $pInputModelOptionFactoryAddressDetailView->create('fields', $label);
+
+ $this->assertEquals($pInputModelOption->getOptionGroup(), 'onoffice');
+ $this->assertEquals($pInputModelOption->getName(), 'fields');
+ $this->assertEquals($pInputModelOption->getDescriptionTextHTML(), null);
+ $this->assertEquals($pInputModelOption->getDescriptionRadioTextHTML(), []);
+ }
+
+ public function testNoNameCreate()
+ {
+ $this->expectException(ExceptionInputModelMissingField::class);
+ $pInputModelOptionFactoryAddressDetailView = new InputModelOptionFactoryAddressDetailView($this->_optionGroup);
+ $label = 'Label Test';
+ $pInputModelOptionFactoryAddressDetailView->create('test', $label);
+ }
+}
diff --git a/tests/TestClassRewriteRuleBuilder.php b/tests/TestClassRewriteRuleBuilder.php
index 0f2e26c67..1726c31f3 100644
--- a/tests/TestClassRewriteRuleBuilder.php
+++ b/tests/TestClassRewriteRuleBuilder.php
@@ -31,6 +31,8 @@
use onOffice\WPlugin\DataView\DataDetailView;
use onOffice\WPlugin\DataView\DataDetailViewHandler;
use onOffice\WPlugin\WP\WPPageWrapper;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataAddressDetailView;
/**
*
@@ -121,4 +123,57 @@ public function testAddDynamicRewriteRules()
'index.php?pagename=test_parent%2Ftest-post&view=$matches[1]&estate_id=$matches[2]'
], $wp_rewrite->extra_rules_top);
}
+
+ public function testAddCustomRewriteTagsForAddressDetail()
+ {
+ global $wp_rewrite;
+ $wp_rewrite->rewritecode = [];
+ $wp_rewrite->rewritereplace = [];
+ $pSubject = $this->_pContainer->get(RewriteRuleBuilder::class);
+ $pSubject->addCustomRewriteTagsForAddressDetail();
+ $this->assertSame('%address_id%', $wp_rewrite->rewritecode[0]);
+ $this->assertSame('([^&]+)', $wp_rewrite->rewritereplace[0]);
+
+ $this->assertSame('%view%', $wp_rewrite->rewritecode[1]);
+ $this->assertSame('([^&]+)', $wp_rewrite->rewritereplace[1]);
+ }
+
+ /**
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
+ public function testAddDynamicRewriteRulesForAddressDetail()
+ {
+ global $wp_rewrite;
+ $wp_rewrite->extra_rules_top = [];
+
+ $pDataAddressDetailViewHandler = $this->getMockBuilder(DataAddressDetailViewHandler::class)
+ ->disableOriginalConstructor()
+ ->setMethods(['getAddressDetailView'])
+ ->getMock();
+
+ $pDataAdressDetailView = new DataAddressDetailView;
+ $pDataAdressDetailView->addToPageIdsHaveDetailShortCode(13);
+ $pDataAdressDetailView->setPageId(13);
+ $pDataAddressDetailViewHandler->expects($this->once())
+ ->method('getAddressDetailView')
+ ->willReturn($pDataAdressDetailView);
+
+ $pWPPageWrapper = $this->getMockBuilder(WPPageWrapper::class)
+ ->setMethods(['getPageUriByPageId'])
+ ->getMock();
+ $pWPPageWrapper->method('getPageUriByPageId')
+ ->with(13)
+ ->willReturn('test_parent/test-post');
+
+ $this->_pContainer->set(DataAddressDetailViewHandler::class, $pDataAddressDetailViewHandler);
+ $this->_pContainer->set(WPPageWrapper::class, $pWPPageWrapper);
+
+ $pSubject = $this->_pContainer->get(RewriteRuleBuilder::class);
+ $pSubject->addDynamicRewriteRulesForAddressDetail();
+ $this->assertSame([
+ '^(test_parent/test\-post)/([0-9]+)(-([^$]+)?)?/?$' =>
+ 'index.php?pagename=test_parent%2Ftest-post&view=$matches[1]&address_id=$matches[2]'
+ ], $wp_rewrite->extra_rules_top);
+ }
}
\ No newline at end of file
From b574c5888a41abad81cc108f46370d7f835f7f8d Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Wed, 29 May 2024 16:13:34 +0700
Subject: [PATCH 08/33] 47945 refactor code & update unit test
---
dist/checkbox.min.js | 2 +-
js/checkbox.js | 2 +-
plugin/DataView/DataAddressDetailView.php | 80 ++++++++---------
.../DataView/DataAddressDetailViewHandler.php | 10 +--
plugin/Gui/AdminPageAddressDetail.php | 2 +-
.../FormModelBuilderAddressDetailSettings.php | 20 ++---
...putModelOptionFactoryAddressDetailView.php | 18 ++--
plugin/Types/ImageTypes.php | 4 +-
tests/TestClassDataAddressDetailView.php | 23 +++--
.../TestClassDataAddressDetailViewHandler.php | 2 +-
...sFormModelBuilderAddressDetailSettings.php | 86 ++++++++++++++++++-
tests/TestClassImageTypes.php | 2 +-
12 files changed, 174 insertions(+), 77 deletions(-)
diff --git a/dist/checkbox.min.js b/dist/checkbox.min.js
index b29aaa010..df366d5fe 100644
--- a/dist/checkbox.min.js
+++ b/dist/checkbox.min.js
@@ -1 +1 @@
-var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name=onoffice-showLinkEstates]":[{element:"select[name=onoffice-referenceEstates]",invert:false},{element:"select[name=onoffice-filterId]",invert:false},{element:"input[name=onoffice-recordsPerPage]",invert:false},{element:"input[name=onoffice-showEstatesStatus]",invert:false},{element:"input[name=onoffice-showPriceOnRequest]",invert:false},{element:"input[name=onoffice-showMap]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){var isChosen=receiverElement[0].classList.contains("chosen-select");if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked");if(isChosen){receiverElement.trigger("chosen:updated")}}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled");if(isChosen){receiverElement.trigger("chosen:updated")}}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
+var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name=onoffice-enableLinkedEstates]":[{element:"select[name=onoffice-referenceEstates]",invert:false},{element:"select[name=onoffice-filterId]",invert:false},{element:"input[name=onoffice-recordsPerPage]",invert:false},{element:"input[name=onoffice-showEstatesStatus]",invert:false},{element:"input[name=onoffice-showPriceOnRequest]",invert:false},{element:"input[name=onoffice-showMap]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){var isChosen=receiverElement[0].classList.contains("chosen-select");if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked");if(isChosen){receiverElement.trigger("chosen:updated")}}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled");if(isChosen){receiverElement.trigger("chosen:updated")}}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
diff --git a/js/checkbox.js b/js/checkbox.js
index 4217cae35..468cd488c 100644
--- a/js/checkbox.js
+++ b/js/checkbox.js
@@ -47,7 +47,7 @@ onOffice.checkboxAdmin = function() {
],
// view: address detail view
- "input[name=onoffice-showLinkEstates]": [
+ "input[name=onoffice-enableLinkedEstates]": [
{
element: "select[name=onoffice-referenceEstates]",
invert: false
diff --git a/plugin/DataView/DataAddressDetailView.php b/plugin/DataView/DataAddressDetailView.php
index a17443029..a5c97e79c 100644
--- a/plugin/DataView/DataAddressDetailView.php
+++ b/plugin/DataView/DataAddressDetailView.php
@@ -49,7 +49,7 @@ class DataAddressDetailView
const SHOW_ESTATES_STATUS = 'showEstatesStatus';
/** */
- const SHOW_LINK_ESTATES = 'showLinkEstates';
+ const ENABLE_LINKED_ESTATES = 'enableLinkedEstates';
/** */
const REFERENCE_ESTATES = 'referenceEstates';
@@ -125,26 +125,26 @@ class DataAddressDetailView
/** @var array */
private $_customLabel = [];
- /** @var int */
- private $_showEstateStatus = 0;
-
- /** @var int */
- private $_showLinkEstates = 0;
+ /** @var bool */
+ private $_enableLinkedEstates = false;
/** @var string */
private $_showReferenceEstates = '0';
/** @var int */
- private $_filter = '';
+ private $_filterId = 0;
/** @var int */
- private $_numberRecordsPerPage = 5;
+ private $_numberRecordsPerPage = 12;
- /** @var int */
- private $_showPriceOnRequest = 0;
+ /** @var bool */
+ private $_showEstateStatus = false;
- /** @var int */
- private $_showEstatesMap = 0;
+ /** @var bool */
+ private $_showPriceOnRequest = false;
+
+ /** @var bool */
+ private $_showEstatesMap = false;
/** @return int */
public function getPageId(): int
@@ -210,21 +210,13 @@ public function getCustomLabels()
public function setCustomLabels(array $customLabel)
{ $this->_customLabel = $customLabel; }
- /** @return int */
- public function getShowEstateStatus(): int
- { return $this->_showEstateStatus;}
-
- /** @param int $estateStatus */
- public function setShowEstateStatus(int $estateStatus)
- { $this->_showEstateStatus = $estateStatus; }
-
- /** @return int */
- public function getShowLinkEstates(): int
- { return $this->_showLinkEstates; }
+ /** @return bool */
+ public function getEnableLinkedEstates(): bool
+ { return $this->_enableLinkedEstates; }
- /** @param int $showLinkEstates */
- public function setShowLinkEstates(int $showLinkEstates)
- { $this->_showLinkEstates = $showLinkEstates; }
+ /** @param bool $enableLinkedEstates */
+ public function setEnableLinkedEstates(bool $enableLinkedEstates)
+ { $this->_enableLinkedEstates = $enableLinkedEstates; }
/** @return string */
public function getShowReferenceEstate(): string
@@ -234,13 +226,13 @@ public function getShowReferenceEstate(): string
public function setShowReferenceEstate(string $referenceEstate)
{ $this->_showReferenceEstates = $referenceEstate; }
- /** @return string */
- public function getFilter(): string
- { return $this->_filter; }
+ /** @return int */
+ public function getFilterId(): int
+ { return $this->_filterId; }
- /** @param string $filter */
- public function setFilter(string $filter)
- { $this->_filter = $filter; }
+ /** @param int $filterId */
+ public function setFilterId(int $filterId)
+ { $this->_filterId = $filterId; }
/** @return int */
public function getRecordsPerPage(): int
@@ -250,19 +242,27 @@ public function getRecordsPerPage(): int
public function setRecordsPerPage(int $numberRecords)
{ $this->_numberRecordsPerPage = $numberRecords; }
- /** @return int */
- public function getShowPriceOnRequest(): int
+ /** @return bool */
+ public function getShowEstateStatus(): bool
+ { return $this->_showEstateStatus;}
+
+ /** @param bool $estateStatus */
+ public function setShowEstateStatus(bool $estateStatus)
+ { $this->_showEstateStatus = $estateStatus; }
+
+ /** @return bool */
+ public function getShowPriceOnRequest(): bool
{ return $this->_showPriceOnRequest; }
- /** @param int $showPriceOnRequest */
- public function setShowPriceOnRequest(int $showPriceOnRequest)
+ /** @param bool $showPriceOnRequest */
+ public function setShowPriceOnRequest(bool $showPriceOnRequest)
{ $this->_showPriceOnRequest = $showPriceOnRequest; }
- /** @return int */
- public function getShowEstateMap(): int
+ /** @return bool */
+ public function getShowEstateMap(): bool
{ return $this->_showEstatesMap; }
- /** @param int $showEstatesMap */
- public function setShowEstateMap(int $showEstatesMap)
+ /** @param bool $showEstatesMap */
+ public function setShowEstateMap(bool $showEstatesMap)
{ $this->_showEstatesMap = $showEstatesMap; }
}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
index 27fac18d9..11485d976 100644
--- a/plugin/DataView/DataAddressDetailViewHandler.php
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -105,13 +105,13 @@ public function createAddressDetailViewByValues(array $row): DataAddressDetailVi
$pDataAddressDetailView->setEstateFields($row[DataAddressDetailView::ESTATE_FIELDS] ?? []);
$pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
$pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
- $pDataAddressDetailView->setShowEstateStatus($row[DataAddressDetailView::SHOW_ESTATES_STATUS] ?? 0);
- $pDataAddressDetailView->setShowLinkEstates($row[DataAddressDetailView::SHOW_LINK_ESTATES] ?? 0);
+ $pDataAddressDetailView->setEnableLinkedEstates($row[DataAddressDetailView::ENABLE_LINKED_ESTATES] ?? false);
+ $pDataAddressDetailView->setShowEstateStatus($row[DataAddressDetailView::SHOW_ESTATES_STATUS] ?? false);
$pDataAddressDetailView->setShowReferenceEstate($row[DataAddressDetailView::REFERENCE_ESTATES] ?? '0');
- $pDataAddressDetailView->setFilter($row[DataAddressDetailView::INPUT_FILTERID] ?? '');
+ $pDataAddressDetailView->setFilterId($row[DataAddressDetailView::INPUT_FILTERID] ?? 0);
$pDataAddressDetailView->setRecordsPerPage($row[DataAddressDetailView::RECORDS_PER_PAGE] ?? 0);
- $pDataAddressDetailView->setShowPriceOnRequest($row[DataAddressDetailView::SHOW_PRICE_ON_REQUEST] ?? 0);
- $pDataAddressDetailView->setShowEstateMap($row[DataAddressDetailView::SHOW_ESTATES_MAP] ?? 0);
+ $pDataAddressDetailView->setShowPriceOnRequest($row[DataAddressDetailView::SHOW_PRICE_ON_REQUEST] ?? false);
+ $pDataAddressDetailView->setShowEstateMap($row[DataAddressDetailView::SHOW_ESTATES_MAP] ?? false);
return $pDataAddressDetailView;
}
diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php
index 8dab48401..273692fd0 100644
--- a/plugin/Gui/AdminPageAddressDetail.php
+++ b/plugin/Gui/AdminPageAddressDetail.php
@@ -289,7 +289,7 @@ protected function buildForms()
$pFormModelPictureTypes->addInputModel($pInputModelPictureTypes);
$this->addFormModel($pFormModelPictureTypes);
- $pInputModelLinkEstates = $pFormModelBuilder->createInputModelShowLinkEstates();
+ $pInputModelLinkEstates = $pFormModelBuilder->createInputModelEnableLinkedEstates();
$pInputModelEstatesStatus = $pFormModelBuilder->createInputModelShowEstatesStatus();
$pInputModelListReferenceEstates = $pFormModelBuilder->createInputModelShowReferenceEstates();
$pInputModelFilters = $pFormModelBuilder->createInputModelFilter();
diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
index ba9bca24b..3ae1732e7 100644
--- a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
+++ b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
@@ -353,20 +353,20 @@ static public function getListViewReferenceEstates(): array
* @return InputModelOption
* @throws ExceptionInputModelMissingField
*/
- public function createInputModelShowLinkEstates(): InputModelOption
+ public function createInputModelEnableLinkedEstates(): InputModelOption
{
- $labelShowStatus = __('Show Linked Estates', 'onoffice-for-wp-websites');
+ $labelEnableLinkedEstates = __('Show Linked Estates', 'onoffice-for-wp-websites');
- $pInputModelShowStatus = $this->_pInputModelAddressDetailFactory->create
- (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_LINK_ESTATES, $labelShowStatus);
- $pInputModelShowStatus->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
+ $pInputModelEnableLinkedEstates = $this->_pInputModelAddressDetailFactory->create
+ (InputModelOptionFactoryAddressDetailView::INPUT_ENABLE_LINKED_ESTATES, $labelEnableLinkedEstates);
+ $pInputModelEnableLinkedEstates->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
- $showEstateStatus = $this->_pDataAddressDetail->getShowLinkEstates();
+ $showEstateStatus = $this->_pDataAddressDetail->getEnableLinkedEstates();
- $pInputModelShowStatus->setValue($showEstateStatus);
- $pInputModelShowStatus->setValuesAvailable(1);
+ $pInputModelEnableLinkedEstates->setValue($showEstateStatus);
+ $pInputModelEnableLinkedEstates->setValuesAvailable(1);
- return $pInputModelShowStatus;
+ return $pInputModelEnableLinkedEstates;
}
/**
@@ -421,7 +421,7 @@ public function createInputModelFilter(): InputModelOption
$pInputModelFilterName->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
$availableFilters = array(0 => '') + $this->readFilters(onOfficeSDK::MODULE_ESTATE);
- $filterIdSelected = $this->_pDataAddressDetail->getFilter();
+ $filterIdSelected = $this->_pDataAddressDetail->getFilterId();
$pInputModelFilterName->setValuesAvailable($availableFilters);
$pInputModelFilterName->setValue($filterIdSelected);
diff --git a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
index 35a7e4da1..3301324a3 100644
--- a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
+++ b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
@@ -51,7 +51,7 @@ class InputModelOptionFactoryAddressDetailView
const INPUT_SHOW_ESTATES_STATUS = 'showEstatesStatus';
/** @var string */
- const INPUT_SHOW_LINK_ESTATES = 'showLinkEstates';
+ const INPUT_ENABLE_LINKED_ESTATES = 'enableLinkedEstates';
/** @var string */
const INPUT_SHOW_REFERENCE_ESTATE = 'referenceEstates';
@@ -89,26 +89,26 @@ class InputModelOptionFactoryAddressDetailView
self::INPUT_ESTATE_FIELD_CONFIG => [
self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
],
- self::INPUT_SHOW_LINK_ESTATES => [
- self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
- ],
- self::INPUT_SHOW_ESTATES_STATUS => [
- self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ self::INPUT_ENABLE_LINKED_ESTATES => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_BOOLEAN,
],
self::INPUT_SHOW_REFERENCE_ESTATE => [
- self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_BOOLEAN,
],
self::INPUT_FILTERID => [
- self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
],
self::INPUT_RECORDS_PER_PAGE => [
self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
],
+ self::INPUT_SHOW_ESTATES_STATUS => [
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_BOOLEAN,
+ ],
self::INPUT_SHOW_PRICE_ON_REQUEST => [
self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING,
],
self::INPUT_SHOW_MAP => [
- self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
+ self::KEY_TYPE => InputModelOption::SETTING_TYPE_BOOLEAN,
],
];
diff --git a/plugin/Types/ImageTypes.php b/plugin/Types/ImageTypes.php
index 0f061031c..f30175869 100644
--- a/plugin/Types/ImageTypes.php
+++ b/plugin/Types/ImageTypes.php
@@ -32,7 +32,7 @@ class ImageTypes
const PANORAMA = 'Panorama';
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
- const PASSPORTPHOTO = 'PassportPhoto';
+ const PASSPORT_PHOTO = 'PassportPhoto';
const IMAGE_TYPES = [
self::TITLE,
@@ -75,7 +75,7 @@ public static function getAllImageTypesTranslated(): array
public static function getImageTypesForAddress(): array
{
return [
- self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
+ self::PASSPORT_PHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
];
}
}
diff --git a/tests/TestClassDataAddressDetailView.php b/tests/TestClassDataAddressDetailView.php
index db5a77292..21541cac5 100644
--- a/tests/TestClassDataAddressDetailView.php
+++ b/tests/TestClassDataAddressDetailView.php
@@ -54,6 +54,12 @@ public function testDefaultValues()
$this->assertEquals('', $pDataAddressDetailView->getTemplate());
$this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
$this->assertEquals([], $pDataAddressDetailView->getCustomLabels());
+ $this->assertEquals(false, $pDataAddressDetailView->getShowPriceOnRequest());
+ $this->assertEquals(false, $pDataAddressDetailView->getShowEstateMap());
+ $this->assertEquals('0', $pDataAddressDetailView->getShowReferenceEstate());
+ $this->assertEquals(0, $pDataAddressDetailView->getFilterId());
+ $this->assertEquals(12, $pDataAddressDetailView->getRecordsPerPage());
+ $this->assertEquals(false, $pDataAddressDetailView->getEnableLinkedEstates());
}
/**
@@ -82,10 +88,17 @@ public function testGetterSetter()
$this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
$pDataAddressDetailView->setCustomLabels(['field1']);
$this->assertEquals(['field1'], $pDataAddressDetailView->getCustomLabels());
- $pDataAddressDetailView->setShowPriceOnRequest(1);
- $this->assertEquals(1, $pDataAddressDetailView->getShowPriceOnRequest());
- $pDataAddressDetailView->setShowEstateMap(1);
- $this->assertEquals(1, $pDataAddressDetailView->getShowEstateMap());
- $pDataAddressDetailView->setShowReferenceEstates('');
+ $pDataAddressDetailView->setShowPriceOnRequest(true);
+ $this->assertTrue($pDataAddressDetailView->getShowPriceOnRequest());
+ $pDataAddressDetailView->setShowEstateMap(true);
+ $this->assertTrue($pDataAddressDetailView->getShowEstateMap());
+ $pDataAddressDetailView->setShowReferenceEstate('0');
+ $this->assertEquals('0', $pDataAddressDetailView->getShowReferenceEstate());
+ $pDataAddressDetailView->setFilterId(1);
+ $this->assertEquals(1, $pDataAddressDetailView->getFilterId());
+ $pDataAddressDetailView->setRecordsPerPage(20);
+ $this->assertEquals(20, $pDataAddressDetailView->getRecordsPerPage());
+ $pDataAddressDetailView->setEnableLinkedEstates(true);
+ $this->assertTrue($pDataAddressDetailView->getEnableLinkedEstates());
}
}
diff --git a/tests/TestClassDataAddressDetailViewHandler.php b/tests/TestClassDataAddressDetailViewHandler.php
index 6c12da083..ba2fa9ecc 100644
--- a/tests/TestClassDataAddressDetailViewHandler.php
+++ b/tests/TestClassDataAddressDetailViewHandler.php
@@ -48,7 +48,7 @@ class TestClassDataAddressDetailViewHandler
'kaufpreis',
],
'pictures' => [
- ImageTypes::PASSPORTPHOTO,
+ ImageTypes::PASSPORT_PHOTO,
],
'oo_plugin_fieldconfig_address_translated_labels' => ['field']
];
diff --git a/tests/TestClassFormModelBuilderAddressDetailSettings.php b/tests/TestClassFormModelBuilderAddressDetailSettings.php
index 1d7773fa7..2d6095410 100644
--- a/tests/TestClassFormModelBuilderAddressDetailSettings.php
+++ b/tests/TestClassFormModelBuilderAddressDetailSettings.php
@@ -86,6 +86,7 @@ public function testConstruct()
$pInstance = $this->_pFormModelBuilderAddressDetailSettings;
$this->assertInstanceOf(FormModelBuilderAddressDetailSettings::class, $pInstance);
}
+
/**
* @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createSortableFieldList
* @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::getInputModelCustomLabel
@@ -108,7 +109,7 @@ public function testCreateSearchFieldForFieldLists()
{
$pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
$pFormModelBuilderAddressDetailSettings->generate('test');
- $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSearchFieldForFieldLists('address', 'searchFieldForFieldLists');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createSearchFieldForFieldLists(['address', 'estate'], 'searchFieldForFieldLists');
$this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
$this->assertNotEmpty($pInputModelOption->getValuesAvailable());
@@ -196,4 +197,87 @@ public function testCreateButtonModelFieldsConfigByCategory()
$this->assertEquals(['field1'], $inputModel->getValuesAvailable());
$this->assertInstanceOf(InputModelOption::class, $inputModel);
}
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelEnableLinkedEstates
+ */
+ public function testCreateInputModelEnableLinkedEstates()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelEnableLinkedEstates();
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'checkbox');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShowEstatesStatus
+ */
+ public function testCreateInputModelShowEstatesStatus()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelShowEstatesStatus();
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'checkbox');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShowReferenceEstates
+ */
+ public function testCreateInputModelShowReferenceEstates()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelShowReferenceEstates();
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'select');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelRecordsPerPage
+ */
+ public function testCreateInputModelRecordsPerPage()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelRecordsPerPage();
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'number');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShowPriceOnRequest
+ */
+ public function testCreateInputModelShowPriceOnRequest()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelShowPriceOnRequest();
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'checkbox');
+ }
+
+ /**
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShowMap
+ */
+ public function testCreateInputModelShowMap()
+ {
+ $pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
+ $pFormModelBuilderAddressDetailSettings->generate('test');
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelShowMap();
+
+ $this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
+ $this->assertNotEmpty($pInputModelOption->getValuesAvailable());
+ $this->assertEquals($pInputModelOption->getHtmlType(), 'checkbox');
+ }
}
diff --git a/tests/TestClassImageTypes.php b/tests/TestClassImageTypes.php
index 3ef024d5b..1b97cb1df 100644
--- a/tests/TestClassImageTypes.php
+++ b/tests/TestClassImageTypes.php
@@ -60,7 +60,7 @@ public function testGetAllImageTypesTranslated()
$pReflection = new ReflectionClass(ImageTypes::class);
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
- unset($nameConstants['PASSPORTPHOTO']);
+ unset($nameConstants['PASSPORT_PHOTO']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}
From a2677089c8a433f4079e253144442dbf15f0b05c Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Thu, 30 May 2024 10:39:36 +0700
Subject: [PATCH 09/33] 47945 refactor code
---
dist/checkbox.min.js | 2 +-
js/checkbox.js | 6 +--
plugin/DataView/DataAddressDetailView.php | 52 +++++++++----------
.../DataView/DataAddressDetailViewHandler.php | 8 +--
plugin/Gui/AdminPageAddressDetail.php | 20 +++----
.../FormModelBuilderAddressDetailSettings.php | 35 +++++--------
...putModelOptionFactoryAddressDetailView.php | 8 +--
plugin/Types/ImageTypes.php | 4 +-
tests/TestClassDataAddressDetailView.php | 6 +--
.../TestClassDataAddressDetailViewHandler.php | 2 +-
...sFormModelBuilderAddressDetailSettings.php | 4 +-
tests/TestClassImageTypes.php | 2 +-
12 files changed, 70 insertions(+), 79 deletions(-)
diff --git a/dist/checkbox.min.js b/dist/checkbox.min.js
index df366d5fe..d9ac774bf 100644
--- a/dist/checkbox.min.js
+++ b/dist/checkbox.min.js
@@ -1 +1 @@
-var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name=onoffice-enableLinkedEstates]":[{element:"select[name=onoffice-referenceEstates]",invert:false},{element:"select[name=onoffice-filterId]",invert:false},{element:"input[name=onoffice-recordsPerPage]",invert:false},{element:"input[name=onoffice-showEstatesStatus]",invert:false},{element:"input[name=onoffice-showPriceOnRequest]",invert:false},{element:"input[name=onoffice-showMap]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){var isChosen=receiverElement[0].classList.contains("chosen-select");if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked");if(isChosen){receiverElement.trigger("chosen:updated")}}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled");if(isChosen){receiverElement.trigger("chosen:updated")}}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
+var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name=onoffice-enableLinkedEstates]":[{element:"select[name=onoffice-showReferenceEstate]",invert:false},{element:"select[name=onoffice-filterId]",invert:false},{element:"input[name=onoffice-recordsPerPage]",invert:false},{element:"input[name=onoffice-showStatus]",invert:false},{element:"input[name=onoffice-showPriceOnRequest]",invert:false},{element:"input[name=onoffice-showMap]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){var isChosen=receiverElement[0].classList.contains("chosen-select");if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked");if(isChosen){receiverElement.trigger("chosen:updated")}}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled");if(isChosen){receiverElement.trigger("chosen:updated")}}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
diff --git a/js/checkbox.js b/js/checkbox.js
index 468cd488c..4ceaaaeba 100644
--- a/js/checkbox.js
+++ b/js/checkbox.js
@@ -49,7 +49,7 @@ onOffice.checkboxAdmin = function() {
// view: address detail view
"input[name=onoffice-enableLinkedEstates]": [
{
- element: "select[name=onoffice-referenceEstates]",
+ element: "select[name=onoffice-showReferenceEstate]",
invert: false
},
{
@@ -61,7 +61,7 @@ onOffice.checkboxAdmin = function() {
invert: false
},
{
- element: "input[name=onoffice-showEstatesStatus]",
+ element: "input[name=onoffice-showStatus]",
invert: false
},
{
@@ -71,7 +71,7 @@ onOffice.checkboxAdmin = function() {
{
element: "input[name=onoffice-showMap]",
invert: false
- },
+ }
]
};
};
diff --git a/plugin/DataView/DataAddressDetailView.php b/plugin/DataView/DataAddressDetailView.php
index a5c97e79c..5dc91549a 100644
--- a/plugin/DataView/DataAddressDetailView.php
+++ b/plugin/DataView/DataAddressDetailView.php
@@ -46,16 +46,16 @@ class DataAddressDetailView
const PICTURES = 'pictures';
/** */
- const SHOW_ESTATES_STATUS = 'showEstatesStatus';
+ const SHOW_STATUS = 'showStatus';
/** */
const ENABLE_LINKED_ESTATES = 'enableLinkedEstates';
/** */
- const REFERENCE_ESTATES = 'referenceEstates';
+ const ENABLE_REFERENCE_ESTATE = 'showReferenceEstate';
/** */
- const INPUT_FILTERID = 'filterId';
+ const FILTERID = 'filterId';
/** */
const RECORDS_PER_PAGE = 'recordsPerPage';
@@ -64,7 +64,7 @@ class DataAddressDetailView
const SHOW_PRICE_ON_REQUEST = 'showPriceOnRequest';
/** */
- const SHOW_ESTATES_MAP = 'showMap';
+ const SHOW_MAP = 'showMap';
/** */
const FIELD_CUSTOM_LABEL = 'oo_plugin_fieldconfig_address_translated_labels';
@@ -129,22 +129,22 @@ class DataAddressDetailView
private $_enableLinkedEstates = false;
/** @var string */
- private $_showReferenceEstates = '0';
+ private $_showReferenceEstate = '0';
/** @var int */
private $_filterId = 0;
/** @var int */
- private $_numberRecordsPerPage = 12;
+ private $_recordsPerPage = 12;
/** @var bool */
- private $_showEstateStatus = false;
+ private $_showStatus = false;
/** @var bool */
private $_showPriceOnRequest = false;
/** @var bool */
- private $_showEstatesMap = false;
+ private $_showMap = false;
/** @return int */
public function getPageId(): int
@@ -220,11 +220,11 @@ public function setEnableLinkedEstates(bool $enableLinkedEstates)
/** @return string */
public function getShowReferenceEstate(): string
- { return $this->_showReferenceEstates; }
+ { return $this->_showReferenceEstate; }
- /** @param string $referenceEstate */
- public function setShowReferenceEstate(string $referenceEstate)
- { $this->_showReferenceEstates = $referenceEstate; }
+ /** @param string $showReferenceEstate */
+ public function setShowReferenceEstate(string $showReferenceEstate)
+ { $this->_showReferenceEstate = $showReferenceEstate; }
/** @return int */
public function getFilterId(): int
@@ -236,19 +236,19 @@ public function setFilterId(int $filterId)
/** @return int */
public function getRecordsPerPage(): int
- { return $this->_numberRecordsPerPage; }
+ { return $this->_recordsPerPage; }
- /** @param int $numberRecords */
- public function setRecordsPerPage(int $numberRecords)
- { $this->_numberRecordsPerPage = $numberRecords; }
+ /** @param int $recordsPerPage */
+ public function setRecordsPerPage(int $recordsPerPage)
+ { $this->_recordsPerPage = $recordsPerPage; }
/** @return bool */
- public function getShowEstateStatus(): bool
- { return $this->_showEstateStatus;}
+ public function getShowStatus(): bool
+ { return $this->_showStatus;}
- /** @param bool $estateStatus */
- public function setShowEstateStatus(bool $estateStatus)
- { $this->_showEstateStatus = $estateStatus; }
+ /** @param bool $showStatus */
+ public function setShowStatus(bool $showStatus)
+ { $this->_showStatus = $showStatus; }
/** @return bool */
public function getShowPriceOnRequest(): bool
@@ -259,10 +259,10 @@ public function setShowPriceOnRequest(bool $showPriceOnRequest)
{ $this->_showPriceOnRequest = $showPriceOnRequest; }
/** @return bool */
- public function getShowEstateMap(): bool
- { return $this->_showEstatesMap; }
+ public function getShowMap(): bool
+ { return $this->_showMap; }
- /** @param bool $showEstatesMap */
- public function setShowEstateMap(bool $showEstatesMap)
- { $this->_showEstatesMap = $showEstatesMap; }
+ /** @param bool $showMap */
+ public function setShowMap(bool $showMap)
+ { $this->_showMap = $showMap; }
}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
index 11485d976..194efd839 100644
--- a/plugin/DataView/DataAddressDetailViewHandler.php
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -106,12 +106,12 @@ public function createAddressDetailViewByValues(array $row): DataAddressDetailVi
$pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
$pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
$pDataAddressDetailView->setEnableLinkedEstates($row[DataAddressDetailView::ENABLE_LINKED_ESTATES] ?? false);
- $pDataAddressDetailView->setShowEstateStatus($row[DataAddressDetailView::SHOW_ESTATES_STATUS] ?? false);
- $pDataAddressDetailView->setShowReferenceEstate($row[DataAddressDetailView::REFERENCE_ESTATES] ?? '0');
- $pDataAddressDetailView->setFilterId($row[DataAddressDetailView::INPUT_FILTERID] ?? 0);
+ $pDataAddressDetailView->setShowStatus($row[DataAddressDetailView::SHOW_STATUS] ?? false);
+ $pDataAddressDetailView->setShowReferenceEstate($row[DataAddressDetailView::ENABLE_REFERENCE_ESTATE] ?? '0');
+ $pDataAddressDetailView->setFilterId($row[DataAddressDetailView::FILTERID] ?? 0);
$pDataAddressDetailView->setRecordsPerPage($row[DataAddressDetailView::RECORDS_PER_PAGE] ?? 0);
$pDataAddressDetailView->setShowPriceOnRequest($row[DataAddressDetailView::SHOW_PRICE_ON_REQUEST] ?? false);
- $pDataAddressDetailView->setShowEstateMap($row[DataAddressDetailView::SHOW_ESTATES_MAP] ?? false);
+ $pDataAddressDetailView->setShowMap($row[DataAddressDetailView::SHOW_MAP] ?? false);
return $pDataAddressDetailView;
}
diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php
index 273692fd0..d2bd25686 100644
--- a/plugin/Gui/AdminPageAddressDetail.php
+++ b/plugin/Gui/AdminPageAddressDetail.php
@@ -289,24 +289,24 @@ protected function buildForms()
$pFormModelPictureTypes->addInputModel($pInputModelPictureTypes);
$this->addFormModel($pFormModelPictureTypes);
- $pInputModelLinkEstates = $pFormModelBuilder->createInputModelEnableLinkedEstates();
- $pInputModelEstatesStatus = $pFormModelBuilder->createInputModelShowEstatesStatus();
- $pInputModelListReferenceEstates = $pFormModelBuilder->createInputModelShowReferenceEstates();
+ $pInputModelEnableLinkedEstates= $pFormModelBuilder->createInputModelEnableLinkedEstates();
+ $pInputModelShowEstateStatus = $pFormModelBuilder->createInputModelShowEstateStatus();
+ $pInputModelShowReferenceEstates = $pFormModelBuilder->createInputModelShowReferenceEstates();
$pInputModelFilters = $pFormModelBuilder->createInputModelFilter();
$pInputModelRecordsPerPage = $pFormModelBuilder->createInputModelRecordsPerPage();
- $pInputModelPriceOnRequest = $pFormModelBuilder->createInputModelShowPriceOnRequest();
- $pInputModelEstateMap = $pFormModelBuilder->createInputModelShowMap();
+ $pInputModelShowPriceOnRequest = $pFormModelBuilder->createInputModelShowPriceOnRequest();
+ $pInputModelShowEstateMap = $pFormModelBuilder->createInputModelShowMap();
$pFormModelEstates = new FormModel();
$pFormModelEstates->setPageSlug($this->getPageSlug());
$pFormModelEstates->setGroupSlug(self::FORM_VIEW_ESTATE_CONFIG);
$pFormModelEstates->setLabel(__('Estates', 'onoffice-for-wp-websites'));
- $pFormModelEstates->addInputModel($pInputModelLinkEstates);
- $pFormModelEstates->addInputModel($pInputModelListReferenceEstates);
+ $pFormModelEstates->addInputModel($pInputModelEnableLinkedEstates);
+ $pFormModelEstates->addInputModel($pInputModelShowReferenceEstates);
$pFormModelEstates->addInputModel($pInputModelFilters);
$pFormModelEstates->addInputModel($pInputModelRecordsPerPage);
- $pFormModelEstates->addInputModel($pInputModelEstatesStatus);
- $pFormModelEstates->addInputModel($pInputModelPriceOnRequest);
- $pFormModelEstates->addInputModel($pInputModelEstateMap);
+ $pFormModelEstates->addInputModel($pInputModelShowEstateStatus);
+ $pFormModelEstates->addInputModel($pInputModelShowPriceOnRequest);
+ $pFormModelEstates->addInputModel($pInputModelShowEstateMap);
$this->addFormModel($pFormModelEstates);
$pEnvironment = new AddressListEnvironmentDefault();
diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
index 3ae1732e7..226288d7b 100644
--- a/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
+++ b/plugin/Model/FormModelBuilder/FormModelBuilderAddressDetailSettings.php
@@ -343,9 +343,9 @@ public function getInputModelCustomLabelLanguageSwitch(): InputModelDB
static public function getListViewReferenceEstates(): array
{
return array(
- DataListView::HIDE_REFERENCE_ESTATE => __( 'Hide reference estates', 'onoffice-for-wp-websites' ),
- DataListView::SHOW_REFERENCE_ESTATE => __( 'Show reference estates (alongside others)', 'onoffice-for-wp-websites' ),
- DataListView::SHOW_ONLY_REFERENCE_ESTATE => __( 'Show only reference estates (filter out all others)', 'onoffice-for-wp-websites' ),
+ DataListView::HIDE_REFERENCE_ESTATE => __('Hide reference estates', 'onoffice-for-wp-websites'),
+ DataListView::SHOW_REFERENCE_ESTATE => __('Show reference estates (alongside others)', 'onoffice-for-wp-websites'),
+ DataListView::SHOW_ONLY_REFERENCE_ESTATE => __('Show only reference estates (filter out all others)', 'onoffice-for-wp-websites'),
);
}
@@ -361,9 +361,7 @@ public function createInputModelEnableLinkedEstates(): InputModelOption
(InputModelOptionFactoryAddressDetailView::INPUT_ENABLE_LINKED_ESTATES, $labelEnableLinkedEstates);
$pInputModelEnableLinkedEstates->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
- $showEstateStatus = $this->_pDataAddressDetail->getEnableLinkedEstates();
-
- $pInputModelEnableLinkedEstates->setValue($showEstateStatus);
+ $pInputModelEnableLinkedEstates->setValue($this->_pDataAddressDetail->getEnableLinkedEstates());
$pInputModelEnableLinkedEstates->setValuesAvailable(1);
return $pInputModelEnableLinkedEstates;
@@ -373,17 +371,14 @@ public function createInputModelEnableLinkedEstates(): InputModelOption
* @return InputModelOption
* @throws ExceptionInputModelMissingField
*/
- public function createInputModelShowEstatesStatus(): InputModelOption
+ public function createInputModelShowEstateStatus(): InputModelOption
{
- $labelShowStatus = __('Show Estates Status', 'onoffice-for-wp-websites');
+ $labelShowStatus = __('Show Estate Status', 'onoffice-for-wp-websites');
$pInputModelShowStatus = $this->_pInputModelAddressDetailFactory->create
- (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_ESTATES_STATUS, $labelShowStatus);
+ (InputModelOptionFactoryAddressDetailView::INPUT_SHOW_STATUS, $labelShowStatus);
$pInputModelShowStatus->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
-
- $showEstateStatus = $this->_pDataAddressDetail->getShowEstateStatus();
-
- $pInputModelShowStatus->setValue($showEstateStatus);
+ $pInputModelShowStatus->setValue($this->_pDataAddressDetail->getShowStatus());
$pInputModelShowStatus->setValuesAvailable(1);
return $pInputModelShowStatus;
@@ -400,10 +395,7 @@ public function createInputModelShowReferenceEstates(): InputModelOption
$pInputModelShowReferenceEstate = $this->_pInputModelAddressDetailFactory->create
(InputModelOptionFactoryAddressDetailView::INPUT_SHOW_REFERENCE_ESTATE, $labelShowReferenceEstate);
$pInputModelShowReferenceEstate->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
-
- $showReferenceEstate = $this->_pDataAddressDetail->getShowReferenceEstate();
-
- $pInputModelShowReferenceEstate->setValue($showReferenceEstate);
+ $pInputModelShowReferenceEstate->setValue($this->_pDataAddressDetail->getShowReferenceEstate());
$pInputModelShowReferenceEstate->setValuesAvailable(self::getListViewReferenceEstates());
return $pInputModelShowReferenceEstate;
@@ -416,15 +408,13 @@ public function createInputModelShowReferenceEstates(): InputModelOption
public function createInputModelFilter(): InputModelOption
{
$labelFilterName = __('Filter', 'onoffice-for-wp-websites');
+
$pInputModelFilterName = $this->_pInputModelAddressDetailFactory->create
(InputModelOptionFactoryAddressDetailView::INPUT_FILTERID, $labelFilterName);
$pInputModelFilterName->setHtmlType(InputModelBase::HTML_TYPE_SELECT);
-
$availableFilters = array(0 => '') + $this->readFilters(onOfficeSDK::MODULE_ESTATE);
- $filterIdSelected = $this->_pDataAddressDetail->getFilterId();
-
$pInputModelFilterName->setValuesAvailable($availableFilters);
- $pInputModelFilterName->setValue($filterIdSelected);
+ $pInputModelFilterName->setValue($this->_pDataAddressDetail->getFilterId());
return $pInputModelFilterName;
}
@@ -436,6 +426,7 @@ public function createInputModelFilter(): InputModelOption
public function createInputModelRecordsPerPage(): InputModelOption
{
$labelRecordsPerPage = __('Estates per page', 'onoffice-for-wp-websites');
+
$pInputModelRecordsPerPage = $this->_pInputModelAddressDetailFactory->create
(InputModelOptionFactoryAddressDetailView::INPUT_RECORDS_PER_PAGE, $labelRecordsPerPage);
$pInputModelRecordsPerPage->setHtmlType(InputModelBase::HTML_TYPE_NUMBER);
@@ -474,7 +465,7 @@ public function createInputModelShowMap(): InputModelOption
$pInputModelShowMap = $this->_pInputModelAddressDetailFactory->create
(InputModelOptionFactoryAddressDetailView::INPUT_SHOW_MAP, $labelShowMap);
$pInputModelShowMap->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
- $pInputModelShowMap->setValue($this->_pDataAddressDetail->getShowEstateMap() ?? true);
+ $pInputModelShowMap->setValue($this->_pDataAddressDetail->getShowMap());
$pInputModelShowMap->setValuesAvailable(1);
return $pInputModelShowMap;
diff --git a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
index 3301324a3..db50b58bc 100644
--- a/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
+++ b/plugin/Model/InputModel/InputModelOptionFactoryAddressDetailView.php
@@ -48,13 +48,13 @@ class InputModelOptionFactoryAddressDetailView
const INPUT_PICTURE_TYPE = DataAddressDetailView::PICTURES;
/** @var string */
- const INPUT_SHOW_ESTATES_STATUS = 'showEstatesStatus';
+ const INPUT_ENABLE_LINKED_ESTATES = 'enableLinkedEstates';
/** @var string */
- const INPUT_ENABLE_LINKED_ESTATES = 'enableLinkedEstates';
+ const INPUT_SHOW_STATUS = 'showStatus';
/** @var string */
- const INPUT_SHOW_REFERENCE_ESTATE = 'referenceEstates';
+ const INPUT_SHOW_REFERENCE_ESTATE = 'showReferenceEstate';
/** @var string */
const INPUT_FILTERID = 'filterId';
@@ -101,7 +101,7 @@ class InputModelOptionFactoryAddressDetailView
self::INPUT_RECORDS_PER_PAGE => [
self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER,
],
- self::INPUT_SHOW_ESTATES_STATUS => [
+ self::INPUT_SHOW_STATUS => [
self::KEY_TYPE => InputModelOption::SETTING_TYPE_BOOLEAN,
],
self::INPUT_SHOW_PRICE_ON_REQUEST => [
diff --git a/plugin/Types/ImageTypes.php b/plugin/Types/ImageTypes.php
index f30175869..0f061031c 100644
--- a/plugin/Types/ImageTypes.php
+++ b/plugin/Types/ImageTypes.php
@@ -32,7 +32,7 @@ class ImageTypes
const PANORAMA = 'Panorama';
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
- const PASSPORT_PHOTO = 'PassportPhoto';
+ const PASSPORTPHOTO = 'PassportPhoto';
const IMAGE_TYPES = [
self::TITLE,
@@ -75,7 +75,7 @@ public static function getAllImageTypesTranslated(): array
public static function getImageTypesForAddress(): array
{
return [
- self::PASSPORT_PHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
+ self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
];
}
}
diff --git a/tests/TestClassDataAddressDetailView.php b/tests/TestClassDataAddressDetailView.php
index 21541cac5..c41b35ee8 100644
--- a/tests/TestClassDataAddressDetailView.php
+++ b/tests/TestClassDataAddressDetailView.php
@@ -55,7 +55,7 @@ public function testDefaultValues()
$this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
$this->assertEquals([], $pDataAddressDetailView->getCustomLabels());
$this->assertEquals(false, $pDataAddressDetailView->getShowPriceOnRequest());
- $this->assertEquals(false, $pDataAddressDetailView->getShowEstateMap());
+ $this->assertEquals(false, $pDataAddressDetailView->getShowMap());
$this->assertEquals('0', $pDataAddressDetailView->getShowReferenceEstate());
$this->assertEquals(0, $pDataAddressDetailView->getFilterId());
$this->assertEquals(12, $pDataAddressDetailView->getRecordsPerPage());
@@ -90,8 +90,8 @@ public function testGetterSetter()
$this->assertEquals(['field1'], $pDataAddressDetailView->getCustomLabels());
$pDataAddressDetailView->setShowPriceOnRequest(true);
$this->assertTrue($pDataAddressDetailView->getShowPriceOnRequest());
- $pDataAddressDetailView->setShowEstateMap(true);
- $this->assertTrue($pDataAddressDetailView->getShowEstateMap());
+ $pDataAddressDetailView->setShowMap(true);
+ $this->assertTrue($pDataAddressDetailView->getShowMap());
$pDataAddressDetailView->setShowReferenceEstate('0');
$this->assertEquals('0', $pDataAddressDetailView->getShowReferenceEstate());
$pDataAddressDetailView->setFilterId(1);
diff --git a/tests/TestClassDataAddressDetailViewHandler.php b/tests/TestClassDataAddressDetailViewHandler.php
index ba2fa9ecc..6c12da083 100644
--- a/tests/TestClassDataAddressDetailViewHandler.php
+++ b/tests/TestClassDataAddressDetailViewHandler.php
@@ -48,7 +48,7 @@ class TestClassDataAddressDetailViewHandler
'kaufpreis',
],
'pictures' => [
- ImageTypes::PASSPORT_PHOTO,
+ ImageTypes::PASSPORTPHOTO,
],
'oo_plugin_fieldconfig_address_translated_labels' => ['field']
];
diff --git a/tests/TestClassFormModelBuilderAddressDetailSettings.php b/tests/TestClassFormModelBuilderAddressDetailSettings.php
index 2d6095410..677e46e65 100644
--- a/tests/TestClassFormModelBuilderAddressDetailSettings.php
+++ b/tests/TestClassFormModelBuilderAddressDetailSettings.php
@@ -213,13 +213,13 @@ public function testCreateInputModelEnableLinkedEstates()
}
/**
- * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShowEstatesStatus
+ * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderAddressDetailSettings::createInputModelShowEstateStatus
*/
public function testCreateInputModelShowEstatesStatus()
{
$pFormModelBuilderAddressDetailSettings = $this->_pFormModelBuilderAddressDetailSettings;
$pFormModelBuilderAddressDetailSettings->generate('test');
- $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelShowEstatesStatus();
+ $pInputModelOption = $pFormModelBuilderAddressDetailSettings->createInputModelShowEstateStatus();
$this->assertInstanceOf(InputModelOption::class, $pInputModelOption);
$this->assertNotEmpty($pInputModelOption->getValuesAvailable());
diff --git a/tests/TestClassImageTypes.php b/tests/TestClassImageTypes.php
index 1b97cb1df..3ef024d5b 100644
--- a/tests/TestClassImageTypes.php
+++ b/tests/TestClassImageTypes.php
@@ -60,7 +60,7 @@ public function testGetAllImageTypesTranslated()
$pReflection = new ReflectionClass(ImageTypes::class);
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
- unset($nameConstants['PASSPORT_PHOTO']);
+ unset($nameConstants['PASSPORTPHOTO']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}
From 38175cfd89acc9b855c5801bf0784c344a65c546 Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Mon, 26 Aug 2024 09:37:48 +0700
Subject: [PATCH 10/33] 47945 fix conflict
---
js/checkbox.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/checkbox.js b/js/checkbox.js
index 9ce007645..c859185c5 100644
--- a/js/checkbox.js
+++ b/js/checkbox.js
@@ -45,7 +45,7 @@ onOffice.checkboxAdmin = function() {
invert: true
}
],
- "input[name^=oopluginformfieldconfig-hiddenfield]": [
+ "input[name^=oopluginformfieldconfig-hiddenfield]": [
{
element: "input[name^=oopluginformfieldconfig-required]",
invert: true
From 6533a6f44cbeb12f0f68657ea880354434e69b1e Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Mon, 26 Aug 2024 11:25:24 +0700
Subject: [PATCH 11/33] 52295 merge add User photo
---
plugin/Controller/RewriteRuleBuilder.php | 1 +
plugin/Gui/AdminPageAddress.php | 33 +++++++++++++++++++++---
plugin/Types/ImageTypes.php | 2 ++
tests/TestClassImageTypes.php | 1 +
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/plugin/Controller/RewriteRuleBuilder.php b/plugin/Controller/RewriteRuleBuilder.php
index e9908eec5..85380ee34 100644
--- a/plugin/Controller/RewriteRuleBuilder.php
+++ b/plugin/Controller/RewriteRuleBuilder.php
@@ -41,6 +41,7 @@ class RewriteRuleBuilder
/**
* @param DataDetailViewHandler $pDataDetailViewHandler
* @param WPPageWrapper $pWPPageWrapper
+ * @param DataAddressDetailViewHandler $pDataAddressDetailViewHandler
*/
public function __construct(
DataDetailViewHandler $pDataDetailViewHandler,
diff --git a/plugin/Gui/AdminPageAddress.php b/plugin/Gui/AdminPageAddress.php
index 1773a6317..172394198 100644
--- a/plugin/Gui/AdminPageAddress.php
+++ b/plugin/Gui/AdminPageAddress.php
@@ -24,7 +24,9 @@
use DI\ContainerBuilder;
use onOffice\WPlugin\Controller\UserCapabilities;
use onOffice\WPlugin\Form\BulkDeleteRecord;
+use onOffice\WPlugin\Gui\Table\AddressListTable;
use onOffice\WPlugin\Record\RecordManagerDeleteListViewAddress;
+use onOffice\WPlugin\Record\RecordManagerDeleteListViewEstate;
use onOffice\WPlugin\Record\RecordManagerDuplicateListViewAddress;
use const ONOFFICE_DI_CONFIG_PATH;
use function __;
@@ -33,7 +35,8 @@
use function add_query_arg;
use function admin_url;
use function check_admin_referer;
-use Exception;
+use function esc_html__;
+use function add_screen_option;
/**
*
@@ -67,8 +70,9 @@ class AdminPageAddress
private $_pSelectedTab = null;
/**
+ *
* @param string $pageSlug
- * @throws Exception
+ *
*/
public function __construct($pageSlug)
@@ -90,7 +94,7 @@ public function __construct($pageSlug)
*
*/
- private function getSelectedTab()
+ private function getSelectedTab(): string
{
$selectedTab = $this->getDefaultTab();
$getParamTab = filter_input(INPUT_GET, self::PARAM_TAB);
@@ -154,11 +158,31 @@ public function renderContent()
*
*/
- private function getDefaultTab()
+ private function getDefaultTab(): string
{
return self::PAGE_ADDRESS_LIST;
}
+ /**
+ *
+ * @param string $subTitle
+ *
+ */
+
+ public function generatePageMainTitle($subTitle)
+ {
+ echo ''.esc_html__('onOffice', 'onoffice-for-wp-websites');
+
+ if ($subTitle != '') {
+ echo ' › ' . esc_html( $subTitle );
+ }
+
+ echo ' ';
+
+ $newLink = admin_url('admin.php?page=onoffice-editlistviewaddress');
+ echo ''.esc_html__('Add New', 'onoffice-for-wp-websites').' ';
+ echo '';
+ }
/**
*
@@ -218,6 +242,7 @@ public function preOutput()
$listViewRootId = $_GET['listViewId'];
$pRecordManagerDuplicateListViewAddress->duplicateByName($listViewRootId);
}
+
return $redirectTo;
};
diff --git a/plugin/Types/ImageTypes.php b/plugin/Types/ImageTypes.php
index 0f061031c..cb87f3685 100644
--- a/plugin/Types/ImageTypes.php
+++ b/plugin/Types/ImageTypes.php
@@ -33,6 +33,7 @@ class ImageTypes
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
const PASSPORTPHOTO = 'PassportPhoto';
+ const USERPHOTO = 'UserPhoto';
const IMAGE_TYPES = [
self::TITLE,
@@ -75,6 +76,7 @@ public static function getAllImageTypesTranslated(): array
public static function getImageTypesForAddress(): array
{
return [
+ self::USERPHOTO => __('User Photo', 'onoffice-for-wp-websites'),
self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
];
}
diff --git a/tests/TestClassImageTypes.php b/tests/TestClassImageTypes.php
index 3ef024d5b..61653358c 100644
--- a/tests/TestClassImageTypes.php
+++ b/tests/TestClassImageTypes.php
@@ -61,6 +61,7 @@ public function testGetAllImageTypesTranslated()
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
unset($nameConstants['PASSPORTPHOTO']);
+ unset($nameConstants['USERPHOTO']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}
From 9c2cb2462bab27c07b2361d2919c3a94dc050a83 Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Mon, 26 Aug 2024 15:54:14 +0700
Subject: [PATCH 12/33] 52995 refactor code
---
plugin/Controller/AdminViewController.php | 6 ------
plugin/Controller/DetailViewPostSaveController.php | 12 ++++++------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/plugin/Controller/AdminViewController.php b/plugin/Controller/AdminViewController.php
index de766c7b0..d12f8f727 100644
--- a/plugin/Controller/AdminViewController.php
+++ b/plugin/Controller/AdminViewController.php
@@ -97,12 +97,6 @@ class AdminViewController
/** @var AdminPageAddress */
private $_pAdminPageAddresses = null;
- /** */
- const VIEW_UNSAVED_CHANGES_MESSAGE = 'view_unsaved_changes_message';
-
- /** */
- const VIEW_LEAVE_WITHOUT_SAVING_TEXT = 'view_leave_without_saving_text';
-
/**
*
*/
diff --git a/plugin/Controller/DetailViewPostSaveController.php b/plugin/Controller/DetailViewPostSaveController.php
index 757ad9b28..afbc4099a 100644
--- a/plugin/Controller/DetailViewPostSaveController.php
+++ b/plugin/Controller/DetailViewPostSaveController.php
@@ -269,13 +269,13 @@ public function onMoveTrash() {
$this->deletePageUseShortCode( $pPost );
}
if ( $hasDetailPost ) {
- if (empty($pDetailView->getPageIdsHaveDetailShortCode())) {
- $pDetailView->setPageId(0);
- } elseif (in_array($pDetailView->getPageId(), $posts)) {
- $firstDetailPageId = min(array_keys($detailPageIds));
- $pDetailView->setPageId((int) $detailPageIds[$firstDetailPageId]);
+ if ( empty( $pDetailView->getPageIdsHaveDetailShortCode() ) ) {
+ $pDetailView->setPageId( 0 );
+ } elseif ( in_array( $pDetailView->getPageId(), $posts ) ) {
+ $firstDetailPageId = min( array_keys( $detailPageIds ) );
+ $pDetailView->setPageId( (int) $detailPageIds[ $firstDetailPageId ] );
}
- $pDataDetailViewHandler->saveDetailView($pDetailView);
+ $pDataDetailViewHandler->saveDetailView( $pDetailView );
flush_rewrite_rules();
}
if ( $hasAddressDetailPost ) {
From 5740fb70ae25db34401282a0ac8fdc3c348c42cd Mon Sep 17 00:00:00 2001
From: "dai.trinh"
Date: Tue, 27 Aug 2024 10:53:57 +0700
Subject: [PATCH 13/33] 52295 refactor code
---
dist/checkbox.min.js | 2 +-
js/checkbox.js | 20 +--
plugin/DataView/DataAddressDetailView.php | 93 ++---------
.../DataView/DataAddressDetailViewHandler.php | 9 +-
plugin/Gui/AdminPageAddressDetail.php | 93 ++---------
.../FormModelBuilderAddressDetailSettings.php | 152 ++++++------------
...putModelOptionFactoryAddressDetailView.php | 40 +----
7 files changed, 81 insertions(+), 328 deletions(-)
diff --git a/dist/checkbox.min.js b/dist/checkbox.min.js
index 60c965118..ef95fcc78 100644
--- a/dist/checkbox.min.js
+++ b/dist/checkbox.min.js
@@ -1 +1 @@
-var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name^=oopluginformfieldconfig-hiddenfield]":[{element:"input[name^=oopluginformfieldconfig-required]",invert:true}],"input[name^=oopluginformfieldconfig-required]":[{element:"input[name^=oopluginformfieldconfig-hiddenfield]",invert:true}],"input[name=onoffice-enableLinkedEstates]":[{element:"select[name=onoffice-showReferenceEstate]",invert:false},{element:"select[name=onoffice-filterId]",invert:false},{element:"input[name=onoffice-recordsPerPage]",invert:false},{element:"input[name=onoffice-showStatus]",invert:false},{element:"input[name=onoffice-showPriceOnRequest]",invert:false},{element:"input[name=onoffice-showMap]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled")}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
+var onOffice=onOffice||{};onOffice.checkboxAdmin=function(){this._isInitialRun=true;this._configuration={"input[name^=oopluginaddressfieldconfig-filterable]":[{element:"input[name^=oopluginaddressfieldconfig-hidden]",invert:false}],"input[name=oopluginforms-createaddress]":[{element:"input[name=oopluginforms-checkduplicates]",invert:false},{element:"input[name=oopluginforms-newsletter]",invert:false}],"input[name^=oopluginfieldconfig-filterable]":[{element:"input[name^=oopluginfieldconfig-hidden]",invert:false},{element:"input[name^=oopluginfieldconfig-availableOptions]",invert:false},{element:"input[name^=oopluginfieldconfig-convertTextToSelectForCityField]",invert:false}],"input[name=oopluginforms-defaultrecipient]":[{element:"input[name=oopluginforms-recipient]",invert:true}],"input[name^=oopluginformfieldconfig-hiddenfield]":[{element:"input[name^=oopluginformfieldconfig-required]",invert:true}],"input[name^=oopluginformfieldconfig-required]":[{element:"input[name^=oopluginformfieldconfig-hiddenfield]",invert:true}],"input[name=onoffice-enableLinkedEstates]":[{element:"select[name=onoffice-activeEstates]",invert:false},{element:"select[name=onoffice-referenceEstate]",invert:false}]}};onOffice.checkboxAdmin.prototype.changeCbStatus=function(topElement){var $=jQuery;var instance=this;var toggleChild=function(receivers,mainElement,fromOnChange){for(var i in receivers){var receiver=receivers[i];var receiverElement=mainElement.parent().parent().find(receiver.element);var invert=receiver.invert;if(receiverElement.length){if(mainElement.prop("checked")){if(!invert){receiverElement[0].checked=receiverElement[0].checked||receiver.checkOnActive&&(instance._isInitialRun||fromOnChange);receiverElement.removeAttr("disabled")}else{receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}}else{if(!invert){receiverElement.prop("disabled","disabled");receiverElement.removeAttr("checked")}else{receiverElement.removeAttr("disabled")}}}}instance._isInitialRun=false};for(var sender in this._configuration){var mainElements=$(topElement).find(sender);if(!mainElements.length){continue}mainElements.each((function(i){var mainElement=$(mainElements[i]);var receivers=instance._configuration[sender];var callback=function(){toggleChild(receivers,mainElement,true)};mainElement.ready((function(){toggleChild(receivers,mainElement,false)})).change(callback)}))}};jQuery(document).ready((function(){var cbAdmin=new onOffice.checkboxAdmin;cbAdmin.changeCbStatus(this)}));
\ No newline at end of file
diff --git a/js/checkbox.js b/js/checkbox.js
index c859185c5..8ec6591fe 100644
--- a/js/checkbox.js
+++ b/js/checkbox.js
@@ -61,27 +61,11 @@ onOffice.checkboxAdmin = function() {
// view: address detail view
"input[name=onoffice-enableLinkedEstates]": [
{
- element: "select[name=onoffice-showReferenceEstate]",
+ element: "select[name=onoffice-activeEstates]",
invert: false
},
{
- element: "select[name=onoffice-filterId]",
- invert: false
- },
- {
- element: "input[name=onoffice-recordsPerPage]",
- invert: false
- },
- {
- element: "input[name=onoffice-showStatus]",
- invert: false
- },
- {
- element: "input[name=onoffice-showPriceOnRequest]",
- invert: false
- },
- {
- element: "input[name=onoffice-showMap]",
+ element: "select[name=onoffice-referenceEstate]",
invert: false
}
]
diff --git a/plugin/DataView/DataAddressDetailView.php b/plugin/DataView/DataAddressDetailView.php
index 6c3b61d9b..1ef1299d7 100644
--- a/plugin/DataView/DataAddressDetailView.php
+++ b/plugin/DataView/DataAddressDetailView.php
@@ -36,36 +36,15 @@ class DataAddressDetailView
/** */
const FIELDS = 'fields';
- /** */
- const ESTATE_FIELDS = 'estateFields';
-
/** */
const TEMPLATE = 'template';
/** */
const PICTURES = 'pictures';
- /** */
- const SHOW_STATUS = 'showStatus';
-
/** */
const ENABLE_LINKED_ESTATES = 'enableLinkedEstates';
- /** */
- const ENABLE_REFERENCE_ESTATE = 'showReferenceEstate';
-
- /** */
- const FILTERID = 'filterId';
-
- /** */
- const RECORDS_PER_PAGE = 'recordsPerPage';
-
- /** */
- const SHOW_PRICE_ON_REQUEST = 'showPriceOnRequest';
-
- /** */
- const SHOW_MAP = 'showMap';
-
/** */
const FIELD_CUSTOM_LABEL = 'oo_plugin_fieldconfig_address_translated_labels';
@@ -132,22 +111,10 @@ class DataAddressDetailView
private $_enableLinkedEstates = false;
/** @var string */
- private $_showReferenceEstate = '0';
-
- /** @var int */
- private $_filterId = 0;
-
- /** @var int */
- private $_recordsPerPage = 12;
-
- /** @var bool */
- private $_showStatus = false;
-
- /** @var bool */
- private $_showPriceOnRequest = false;
+ private $_shortCodeActiveEstate = '';
- /** @var bool */
- private $_showMap = false;
+ /** @var string */
+ private $_shortCodeReferenceEstate = '';
/** @return int */
public function getPageId(): int
@@ -230,50 +197,18 @@ public function setEnableLinkedEstates(bool $enableLinkedEstates)
{ $this->_enableLinkedEstates = $enableLinkedEstates; }
/** @return string */
- public function getShowReferenceEstate(): string
- { return $this->_showReferenceEstate; }
+ public function getShortCodeActiveEstate(): string
+ { return $this->_shortCodeActiveEstate; }
- /** @param string $showReferenceEstate */
- public function setShowReferenceEstate(string $showReferenceEstate)
- { $this->_showReferenceEstate = $showReferenceEstate; }
-
- /** @return int */
- public function getFilterId(): int
- { return $this->_filterId; }
-
- /** @param int $filterId */
- public function setFilterId(int $filterId)
- { $this->_filterId = $filterId; }
-
- /** @return int */
- public function getRecordsPerPage(): int
- { return $this->_recordsPerPage; }
+ /** @param string $shortCodeActiveEstate */
+ public function setShortCodeActiveEstate(string $shortCodeActiveEstate)
+ { $this->_shortCodeActiveEstate = $shortCodeActiveEstate; }
- /** @param int $recordsPerPage */
- public function setRecordsPerPage(int $recordsPerPage)
- { $this->_recordsPerPage = $recordsPerPage; }
-
- /** @return bool */
- public function getShowStatus(): bool
- { return $this->_showStatus;}
-
- /** @param bool $showStatus */
- public function setShowStatus(bool $showStatus)
- { $this->_showStatus = $showStatus; }
-
- /** @return bool */
- public function getShowPriceOnRequest(): bool
- { return $this->_showPriceOnRequest; }
-
- /** @param bool $showPriceOnRequest */
- public function setShowPriceOnRequest(bool $showPriceOnRequest)
- { $this->_showPriceOnRequest = $showPriceOnRequest; }
-
- /** @return bool */
- public function getShowMap(): bool
- { return $this->_showMap; }
+ /** @return string */
+ public function getShortCodeReferenceEstate(): string
+ { return $this->_shortCodeReferenceEstate; }
- /** @param bool $showMap */
- public function setShowMap(bool $showMap)
- { $this->_showMap = $showMap; }
+ /** @param string $shortCodeReferenceEstate */
+ public function setShortCodeReferenceEstate(string $shortCodeReferenceEstate)
+ { $this->_shortCodeReferenceEstate = $shortCodeReferenceEstate; }
}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
index ccb1496f5..f201761d1 100644
--- a/plugin/DataView/DataAddressDetailViewHandler.php
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -105,16 +105,11 @@ public function createAddressDetailViewByValues(array $row): DataAddressDetailVi
$pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
$pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
$pDataAddressDetailView->setShortCodeForm($row['shortcodeform'] ?? '');
- $pDataAddressDetailView->setEstateFields($row[DataAddressDetailView::ESTATE_FIELDS] ?? []);
$pDataAddressDetailView->setPictureTypes($row[DataAddressDetailView::PICTURES] ?? []);
$pDataAddressDetailView->setCustomLabels($row[DataAddressDetailView::FIELD_CUSTOM_LABEL] ?? $pDataAddressDetailView->getCustomLabels());
$pDataAddressDetailView->setEnableLinkedEstates($row[DataAddressDetailView::ENABLE_LINKED_ESTATES] ?? false);
- $pDataAddressDetailView->setShowStatus($row[DataAddressDetailView::SHOW_STATUS] ?? false);
- $pDataAddressDetailView->setShowReferenceEstate($row[DataAddressDetailView::ENABLE_REFERENCE_ESTATE] ?? '0');
- $pDataAddressDetailView->setFilterId($row[DataAddressDetailView::FILTERID] ?? 0);
- $pDataAddressDetailView->setRecordsPerPage($row[DataAddressDetailView::RECORDS_PER_PAGE] ?? 0);
- $pDataAddressDetailView->setShowPriceOnRequest($row[DataAddressDetailView::SHOW_PRICE_ON_REQUEST] ?? false);
- $pDataAddressDetailView->setShowMap($row[DataAddressDetailView::SHOW_MAP] ?? false);
+ $pDataAddressDetailView->setShortCodeActiveEstate($row['shortcodeActiveEstates'] ?? '');
+ $pDataAddressDetailView->setShortCodeReferenceEstate($row['shortcodeReferenceEstate'] ?? '');
return $pDataAddressDetailView;
}
diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php
index 8375f030d..4ab34e1f7 100644
--- a/plugin/Gui/AdminPageAddressDetail.php
+++ b/plugin/Gui/AdminPageAddressDetail.php
@@ -25,7 +25,6 @@
use DI\NotFoundException;
use Exception;
use onOffice\SDK\onOfficeSDK;
-use onOffice\WPlugin\Controller\Exception\UnknownModuleException;
use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
use onOffice\WPlugin\Model\ExceptionInputModelMissingField;
use onOffice\WPlugin\Model\FormModel;
@@ -72,9 +71,6 @@ class AdminPageAddressDetail
/** */
const FORM_VIEW_SORTABLE_FIELDS_CONFIG = 'viewSortableFieldsConfig';
- /** */
- const FORM_VIEW_CONTACT_DATA_FIELDS = 'viewcontactdatafields';
-
/** */
const FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG = 'viewSearchFieldForFieldListsConfig';
@@ -116,7 +112,6 @@ public function renderContent()
$pRenderer = $this->getContainer()->get(InputModelRenderer::class);
$pFormViewSortableFields = $this->getFormModelByGroupSlug(self::FORM_VIEW_SORTABLE_FIELDS_CONFIG);
$pFormViewSearchFieldForFieldLists = $this->getFormModelByGroupSlug(self::FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG);
- $pFormViewSortableContactFields = $this->getFormModelByGroupSlug(self::FORM_VIEW_CONTACT_DATA_FIELDS);
echo '
\ No newline at end of file
+
diff --git a/templates.dist/form/formsubmit.php b/templates.dist/form/formsubmit.php
index e9276289f..6dca2ac64 100644
--- a/templates.dist/form/formsubmit.php
+++ b/templates.dist/form/formsubmit.php
@@ -57,4 +57,5 @@ function submitForm() {
Date: Mon, 2 Sep 2024 13:09:45 +0200
Subject: [PATCH 20/33] fix tests
---
tests/TestClassAddressList.php | 2 +-
tests/TestClassAddressListFactory.php | 7 ++++---
tests/TestClassContentFilterShortCodeEstate.php | 6 ++++--
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/tests/TestClassAddressList.php b/tests/TestClassAddressList.php
index b4cade236..6934e5569 100644
--- a/tests/TestClassAddressList.php
+++ b/tests/TestClassAddressList.php
@@ -213,7 +213,7 @@ public function prepare()
$pMockConfig->method('getFieldsCollectionBuilderShort')->willReturn($pFieldsCollectionBuilderMock);
- $this->_pAddressList = new AddressList($pMockConfig);
+ $this->_pAddressList = new AddressList(null, $pMockConfig);
}
diff --git a/tests/TestClassAddressListFactory.php b/tests/TestClassAddressListFactory.php
index b674c6805..0b68eb797 100644
--- a/tests/TestClassAddressListFactory.php
+++ b/tests/TestClassAddressListFactory.php
@@ -24,6 +24,7 @@
use DI\ContainerBuilder;
use onOffice\WPlugin\AddressList;
+use onOffice\WPlugin\DataAddressDetailViewHandler;
use onOffice\WPlugin\Controller\AddressListEnvironment;
use onOffice\WPlugin\Factory\AddressListFactory;
@@ -44,8 +45,8 @@ public function prepare()
$pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
$pContainer = $pContainerBuilder->build();
$pAddressListEnvironment = $pContainer->get(AddressListEnvironment::class);
-
- $this->_pFactory = new AddressListFactory($pAddressListEnvironment);
+ $detailViewHandler = new DataAddressDetailViewHandler(null);
+ $this->_pFactory = new AddressListFactory($pAddressListEnvironment, $detailViewHandler);
}
/**
@@ -63,4 +64,4 @@ public function testCreate()
{
$this->assertInstanceOf(AddressList::class, $this->_pFactory->create());
}
-}
\ No newline at end of file
+}
diff --git a/tests/TestClassContentFilterShortCodeEstate.php b/tests/TestClassContentFilterShortCodeEstate.php
index 2d3a3429a..aa2992e83 100644
--- a/tests/TestClassContentFilterShortCodeEstate.php
+++ b/tests/TestClassContentFilterShortCodeEstate.php
@@ -21,6 +21,7 @@
declare (strict_types=1);
+
namespace onOffice\tests;
use DI\Container;
@@ -70,6 +71,7 @@ public function testReplaceShortCodesForDetail()
$input = [
'view' => 'default_view',
'units' => 'test_units',
+ 'address' => null
];
$pContentFilterDetail = $this->_pContainer->get(ContentFilterShortCodeEstateDetail::class);
$pContentFilterDetail->expects($this->once())
@@ -80,11 +82,11 @@ public function testReplaceShortCodesForDetail()
$pContentFilterList = $this->_pContainer->get(ContentFilterShortCodeEstateList::class);
$pContentFilterList->expects($this->once())
->method('render')
- ->with(['view' => 'other', 'units' => null])
+ ->with(['view' => 'other', 'units' => null, 'address' => null])
->will($this->returnValue('rendered list'));
$pSubject = $this->_pContainer->get(ContentFilterShortCodeEstate::class);
$this->assertSame('rendered detail', $pSubject->replaceShortCodes($input));
$this->assertSame('rendered list', $pSubject->replaceShortCodes(['view' => 'other']));
}
-}
\ No newline at end of file
+}
From 65a9388c91dad571eb80b187c46efef5bc53e9be Mon Sep 17 00:00:00 2001
From: Ingo Kruetzen
Date: Mon, 2 Sep 2024 13:12:53 +0200
Subject: [PATCH 21/33] some fixes
---
.../ContentFilterShortCodeAddress.php | 33 ++++++++-----------
.../ContentFilterShortCodeAddressDetail.php | 8 ++++-
.../ContentFilterShortCodeEstateList.php | 2 +-
.../DataView/DataAddressDetailViewHandler.php | 4 ++-
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/plugin/Controller/ContentFilter/ContentFilterShortCodeAddress.php b/plugin/Controller/ContentFilter/ContentFilterShortCodeAddress.php
index c3a9d904e..71ced9d8c 100644
--- a/plugin/Controller/ContentFilter/ContentFilterShortCodeAddress.php
+++ b/plugin/Controller/ContentFilter/ContentFilterShortCodeAddress.php
@@ -35,16 +35,9 @@
use onOffice\WPlugin\Template;
use onOffice\WPlugin\Utility\Logger;
use onOffice\WPlugin\WP\WPQueryWrapper;
-use function shortcode_atts;
-/**
- *
- * render address short codes
- *
- */
-class ContentFilterShortCodeAddress
- implements ContentFilterShortCode
+class ContentFilterShortCodeAddress implements ContentFilterShortCode
{
/** @var SearchParametersModelBuilder */
private $_pSearchParametersModelBuilder;
@@ -64,8 +57,8 @@ class ContentFilterShortCodeAddress
/** @var AddressListFactory */
private $_pAddressListFactory;
- /** @var ContentFilterShortCodeAddressDetail */
- private ContentFilterShortCodeAddressDetail $_pContentFilterShortCodeAddressDetail;
+ /** @var ContentFilterShortCodeAddressDetail */
+ private ContentFilterShortCodeAddressDetail $_pContentFilterShortCodeAddressDetail;
/**
* ContentFilterShortCodeAddress constructor.
@@ -76,7 +69,7 @@ class ContentFilterShortCodeAddress
* @param DataListViewFactoryAddress $pDataListFactory
* @param Template $pTemplate
* @param WPQueryWrapper $pWPQueryWrapper,
- * @param ContentFilterShortCodeAddressDetail $pContentFilterShortCodeAddressDetail
+ * @param ContentFilterShortCodeAddressDetail $pContentFilterShortCodeAddressDetail
*/
public function __construct(
SearchParametersModelBuilder $pSearchParametersModelBuilder,
@@ -85,7 +78,7 @@ public function __construct(
DataListViewFactoryAddress $pDataListFactory,
Template $pTemplate,
WPQueryWrapper $pWPQueryWrapper,
- ContentFilterShortCodeAddressDetail $pContentFilterShortCodeAddressDetail)
+ ContentFilterShortCodeAddressDetail $pContentFilterShortCodeAddressDetail)
{
$this->_pSearchParametersModelBuilder = $pSearchParametersModelBuilder;
@@ -94,8 +87,8 @@ public function __construct(
$this->_pAddressListFactory = $pAddressListFactory;
$this->_pTemplate = $pTemplate;
$this->_pWPQueryWrapper = $pWPQueryWrapper;
- $this->_pContentFilterShortCodeAddressDetail = $pContentFilterShortCodeAddressDetail;
- }
+ $this->_pContentFilterShortCodeAddressDetail = $pContentFilterShortCodeAddressDetail;
+ }
/**
* @param array $attributesInput
@@ -109,12 +102,12 @@ public function replaceShortCodes(array $attributesInput): string
$addressListName = $attributes['view'];
try {
- if ($attributes['view'] === $this->_pContentFilterShortCodeAddressDetail->getViewName()) {
- return $this->_pContentFilterShortCodeAddressDetail->render();
- } else {
- $pTemplate = $this->createTemplate($addressListName);
- return $pTemplate->render();
- }
+ if ($attributes['view'] === $this->_pContentFilterShortCodeAddressDetail->getViewName()) {
+ return $this->_pContentFilterShortCodeAddressDetail->render();
+ } else {
+ $pTemplate = $this->createTemplate($addressListName);
+ return $pTemplate->render();
+ }
} catch (Exception $pException) {
return $this->_pLogger->logErrorAndDisplayMessage($pException);
}
diff --git a/plugin/Controller/ContentFilter/ContentFilterShortCodeAddressDetail.php b/plugin/Controller/ContentFilter/ContentFilterShortCodeAddressDetail.php
index dc8ab03ac..5657e87f4 100644
--- a/plugin/Controller/ContentFilter/ContentFilterShortCodeAddressDetail.php
+++ b/plugin/Controller/ContentFilter/ContentFilterShortCodeAddressDetail.php
@@ -19,6 +19,8 @@
*
*/
+declare (strict_types=1);
+
namespace onOffice\WPlugin\Controller\ContentFilter;
use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
@@ -49,7 +51,11 @@ public function __construct(DataAddressDetailViewHandler $dataAddressDetailViewH
$this->_pAddressDetailFactory = $pAddressDetailFactory;
$this->_pWPQueryWrapper = $pWPQueryWrapper;
}
-
+ /**
+ * @return string
+ * @throws DependencyException
+ * @throws NotFoundException
+ */
public function render(): string {
$addressDetailView = $this->_pDataAddressDetailViewHandler->getAddressDetailView();
$template = $this->_pTemplate->withTemplateName($addressDetailView->getTemplate());
diff --git a/plugin/Controller/ContentFilter/ContentFilterShortCodeEstateList.php b/plugin/Controller/ContentFilter/ContentFilterShortCodeEstateList.php
index 53c6cf84c..3841ad9ee 100644
--- a/plugin/Controller/ContentFilter/ContentFilterShortCodeEstateList.php
+++ b/plugin/Controller/ContentFilter/ContentFilterShortCodeEstateList.php
@@ -130,7 +130,7 @@ public function render(array $attributes): string
$pEstateList->setUnitsViewName($attributes['units']);
$pEstateList->setGeoSearchBuilder($pGeoSearchBuilder);
- if(isset($attributes['address']))
+ if(isset($attributes['address']) && intval($attributes['address']) != 0)
{
$pEstateList->setFilterAdressId($attributes['address']);
}
diff --git a/plugin/DataView/DataAddressDetailViewHandler.php b/plugin/DataView/DataAddressDetailViewHandler.php
index f201761d1..c39f724f6 100644
--- a/plugin/DataView/DataAddressDetailViewHandler.php
+++ b/plugin/DataView/DataAddressDetailViewHandler.php
@@ -19,6 +19,8 @@
*
*/
+declare(strict_types=1);
+
namespace onOffice\WPlugin\DataView;
use onOffice\WPlugin\WP\WPOptionWrapperBase;
@@ -113,4 +115,4 @@ public function createAddressDetailViewByValues(array $row): DataAddressDetailVi
return $pDataAddressDetailView;
}
-}
\ No newline at end of file
+}
From c2fddcf38db5febcff17ceea5964ee8c5c8fe9a8 Mon Sep 17 00:00:00 2001
From: Ingo Kruetzen
Date: Mon, 2 Sep 2024 13:46:19 +0200
Subject: [PATCH 22/33] remove AddressListEnvironment from AdressList
---
plugin/Factory/AddressListFactory.php | 8 ++++----
tests/TestClassAddressListFactory.php | 12 +++++++-----
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/plugin/Factory/AddressListFactory.php b/plugin/Factory/AddressListFactory.php
index b2caa7469..3e91b9771 100644
--- a/plugin/Factory/AddressListFactory.php
+++ b/plugin/Factory/AddressListFactory.php
@@ -29,8 +29,8 @@
class AddressListFactory
{
- /** @var AddressListEnvironment */
- private $_pEnvironment;
+ // /** @var AddressListEnvironment */
+ // private $_pEnvironment;
/** @var DataAddressDetailViewHandler */
private $_pDataAddressDetailViewHandler;
@@ -38,9 +38,9 @@ class AddressListFactory
/**
* @param AddressListEnvironment $pEnvironment
*/
- public function __construct(AddressListEnvironment $pEnvironment, DataAddressDetailViewHandler $pDataAddressDetailViewHandler)
+ public function __construct(DataAddressDetailViewHandler $pDataAddressDetailViewHandler)
{
- $this->_pEnvironment = $pEnvironment;
+ // $this->_pEnvironment = $pEnvironment;
$this->_pDataAddressDetailViewHandler = $pDataAddressDetailViewHandler;
}
diff --git a/tests/TestClassAddressListFactory.php b/tests/TestClassAddressListFactory.php
index 0b68eb797..616c1771d 100644
--- a/tests/TestClassAddressListFactory.php
+++ b/tests/TestClassAddressListFactory.php
@@ -24,13 +24,16 @@
use DI\ContainerBuilder;
use onOffice\WPlugin\AddressList;
-use onOffice\WPlugin\DataAddressDetailViewHandler;
-use onOffice\WPlugin\Controller\AddressListEnvironment;
+use onOffice\WPlugin\DataView\DataAddressDetailViewHandler;
+use onOffice\WPlugin\DataView\DataListViewAddress;
use onOffice\WPlugin\Factory\AddressListFactory;
class TestClassAddressListFactory
extends \WP_UnitTestCase
{
+ /** @var Container */
+ private $_pContainer;
+
/**
* @var AddressListFactory
*/
@@ -44,9 +47,8 @@ public function prepare()
$pContainerBuilder = new ContainerBuilder();
$pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH);
$pContainer = $pContainerBuilder->build();
- $pAddressListEnvironment = $pContainer->get(AddressListEnvironment::class);
$detailViewHandler = new DataAddressDetailViewHandler(null);
- $this->_pFactory = new AddressListFactory($pAddressListEnvironment, $detailViewHandler);
+ $this->_pFactory = new AddressListFactory($detailViewHandler);
}
/**
@@ -62,6 +64,6 @@ public function testInstance()
*/
public function testCreate()
{
- $this->assertInstanceOf(AddressList::class, $this->_pFactory->create());
+ $this->assertInstanceOf(AddressList::class, $this->_pFactory->create(new DataListViewAddress(0, 'default')));
}
}
From 0f4bd6fac85c6a49c681aa63726837a932660235 Mon Sep 17 00:00:00 2001
From: Ingo Kruetzen
Date: Mon, 2 Sep 2024 14:23:10 +0200
Subject: [PATCH 23/33] remove useless test
---
tests/TestClassFormPostContact.php | 28 ----------------------------
1 file changed, 28 deletions(-)
diff --git a/tests/TestClassFormPostContact.php b/tests/TestClassFormPostContact.php
index ebf8f0808..e3efd0a82 100644
--- a/tests/TestClassFormPostContact.php
+++ b/tests/TestClassFormPostContact.php
@@ -448,34 +448,6 @@ public function testFormHoneypot()
$this->assertEquals(FormPost::MESSAGE_SUCCESS, $pFormData->getStatus());
}
-
- /**
- *
- */
-
- public function testFormHoneypotEmpty()
- {
- $_POST = [
- 'Vorname' => 'John',
- 'Name' => 'Doe',
- 'Email' => 'john.doe@my-onoffice.com',
- 'Plz' => '52068',
- 'Ort' => 'Aachen',
- 'Telefon1' => '0815/2345677',
- 'AGB_akzeptiert' => 'y',
- 'newsletter' => 'y',
- 'Id' => '1337',
- 'Anrede' => '',
- 'tmpField' => 'content',
- ];
-
- $pDataFormConfiguration = $this->getNewDataFormConfiguration();
- $this->_pFormPostContact->initialCheck($pDataFormConfiguration, 2);
-
- $pFormData = $this->_pFormPostContact->getFormDataInstance('contactForm', 2);
- $this->assertEquals(FormPost::MESSAGE_SUCCESS, $pFormData->getStatus());
- }
-
/**
*
*/
From 5252947a6c2ce140af6c57c203e9a3847ebb50f4 Mon Sep 17 00:00:00 2001
From: Ingo Kruetzen
Date: Mon, 2 Sep 2024 14:23:23 +0200
Subject: [PATCH 24/33] remove php 7.3 tests
---
.github/workflows/unit-tests.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
index 76bdcb053..0f12ebe7c 100644
--- a/.github/workflows/unit-tests.yml
+++ b/.github/workflows/unit-tests.yml
@@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
- php-versions: ['7.3', '7.4', '8.0']
+ php-versions: ['7.4', '8.0']
name: Unittest on ${{ matrix.operating-system }} with PHP version ${{ matrix.php-versions }}
steps:
- name: Set up MySQL
From 42e47f01707da1cc41de86c030054f1fde305594 Mon Sep 17 00:00:00 2001
From: Ingo Kruetzen
Date: Mon, 2 Sep 2024 15:48:26 +0200
Subject: [PATCH 25/33] fix tests and remove comments
---
plugin/Factory/AddressListFactory.php | 3 ---
plugin/FormPostContact.php | 7 +++----
tests/TestClassFormPostContact.php | 29 +++++++++++++++++++++++++++
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/plugin/Factory/AddressListFactory.php b/plugin/Factory/AddressListFactory.php
index 3e91b9771..99ff1a37e 100644
--- a/plugin/Factory/AddressListFactory.php
+++ b/plugin/Factory/AddressListFactory.php
@@ -29,8 +29,6 @@
class AddressListFactory
{
- // /** @var AddressListEnvironment */
- // private $_pEnvironment;
/** @var DataAddressDetailViewHandler */
private $_pDataAddressDetailViewHandler;
@@ -40,7 +38,6 @@ class AddressListFactory
*/
public function __construct(DataAddressDetailViewHandler $pDataAddressDetailViewHandler)
{
- // $this->_pEnvironment = $pEnvironment;
$this->_pDataAddressDetailViewHandler = $pDataAddressDetailViewHandler;
}
diff --git a/plugin/FormPostContact.php b/plugin/FormPostContact.php
index d28575d2e..71f3e9c63 100644
--- a/plugin/FormPostContact.php
+++ b/plugin/FormPostContact.php
@@ -218,13 +218,13 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '',
if ($recipient !== '') {
$requestParams['recipient'] = $recipient;
}
-
$pDataAddressDetailViewHandler = new DataAddressDetailViewHandler();
$pAddressDataView = $pDataAddressDetailViewHandler->getAddressDetailView();
$referrerURL = get_site_url().$requestParams['referrer'];
- if(str_starts_with($referrerURL, get_permalink($pAddressDataView->getPageId()))
- || str_starts_with($referrerURL, get_permalink($pAddressDataView->getPageId())))
+ if($pAddressDataView->getPageId() != "" && (
+ str_starts_with($referrerURL, get_permalink($pAddressDataView->getPageId()))
+ || str_starts_with($referrerURL, get_permalink($pAddressDataView->getPageId()))))
{
//if form posted on address detail page, change recipient
$addressId = str_replace(get_permalink($pAddressDataView->getPageId()),"",$referrerURL);
@@ -241,7 +241,6 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '',
($pSDKWrapper, onOfficeSDK::ACTION_ID_DO, 'contactaddress');
$pAPIClientAction->setParameters($requestParams);
$pAPIClientAction->addRequestToQueue()->sendRequests();
-
if (!$pAPIClientAction->getResultStatus()) {
throw new ApiClientException($pAPIClientAction);
}
diff --git a/tests/TestClassFormPostContact.php b/tests/TestClassFormPostContact.php
index e3efd0a82..a5bd64d03 100644
--- a/tests/TestClassFormPostContact.php
+++ b/tests/TestClassFormPostContact.php
@@ -448,6 +448,35 @@ public function testFormHoneypot()
$this->assertEquals(FormPost::MESSAGE_SUCCESS, $pFormData->getStatus());
}
+
+ /**
+ *
+ */
+
+ public function testFormHoneypotEmpty()
+ {
+ $_POST = [
+ 'Vorname' => 'John',
+ 'Name' => 'Doe',
+ 'Email' => 'john.doe@my-onoffice.com',
+ 'Plz' => '52068',
+ 'Ort' => 'Aachen',
+ 'Telefon1' => '0815/2345677',
+ 'AGB_akzeptiert' => 'y',
+ 'newsletter' => 'y',
+ 'Id' => '1337',
+ 'Anrede' => '',
+ 'tmpField' => 'content',
+ ];
+
+ $pDataFormConfiguration = $this->getNewDataFormConfiguration();
+ $pDataFormConfiguration->setCreateAddress(true);
+ $this->_pFormPostContact->initialCheck($pDataFormConfiguration, 2);
+
+ $pFormData = $this->_pFormPostContact->getFormDataInstance('contactForm', 2);
+ $this->assertEquals(FormPost::MESSAGE_SUCCESS, $pFormData->getStatus());
+ }
+
/**
*
*/
From 271c63ffe862abc0b15c299d3473d0ea47050473 Mon Sep 17 00:00:00 2001
From: Ingo Kruetzen
Date: Mon, 2 Sep 2024 16:03:10 +0200
Subject: [PATCH 26/33] validate integer pageId
---
plugin/FormPostContact.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/plugin/FormPostContact.php b/plugin/FormPostContact.php
index 71f3e9c63..8bbfb2108 100644
--- a/plugin/FormPostContact.php
+++ b/plugin/FormPostContact.php
@@ -222,7 +222,8 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '',
$pAddressDataView = $pDataAddressDetailViewHandler->getAddressDetailView();
$referrerURL = get_site_url().$requestParams['referrer'];
- if($pAddressDataView->getPageId() != "" && (
+
+ if(intval($pAddressDataView->getPageId()) != 0 && (
str_starts_with($referrerURL, get_permalink($pAddressDataView->getPageId()))
|| str_starts_with($referrerURL, get_permalink($pAddressDataView->getPageId()))))
{
From 5a7d1da2ba3d162dee2bc310d29d8e2667b4cce6 Mon Sep 17 00:00:00 2001
From: andernath
Date: Wed, 4 Sep 2024 09:08:36 +0200
Subject: [PATCH 27/33] prepare style sheets for address styling
---
css/onoffice-address-detail.css | 4 ++++
css/onoffice-address.css | 3 +++
...ScriptLoaderGenericConfigurationDefault.php | 18 ++++++++++++++++++
templates.dist/address/default_detail.php | 8 ++++++--
4 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 css/onoffice-address-detail.css
create mode 100644 css/onoffice-address.css
diff --git a/css/onoffice-address-detail.css b/css/onoffice-address-detail.css
new file mode 100644
index 000000000..840e0289a
--- /dev/null
+++ b/css/onoffice-address-detail.css
@@ -0,0 +1,4 @@
+.oo-addressdetail-headline {
+ color: grey;
+ font-size: 3rem;
+}
\ No newline at end of file
diff --git a/css/onoffice-address.css b/css/onoffice-address.css
new file mode 100644
index 000000000..894ec9126
--- /dev/null
+++ b/css/onoffice-address.css
@@ -0,0 +1,3 @@
+.oo-address-headline {
+
+}
\ No newline at end of file
diff --git a/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php b/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php
index b65dcff72..e89411e75 100644
--- a/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php
+++ b/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php
@@ -79,6 +79,7 @@ public function getScriptLoaderGenericConfiguration(): array
$values []= (new IncludeFileModel($script, 'onoffice-favorites', plugins_url('/dist/favorites.min.js', $pluginPath)))
->setDependencies(['jquery']);
}
+ $values = $this->addAddressStyle($values, $style, $pluginPath);
return array_merge($values, $this->addScripts($pluginPath, $script, $style, $defer, $async));
}
@@ -346,6 +347,23 @@ private function extractFormNames(string $pageContent): array
return $matches[1];
}
+ /**
+ * @param array $values
+ * @param string $style
+ * @param string $pluginPath
+ * @return array
+ */
+ private function addAddressStyle(array $values, string $style, string $pluginPath) {
+ $pageContent = get_the_content();
+ if ($this->isAddressListPage($pageContent)) {
+ $values []= (new IncludeFileModel($style, 'onoffice-address', plugins_url('/css/onoffice-address.css', $pluginPath)));
+ }
+ if ($this->isDetailAddressPage($pageContent)) {
+ $values []= (new IncludeFileModel($style, 'onoffice-address-detail', plugins_url('/css/onoffice-address-detail.css', $pluginPath)));
+ }
+ return $values;
+ }
+
/**
* @param array $scripts
* @param string $pluginPath
diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php
index ecba9ec44..210f1c9b9 100644
--- a/templates.dist/address/default_detail.php
+++ b/templates.dist/address/default_detail.php
@@ -2,7 +2,7 @@
/**
*
- * Copyright (C) 2020 onOffice GmbH
+ * Copyright (C) 2024 onOffice GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
*
*/
-use onOffice\WPlugin\AdressDetail;
+use onOffice\WPlugin\AddressDetail;
use onOffice\WPlugin\ViewFieldModifier\AddressViewFieldModifierTypes;
@@ -27,9 +27,13 @@
getCurrentAddress();
foreach ($currentAddressArr as $addressId => $escapedValues) {
?>
+
+
+
From 35957be50fd7602eb413b0b4e54f4db1566e1fff Mon Sep 17 00:00:00 2001
From: andernath
Date: Thu, 12 Sep 2024 10:44:11 +0200
Subject: [PATCH 28/33] Use getRows() to avoid duplicated fields with default
email and phone Add Styling Merge conflicts #p110445
---
css/onoffice-address-detail.css | 12 +-
plugin/AddressList.php | 2 +-
...criptLoaderGenericConfigurationDefault.php | 23 ----
templates.dist/address/default_detail.php | 120 ++++++++++--------
templates.dist/estate/default.php | 3 -
templates.dist/estate/default_detail.php | 3 -
.../templates/output_default_detail.html | 3 -
7 files changed, 75 insertions(+), 91 deletions(-)
diff --git a/css/onoffice-address-detail.css b/css/onoffice-address-detail.css
index 840e0289a..c50eca5f4 100644
--- a/css/onoffice-address-detail.css
+++ b/css/onoffice-address-detail.css
@@ -1,4 +1,10 @@
-.oo-addressdetail-headline {
- color: grey;
- font-size: 3rem;
+
+.oo-addresscontact {
+ display: flex;
+ flex-direction: column;
+ margin-bottom: 4rem;
+}
+.oo-addresscontact-field {
+ font-size: 1rem;
+ margin-bottom: 0.5rem;
}
\ No newline at end of file
diff --git a/plugin/AddressList.php b/plugin/AddressList.php
index 3a942dca9..4a1345955 100644
--- a/plugin/AddressList.php
+++ b/plugin/AddressList.php
@@ -227,7 +227,7 @@ private function generateRecordModifier(): ViewFieldModifierHandler
{
$fields = $this->_pDataViewAddress->getFields();
- if ($this->_pDataViewAddress->getShowPhoto()) {
+ if ($this->getDataViewAddress() instanceof DataListViewAddress && $this->_pDataViewAddress->getShowPhoto()) {
$fields []= 'imageUrl';
}
diff --git a/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php b/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php
index 771589f48..7e5f47118 100644
--- a/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php
+++ b/plugin/ScriptLoader/ScriptLoaderGenericConfigurationDefault.php
@@ -368,7 +368,6 @@ private function addAddressStyle(array $values, string $style, string $pluginPat
* @param array $scripts
* @param string $pluginPath
* @param string $script
- * @param string $style
* @param string $defer
* @return array
*/
@@ -389,28 +388,6 @@ private function renderScriptForAddressDetailPage(array $scripts, string $plugin
* @param array $scripts
* @param string $pluginPath
* @param string $script
- * @param string $style
- * @param string $defer
- * @return array
- */
-
- private function renderScriptForAddressDetailPage(array $scripts, string $pluginPath, string $script, string $defer): array
- {
- $scripts[] = (new IncludeFileModel($script, 'slick', plugins_url('/third_party/slick/slick.js', $pluginPath)))
- ->setDependencies(['jquery'])
- ->setLoadInFooter(true)
- ->setLoadAsynchronous($defer);
- $scripts[] = (new IncludeFileModel($script, 'onoffice_defaultview', plugins_url('/dist/onoffice_defaultview.min.js', $pluginPath)))
- ->setDependencies(['jquery'])
- ->setLoadInFooter(true);
-
- return $scripts;
- }
- /**
- * @param array $scripts
- * @param string $pluginPath
- * @param string $script
- * @param string $style
* @param string $defer
* @return array
*/
diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php
index ee80052e1..46b4a9df3 100644
--- a/templates.dist/address/default_detail.php
+++ b/templates.dist/address/default_detail.php
@@ -21,63 +21,73 @@
use onOffice\WPlugin\AddressList;
-?>
-
-
- getCurrentAddress();
- foreach ($currentAddressArr as $addressId => $escapedValues) {
- $imageUrl = $escapedValues['imageUrl'];
- unset($escapedValues['imageUrl']);
- ?>
+$addressName = array('Anrede', 'Titel', 'Vorname', 'Name');
+/* @var $pAddressList AddressList */
+$currentAddressArr = $pAddressList->getRows();
+foreach ($currentAddressArr as $addressId => $escapedValues) {
+ $imageUrl = $escapedValues['imageUrl'];
+ unset($escapedValues['imageUrl']);
+ ?>
+
+
+
+getShortCodeActiveEstates();
+ if (!empty($shortCodeActiveEstates)) {
+ ?>
-
+
-
- getShortCodeForm();
- if (!empty($shortCodeForm)) {
- ?>
-
-
-
-
-
+
+getShortCodeReferenceEstates();
+if (!empty($shortCodeReferenceEstates)) {
+ ?>
+
+
+
+
+getShortCodeForm();
+ if (!empty($shortCodeForm)) {
+ ?>
+
+
+
+
diff --git a/templates.dist/estate/default.php b/templates.dist/estate/default.php
index 4c1fdfe92..3814757cd 100644
--- a/templates.dist/estate/default.php
+++ b/templates.dist/estate/default.php
@@ -92,9 +92,6 @@
ul.oo-listparking {
padding: 0 10px;
}
- .clear {
- width: 50%;
- }
diff --git a/templates.dist/estate/default_detail.php b/templates.dist/estate/default_detail.php
index 68ef09cbb..ea8fd9a72 100644
--- a/templates.dist/estate/default_detail.php
+++ b/templates.dist/estate/default_detail.php
@@ -84,9 +84,6 @@
ul.oo-listparking {
padding: 0 10px;
}
- .clear {
- width: 25%;
- }
From c581dbb05d2dab102f16be648f43d58092fed813 Mon Sep 17 00:00:00 2001
From: andernath
Date: Fri, 13 Sep 2024 09:20:46 +0200
Subject: [PATCH 29/33] Add image alt tag #p110445
---
plugin/AddressList.php | 29 ++++++++++++++++++-----
templates.dist/address/default_detail.php | 5 ++--
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/plugin/AddressList.php b/plugin/AddressList.php
index 4a1345955..bccdc3366 100644
--- a/plugin/AddressList.php
+++ b/plugin/AddressList.php
@@ -165,12 +165,20 @@ public function loadAddressesById(array $addressIds, array $fields)
'outputlanguage' => Language::getDefault(),
'formatoutput' => true,
];
+ $parametersRaw = [
+ 'recordids' => $addressIds,
+ 'data' => $this->_addressParametersForImageAlt,
+ 'outputlanguage' => Language::getDefault(),
+ 'formatoutput' => false,
+ ];
$pApiCall->setParameters($parameters);
$pApiCall->addRequestToQueue()->sendRequests();
$records = $pApiCall->getResultRecords();
$this->fillAddressesById($records);
$this->_pDataViewAddress->setFields($fields);
+
+ $this->addRawRecordsByAPICall(clone $pApiCall, $parametersRaw);
}
/**
@@ -202,12 +210,7 @@ public function loadAddresses(int $inputPage = 1)
$addressParameterRaws = $pDataListViewToApi->buildParameters($this->_addressParametersForImageAlt,
$this->_pDataViewAddress, $newPage);
-
- $pAddressRawApiCall = clone $pApiCall;
- $pAddressRawApiCall->setParameters($addressParameterRaws);
- $pAddressRawApiCall->addRequestToQueue()->sendRequests();
- $recordsRaw = $pAddressRawApiCall->getResultRecords();
- $this->_recordsRaw = array_combine(array_column($recordsRaw, 'id'), $recordsRaw);
+ $this->addRawRecordsByAPICall(clone $pApiCall, $addressParameterRaws);
$this->_records = $pApiCall->getResultRecords();
$this->fillAddressesById($this->_records);
@@ -460,4 +463,18 @@ public function getCurrentAddress(): array
{
return $this->_addressesById;
}
+
+ /**
+ * @param APIClientActionGeneric $addressApiCall
+ * @param array $parameters
+ * @throws API\ApiClientException
+ */
+ private function addRawRecordsByAPICall(APIClientActionGeneric $addressApiCall, array $parameters) {
+ $addressApiCall->setParameters($parameters);
+ $addressApiCall->addRequestToQueue()->sendRequests();
+ $recordsRaw = $addressApiCall->getResultRecords();
+
+ $this->_recordsRaw = array_combine(array_column($recordsRaw, 'id'), $recordsRaw);
+
+ }
}
diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php
index 46b4a9df3..422946e5b 100644
--- a/templates.dist/address/default_detail.php
+++ b/templates.dist/address/default_detail.php
@@ -23,6 +23,7 @@
$addressName = array('Anrede', 'Titel', 'Vorname', 'Name');
/* @var $pAddressList AddressList */
+/*todo getRows()*/
$currentAddressArr = $pAddressList->getRows();
foreach ($currentAddressArr as $addressId => $escapedValues) {
$imageUrl = $escapedValues['imageUrl'];
@@ -42,6 +43,7 @@
if (!empty($imageUrl)) {
$imageAlt = $pAddressList->generateImageAlt($addressId);
echo '';
+ /*todo alttag*/
echo ' ';
}
foreach ($escapedValues as $field => $value) {
- /*if (in_array($field, $addressName) || !in_array($field, $fields)) {
- continue;
- }*/
if (in_array($field, $addressName)) {
continue;
}
From c0da892802a821b23d449d58d484553ee0f5f6e6 Mon Sep 17 00:00:00 2001
From: andernath
Date: Mon, 16 Sep 2024 11:35:16 +0200
Subject: [PATCH 30/33] Adjust styling #p110445
---
css/onoffice-address-detail.css | 51 +++++++++++++++++++++--
templates.dist/address/default_detail.php | 44 ++++++++++++-------
2 files changed, 77 insertions(+), 18 deletions(-)
diff --git a/css/onoffice-address-detail.css b/css/onoffice-address-detail.css
index c50eca5f4..d6cd43bf1 100644
--- a/css/onoffice-address-detail.css
+++ b/css/onoffice-address-detail.css
@@ -1,10 +1,53 @@
-
-.oo-addresscontact {
+.oo-address {
display: flex;
flex-direction: column;
+ flex-wrap: wrap;
margin-bottom: 4rem;
}
-.oo-addresscontact-field {
+.oo-address-name {
+ flex: 1 0 100%;
+}
+.oo-address-picture {
+ margin-bottom: 0.25rem;
+}
+.oo-address-fieldlist {
+ display: flex;
+ flex-direction: column;
+}
+.oo-address-placefieldlist {
+ display: flex;
+ flex-direction: column;
+ margin-top: 0.25rem;
+ margin-bottom: 0.25rem;
+}
+.oo-address-field {
font-size: 1rem;
- margin-bottom: 0.5rem;
+ margin-top: 0.25rem;
+ margin-bottom: 0.25rem;
+}
+.oo-address-estatelist {
+ margin-bottom: 4rem;
+}
+.oo-address-form {
+ margin-bottom: 4rem;
+}
+@media only screen and (min-width: 960px) {
+ .oo-address {
+ flex-direction: row;
+ margin-bottom: 7.5rem;
+ }
+ .oo-address-picture {
+ flex: 1 0 50%;
+ padding-right: 2rem
+ }
+ .oo-address-fieldlist {
+ flex: 1 0 50%;
+ padding-left: 2rem;
+ }
+ .oo-address-estatelist {
+ margin-bottom: 7.5rem;
+ }
+ .oo-address-form {
+ margin-bottom: 7.5rem;
+ }
}
\ No newline at end of file
diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php
index 422946e5b..54c18ec1c 100644
--- a/templates.dist/address/default_detail.php
+++ b/templates.dist/address/default_detail.php
@@ -22,6 +22,7 @@
use onOffice\WPlugin\AddressList;
$addressName = array('Anrede', 'Titel', 'Vorname', 'Name');
+$addressPlace = array('Strasse', 'Plz', 'Ort', 'Plz-Ort');
/* @var $pAddressList AddressList */
/*todo getRows()*/
$currentAddressArr = $pAddressList->getRows();
@@ -29,8 +30,8 @@
$imageUrl = $escapedValues['imageUrl'];
unset($escapedValues['imageUrl']);
?>
-