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

P#50179 Show or hide reference estate in estate lis #158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions js/onoffice-reference-estate-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
jQuery(document).ready(function() {
const valueSelect = 'reference';
const mainElement = document.querySelector('select[name=oopluginlistviews-listtype');
const Element = document.querySelector('input[name=oopluginlistviews-showreferenceestate');
mainElement.addEventListener('change',function(event){
let val = event.target.value;
if (val === valueSelect) {
Element.setAttribute('disabled', 'disabled');
Element.checked = true;
} else {
Element.removeAttribute('disabled');
Element.checked = false;
}
});
});
19 changes: 19 additions & 0 deletions plugin/DataView/DataListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class DataListView
/** @var bool */
private $_adjustableSorting = false;

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


/**
*
Expand Down Expand Up @@ -333,4 +336,20 @@ public function isAdjustableSorting(): bool
{
return $this->_adjustableSorting;
}

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

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

$geoFieldsAll = [
InputModelDBFactoryConfigGeoFields::FIELDNAME_COUNTRY_ACTIVE => GeoPosition::ESTATE_LIST_SEARCH_COUNTRY,
Expand Down
13 changes: 13 additions & 0 deletions plugin/EstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ private function getEstateParameters(int $currentPage, bool $formatOutput)
];
}

if (!$this->getShowReferenceStatus()) {
$requestParams['filter']['referenz'][] = ['op' => '=', 'val' => 0];
}

$requestParams += $this->addExtraParams();

return $requestParams;
Expand Down Expand Up @@ -664,6 +668,15 @@ public function getShowEstateMarketingStatus(): bool
$this->_pDataView->getShowStatus();
}

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

/**
* @return array
*/
Expand Down
4 changes: 4 additions & 0 deletions plugin/Gui/AdminPageEstateListSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected function buildForms()
$pInputModelSortOrder = $pFormModelBuilder->createInputModelSortOrder();
$pInputModelListType = $pFormModelBuilder->createInputModelListType();
$pInputModelShowStatus = $pFormModelBuilder->createInputModelShowStatus();
$pInputModelShowReferenceEstate = $pFormModelBuilder->createInputModelShowReferenceEstate();
$pInputModelRandomSort = $pFormModelBuilder->createInputModelRandomSort();

$pInputModelSortBySetting = $pFormModelBuilder->createInputModelSortBySetting();
Expand All @@ -115,6 +116,8 @@ protected function buildForms()
$pFormModelRecordsFilter->addInputModel($pInputModelRandomSort);

$pFormModelRecordsFilter->addInputModel($pInputModelListType);
$pFormModelRecordsFilter->addInputModel($pInputModelShowStatus);
$pFormModelRecordsFilter->addInputModel($pInputModelShowReferenceEstate);
$this->addFormModel($pFormModelRecordsFilter);

$pInputModelTemplate = $pFormModelBuilder->createInputModelTemplate('estate');
Expand Down Expand Up @@ -262,6 +265,7 @@ public function doExtraEnqueues()
{
parent::doExtraEnqueues();
wp_enqueue_script('oo-checkbox-js');
wp_enqueue_script('oo-reference-estate-js');
wp_localize_script('oo-sanitize-shortcode-name', 'shortcode', ['name' => 'oopluginlistviews-name']);
wp_enqueue_script('oo-sanitize-shortcode-name');
}
Expand Down
3 changes: 3 additions & 0 deletions plugin/Gui/AdminPageSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ public function doExtraEnqueues()
wp_register_script('admin-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'/js/admin.js',
['jquery'], '', true);

wp_register_script('oo-reference-estate-js',
plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'/js/onoffice-reference-estate-select.js', ['jquery'], '', true);

wp_register_script('oo-checkbox-js',
plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'/js/checkbox.js', ['jquery'], '', true);
wp_register_script('onoffice-default-form-values-js',
Expand Down
45 changes: 30 additions & 15 deletions plugin/Installer/DatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class DatabaseChanges implements DatabaseChangesInterface
{
/** @var int */
const MAX_VERSION = 21;
const MAX_VERSION = 22;

/** @var WPOptionWrapperBase */
private $_pWpOption;
Expand Down Expand Up @@ -132,7 +132,7 @@ public function install()
$this->updateSortByUserDefinedDefault();
$dbversion = 15;
}

if ($dbversion == 15) {
dbDelta( $this->getCreateQueryFieldConfigDefaults() );
dbDelta( $this->getCreateQueryFieldConfigDefaultsValues() );
Expand Down Expand Up @@ -164,6 +164,11 @@ public function install()
$dbversion = 21;
}

if ($dbversion == 21) {
dbDelta($this->getCreateQueryListviews());
$dbversion = 22;
}

$this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true);
}

Expand Down Expand Up @@ -234,6 +239,7 @@ private function getCreateQueryListviews()
`sortBySetting` ENUM('0','1') NOT NULL DEFAULT '0' COMMENT 'Sortierung nach Benutzerwahl: 0 means preselected, 1 means userDefined',
`sortByUserDefinedDefault` VARCHAR(200) NOT NULL COMMENT 'Standardsortierung',
`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',
PRIMARY KEY (`listview_id`),
UNIQUE KEY `name` (`name`)
) $charsetCollate;";
Expand Down Expand Up @@ -296,19 +302,28 @@ private function installDataQueryForms()
$template = $templatePathsForm;
}
}
$this->_pWPDB->insert(
$tableName,
array(
'name' => 'Default Form',
'form_type' => 'contact',
'template' => $template,
'country_active' => 1,
'zip_active' => 1,
'street_active' => 1,
'radius_active' => 1,
'geo_order' => 'street,zip,city,country,radius'
)
$data = array(
'name' => 'Default Form',
'form_type' => 'contact',
'template' => $template,
'country_active' => 1,
'zip_active' => 1,
'street_active' => 1,
'radius_active' => 1,
'geo_order' => 'street,zip,city,country,radius'
);
$query = "INSERT IGNORE $tableName (name, form_type, template, country_active, zip_active, street_active, radius_active, geo_order)";
$query .= "VALUES (";
$query .= "'" . esc_sql($data['name']) ."',";
$query .= "'" . esc_sql($data['form_type']) ."',";
$query .= "'" . esc_sql($data['template']) ."',";
$query .= esc_sql($data['country_active']) . ",";
$query .= esc_sql($data['zip_active']) . ",";
$query .= esc_sql($data['street_active']) . ",";
$query .= esc_sql($data['radius_active']) . ",";
$query .= "'" . esc_sql($data['geo_order']) ."')";
$this->_pWPDB->query($query);

$defaultFormId = $this->_pWPDB->insert_id;
$this->installDataQueryFormFieldConfig($defaultFormId);
}
Expand Down Expand Up @@ -788,4 +803,4 @@ protected function readTemplatePaths($directory, $pattern = '*')

return $templates;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,25 @@ public function createInputModelShowStatus()
return $pInputModelShowStatus;
}

/**
*
* @return InputModelDB
*
*/

public function createInputModelShowReferenceEstate()
{
$labelShowReferenceEstate = __('Show reference estates', 'onoffice-for-wp-websites');

$pInputModelShowStatus = $this->getInputModelDBFactory()->create
(InputModelDBFactory::INPUT_SHOW_REFERENCE_ESTATE, $labelShowReferenceEstate);
$pInputModelShowStatus->setHtmlType(InputModelOption::HTML_TYPE_CHECKBOX);
$pInputModelShowStatus->setValue($this->getValue('show_reference_estate') ?? 1);
$pInputModelShowStatus->setValuesAvailable(1);

return $pInputModelShowStatus;
}


/**
*
Expand Down
3 changes: 3 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class InputModelDBFactory
/** */
const INPUT_SHOW_STATUS = 'showStatus';

/** */
const INPUT_SHOW_REFERENCE_ESTATE = 'showReferenceEstate';

/** */
const INPUT_RANDOM_ORDER = 'randomOrder';

Expand Down
4 changes: 4 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactoryConfigEstate.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class InputModelDBFactoryConfigEstate
self::KEY_TABLE => 'oo_plugin_listviews',
self::KEY_FIELD => 'show_status',
],
InputModelDBFactory::INPUT_SHOW_REFERENCE_ESTATE => [
self::KEY_TABLE => 'oo_plugin_listviews',
self::KEY_FIELD => 'show_reference_estate',
],
InputModelDBFactory::INPUT_EXPOSE => [
self::KEY_TABLE => 'oo_plugin_listviews',
self::KEY_FIELD => 'expose',
Expand Down
12 changes: 12 additions & 0 deletions tests/TestClassDataListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,16 @@ public function testAdjustableSorting()
$this->_pSubject->setAdjustableSorting(true);
$this->assertTrue($this->_pSubject->isAdjustableSorting());
}


/**
*
*/

public function testShowReferenceStatus()
{
$this->assertFalse($this->_pSubject->getShowReferenceStatus());
$this->_pSubject->setShowReferenceStatus(true);
$this->assertTrue($this->_pSubject->getShowReferenceStatus());
}
}
2 changes: 2 additions & 0 deletions tests/TestClassDataListViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TestClassDataListViewFactory
'sortByUserDefinedDirection' => 1,
'sortbyuservalues' => ['kaufpreis,anzahl_zimmer'],
'radius' => '200',
'show_reference_estate' => 1
];

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

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

Expand Down Expand Up @@ -191,7 +191,7 @@ public function testDeleteCommentFieldApplicantSearchForm()
*/
public function testMaxVersion()
{
$this->assertEquals(21, DatabaseChanges::MAX_VERSION);
$this->assertEquals(22, DatabaseChanges::MAX_VERSION);
}


Expand Down
16 changes: 16 additions & 0 deletions tests/TestClassEstateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,21 @@ public function testGeoSearchBuilder()
$this->assertInstanceOf(GeoSearchBuilderFromInputVars::class, $this->_pEstateList->getGeoSearchBuilder());
}

/**
*
*/
public function testShowReferenceStatus()
{
$EstateListMock = $this->getMockBuilder(EstateList::class)
->disableOriginalConstructor()
->setMethods(['getShowReferenceStatus'])
->getMock();
$EstateListMock->method('getShowReferenceStatus')->willReturn(false);
$this->_pEstateList->loadEstates();
$result = $this->_pEstateList->estateIterator();
$this->assertEquals('', $result['vermarktungsstatus']);
}


/**
*
Expand Down Expand Up @@ -771,6 +786,7 @@ private function getDataView(): DataListView
$pDataView->setPictureTypes(['Titelbild', 'Foto']);
$pDataView->setAddressFields(['Vorname', 'Name']);
$pDataView->setShowStatus(true);
$pDataView->setShowReferenceStatus(false);
$pDataView->setFilterableFields([GeoPosition::FIELD_GEO_POSITION]);
$pDataView->setExpose('testExpose');
return $pDataView;
Expand Down
21 changes: 20 additions & 1 deletion tests/TestClassFormModelBuilderDBEstateListSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,23 @@ public function testCreateSortableFieldList()
$instance = $pInstance->createSortableFieldList('address', 'checkbox', false);
$this->assertEquals($instance->getReferencedInputModels(), null);
}
}

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

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

$pInputModelDB = $pInstance->createInputModelShowReferenceEstate();
$this->assertInstanceOf(InputModelDB::class, $pInputModelDB);
$this->assertEquals($pInputModelDB->getValue(), '0');
$this->assertEquals('checkbox', $pInputModelDB->getHtmlType());
}
}
8 changes: 7 additions & 1 deletion tests/resources/ApiResponseReadEstatesPublishedENG.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"op": "=",
"val": 1
}
],
"referenz": [
{
"op": "=",
"val": 0
}
]
},
"estatelanguage": "ENG",
Expand Down Expand Up @@ -214,4 +220,4 @@
"message": "OK"
}
}
}
}
8 changes: 7 additions & 1 deletion tests/resources/ApiResponseReadEstatesPublishedENGRaw.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"op": "=",
"val": 1
}
],
"referenz": [
{
"op": "=",
"val": 0
}
]
},
"estatelanguage": "ENG",
Expand Down Expand Up @@ -228,4 +234,4 @@
"message": "OK"
}
}
}
}