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 25 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.
6 changes: 6 additions & 0 deletions languages/onoffice-for-wp-websites-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,12 @@ msgstr "Pflichtangabe"

#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:401
#: plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php:415
#: 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"
msgstr "Sprache hinzufügen"

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 @@ -320,6 +321,7 @@ private function configureOwner(array $row, DataFormConfigurationOwner $pConfig)
$pConfig->setPages($row['pages']);
$pConfig->setCreateOwner((bool)$row['createaddress']);
$pConfig->setCheckDuplicateOnCreateAddress((bool)$row['checkduplicates']);
$pConfig->setContactTypeField($row['contact_type'] ?? '');
}


Expand All @@ -336,6 +338,7 @@ private function configureInterest(array $row, DataFormConfigurationInterest $pC
$pConfig->setSubject($row['subject']);
$pConfig->setCreateInterest((bool)$row['createaddress']);
$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
11 changes: 8 additions & 3 deletions 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 Expand Up @@ -166,6 +167,8 @@ private function createAddress(FormData $pFormData)

private function sendContactRequest(FormData $pFormData, string $recipient = '', $subject = null)
{
$pFormConfig = $pFormData->getDataFormConfiguration();
$contactType = $pFormConfig->getContactType();
$values = $pFormData->getValues();
$pWPQuery = $this->_pFormPostContactConfiguration->getWPQueryWrapper()->getWPQuery();
$pWPWrapper = $this->_pFormPostContactConfiguration->getWPWrapper();
Expand All @@ -180,6 +183,9 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '',
'estatedata' => ["objekttitel", "ort", "plz", "land"],
'estateurl' => home_url($pWPWrapper->getRequest()),
];
if (isset($addressData['ArtDaten']) && !empty($contactType)) {
$requestParams['addressdata']['ArtDaten'] = $contactType;
}
if (isset($addressData['newsletter'])) {
$requestParams['addressdata']['newsletter_aktiv'] = $this->_pFormPostContactConfiguration
->getNewsletterAccepted();
Expand All @@ -188,7 +194,6 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '',
if ($recipient !== '') {
$requestParams['recipient'] = $recipient;
}

$pSDKWrapper = $this->_pFormPostContactConfiguration->getSDKWrapper();
$pAPIClientAction = new APIClientActionGeneric
($pSDKWrapper, onOfficeSDK::ACTION_ID_DO, 'contactaddress');
Expand All @@ -199,4 +204,4 @@ private function sendContactRequest(FormData $pFormData, string $recipient = '',
throw new ApiClientException($pAPIClientAction);
}
}
}
}
5 changes: 3 additions & 2 deletions plugin/FormPostInterest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
try {
if ( $pFormConfiguration->getCreateInterest() ) {
$checkduplicate = $pFormConfiguration->getCheckDuplicateOnCreateAddress();
$contactType = $pFormConfiguration->getContactType();
$addressId = $this->_pFormPostInterestConfiguration->getFormAddressCreator()
->createOrCompleteAddress( $pFormData,
$checkduplicate );
$checkduplicate, $contactType);
$this->createSearchcriteria( $pFormData, $addressId );
}
} finally {
Expand Down Expand Up @@ -192,4 +193,4 @@ private function createSearchcriteria(FormData $pFormData, int $addressId)
throw new ApiClientException($pApiClientAction);
}
}
}
}
5 changes: 3 additions & 2 deletions plugin/FormPostOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ protected function analyseFormContentByPrefix(FormData $pFormData)
try {
if ( $pDataFormConfiguration->getCreateOwner() ) {
$checkduplicate = $pDataFormConfiguration->getCheckDuplicateOnCreateAddress();
$contactType = $pDataFormConfiguration->getContactType();
$addressId = $this->_pFormPostOwnerConfiguration->getFormAddressCreator()
->createOrCompleteAddress( $pFormData,
$checkduplicate );
$checkduplicate, $contactType);
$estateData = $this->getEstateData();
$estateId = $this->createEstate( $estateData );
$this->createOwnerRelation( $estateId, $addressId );
Expand Down Expand Up @@ -244,4 +245,4 @@ private function sendContactRequest(string $recipient, int $estateId, array $est
throw new ApiClientException($pApiClientAction);
}
}
}
}
12 changes: 12 additions & 0 deletions plugin/Gui/AdminPageFormSettingsContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class AdminPageFormSettingsContact
/** @var bool */
private $_showEstateContextCheckbox = false;

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


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

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

if ($this->_showCheckDuplicatesInterestOwner) {
$pInputModel = $pInputModelBuilder->build(InputModelDBFactoryConfigForm::INPUT_FORM_CHECKDUPLICATES_INTEREST_OWNER);
$pFormModelFormSpecific->addInputModel($pInputModel);
Expand Down Expand Up @@ -274,6 +282,10 @@ public function setShowGeoPositionSettings(bool $showGeoPositionSettings)
public function setShowEstateContextCheckbox(bool $showEstateContextCheckbox)
{ $this->_showEstateContextCheckbox = $showEstateContextCheckbox; }

/** @param bool $showContactTypeSelect */
public function setShowContactTypeSelect(bool $showContactTypeSelect)
{ $this->_showContactTypeSelect = $showContactTypeSelect; }

/**
* @param bool $showCreateInterest
*/
Expand Down
3 changes: 3 additions & 0 deletions plugin/Gui/AdminPageFormSettingsMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin
$pAdminPage->setShowCreateInterest(true);
$pAdminPage->setShowCheckDuplicatesInterestOwner(true);
$pAdminPage->setShowGeoPositionSettings(true);
$pAdminPage->setShowContactTypeSelect(true);
break;
case Form::TYPE_OWNER:
/* @var $pAdminPage AdminPageFormSettingsInquiry */
Expand All @@ -129,6 +130,7 @@ private function configureAdminPage(AdminPageFormSettingsBase $pAdminPage, strin
$pAdminPage->setShowCreateOwner(true);
$pAdminPage->setShowCheckDuplicatesInterestOwner(true);
$pAdminPage->setShowMessageInput(true);
$pAdminPage->setShowContactTypeSelect(true);
break;
case Form::TYPE_CONTACT:
/* @var $pAdminPage AdminPageFormSettingsContact */
Expand All @@ -138,6 +140,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
46 changes: 30 additions & 16 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->getCreateQueryForms());
$dbversion = 22;
}

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

Expand Down Expand Up @@ -274,6 +279,7 @@ private function getCreateQueryForms()
`radius` INT( 10 ) NULL DEFAULT NULL,
`geo_order` VARCHAR( 255 ) NOT NULL DEFAULT 'street,zip,city,country,radius',
`show_estate_context` tinyint(1) NOT NULL DEFAULT '0',
`contact_type` varchar(255) NULL DEFAULT NULL,
PRIMARY KEY (`form_id`),
UNIQUE KEY `name` (`name`)
) $charsetCollate;";
Expand All @@ -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 @@ -689,7 +704,6 @@ private function deleteCommentFieldApplicantSearchForm()
}
}


/**
*
*/
Expand Down Expand Up @@ -788,4 +802,4 @@ protected function readTemplatePaths($directory, $pattern = '*')

return $templates;
}
}
}
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 @@ -89,6 +89,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 @@ -152,6 +155,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
Loading