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#48327(Task) Make contact selectable #88

Merged
merged 27 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2e30a45
make contact type selectable for form
kellyfa12 Jun 18, 2021
d425827
update unit test
kellyfa12 Jun 21, 2021
18760bf
update format code
kellyfa12 Jun 22, 2021
02c574f
update format code
kellyfa12 Jun 22, 2021
1157b14
update format code
kellyfa12 Jun 22, 2021
bb774ab
Merge branch 'master' of github.com:onOfficeGmbH/oo-wp-plugin into 13…
kellyfa12 Jul 23, 2021
bc29621
update fix conflict
kellyfa12 Jul 23, 2021
c7d99af
Merge branch 'master' of github.com:onOfficeGmbH/oo-wp-plugin into 13…
kellyfa12 Jul 29, 2021
7d4bd56
update unit test
kellyfa12 Jul 29, 2021
69dd045
update unit test
kellyfa12 Jul 30, 2021
f765224
update query alter table
hungnc89 Oct 27, 2021
a69808c
Merge branch 'master' of github.com:onOfficeGmbH/oo-wp-plugin into 13…
hungnc89 Oct 27, 2021
6f3d929
update query alter table
hungnc89 Oct 27, 2021
914307e
update query insert ignore
hungnc89 Oct 27, 2021
1ce37b0
update esc query
hungnc89 Oct 27, 2021
8fbf2b6
update label contact type
hungnc89 Nov 1, 2021
88bd1cd
remove debug
hungnc89 Nov 3, 2021
fc32cdd
Merge branch 'master' of github-egs:onOfficeGmbH/oo-wp-plugin into 13…
kellyfa12 Nov 17, 2021
6927d66
update test
kellyfa12 Nov 17, 2021
32369c1
fix migration and conflict
kellyfa12 Dec 8, 2021
86c90f9
Merge branch 'master' of github-egs.com:onOfficeGmbH/oo-wp-plugin int…
kellyfa12 Dec 20, 2021
272acc3
Merge branch 'master' of github-egs.com:onOfficeGmbH/oo-wp-plugin int…
kellyfa12 Jan 5, 2022
3ee3c3c
update unit test
kellyfa12 Jan 10, 2022
8d09228
Merge branch 'master' of github-egs.com:onOfficeGmbH/oo-wp-plugin int…
kellyfa12 Jan 10, 2022
403d5e2
update fix send newsletter
kellyfa12 Feb 8, 2022
daea708
fix conflict file DatabaseChange
tang-hien-egs Mar 2, 2022
66cc6ff
change const MAX_VERSION
tang-hien-egs Mar 2, 2022
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
Binary file modified languages/onoffice-for-wp-websites-de_DE.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions languages/onoffice-for-wp-websites-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@ msgstr "Maximale Ergebnisanzahl"
msgid "Required"
msgstr "Pflichtangabe"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:345
msgid "Contact Type of New Address"
msgstr "Kontaktart der neuen Adresse"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:390
#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:404
msgid "Add language"
Expand Down
11 changes: 10 additions & 1 deletion plugin/DataFormConfiguration/DataFormConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class DataFormConfiguration
/** @var bool */
private $_showEstateContext = false;

/** @var bool */
private $_contactType = '';

/**
*
* Override to set default fields for new, empty forms
Expand Down Expand Up @@ -128,7 +131,9 @@ public function addAvailableOptionsField(string $availableOptionsField)
public function setShowEstateContext(bool $showEstateContext)
{ $this->_showEstateContext = $showEstateContext; }


/** @param string $contactTypeField */
public function setContactTypeField(string $contactTypeField)
{ $this->_contactType = $contactTypeField; }
/**
*
* @param string $input
Expand Down Expand Up @@ -182,4 +187,8 @@ public function setId(int $id)
/** @return bool */
public function getShowEstateContext(): bool
{ return $this->_showEstateContext; }

/** @return string */
public function getContactType(): string
{ return $this->_contactType; }
}
3 changes: 3 additions & 0 deletions plugin/DataFormConfiguration/DataFormConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private function configureContact(array $row, DataFormConfigurationContact $pCon
$pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']);
$pConfig->setNewsletterCheckbox((bool)$row['newsletter']);
$pConfig->setShowEstateContext((bool)$row['show_estate_context']);
$pConfig->setContactTypeField($row['contact_type'] ?? '');
}


Expand Down Expand Up @@ -319,6 +320,7 @@ private function configureOwner(array $row, DataFormConfigurationOwner $pConfig)
$pConfig->setSubject($row['subject']);
$pConfig->setPages($row['pages']);
$pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']);
$pConfig->setContactTypeField($row['contact_type'] ?? '');
}


Expand All @@ -334,6 +336,7 @@ private function configureInterest(array $row, DataFormConfigurationInterest $pC
$pConfig->setRecipient($row['recipient']);
$pConfig->setSubject($row['subject']);
$pConfig->setCheckDuplicateOnCreateAddress($row['checkduplicates']);
$pConfig->setContactTypeField($row['contact_type'] ?? '');
}


Expand Down
5 changes: 4 additions & 1 deletion plugin/Form/FormAddressCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ public function __construct(
* @throws NotFoundException
*/
public function createOrCompleteAddress(
FormData $pFormData, bool $mergeExisting = false): int
FormData $pFormData, bool $mergeExisting = false, string $contactType = ''): int
{
$requestParams = $this->getAddressDataForApiCall($pFormData);
$requestParams['checkDuplicate'] = $mergeExisting;
if (!empty($contactType)) {
$requestParams['ArtDaten'] = $contactType;
}

$pApiClientAction = new APIClientActionGeneric
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_CREATE, 'address');
Expand Down
3 changes: 2 additions & 1 deletion plugin/FormPostContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ private function createAddress(FormData $pFormData)
{
$pFormConfig = $pFormData->getDataFormConfiguration();
$checkDuplicate = $pFormConfig->getCheckDuplicateOnCreateAddress();
$contactType = $pFormConfig->getContactType();
$addressId = $this->_pFormPostContactConfiguration->getFormAddressCreator()
->createOrCompleteAddress($pFormData, $checkDuplicate);
->createOrCompleteAddress($pFormData, $checkDuplicate, $contactType);

if (!$this->_pFormPostContactConfiguration->getNewsletterAccepted()) {
// No subscription for newsletter, which is ok
Expand Down
4 changes: 2 additions & 2 deletions plugin/FormPostInterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
$recipient = $pFormConfiguration->getRecipient();
$subject = $pFormConfiguration->getSubject();
$checkduplicate = $pFormConfiguration->getCheckDuplicateOnCreateAddress();

$contactType = $pFormConfiguration->getContactType();
$addressId = $this->_pFormPostInterestConfiguration->getFormAddressCreator()
->createOrCompleteAddress($pFormData, $checkduplicate);
->createOrCompleteAddress($pFormData, $checkduplicate, $contactType);
$this->createSearchcriteria($pFormData, $addressId);

if ($recipient != null) {
Expand Down
3 changes: 2 additions & 1 deletion plugin/FormPostOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
$recipient = $pDataFormConfiguration->getRecipient();
$subject = $pDataFormConfiguration->getSubject();
$checkduplicate = $pDataFormConfiguration->getCheckDuplicateOnCreateAddress();
$contactType = $pDataFormConfiguration->getContactType();

$addressId = $this->_pFormPostOwnerConfiguration->getFormAddressCreator()
->createOrCompleteAddress($pFormData, $checkduplicate);
->createOrCompleteAddress($pFormData, $checkduplicate, $contactType);
$estateData = $this->getEstateData();
$estateId = $this->createEstate($estateData);
$this->createOwnerRelation($estateId, $addressId);
Expand Down
12 changes: 12 additions & 0 deletions plugin/Gui/AdminPageFormSettingsContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class AdminPageFormSettingsContact
/** @var bool */
private $_showEstateContextCheckbox = false;

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


/**
*
Expand Down Expand Up @@ -112,6 +115,11 @@ protected function buildForms()
$pFormModelFormSpecific->addInputModel($pInputModel);
}

if ($this->_showContactTypeSelect) {
$pInputModelContactType = $pFormModelBuilder->createInputModelContactType();
$pFormModelFormSpecific->addInputModel($pInputModelContactType);
}

if ($this->_showNewsletterCheckbox) {
$pInputModel = $pInputModelBuilder->build(InputModelDBFactoryConfigForm::INPUT_FORM_NEWSLETTER);
$pFormModelFormSpecific->addInputModel($pInputModel);
Expand Down Expand Up @@ -238,4 +246,8 @@ public function setShowGeoPositionSettings(bool $showGeoPositionSettings)
/** @param bool $showEstateContextCheckbox */
public function setShowEstateContextCheckbox(bool $showEstateContextCheckbox)
{ $this->_showEstateContextCheckbox = $showEstateContextCheckbox; }

/** @param bool $showContactTypeSelect */
public function setShowContactTypeSelect(bool $showContactTypeSelect)
{ $this->_showContactTypeSelect = $showContactTypeSelect; }
}
3 changes: 3 additions & 0 deletions plugin/Gui/AdminPageFormSettingsMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin
$pAdminPage->setShowAddressFields(true);
$pAdminPage->setShowCheckDuplicates(true); // address will be created anyway
$pAdminPage->setShowGeoPositionSettings(true);
$pAdminPage->setShowContactTypeSelect(true);
break;
case Form::TYPE_OWNER:
/* @var $pAdminPage AdminPageFormSettingsInquiry */
$pAdminPage->setShowEstateFields(true);
$pAdminPage->setShowAddressFields(true);
$pAdminPage->setShowCheckDuplicates(true); // address will be created anyway
$pAdminPage->setShowMessageInput(true);
$pAdminPage->setShowContactTypeSelect(true);
break;
case Form::TYPE_CONTACT:
/* @var $pAdminPage AdminPageFormSettingsContact */
Expand All @@ -136,6 +138,7 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin
$pAdminPage->setShowMessageInput(true);
$pAdminPage->setShowNewsletterCheckbox(true);
$pAdminPage->setShowEstateContextCheckbox(true);
$pAdminPage->setShowContactTypeSelect(true);
break;
case Form::TYPE_APPLICANT_SEARCH:
/* @var $pAdminPage AdminPageFormSettingsApplicantSearch */
Expand Down
53 changes: 39 additions & 14 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 = 20;
const MAX_VERSION = 21;

/** @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 All @@ -159,6 +159,11 @@ public function install()
$dbversion = 20;
}

if ($dbversion == 20) {
dbDelta($this->getQueryAddColumnContactTypePluginFormTable());
$dbversion = 21;
}

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

Expand Down Expand Up @@ -291,19 +296,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 @@ -684,6 +698,17 @@ private function deleteCommentFieldApplicantSearchForm()
}
}

public function getQueryAddColumnContactTypePluginFormTable() :string
{
$prefix = $this->getPrefix();
$charsetCollate = $this->getCharsetCollate();
$tableName = $prefix . "oo_plugin_forms";

return "CREATE TABLE $tableName (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unstable.
The best way to add a column to the table would be to add it to the CREATE TABLE definition in the method getCreateQueryForms.

Then change this block if ($dbversion == 20) { to

if ($dbversion == 20) {
	dbDelta($this->getCreateQueryForms());
	$dbversion = 21;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new column literally needs to be added in the method getCreateQueryForms.

`contact_type` varchar(255) NULL DEFAULT NULL
) $charsetCollate;";
}


/**
*
Expand Down
43 changes: 43 additions & 0 deletions plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
use DI\DependencyException;
use DI\NotFoundException;
use Exception;
use onOffice\SDK\onOfficeSDK;
use onOffice\WPlugin\API\APIClientCredentialsException;
use onOffice\WPlugin\DataFormConfiguration\DataFormConfiguration;
use onOffice\WPlugin\DataFormConfiguration\DataFormConfigurationFactory;
use onOffice\WPlugin\Field\Collection\FieldLoaderGeneric;
use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilder;
use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderShort;
use onOffice\WPlugin\Model\FormModel;
use onOffice\WPlugin\Model\InputModel\InputModelDBFactory;
Expand Down Expand Up @@ -334,6 +338,45 @@ public function createInputModelResultLimit()
return $pInputModelFormLimitResult;
}

/**
* @return InputModelDB
*/
public function createInputModelContactType()
{
$labelContactType = __('Contact Type of New Address', 'onoffice-for-wp-websites');
$pInputModelFormContactType = $this->getInputModelDBFactory()->create
(InputModelDBFactoryConfigForm::INPUT_FORM_CONTACT_TYPE, $labelContactType);
$field = $pInputModelFormContactType->getField();
$pInputModelFormContactType->setHtmlType(InputModelOption::HTML_TYPE_SELECT);
$availableContactType = array('' => 'No contact type') + $this->getDataContactType(onOfficeSDK::MODULE_ADDRESS);
$pInputModelFormContactType->setValuesAvailable($availableContactType);
$selectedValue = $this->getValue($field);
$pInputModelFormContactType->setValue($selectedValue);

return $pInputModelFormContactType;
}

public function getDataContactType($module)
{
try {
$pFieldLoader = $this->_pContainer->get(FieldLoaderGeneric::class);
$pFieldCollectionAddressEstate = $this->_pContainer->get(FieldsCollectionBuilder::class)
->buildFieldsCollection($pFieldLoader);
$fields = $pFieldCollectionAddressEstate->getFieldsByModule($module);
$result = [];
if (!empty($fields['ArtDaten']->getPermittedvalues())) {
foreach ($fields['ArtDaten']->getPermittedvalues() as $field => $type) {
$result[$field] = !empty($type) ? $type: $field;
}
}

return $result;
} catch (APIClientCredentialsException $pCredentialsException) {
return [];
}

}

/**
* @return InputModelDB
*/
Expand Down
7 changes: 7 additions & 0 deletions plugin/Model/InputModel/InputModelDBFactoryConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class InputModelDBFactoryConfigForm
/** */
const INPUT_FORM_ESTATE_CONTEXT_AS_HEADING = 'show_estate_context';

/** */
const INPUT_FORM_CONTACT_TYPE = 'contactType';


/** @var array */
private $_inputConfig = [
Expand Down Expand Up @@ -131,6 +134,10 @@ class InputModelDBFactoryConfigForm
self::KEY_TABLE => 'oo_plugin_forms',
self::KEY_FIELD => 'show_estate_context',
],
self::INPUT_FORM_CONTACT_TYPE => [
self::KEY_TABLE => 'oo_plugin_forms',
self::KEY_FIELD => 'contact_type',
],

InputModelDBFactory::INPUT_FIELD_CONFIG => [
self::KEY_TABLE => 'oo_plugin_form_fieldconfig',
Expand Down
4 changes: 4 additions & 0 deletions tests/TestClassDataFormConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ private function getBasicFieldsArray(int $formId, string $formType): array
'individual_fieldname' => '0',
'availableOptions' => '0',
'required' => '1',
'contact_type' => '',
],
[
'form_fieldconfig_id' => '2',
Expand All @@ -373,6 +374,7 @@ private function getBasicFieldsArray(int $formId, string $formType): array
'individual_fieldname' => '0',
'availableOptions' => '0',
'required' => '1',
'contact_type' => '',
],
[
'form_fieldconfig_id' => '3',
Expand All @@ -384,6 +386,7 @@ private function getBasicFieldsArray(int $formId, string $formType): array
'individual_fieldname' => '0',
'availableOptions' => '1',
'required' => '0',
'contact_type' => '',
],
];

Expand Down Expand Up @@ -436,6 +439,7 @@ private function getBaseRow(int $formId, string $formType): array
'newsletter' => '1',
'availableOptions' => '1',
'show_estate_context' => '0',
'contact_type' => '',
];
}
}
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(20, $dbversion);
$this->assertEquals(21, $dbversion);
return $this->_createQueries;
}

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


Expand Down
2 changes: 1 addition & 1 deletion tests/TestClassFormAddressCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function addCreateAddressResponseToSKDWrapper(array $response)
$this->_pSDKWrapper->addResponseByParameters(onOfficeSDK::ACTION_ID_CREATE, 'address', '', [
'testaddressfield1varchar' => 'testValue',
'testaddressfield1multiselect' => ['hut','tut'],
'checkDuplicate' => false
'checkDuplicate' => false,
], null, $response);
}
}
Loading