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 838c2be74..03d9c67ab 100644 --- a/plugin/DataView/DataViewSimilarEstates.php +++ b/plugin/DataView/DataViewSimilarEstates.php @@ -122,6 +122,12 @@ class DataViewSimilarEstates 'calculatedPrice' ]; + /** @var string */ + private $_showReferenceEstate = '0'; + + /** @var int */ + private $_filterId = 0; + /** @param bool $sameEstateKind */ public function setSameEstateKind(bool $sameEstateKind) { $this->_sameEstateKind = $sameEstateKind; } @@ -207,8 +213,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 @@ -243,4 +253,12 @@ public function setListFieldsShowPriceOnRequest(array $priceFields) { $this->_priceFields = $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 83e2997f5..4ac37e089 100644 --- a/plugin/EstateList.php +++ b/plugin/EstateList.php @@ -1214,7 +1214,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/tests/TestClassDataViewSimilarEstates.php b/tests/TestClassDataViewSimilarEstates.php index 82af54ec7..f1a7a52c7 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/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'], ], diff --git a/tests/TestClassFormModelBuilderSimilarEstateSettings.php b/tests/TestClassFormModelBuilderSimilarEstateSettings.php index 66b99a1b3..e5e8c7b4a 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,38 @@ public function testCreateSearchFieldForFieldLists() $this->assertNotEmpty($pInputModelOption->getValuesAvailable()); $this->assertEquals($pInputModelOption->getHtmlType(), 'searchFieldForFieldLists'); } + + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings::createInputModelShowReferenceEstates + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderSimilarEstateSettings::getListViewReferenceEstates + */ + public function testCreateInputModelShowReferenceEstates() + { + $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