Skip to content

Commit

Permalink
48659 merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-eastgate committed Oct 22, 2024
2 parents 021f908 + 7ed2565 commit 9b735b0
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public function buildParameters(array $fields, DataViewAddress $pDataListView, i
$parameters['data'] []= 'imageUrl';
}

if ($pDataListView->getBildWebseite()) {
$parameters['data'] []= 'bildWebseite';
}

return $parameters;
}
}
21 changes: 16 additions & 5 deletions plugin/AddressDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use onOffice\WPlugin\DataView\DataAddressDetailView;
use onOffice\WPlugin\DataView\DataViewAddress;
use onOffice\WPlugin\Types\ImageTypes;

class AddressDetail
extends AddressList {
Expand Down Expand Up @@ -52,11 +53,21 @@ protected function getNumAddressPages()
public function loadSingleAddress($id)
{
$this->_addressId = $id;
$fields = $this->getDataViewAddress()->getFields();
if($this->getDataViewAddress() instanceof DataAddressDetailView &&
$this->getDataViewAddress()->getPictureTypes() != [] && $this->getDataViewAddress()->getPictureTypes() != null)
array_push($fields, "imageUrl");
$this->loadAddressesById([$id], $fields);
$fields = $this->getDataViewAddress()->getFields();

if ($this->getDataViewAddress() instanceof DataAddressDetailView) {
$pictureTypes = $this->getDataViewAddress()->getPictureTypes();

if (in_array(ImageTypes::PASSPORTPHOTO, $pictureTypes)) {
array_push($fields, "imageUrl");
}

if (in_array(ImageTypes::BILDWEBSEITE, $pictureTypes)) {
array_push($fields, ImageTypes::BILDWEBSEITE);
}
}

$this->loadAddressesById([$id], $fields);
}


Expand Down
10 changes: 10 additions & 0 deletions plugin/AddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ private function generateRecordModifier(): ViewFieldModifierHandler
$fields []= 'imageUrl';
}

if ($this->getDataViewAddress() instanceof DataListViewAddress && $this->_pDataViewAddress->getBildWebseite()) {
$fields []= 'bildWebseite';
}

// only active fields
$fields = array_intersect($fields,
array_keys($this->_pEnvironment->getFieldnames()->getFieldList(onOfficeSDK::MODULE_ADDRESS)));
Expand Down Expand Up @@ -388,6 +392,12 @@ public function getRows(bool $raw = false): array
$pAddressFieldModifier = $this->generateRecordModifier();
return array_map(function($values) use ($pAddressFieldModifier, $raw): ArrayContainer {
$valuesNew = $pAddressFieldModifier->processRecord($values);

if (!empty($valuesNew['bildWebseite'])) {
$valuesNew['imageUrl'] = $valuesNew['bildWebseite'];
unset($valuesNew['bildWebseite']);
}

return $this->getArrayContainerByRow($raw, $valuesNew);
}, $this->_addressesById);
}
Expand Down
6 changes: 5 additions & 1 deletion plugin/DataView/DataAddressDetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace onOffice\WPlugin\DataView;

use onOffice\WPlugin\Types\ImageTypes;

/**
*
* @url http://www.onoffice.de
Expand Down Expand Up @@ -57,7 +59,9 @@ class DataAddressDetailView
];

/** @var string[] */
private $_pictureTypes = [];
private $_pictureTypes = [
ImageTypes::PASSPORTPHOTO
];

/** @var string */
private $_template = '';
Expand Down
11 changes: 11 additions & 0 deletions plugin/DataView/DataListViewAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class DataListViewAddress
/** @var string[] */
private $_convertInputTextToSelectForField = [];

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

/**
*
* @param int $id
Expand Down Expand Up @@ -184,4 +187,12 @@ public function getConvertInputTextToSelectForField(): array
/** @param array $convertInputTextToSelectForField */
public function setConvertInputTextToSelectForField(array $convertInputTextToSelectForField)
{ $this->_convertInputTextToSelectForField = $convertInputTextToSelectForField; }

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

/** @param bool $bildWebseite */
public function setBildWebseite(bool $bildWebseite)
{ $this->_bildWebseite = $bildWebseite; }
}
1 change: 1 addition & 0 deletions plugin/DataView/DataListViewFactoryAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function createListViewByRow(array $row): DataViewFilterableFields
$pDataListViewAddress->setFilterableFields($row['filterable']);
$pDataListViewAddress->setHiddenFields($row['hidden']);
$pDataListViewAddress->setConvertInputTextToSelectForField($row['convertInputTextToSelectForField']);
$pDataListViewAddress->setBildWebseite((bool)$row['bildWebseite']);

return $pDataListViewAddress;
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/Gui/AdminPageAddressListSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ private function addFormModelRecordsSorting() {
private function addFormModelPictureTypes()
{
$pInputModelPictureTypes = $this->_pFormModelBuilderAddress->createInputModelPictureTypes();
$pInputModelBildWebseite = $this->_pFormModelBuilderAddress->createInputModelBildWebseite();
$pFormModelPictureTypes = new FormModel();
$pFormModelPictureTypes->setPageSlug($this->getPageSlug());
$pFormModelPictureTypes->setGroupSlug(self::FORM_VIEW_PICTURE_TYPES);
$pFormModelPictureTypes->setLabel(__('Photo Types', 'onoffice-for-wp-websites'));
$pFormModelPictureTypes->addInputModel($pInputModelPictureTypes);
$pFormModelPictureTypes->addInputModel($pInputModelBildWebseite);
$this->addFormModel($pFormModelPictureTypes);
}

Expand Down
13 changes: 9 additions & 4 deletions plugin/Installer/DatabaseChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
class DatabaseChanges implements DatabaseChangesInterface
{
/** @var int */
const MAX_VERSION = 52;
const MAX_VERSION = 53;

/** @var WPOptionWrapperBase */
private $_pWpOption;
Expand Down Expand Up @@ -334,7 +334,7 @@ public function install()
dbDelta($this->getCreateQueryAddressFieldConfig());
$dbversion = 49;
}

if ($dbversion == 49) {
dbDelta($this->getCreateQueryFieldConfigAddressCustomsLabels());
dbDelta($this->getCreateQueryFieldConfigAddressTranslatedLabels());
Expand All @@ -347,10 +347,14 @@ public function install()
}

if ($dbversion == 51) {
dbDelta($this->getCreateQueryFormTaskConfig());
dbDelta($this->getCreateQueryListViewsAddress());
$dbversion = 52;
}


if ($dbversion == 52) {
dbDelta($this->getCreateQueryFormTaskConfig());
$dbversion = 53;
}

$this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true );
}
Expand Down Expand Up @@ -704,6 +708,7 @@ private function getCreateQueryListViewsAddress()
`template` tinytext NOT NULL,
`recordsPerPage` int(10) NOT NULL DEFAULT '10',
`showPhoto` tinyint(1) NOT NULL DEFAULT '0',
`bildWebseite` tinyint(1) NOT NULL DEFAULT '0',
`page_shortcode` tinytext NOT NULL,
PRIMARY KEY (`listview_address_id`),
UNIQUE KEY `name` (`name`)
Expand Down
20 changes: 20 additions & 0 deletions plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function generate(string $pageSlug, $listViewId = null): FormModel
$this->setValues([
DataListViewAddress::FIELDS => self::$_defaultFields,
'recordsPerPage' => self::DEFAULT_RECORDS_PER_PAGE,
'showPhoto' => true
]);
if ($listViewId !== null)
{
Expand Down Expand Up @@ -400,6 +401,25 @@ public function callbackValueInputModelConvertInputTextToSelectForField(InputMod
$pInputModel->setValuesAvailable($key);
}

/**
*
* @return InputModelDB
*
*/

public function createInputModelBildWebseite()
{
$labelPhoto = __('Image website', 'onoffice-for-wp-websites');
$pInputModelBildWebseite = $this->getInputModelDBFactory()->create
(InputModelDBFactory::INPUT_BILD_WEBSEITE, $labelPhoto);
$pInputModelBildWebseite->setHtmlType(InputModelBase::HTML_TYPE_CHECKBOX);
$pInputModelBildWebseite->setValuesAvailable(1);
$pictureTypeSelected = $this->getValue($pInputModelBildWebseite->getField());
$pInputModelBildWebseite->setValue((int)$pictureTypeSelected);

return $pInputModelBildWebseite;
}

/**
* @param FieldsCollection $pFieldsCollection
* @return InputModelDB
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 @@ -51,6 +51,9 @@ class InputModelDBFactory
/** */
const INPUT_PICTURE_TYPE = 'pictureType';

/** */
const INPUT_BILD_WEBSEITE = 'bildWebseite';

/** */
const INPUT_TEMPLATE = 'template';

Expand Down
4 changes: 4 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactoryConfigAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class InputModelDBFactoryConfigAddress
self::KEY_TABLE => 'oo_plugin_address_fieldconfig',
self::KEY_FIELD => 'convertInputTextToSelectForField',
],
InputModelDBFactory::INPUT_BILD_WEBSEITE => [
self::KEY_TABLE => 'oo_plugin_listviews_address',
self::KEY_FIELD => 'bildWebseite',
],
];


Expand Down
6 changes: 3 additions & 3 deletions plugin/Types/ImageTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ImageTypes
const LOCATION_MAP = 'Lageplan';
const ENERGY_PASS_RANGE = 'Epass_Skala';
const PASSPORTPHOTO = 'PassportPhoto';
const USERPHOTO = 'UserPhoto';
const BILDWEBSEITE = 'bildWebseite';

const IMAGE_TYPES = [
self::TITLE,
Expand Down Expand Up @@ -76,8 +76,8 @@ public static function getAllImageTypesTranslated(): array
public static function getImageTypesForAddress(): array
{
return [
self::USERPHOTO => __('User Photo', 'onoffice-for-wp-websites'),
self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites')
self::PASSPORTPHOTO => __('Passport Photo', 'onoffice-for-wp-websites'),
self::BILDWEBSEITE => __('Image website', 'onoffice-for-wp-websites')
];
}
}
3 changes: 3 additions & 0 deletions tests/TestClassAddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ public function prepare()
$pSDKWrapper->addResponseByParameters
(onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithoutFormat, null, $response);
$addressParametersWithoutFormat['data'][] = 'imageUrl';
$addressParametersWithoutFormat['data'][] = 'bildWebseite';
$pSDKWrapper->addResponseByParameters
(onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithoutFormat, null, $response);
$pSDKWrapper->addResponseByParameters
(onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithFormat, null, $responseRaw);
$addressParametersWithFormat['data'][] = 'imageUrl';
$addressParametersWithFormat['data'][] = 'bildWebseite';
$pSDKWrapper->addResponseByParameters
(onOfficeSDK::ACTION_ID_READ, 'address', '', $addressParametersWithFormat, null, $responseRaw);
$pSDKWrapper->addResponseByParameters
Expand Down Expand Up @@ -310,6 +312,7 @@ public function testLoadAddresses()
{
$pAddressView = new DataListViewAddress(3, 'testView');
$pAddressView->setShowPhoto(true);
$pAddressView->setBildWebseite(true);

$pAddressList = $this->_pAddressList->withDataListViewAddress($pAddressView);
$pAddressList->loadAddresses();
Expand Down
3 changes: 2 additions & 1 deletion tests/TestClassDataAddressDetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use onOffice\WPlugin\DataView\DataAddressDetailView;
use WP_UnitTestCase;
use onOffice\WPlugin\Types\ImageTypes;

class TestClassDataAddressDetailView
extends WP_UnitTestCase
Expand All @@ -50,7 +51,7 @@ public function testDefaultValues()
$this->assertEquals(self::DEFAULT_FIELDS, $pDataAddressDetailView->getFields());
$this->assertEquals('detail', $pDataAddressDetailView->getName());
$this->assertEquals(0, $pDataAddressDetailView->getPageId());
$this->assertEquals([], $pDataAddressDetailView->getPictureTypes());
$this->assertEquals([ImageTypes::PASSPORTPHOTO], $pDataAddressDetailView->getPictureTypes());
$this->assertEquals('', $pDataAddressDetailView->getTemplate());
$this->assertEquals([], $pDataAddressDetailView->getPageIdsHaveDetailShortCode());
$this->assertEquals([], $pDataAddressDetailView->getCustomLabels());
Expand Down
2 changes: 2 additions & 0 deletions tests/TestClassDataListViewFactoryAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testCreateListViewByRow()
$this->assertEquals($row['filterable'], $pDataListViewAddress->getFilterableFields());
$this->assertEquals($row['hidden'], $pDataListViewAddress->getHiddenFields());
$this->assertEquals($row['convertInputTextToSelectForField'], $pDataListViewAddress->getConvertInputTextToSelectForField());
$this->assertEquals($row['bildWebseite'], $pDataListViewAddress->getBildWebseite());
}


Expand All @@ -99,6 +100,7 @@ private function getTestRow(): array
'sortorder' => 'DESC',
'template' => 'testtemplate',
'convertInputTextToSelectForField' => ['Ort'],
'bildWebseite' => true,
];

return $row;
Expand Down
17 changes: 17 additions & 0 deletions tests/TestClassFormModelBuilderDBAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,23 @@ public function testGetInputModelConvertInputTextToSelectField()
$this->assertEquals([$pInstance, 'callbackValueInputModelConvertInputTextToSelectForField'], $pInputModelDB->getValueCallback());
}

/**
* @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBAddress::createInputModelBildWebseite
*/
public function testCreateInputModelBildWebseite()
{
$pInstance = $this->getMockBuilder(FormModelBuilderDBAddress::class)
->disableOriginalConstructor()
->setMethods(['getInputModelDBFactory', 'getValue'])
->getMock();
$pInstance->method('getInputModelDBFactory')->willReturn($this->_pInputModelFactoryDBEntry);
$pInstance->method('getValue')->willReturn('1');

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

/**
* @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBAddress::getInputModelCustomLabelLanguageSwitch
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/TestClassImageTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testGetAllImageTypesTranslated()
$nameConstants = $pReflection->getConstants();
unset($nameConstants['IMAGE_TYPES']);
unset($nameConstants['PASSPORTPHOTO']);
unset($nameConstants['USERPHOTO']);
unset($nameConstants['BILDWEBSEITE']);
$this->assertEqualSets($nameConstants, array_keys(ImageTypes::getAllImageTypesTranslated()));
}

Expand Down

0 comments on commit 9b735b0

Please sign in to comment.