From c9a6b36417f2ac2c5bf2efdedd936f8dba32389a Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Thu, 6 Jun 2024 09:20:04 +0700 Subject: [PATCH 1/3] 48938 implement filtering in similar estate --- .../DataSimilarEstatesSettingsHandler.php | 2 + plugin/DataView/DataViewSimilarEstates.php | 22 +++++- plugin/EstateList.php | 2 +- .../DefaultFilterBuilderSimilarEstates.php | 5 +- plugin/Gui/AdminPageSimilarEstates.php | 16 +++++ .../FormModelBuilderSimilarEstateSettings.php | 67 +++++++++++++++++++ .../InputModelOptionFactorySimilarView.php | 12 ++++ templates.dist/estate/similar_estates.php | 2 +- tests/TestClassDataViewSimilarEstates.php | 7 +- ...sFormModelBuilderSimilarEstateSettings.php | 34 ++++++++++ 10 files changed, 160 insertions(+), 9 deletions(-) diff --git a/plugin/DataView/DataSimilarEstatesSettingsHandler.php b/plugin/DataView/DataSimilarEstatesSettingsHandler.php index f86b18375..cc19cbe38 100644 --- a/plugin/DataView/DataSimilarEstatesSettingsHandler.php +++ b/plugin/DataView/DataSimilarEstatesSettingsHandler.php @@ -136,5 +136,7 @@ private function configureDataSimilarEstatesSettings(DataViewSimilarEstates $pDa $pDataViewSimilar->setPictureTypes ($row[DataViewSimilarEstates::PICTURES] ?? $pDataViewSimilar->getPictureTypes()); + $pDataViewSimilar->setFilterId($row['filterId'] ?? $pDataViewSimilar->getFilterId()); + $pDataViewSimilar->setShowReferenceEstate($row['showReferenceEstate'] ?? $pDataViewSimilar->getShowReferenceEstate()); } } diff --git a/plugin/DataView/DataViewSimilarEstates.php b/plugin/DataView/DataViewSimilarEstates.php index d2be77b08..28d773cc5 100644 --- a/plugin/DataView/DataViewSimilarEstates.php +++ b/plugin/DataView/DataViewSimilarEstates.php @@ -121,6 +121,12 @@ class DataViewSimilarEstates 'mietpreis_pro_qm', ]; + /** @var string */ + private $_showReferenceEstate = '0'; + + /** @var int */ + private $_filterId = 0; + /** @param bool $sameEstateKind */ public function setSameEstateKind(bool $sameEstateKind) { $this->_sameEstateKind = $sameEstateKind; } @@ -206,8 +212,12 @@ public function getSortOrder() { return null; } /** @return int */ - public function getFilterId() - { return null; } + public function getFilterId(): int + { return $this->_filterId; } + + /** @param int $filterId */ + public function setFilterId(int $filterId) + { $this->_filterId = $filterId; } /** @return bool */ public function getRandom(): bool @@ -236,4 +246,12 @@ public function getListFieldsShowPriceOnRequest(): array { return $this->_priceFields; } + + /** @return string */ + public function getShowReferenceEstate(): string + { return $this->_showReferenceEstate; } + + /** @param string $showReferenceEstate */ + public function setShowReferenceEstate(string $showReferenceEstate) + { $this->_showReferenceEstate = $showReferenceEstate; } } \ No newline at end of file diff --git a/plugin/EstateList.php b/plugin/EstateList.php index 5ae2e6fb4..6e6560882 100644 --- a/plugin/EstateList.php +++ b/plugin/EstateList.php @@ -1009,7 +1009,7 @@ public function getShowReferenceStatus(): bool */ public function getShowReferenceEstate(): string { - if ( $this->_pDataView instanceof DataListView ) { + if ( $this->_pDataView instanceof DataListView || $this->_pDataView instanceof DataViewSimilarEstates) { return $this->_pDataView->getShowReferenceEstate(); } diff --git a/plugin/Filter/DefaultFilterBuilderSimilarEstates.php b/plugin/Filter/DefaultFilterBuilderSimilarEstates.php index c62465718..4c55de62c 100644 --- a/plugin/Filter/DefaultFilterBuilderSimilarEstates.php +++ b/plugin/Filter/DefaultFilterBuilderSimilarEstates.php @@ -69,10 +69,7 @@ public function buildFilter(): array ], 'reserviert' => [ ['op' => '!=', 'val' => 1], - ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], + ] ]; $pFilterConfiguration = $this->_pFilterConfigurationSimilarEstates; diff --git a/plugin/Gui/AdminPageSimilarEstates.php b/plugin/Gui/AdminPageSimilarEstates.php index 801f019a5..36b5660cf 100644 --- a/plugin/Gui/AdminPageSimilarEstates.php +++ b/plugin/Gui/AdminPageSimilarEstates.php @@ -97,6 +97,9 @@ class AdminPageSimilarEstates /** */ const FORM_VIEW_SEARCH_FIELD_FOR_FIELD_LISTS_CONFIG = 'viewSearchFieldForFieldListsConfig'; + /** */ + const FORM_VIEW_FILTER_RECORDS = 'viewFilterRecords'; + /** * @throws DependencyException * @throws NotFoundException @@ -190,6 +193,9 @@ private function generateMetaBoxes() $pFormPictureTypes = $this->getFormModelByGroupSlug(self::FORM_VIEW_PICTURE_TYPES); $this->createMetaBoxByForm($pFormPictureTypes, 'normal'); + + $pFormFilterRecords = $this->getFormModelByGroupSlug(self::FORM_VIEW_FILTER_RECORDS); + $this->createMetaBoxByForm($pFormFilterRecords, 'normal'); } /** @@ -249,6 +255,16 @@ protected function buildForms() $pFormModelPictureTypes->addInputModel($pInputModelSimilarEstatesPictureTypes); $this->addFormModel($pFormModelPictureTypes); + $pInputModelShowReferenceEstate = $pFormModelBuilder->createInputModelShowReferenceEstates(); + $pInputModelFilter = $pFormModelBuilder->createInputModelFilter(); + $pFormModelFilterRecords = new FormModel(); + $pFormModelFilterRecords->setPageSlug($this->getPageSlug()); + $pFormModelFilterRecords->setGroupSlug(self::FORM_VIEW_FILTER_RECORDS); + $pFormModelFilterRecords->setLabel(__('Filter & Records', 'onoffice-for-wp-websites')); + $pFormModelFilterRecords->addInputModel($pInputModelShowReferenceEstate); + $pFormModelFilterRecords->addInputModel($pInputModelFilter); + $this->addFormModel($pFormModelFilterRecords); + $pFieldsCollection = $this->readAllFields(); $pFieldsCollectionConverter = $this->getContainer()->get(FieldsCollectionToContentFieldLabelArrayConverter::class); $fieldsEstate = $pFieldsCollectionConverter->convert($pFieldsCollection, onOfficeSDK::MODULE_ESTATE); diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php b/plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php index a45ab7359..656fc9ced 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderSimilarEstateSettings.php @@ -26,6 +26,7 @@ use DI\NotFoundException; use onOffice\SDK\onOfficeSDK; use onOffice\WPlugin\Controller\Exception\UnknownModuleException; +use onOffice\WPlugin\DataView\DataDetailViewHandler; use onOffice\WPlugin\DataView\DataSimilarView; use onOffice\WPlugin\DataView\DataSimilarEstatesSettingsHandler; use onOffice\WPlugin\DataView\DataListView; @@ -537,4 +538,70 @@ public function createSearchFieldForFieldLists($module, string $htmlType) return $pInputModelFieldsConfig; } + + /** + * @return InputModelOption + */ + public function createInputModelShowReferenceEstates(): InputModelOption + { + $pDataViewSimilarEstates = $this->_pDataSimilarView->getDataViewSimilarEstates(); + $labelShowReferenceEstate = __('Reference estates', 'onoffice-for-wp-websites'); + + $pInputModelShowReferenceEstate = $this->_pInputModelSimilarViewFactory->create + (InputModelOptionFactorySimilarView::INPUT_SHOW_REFERENCE_ESTATE, $labelShowReferenceEstate); + $pInputModelShowReferenceEstate->setHtmlType(InputModelBase::HTML_TYPE_SELECT); + $pInputModelShowReferenceEstate->setValue($pDataViewSimilarEstates->getShowReferenceEstate()); + $pInputModelShowReferenceEstate->setValuesAvailable(self::getListViewReferenceEstates()); + $pDataDetailViewHandler = $this->_pContainer->get(DataDetailViewHandler::class); + $pDataDetailView = $pDataDetailViewHandler->getDetailView(); + $restrictAccessControl = $pDataDetailView->getViewRestrict(); + if ($restrictAccessControl) { + $restrictedPageDetail = '' . __('restricted', + 'onoffice-for-wp-websites') . ''; + $pInputModelShowReferenceEstate->setHintHtml(sprintf(__('Reference estates will not link to their detail page, because the access is %s.', + 'onoffice-for-wp-websites'), $restrictedPageDetail)); + } else { + $restrictedPageDetail = '' . __('not restricted', + 'onoffice-for-wp-websites') . ''; + $pInputModelShowReferenceEstate->setHintHtml(sprintf(__('Reference estates will link to their detail page, because the access is %s.', + 'onoffice-for-wp-websites'), $restrictedPageDetail)); + } + + return $pInputModelShowReferenceEstate; + } + + /** + * @return InputModelOption + * @throws ExceptionInputModelMissingField + */ + public function createInputModelFilter(): InputModelOption + { + $pDataViewSimilarEstates = $this->_pDataSimilarView->getDataViewSimilarEstates(); + $labelFilterName = __('Filter', 'onoffice-for-wp-websites'); + + $pInputModelFilterName = $this->_pInputModelSimilarViewFactory->create + (InputModelOptionFactorySimilarView::INPUT_FILTERID, $labelFilterName); + $pInputModelFilterName->setHtmlType(InputModelBase::HTML_TYPE_SELECT); + $availableFilters = array(0 => '') + $this->readFilters(onOfficeSDK::MODULE_ESTATE); + $pInputModelFilterName->setValuesAvailable($availableFilters); + $pInputModelFilterName->setValue($pDataViewSimilarEstates->getFilterId()); + $linkUrl = __("https://de.enterprisehilfe.onoffice.com/help_entries/property-filter/?lang=en", "onoffice-for-wp-websites"); + $linkLabel = '' . __('Learn more.', 'onoffice-for-wp-websites') . ''; + $pInputModelFilterName->setHintHtml(sprintf(__('Choose an estate filter from onOffice enterprise. %s', + 'onoffice-for-wp-websites'), $linkLabel)); + + return $pInputModelFilterName; + } + + /** + * @return array + */ + private function getListViewReferenceEstates(): array + { + return [ + 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'), + ]; + } } diff --git a/plugin/Model/InputModel/InputModelOptionFactorySimilarView.php b/plugin/Model/InputModel/InputModelOptionFactorySimilarView.php index f03c0becf..abd750eba 100644 --- a/plugin/Model/InputModel/InputModelOptionFactorySimilarView.php +++ b/plugin/Model/InputModel/InputModelOptionFactorySimilarView.php @@ -73,6 +73,12 @@ class InputModelOptionFactorySimilarView /** */ const INPUT_PICTURE_TYPE = DataSimilarView::PICTURES; + /** */ + const INPUT_SHOW_REFERENCE_ESTATE = 'showReferenceEstate'; + + /** */ + const INPUT_FILTERID = 'filterId'; + /** @var string */ private $_optionGroup = null; @@ -108,6 +114,12 @@ class InputModelOptionFactorySimilarView ], self::INPUT_SHOW_PRICE_ON_REQUEST => [ self::KEY_TYPE => InputModelOption::SETTING_TYPE_BOOLEAN + ], + self::INPUT_SHOW_REFERENCE_ESTATE => [ + self::KEY_TYPE => InputModelOption::SETTING_TYPE_STRING + ], + self::INPUT_FILTERID => [ + self::KEY_TYPE => InputModelOption::SETTING_TYPE_INTEGER ] ]; diff --git a/templates.dist/estate/similar_estates.php b/templates.dist/estate/similar_estates.php index be99fda15..4c4a14311 100644 --- a/templates.dist/estate/similar_estates.php +++ b/templates.dist/estate/similar_estates.php @@ -27,7 +27,7 @@ foreach ( $estatePictures as $id ) { $pictureValues = $pEstates->getEstatePictureValues( $id ); if ( $referenz === "1" && $pEstates->getViewRestrict() ) { - echo 'div style="background-image: url('.esc_url($pEstates->getEstatePictureUrl( $id )).');" class="oo-listimage">'; + echo '
'; } else { echo ''; } diff --git a/tests/TestClassDataViewSimilarEstates.php b/tests/TestClassDataViewSimilarEstates.php index 594b2ffc7..01b4bcfe0 100644 --- a/tests/TestClassDataViewSimilarEstates.php +++ b/tests/TestClassDataViewSimilarEstates.php @@ -51,6 +51,8 @@ public function testDefaultValues() $this->assertEquals(10, $pDataViewSimilarEstates->getRadius()); $this->assertEquals(6, $pDataViewSimilarEstates->getRecordsPerPage()); $this->assertEquals(false, $pDataViewSimilarEstates->getShowPriceOnRequest()); + $this->assertEquals('0', $pDataViewSimilarEstates->getShowReferenceEstate()); + $this->assertEquals(0, $pDataViewSimilarEstates->getFilterId()); } @@ -75,7 +77,10 @@ public function testGetterSetter() $this->assertTrue($pDataViewSimilarEstates->getShowPriceOnRequest()); $this->assertEquals(['Id' => 'ASC'], $pDataViewSimilarEstates->getSortBy()); $this->assertNull($pDataViewSimilarEstates->getSortOrder()); - $this->assertNull($pDataViewSimilarEstates->getFilterId()); + $pDataViewSimilarEstates->setFilterId(10); + $this->assertEquals($pDataViewSimilarEstates->getFilterId(), 10); + $pDataViewSimilarEstates->setShowReferenceEstate('0'); + $this->assertEquals($pDataViewSimilarEstates->getShowReferenceEstate(), '0'); } diff --git a/tests/TestClassFormModelBuilderSimilarEstateSettings.php b/tests/TestClassFormModelBuilderSimilarEstateSettings.php index 66b99a1b3..0afc33a95 100644 --- a/tests/TestClassFormModelBuilderSimilarEstateSettings.php +++ b/tests/TestClassFormModelBuilderSimilarEstateSettings.php @@ -27,6 +27,7 @@ use DI\ContainerBuilder; use onOffice\WPlugin\DataView\DataSimilarEstatesSettingsHandler; use onOffice\WPlugin\DataView\DataSimilarView; +use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBEstateListSettings; use onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings; use onOffice\WPlugin\Model\InputModel\InputModelOptionFactorySimilarView; use onOffice\WPlugin\DataView\DataDetailView; @@ -386,4 +387,37 @@ public function testCreateSearchFieldForFieldLists() $this->assertNotEmpty($pInputModelOption->getValuesAvailable()); $this->assertEquals($pInputModelOption->getHtmlType(), 'searchFieldForFieldLists'); } + + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings::createInputModelShowReferenceEstates + */ + public function testCreateInputModelShowReferenceEstates1() + { + $pFormModelBuilderSimilarEstateSettings = new FormModelBuilderSimilarEstateSettings($this->_pContainer); + $pFormModelBuilderSimilarEstateSettings->generate('test'); + $pInputModelOption = $pFormModelBuilderSimilarEstateSettings->createInputModelShowReferenceEstates(); + + $this->assertInstanceOf(InputModelOption::class, $pInputModelOption); + $this->assertNotEmpty($pInputModelOption->getValuesAvailable()); + $this->assertEquals($pInputModelOption->getHtmlType(), 'select'); + } + + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings::createInputModelFilter + */ + public function testCreateInputModelFilter() + { + $pInstance = $this->getMockBuilder(FormModelBuilderSimilarEstateSettings::class) + ->disableOriginalConstructor() + ->setMethods(['getInputModelDBFactory', 'readFilters']) + ->getMock(); + $pInstance->method('readFilters')->willReturn(['a']); + $pInstance->generate('test'); + + $pInputModelOption = $pInstance->createInputModelFilter(); + $this->assertInstanceOf(InputModelOption::class, $pInputModelOption); + $this->assertNotEmpty($pInputModelOption->getValuesAvailable()); + $this->assertEquals($pInputModelOption->getHtmlType(), 'select'); + $this->assertEquals('Choose an estate filter from onOffice enterprise. Learn more.', $pInputModelOption->getHintHtml()); + } } \ No newline at end of file From 11d5c9be247c814dcf4472074fd85252a1c2c236 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Thu, 6 Jun 2024 09:55:19 +0700 Subject: [PATCH 2/3] 48938 update unit test --- ...ClassDefaultFilterBuilderSimilarEstates.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tests/TestClassDefaultFilterBuilderSimilarEstates.php b/tests/TestClassDefaultFilterBuilderSimilarEstates.php index f9cb323c9..6fd0b14b7 100644 --- a/tests/TestClassDefaultFilterBuilderSimilarEstates.php +++ b/tests/TestClassDefaultFilterBuilderSimilarEstates.php @@ -83,9 +83,6 @@ public function testBuildFilterBase() 'reserviert' => [ ['op' => '!=', 'val' => 1], ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], ]; $this->assertEquals($expectation, $result); } @@ -112,9 +109,6 @@ public function testBuildFilterSameEstateKind() 'reserviert' => [ ['op' => '!=', 'val' => 1], ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], ]; $this->assertEquals($expectation, $result); } @@ -141,9 +135,6 @@ public function testBuildFilterSameMarketingMethod() 'reserviert' => [ ['op' => '!=', 'val' => 1], ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], ]; $this->assertEquals($expectation, $result); } @@ -167,9 +158,6 @@ public function testBuildFilterSamePostalCode() 'reserviert' => [ ['op' => '!=', 'val' => 1], ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], 'plz' => [ ['op' => '=', 'val' => '52070'], ], @@ -198,9 +186,6 @@ public function testExcludeIds() 'reserviert' => [ ['op' => '!=', 'val' => 1], ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], 'plz' => [ ['op' => '=', 'val' => '52070'], ], @@ -233,9 +218,6 @@ public function testBuildFilterCombined() 'reserviert' => [ ['op' => '!=', 'val' => 1], ], - 'referenz' => [ - ['op' => '!=', 'val' => 1], - ], 'vermarktungsart' => [ ['op' => '=', 'val' => 'kauf'], ], From c49a3961328e6e3b72527334f62d27cfa930e497 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Thu, 6 Jun 2024 14:12:56 +0700 Subject: [PATCH 3/3] 48938 update unit test --- tests/TestClassFormModelBuilderSimilarEstateSettings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/TestClassFormModelBuilderSimilarEstateSettings.php b/tests/TestClassFormModelBuilderSimilarEstateSettings.php index 0afc33a95..e5e8c7b4a 100644 --- a/tests/TestClassFormModelBuilderSimilarEstateSettings.php +++ b/tests/TestClassFormModelBuilderSimilarEstateSettings.php @@ -390,8 +390,9 @@ public function testCreateSearchFieldForFieldLists() /** * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings::createInputModelShowReferenceEstates + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings::getListViewReferenceEstates */ - public function testCreateInputModelShowReferenceEstates1() + public function testCreateInputModelShowReferenceEstates() { $pFormModelBuilderSimilarEstateSettings = new FormModelBuilderSimilarEstateSettings($this->_pContainer); $pFormModelBuilderSimilarEstateSettings->generate('test');