Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

48938 implement filtering in similar estate #832

Merged
merged 18 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c9a6b36
48938 implement filtering in similar estate
dai-eastgate Jun 6, 2024
11d5c9b
48938 update unit test
dai-eastgate Jun 6, 2024
c49a396
48938 update unit test
dai-eastgate Jun 6, 2024
97d5782
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Jun 6, 2024
aa8b934
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Jun 17, 2024
7e3cdfc
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Jun 19, 2024
59b590c
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
yeneastgate Jun 21, 2024
bbc67aa
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Aug 29, 2024
0c73f35
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Sep 10, 2024
2594fb9
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
fredericalpers Sep 30, 2024
5bd6f53
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Oct 1, 2024
4f20ebb
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Oct 10, 2024
df8b997
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Oct 21, 2024
731067d
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Oct 22, 2024
c5407b1
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Oct 24, 2024
829a7c6
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
yeneastgate Oct 25, 2024
c4008e5
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
dai-eastgate Oct 28, 2024
a89f546
Merge branch 'master' into 48938-implement-filtering-in-similar-estate
andernath Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugin/DataView/DataSimilarEstatesSettingsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
22 changes: 20 additions & 2 deletions plugin/DataView/DataViewSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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; }
}
2 changes: 1 addition & 1 deletion plugin/EstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 1 addition & 4 deletions plugin/Filter/DefaultFilterBuilderSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ public function buildFilter(): array
],
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
]
];

$pFilterConfiguration = $this->_pFilterConfigurationSimilarEstates;
Expand Down
16 changes: 16 additions & 0 deletions plugin/Gui/AdminPageSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = '<a href="' . esc_attr(admin_url('admin.php?page=onoffice-estates&tab=detail')) . '" target="_blank">' . __('restricted',
'onoffice-for-wp-websites') . '</a>';
$pInputModelShowReferenceEstate->setHintHtml(sprintf(__('Reference estates will not link to their detail page, because the access is %s.',
'onoffice-for-wp-websites'), $restrictedPageDetail));
} else {
$restrictedPageDetail = '<a href="' . esc_attr(admin_url('admin.php?page=onoffice-estates&tab=detail')) . '" target="_blank">' . __('not restricted',
'onoffice-for-wp-websites') . '</a>';
$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 = '<a href="' . $linkUrl . '" target="_blank">' . __('Learn more.', 'onoffice-for-wp-websites') . '</a>';
$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'),
];
}
}
12 changes: 12 additions & 0 deletions plugin/Model/InputModel/InputModelOptionFactorySimilarView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
]
];

Expand Down
7 changes: 6 additions & 1 deletion tests/TestClassDataViewSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}


Expand All @@ -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');
}


Expand Down
18 changes: 0 additions & 18 deletions tests/TestClassDefaultFilterBuilderSimilarEstates.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public function testBuildFilterBase()
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
];
$this->assertEquals($expectation, $result);
}
Expand All @@ -112,9 +109,6 @@ public function testBuildFilterSameEstateKind()
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
];
$this->assertEquals($expectation, $result);
}
Expand All @@ -141,9 +135,6 @@ public function testBuildFilterSameMarketingMethod()
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
];
$this->assertEquals($expectation, $result);
}
Expand All @@ -167,9 +158,6 @@ public function testBuildFilterSamePostalCode()
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
'plz' => [
['op' => '=', 'val' => '52070'],
],
Expand Down Expand Up @@ -198,9 +186,6 @@ public function testExcludeIds()
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
'plz' => [
['op' => '=', 'val' => '52070'],
],
Expand Down Expand Up @@ -233,9 +218,6 @@ public function testBuildFilterCombined()
'reserviert' => [
['op' => '!=', 'val' => 1],
],
'referenz' => [
['op' => '!=', 'val' => 1],
],
'vermarktungsart' => [
['op' => '=', 'val' => 'kauf'],
],
Expand Down
35 changes: 35 additions & 0 deletions tests/TestClassFormModelBuilderSimilarEstateSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. <a href="https://de.enterprisehilfe.onoffice.com/help_entries/property-filter/?lang=en" target="_blank">Learn more.</a>', $pInputModelOption->getHintHtml());
}
}
Loading