Skip to content

Commit

Permalink
34563-map-in-property-listing
Browse files Browse the repository at this point in the history
  • Loading branch information
yeneastgate committed Jun 14, 2023
1 parent c91f195 commit 9354ea3
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 4 deletions.
10 changes: 10 additions & 0 deletions plugin/DataView/DataListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class DataListView
/** @var string */
private $_showReferenceEstate = '0';

/** @var bool */
private $_showMap = false;

/**
*
Expand Down Expand Up @@ -212,6 +214,14 @@ public function getExpose(): string
public function getAddressFields(): array
{ return $this->_addressFields; }

/** @return bool */
public function getShowMap(): bool
{ return (bool) $this->_showMap; }

/** @param bool $showMap */
public function setShowMap(bool $showMap)
{ $this->_showMap = $showMap; }

/** @param bool $random */
public function setRandom(bool $random)
{ $this->_random = $random; }
Expand Down
1 change: 1 addition & 0 deletions plugin/DataView/DataListViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function createListViewByRow(array $row): DataViewFilterableFields
$pListView->setSortByUserDefinedDirection((int)$row['sortByUserDefinedDirection']);
$pListView->setSortByUserValues($row[DataListView::SORT_BY_USER_VALUES]);
$pListView->setShowReferenceStatus($row['show_reference_estate'] ?? 1);
$pListView->setShowMap($row['show_map']);

$geoFieldsAll = [
InputModelDBFactoryConfigGeoFields::FIELDNAME_COUNTRY_ACTIVE => GeoPosition::ESTATE_LIST_SEARCH_COUNTRY,
Expand Down
16 changes: 16 additions & 0 deletions plugin/EstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ public function estateIterator($modifier = EstateViewFieldModifierTypes::MODIFIE
$recordModified['vermarktungsstatus'] = $pEstateStatusLabel->getLabel($recordRaw);
}

if ($modifier === EstateViewFieldModifierTypes::MODIFIER_TYPE_MAP && $this->_pDataView instanceof DataListView) {
$recordModified['showGoogleMap'] = $this->getShowMap();
}

if ( $checkEstateIdRequestGuard && $this->_pWPOptionWrapper->getOption( 'onoffice-settings-title-and-description' ) == 0 ) {
add_action( 'wp_head', function () use ( $recordModified )
{
Expand Down Expand Up @@ -815,6 +819,18 @@ public function getVisibleFilterableFields(): array
return $result;
}

/**
* @return bool
*/
public function getShowMap(): bool
{
if ($this->_pDataView instanceof DataListView) {
return $this->_pDataView->getShowMap();
}

return false;
}

/**
*
*/
Expand Down
2 changes: 2 additions & 0 deletions plugin/Gui/AdminPageEstateListSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected function buildForms()
$pInputModelFilter = $pFormModelBuilder->createInputModelFilter();
$pInputModelRecordsPerPage = $pFormModelBuilder->createInputModelRecordsPerPage();
$pInputModelShowStatus = $pFormModelBuilder->createInputModelShowStatus();
$pInputModelShowMap = $pFormModelBuilder->createInputModelShowMap();
$pDataDetailViewHandler = new DataDetailViewHandler();
$pDataDetailView = $pDataDetailViewHandler->getDetailView();
$restrictAccessControl = $pDataDetailView->getViewRestrict();
Expand Down Expand Up @@ -157,6 +158,7 @@ protected function buildForms()
$pFormModelLayoutDesign->setLabel(__('Layout & Design', 'onoffice-for-wp-websites'));
$pFormModelLayoutDesign->addInputModel($pInputModelTemplate);
$pFormModelLayoutDesign->addInputModel($pInputModelShowStatus);
$pFormModelLayoutDesign->addInputModel($pInputModelShowMap);
$this->addFormModel($pFormModelLayoutDesign);

$pInputModelPictureTypes = $pFormModelBuilder->createInputModelPictureTypes();
Expand Down
8 changes: 7 additions & 1 deletion plugin/Installer/DatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
class DatabaseChanges implements DatabaseChangesInterface
{
/** @var int */
const MAX_VERSION = 38;
const MAX_VERSION = 39;

/** @var WPOptionWrapperBase */
private $_pWpOption;
Expand Down Expand Up @@ -278,6 +278,11 @@ public function install()
$this->_pWpOption->updateOption( 'onoffice-settings-honeypot', false );
$dbversion = 38;
}

if ( $dbversion == 38 ) {
dbDelta($this->getCreateQueryListviews());
$dbversion = 39;
}
$this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true );
}

Expand Down Expand Up @@ -368,6 +373,7 @@ private function getCreateQueryListviews()
`sortByUserDefinedDirection` ENUM('0','1') NOT NULL DEFAULT '0' COMMENT 'Formulierung der Sortierrichtung: 0 means highestFirst/lowestFirt, 1 means descending/ascending',
`show_reference_estate` tinyint(1) NOT NULL DEFAULT '0',
`page_shortcode` tinytext NOT NULL,
`show_map` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`listview_id`),
UNIQUE KEY `name` (`name`)
) $charsetCollate;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,4 +750,23 @@ public function getInputModelCustomLabelLanguageSwitch(): InputModelDB
});
return $pInputModel;
}

/**
*
* @return InputModelDB
*
*/

public function createInputModelShowMap()
{
$labelShowMap = __('Show estate map', 'onoffice-for-wp-websites');

$pInputModelShowMap = $this->getInputModelDBFactory()->create
(InputModelDBFactory::INPUT_SHOW_MAP, $labelShowMap);
$pInputModelShowMap->setHtmlType(InputModelOption::HTML_TYPE_CHECKBOX);
$pInputModelShowMap->setValue($this->getValue('show_map') ?? true);
$pInputModelShowMap->setValuesAvailable(1);

return $pInputModelShowMap;
}
}
2 changes: 2 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class InputModelDBFactory
/** */
const INPUT_FIELD_CONFIG = 'fieldConfig';

/** */
const INPUT_SHOW_MAP = 'showMap';

/** @var InputModelDBFactoryConfigBase */
private $_pInputModelDBFactoryConfig = null;
Expand Down
5 changes: 5 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactoryConfigEstate.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ class InputModelDBFactoryConfigEstate
self::KEY_TABLE => 'oo_plugin_listviews',
self::KEY_FIELD => 'sortByUserDefinedDirection',
],

InputModelDBFactory::INPUT_SHOW_MAP => [
self::KEY_TABLE => 'oo_plugin_listviews',
self::KEY_FIELD => 'show_map',
],
];


Expand Down
4 changes: 3 additions & 1 deletion tests/TestClassDataListViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class TestClassDataListViewFactory
'sortByUserDefinedDirection' => 1,
'sortbyuservalues' => ['kaufpreis,anzahl_zimmer'],
'radius' => '200',
'show_reference_estate' => '1'
'show_reference_estate' => '1',
'show_map' => '1'
];

/**
Expand Down Expand Up @@ -106,6 +107,7 @@ public function testCreateListViewByRow()
$this->assertEquals($this->_baseRow['sortByUserDefinedDirection'], $pDataListView->getSortByUserDefinedDirection());
$this->assertEquals($this->_baseRow['sortbyuservalues'], $pDataListView->getSortByUserValues());
$this->assertEquals($this->_baseRow['show_reference_estate'], $pDataListView->getShowReferenceEstate());
$this->assertEquals($this->_baseRow['show_map'], $pDataListView->getShowMap());
$pDataListView->getFilterableFields();
}
}
4 changes: 2 additions & 2 deletions tests/TestClassDatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function testInstall(): array
$this->assertGreaterThanOrEqual(self::NUM_NEW_TABLES, count($this->_createQueries));

$dbversion = $this->_pDbChanges->getDbVersion();
$this->assertEquals(38, $dbversion);
$this->assertEquals(39, $dbversion);
return $this->_createQueries;
}

Expand Down Expand Up @@ -241,7 +241,7 @@ public function testDeleteMessageFieldApplicantSearchForm()
*/
public function testMaxVersion()
{
$this->assertEquals(38, DatabaseChanges::MAX_VERSION);
$this->assertEquals(39, DatabaseChanges::MAX_VERSION);
}


Expand Down
19 changes: 19 additions & 0 deletions tests/TestClassFormModelBuilderDBEstateListSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,4 +657,23 @@ public function testCallbackValueInputModelAvailableOptions()
$this->assertFalse($pInputModelBase->getValue());
$this->assertEquals($key, $pInputModelBase->getValuesAvailable());
}

/**
* @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBEstateListSettings::createInputModelShowMap
*/
public function testCreateInputModelShowMap()
{
$pInstance = $this->getMockBuilder(FormModelBuilderDBEstateListSettings::class)
->disableOriginalConstructor()
->setMethods(['getInputModelDBFactory', 'getValue', 'getOnlyDefaultSortByFields'])
->getMock();

$pInstance->method('getInputModelDBFactory')->willReturn($this->_pInputModelFactoryDBEntry);
$pInstance->method('getValue')->willReturn('1');

$pInputModelDB = $pInstance->createInputModelShowMap();
$this->assertInstanceOf(InputModelDB::class, $pInputModelDB);
$this->assertEquals($pInputModelDB->getValue(), '1');
$this->assertEquals('checkbox', $pInputModelDB->getHtmlType());
}
}

0 comments on commit 9354ea3

Please sign in to comment.