From beb4dc088775de8cbfa7268275d687b4b6d6e255 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Mon, 30 Sep 2024 15:05:53 +0700 Subject: [PATCH 01/12] 53258 refactor code --- css/onoffice-address-detail.css | 3 +- plugin/AddressList.php | 39 +++++- .../FieldsCollectionBuilderShort.php | 17 +++ ...eCollectionDecoratorCustomLabelAddress.php | 127 ++++++++++++++++++ plugin/Gui/AdminPageAddressListSettings.php | 117 ++++++++++++++++ plugin/Gui/AdminPageSettingsBase.php | 6 + plugin/Installer/DatabaseChanges.php | 45 ++++++- .../FormModelBuilderDBAddress.php | 51 +++++++ plugin/Record/RecordManager.php | 6 + templates.dist/address/default_detail.php | 1 + 10 files changed, 408 insertions(+), 4 deletions(-) create mode 100644 plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php diff --git a/css/onoffice-address-detail.css b/css/onoffice-address-detail.css index 2cad9c625..6ca37ed7a 100644 --- a/css/onoffice-address-detail.css +++ b/css/onoffice-address-detail.css @@ -12,7 +12,7 @@ } .oo-address-fieldlist { display: flex; - flex-direction: column; + flex-wrap: wrap; } .oo-address-placefieldlist { display: flex; @@ -24,6 +24,7 @@ font-size: 1rem; } .oo-address-field { + width: 25%; font-size: 1rem; margin-top: 0.25rem; margin-bottom: 0.25rem; diff --git a/plugin/AddressList.php b/plugin/AddressList.php index 8ec4022d0..fe5393235 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -43,6 +43,8 @@ use onOffice\WPlugin\Utility\__String; use onOffice\WPlugin\ViewFieldModifier\ViewFieldModifierHandler; use function esc_html; +use onOffice\WPlugin\Field\UnknownFieldException; +use onOffice\WPlugin\DataView\DataAddressDetailView; /** * @@ -136,6 +138,10 @@ class AddressList /** @var array */ private $_countEstates = []; + + /** @var FieldsCollection */ + private $_pFieldsCollection = []; + /** * * @param DataViewAddress $pDataViewAddress @@ -147,6 +153,7 @@ public function __construct(DataViewAddress $pDataViewAddress = null, AddressLis { $this->_pEnvironment = $pEnvironment ?? new AddressListEnvironmentDefault(); $this->_pDataViewAddress = $pDataViewAddress ?? new DataListViewAddress(0, 'default'); + $this->buildFieldsCollectionForAddressCustomLabel(); } /** @@ -374,8 +381,22 @@ public function getDataViewAddress(): DataViewAddress */ public function getFieldLabel($field, bool $raw = false): string { - $label = $this->_pEnvironment->getFieldnames() - ->getFieldLabel($field, onOfficeSDK::MODULE_ADDRESS); + $recordType = onOfficeSDK::MODULE_ADDRESS; + $label = ''; + + try { + $label = $this->_pFieldsCollection->getFieldByModuleAndName($recordType, $field)->getLabel(); + } catch (UnknownFieldException $pE) { + $label = $this->_pEnvironment->getFieldnames()->getFieldLabel($field, $recordType); + } + if ($this->_pDataViewAddress instanceof DataAddressDetailView) { + $pLanguage = $this->_pEnvironment->getContainer()->get(Language::class)->getLocale(); + $dataView = $this->_pDataViewAddress->getCustomLabels(); + if (!empty( $dataView[ $field ][ $pLanguage ])) { + $label = $dataView[ $field ][ $pLanguage ]; + } + } + return $raw ? $label : esc_html($label); } @@ -392,6 +413,20 @@ public function getFieldType($field): string return $fieldInformation['type']; } + /** + * + */ + private function buildFieldsCollectionForAddressCustomLabel() + { + $this->_pFieldsCollection = new FieldsCollection(); + $pFieldBuilderShort = $this->_pEnvironment->getContainer()->get(FieldsCollectionBuilderShort::class); + $pFieldBuilderShort->addFieldsAddressEstate($this->_pFieldsCollection); + + if ($this->_pDataViewAddress instanceof DataListViewAddress) { + $pFieldBuilderShort->addCustomLabelFieldsAddressFrontend($this->_pFieldsCollection, $this->_pDataViewAddress->getName()); + } + } + /** * @return string[] An array of visible fields * @throws Field\UnknownFieldException diff --git a/plugin/Field/Collection/FieldsCollectionBuilderShort.php b/plugin/Field/Collection/FieldsCollectionBuilderShort.php index 86fb40219..e06f369bb 100644 --- a/plugin/Field/Collection/FieldsCollectionBuilderShort.php +++ b/plugin/Field/Collection/FieldsCollectionBuilderShort.php @@ -42,6 +42,7 @@ use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorCustomLabelEstate; use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorGeoPositionBackend; use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorReadAddress; +use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorCustomLabelAddress; /** @@ -320,4 +321,20 @@ public function addFieldSupervisorForSearchCriteria(FieldsCollection $pFieldsCol $pFieldsCollection->merge($pFieldCollectionSupervisor); return $this; } + /** + * + * @param FieldsCollection $pFieldsCollection + * @param string $formName + * @return $this + * @throws DependencyException + * @throws NotFoundException + * @throws UnknownFormException + */ + + public function addCustomLabelFieldsAddressFrontend(FieldsCollection $pFieldsCollection, $formName): self + { + $pFieldsCollectionTmp = new FieldModuleCollectionDecoratorCustomLabelAddress($pFieldsCollection, $formName); + $pFieldsCollection->merge($pFieldsCollectionTmp); + return $this; + } } diff --git a/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php b/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php new file mode 100644 index 000000000..55c9bbf5a --- /dev/null +++ b/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php @@ -0,0 +1,127 @@ +. + * + */ + +declare(strict_types=1); + +namespace onOffice\WPlugin\Field; + +use DI\Container; +use DI\ContainerBuilder; +use onOffice\SDK\onOfficeSDK; +use onOffice\WPlugin\Language; +use onOffice\WPlugin\Types\Field; +use onOffice\WPlugin\Record\RecordManager; + +use onOffice\WPlugin\Field\CustomLabel\CustomLabelRead; +use onOffice\WPlugin\Record\RecordManagerReadListViewAddress; + +/** + * + * @url http://www.onoffice.de + * @copyright 2003-2021, onOffice(R) GmbH + * + */ +class FieldModuleCollectionDecoratorCustomLabelAddress + extends FieldModuleCollectionDecoratorAbstract +{ + /** @var Container */ + private $_pContainer; + + /** @var array */ + private $_fieldCustomLabels = []; + + public function __construct(FieldModuleCollection $pFieldModuleCollection, $formName, Container $pContainer = null) + { + parent::__construct($pFieldModuleCollection); + $this->_pContainer = $pContainer ?? $this->buildContainer(); + $recordManagerReadAddress = $this->_pContainer->get(RecordManagerReadListViewAddress::class); + + try { + $results = $recordManagerReadAddress->getRowByName($formName); + } catch (\Exception $e) { + return; + } + + if (empty($results['listview_address_id'])) { + return; + } + + $fieldsByFormIds = $recordManagerReadAddress->readFieldconfigByListviewId(intval($results['listview_address_id'])); + + foreach ($fieldsByFormIds as $fieldsByFormId) { + $lang = $this->_pContainer->get(Language::class); + $customLabelRead = $this->_pContainer->get(CustomLabelRead::class); + $query = $customLabelRead->readCustomLabelByFormIdAndFieldName(intval($results['listview_address_id']), + $fieldsByFormId['fieldname'], $lang->getLocale(), + RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_CUSTOMS_LABELS, RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS); + if (empty($query[0]->value)) { + continue; + } + $this->_fieldCustomLabels[onOfficeSDK::MODULE_ADDRESS][$fieldsByFormId['fieldname']] = $query[0]->value; + } + } + + /** + * + * @return Field[] + * + */ + + public function getAllFields(): array + { + $fields = parent::getAllFields(); + $cloneFields = array(); + foreach ($fields as $key => $field) { + $cloneFields[$key] = clone $field; + $module = $cloneFields[$key]->getModule(); + $name = $cloneFields[$key]->getName(); + $label = $this->_fieldCustomLabels[$module][$name] ?? null; + + if ($label !== null) { + $cloneFields[$key]->setLabel($label); + } + } + return $cloneFields; + } + + /** + * @return Container + * @throws \Exception + */ + private function buildContainer(): Container + { + $pContainerBuilder = new ContainerBuilder; + $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH); + return $pContainerBuilder->build(); + } + + /** + * + * @return array + * + */ + + public function getFieldCustomLabels(): array + { + return $this->_fieldCustomLabels; + } + +} diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index a73f5059a..dcc0d4d3b 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -41,6 +41,15 @@ use function __; use function wp_enqueue_script; use onOffice\WPlugin\DataView\DataAddressDetailView; +use onOffice\WPlugin\Field\CustomLabel\CustomLabelRead; +use onOffice\WPlugin\Language; +use onOffice\WPlugin\Field\CustomLabel\CustomLabelDelete; +use onOffice\WPlugin\Field\CustomLabel\ModelToOutputConverter\CustomLabelRowSaver; +use onOffice\WPlugin\Field\Collection\FieldsCollectionBuilderFromNamesForm; +use onOffice\WPlugin\Field\CustomLabel\Exception\CustomLabelDeleteException; +use DI\DependencyException; +use DI\NotFoundException; +use onOffice\WPlugin\Field\UnknownFieldException; /** * @@ -55,6 +64,12 @@ class AdminPageAddressListSettings /** @var FormModelBuilderDBAddress */ private $_pFormModelBuilderAddress = null; + /** @var FieldsCollection */ + private $_pFieldsCollection = null; + + /** */ + const CUSTOM_LABELS = 'customlabels'; + /** * * @param string $pageSlug @@ -65,6 +80,7 @@ public function __construct($pageSlug) { parent::__construct($pageSlug); $this->setPageTitle(__('Edit Address List', 'onoffice-for-wp-websites')); + $this->_pFieldsCollection = $this->buildFieldsCollectionForCurrentAddress(); } /** @@ -293,6 +309,8 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null) $row = [ RecordManager::TABLENAME_FIELDCONFIG_ADDRESS => $this->prepareRelationValues (RecordManager::TABLENAME_FIELDCONFIG_ADDRESS, 'listview_address_id', $row, $recordId), + RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS => $this->prepareRelationValues + (RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS, 'listview_address_id', $row, $recordId), ]; $pRecordManagerInsert->insertAdditionalValues($row); $result = true; @@ -302,6 +320,9 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null) } } + if ($result) { + $this->saveCustomLabels($recordId, $row, RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_CUSTOMS_LABELS, RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS); + } $pResult->result = $result; $pResult->record_id = $recordId; } @@ -375,6 +396,8 @@ public function getEnqueueData(): array AdminPageSettingsBase::POST_RECORD_ID => $this->getListViewId(), self::VIEW_UNSAVED_CHANGES_MESSAGE => __('Your changes have not been saved yet! Do you want to leave the page without saving?', 'onoffice-for-wp-websites'), self::VIEW_LEAVE_WITHOUT_SAVING_TEXT => __('Leave without saving', 'onoffice-for-wp-websites'), + self::CUSTOM_LABELS => $this->readCustomLabels(), + 'label_custom_label' => __('Custom Label: %s', 'onoffice-for-wp-websites'), ); } @@ -390,6 +413,100 @@ public function doExtraEnqueues() wp_localize_script('oo-sanitize-shortcode-name', 'shortcode', ['name' => 'oopluginlistviewsaddress-name']); wp_enqueue_script('oo-sanitize-shortcode-name'); wp_enqueue_script( 'oo-copy-shortcode'); + wp_register_script('onoffice-custom-form-label-js', + plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true); + wp_enqueue_script('onoffice-custom-form-label-js'); + $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php'; + wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath)); + wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath)); + wp_enqueue_script('onoffice-multiselect'); + wp_enqueue_style('onoffice-multiselect'); + } + + /** + * + * @return FieldsCollection + * @throws DependencyException + * @throws NotFoundException + * @throws UnknownFieldException + */ + + private function buildFieldsCollectionForCurrentAddress(): FieldsCollection + { + $pEnvironment = new AddressListEnvironmentDefault(); + + $pBuilderShort = $pEnvironment->getFieldsCollectionBuilderShort(); + $pFieldsCollection = new FieldsCollection(); + $pBuilderShort->addFieldsAddressEstate($pFieldsCollection); + + foreach ($pFieldsCollection->getAllFields() as $pField) { + if (!in_array($pField->getModule(), [onOfficeSDK::MODULE_ADDRESS], true)) { + $pFieldsCollection->removeFieldByModuleAndName + ($pField->getModule(), $pField->getName()); + } + } + + return $pFieldsCollection; + } + + /** + * @return array + * @throws DependencyException + * @throws NotFoundException + * @throws UnknownFieldException + */ + private function readCustomLabels(): array + { + $result = []; + /** @var CustomLabelRead $pCustomLabelRead*/ + $pCustomLabelRead = $this->getContainer()->get(CustomLabelRead::class); + $pLanguage = $this->getContainer()->get(Language::class); + $currentLocale = $pLanguage->getLocale(); + + foreach (array_chunk($this->_pFieldsCollection->getAllFields(), 100) as $pField) { + $pCustomLabelModel = $pCustomLabelRead->getCustomLabelsFieldsForAdmin + ((int)$this->getListViewId(), $pField, $currentLocale, RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_CUSTOMS_LABELS, RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS); + if (count($pCustomLabelModel)) $result = array_merge($result, $pCustomLabelModel); + } + + return $result; + } + + /** + * @param int $recordId + * @param array $row + * @param string $pCustomsLabelConfigurationField + * @param string $pTranslateLabelConfigurationField + * @throws CustomLabelDeleteException + * @throws DependencyException + * @throws NotFoundException + * @throws RecordManagerInsertException + * @throws UnknownFieldException + */ + + private function saveCustomLabels(int $recordId, array $row ,string $pCustomsLabelConfigurationField, string $pTranslateLabelConfigurationField) + { + $fields = $row[RecordManager::TABLENAME_FIELDCONFIG_ADDRESS] ?? []; + $fieldNamesSelected = array_column($fields, 'fieldname'); + + foreach ($fieldNamesSelected as $key => $name) { + if (!$this->_pFieldsCollection->containsFieldByModule(onOfficeSDK::MODULE_ADDRESS, $name)) { + unset($fieldNamesSelected[$key]); + unset($row['oo_plugin_fieldconfig_address_translated_labels'][$name]); + } + } + /** @var FieldsCollectionBuilderFromNamesForm $pFieldsCollectionBuilder */ + $pFieldsCollectionBuilder = $this->getContainer()->get(FieldsCollectionBuilderFromNamesForm::class); + $pFieldsCollectionCurrent = $pFieldsCollectionBuilder->buildFieldsCollectionFromBaseCollection + ($fieldNamesSelected, $this->_pFieldsCollection); + + /** @var CustomLabelDelete $pCustomLabelDelete */ + $pCustomLabelDelete = $this->getContainer()->get(CustomLabelDelete::class); + $pCustomLabelDelete->deleteByFormIdAndFieldNames($recordId, $fieldNamesSelected, $pCustomsLabelConfigurationField, $pTranslateLabelConfigurationField); + + $pCustomLabelSave = $this->getContainer()->get(CustomLabelRowSaver::class); + $pCustomLabelSave->saveCustomLabels($recordId, + $row['oo_plugin_fieldconfig_address_translated_labels'] ?? [], $pFieldsCollectionCurrent, $pCustomsLabelConfigurationField, $pTranslateLabelConfigurationField); } /** diff --git a/plugin/Gui/AdminPageSettingsBase.php b/plugin/Gui/AdminPageSettingsBase.php index dace6fc58..fd5f8ab21 100644 --- a/plugin/Gui/AdminPageSettingsBase.php +++ b/plugin/Gui/AdminPageSettingsBase.php @@ -257,6 +257,9 @@ public function ajax_action() $row['oo_plugin_fieldconfig_estate_translated_labels'] = (array)($row['oo_plugin_fieldconfig_form_translated_labels']['value'] ?? []) + (array)($values->{'customlabel-lang'}) ?? []; + $row['oo_plugin_fieldconfig_address_translated_labels'] = + (array)($row['oo_plugin_fieldconfig_form_translated_labels']['value'] ?? []) + + (array)($values->{'customlabel-lang'}) ?? []; if ($checkResult) { $this->updateValues($row, $pResultObject, $recordId); @@ -320,6 +323,9 @@ public function save_form() $row['oo_plugin_fieldconfig_estate_translated_labels'] = (array)($row['oo_plugin_fieldconfig_form_translated_labels']['value'] ?? []) + (array)($values->{'customlabel-lang'} ?? [] ); + $row['oo_plugin_fieldconfig_address_translated_labels'] = + (array)($row['oo_plugin_fieldconfig_form_translated_labels']['value'] ?? []) + + (array)($values->{'customlabel-lang'}) ?? []; if ( $checkResult ) { $this->updateValues( $row, $pResultObject, $recordId ); diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index 6f258e577..a76f3f0b9 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -41,7 +41,7 @@ class DatabaseChanges implements DatabaseChangesInterface { /** @var int */ - const MAX_VERSION = 48; + const MAX_VERSION = 49; /** @var WPOptionWrapperBase */ private $_pWpOption; @@ -330,6 +330,12 @@ public function install() $dbversion = 48; } + if ($dbversion == 48) { + dbDelta($this->getCreateQueryFieldConfigAddressCustomsLabels()); + dbDelta($this->getCreateQueryFieldConfigAddressTranslatedLabels()); + $dbversion = 49; + } + $this->_pWpOption->updateOption( 'oo_plugin_db_version', $dbversion, true ); } @@ -1214,4 +1220,41 @@ public function updateValueGeoFieldsForEsateList() $this->_pWPDB->query($sql); } + + /** + * @return string + */ + private function getCreateQueryFieldConfigAddressCustomsLabels(): string + { + $prefix = $this->getPrefix(); + $charsetCollate = $this->getCharsetCollate(); + $tableName = $prefix . "oo_plugin_fieldconfig_address_customs_labels"; + $sql = "CREATE TABLE $tableName ( + `customs_labels_id` bigint(20) NOT NULL AUTO_INCREMENT, + `form_id` bigint(20) NOT NULL, + `fieldname` tinytext NOT NULL, + PRIMARY KEY (`customs_labels_id`) + ) $charsetCollate;"; + + return $sql; + } + + /** + * @return string + */ + private function getCreateQueryFieldConfigAddressTranslatedLabels(): string + { + $prefix = $this->getPrefix(); + $charsetCollate = $this->getCharsetCollate(); + $tableName = $prefix . "oo_plugin_fieldconfig_address_translated_labels"; + $sql = "CREATE TABLE $tableName ( + `translated_label_id` bigint(20) NOT NULL AUTO_INCREMENT, + `input_id` bigint(20) NOT NULL, + `locale` tinytext NULL DEFAULT NULL, + `value` text, + PRIMARY KEY (`translated_label_id`) + ) $charsetCollate;"; + + return $sql; + } } diff --git a/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php b/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php index a2669e957..954092b65 100644 --- a/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php +++ b/plugin/Model/FormModelBuilder/FormModelBuilderDBAddress.php @@ -36,6 +36,12 @@ use onOffice\WPlugin\Record\RecordManagerReadListViewAddress; use onOffice\WPlugin\Types\FieldsCollection; use function __; +use DI\ContainerBuilder; +use onOffice\WPlugin\Model\InputModelBuilder\InputModelBuilderCustomLabel; +use onOffice\WPlugin\WP\InstalledLanguageReader; +use onOffice\WPlugin\Types\Field; +use DI\DependencyException; +use DI\NotFoundException; /** * @@ -228,8 +234,17 @@ public function createSortableFieldList($module, $htmlType) $pSortableFieldsList = parent::createSortableFieldList($module, $htmlType); $pInputModelIsFilterable = $this->getInputModelIsFilterable(); $pInputModelIsHidden = $this->getInputModelIsHidden(); + + $pFieldsCollectionUsedFields = new FieldsCollection; + foreach ($pSortableFieldsList->getValuesAvailable() as $key => $pField) { + $field = Field::createByRow($key, $pField); + $pFieldsCollectionUsedFields->addField($field); + } + $pSortableFieldsList->addReferencedInputModel($pInputModelIsFilterable); $pSortableFieldsList->addReferencedInputModel($pInputModelIsHidden); + $pSortableFieldsList->addReferencedInputModel($this->getInputModelCustomLabel($pFieldsCollectionUsedFields)); + $pSortableFieldsList->addReferencedInputModel($this->getInputModelCustomLabelLanguageSwitch()); return $pSortableFieldsList; } @@ -344,4 +359,40 @@ public function createInputModelRecordsPerPage() return $pInputModelRecordsPerPage; } + + /** + * @param FieldsCollection $pFieldsCollection + * @return InputModelDB + * @throws DependencyException + * @throws NotFoundException + */ + private function getInputModelCustomLabel(FieldsCollection $pFieldsCollection): InputModelDB + { + $pDIContainerBuilder = new ContainerBuilder(); + $pDIContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH); + $pContainer = $pDIContainerBuilder->build(); + $pInputModelBuilder = $pContainer->get(InputModelBuilderCustomLabel::class); + return $pInputModelBuilder->createInputModelCustomLabel($pFieldsCollection, $this->getValue('customlabel', [])); + } + + /** + * @return InputModelDB + */ + public function getInputModelCustomLabelLanguageSwitch(): InputModelDB + { + $pInputModel = new InputModelDB('customlabel_newlang', + __('Add custom label language', 'onoffice-for-wp-websites')); + $pInputModel->setTable('language-custom-label'); + $pInputModel->setField('language'); + + $pLanguageReader = new InstalledLanguageReader; + $languages = ['' => __('Choose Language', 'onoffice-for-wp-websites')] + + $pLanguageReader->readAvailableLanguageNamesUsingNativeName(); + $pInputModel->setValuesAvailable(array_diff_key($languages, [get_locale() => []])); + $pInputModel->setValueCallback(function (InputModelDB $pInputModel) { + $pInputModel->setHtmlType(InputModelBase::HTML_TYPE_SELECT); + $pInputModel->setLabel(__('Add custom label language', 'onoffice-for-wp-websites')); + }); + return $pInputModel; + } } diff --git a/plugin/Record/RecordManager.php b/plugin/Record/RecordManager.php index caad9fb04..d4bfda6b9 100644 --- a/plugin/Record/RecordManager.php +++ b/plugin/Record/RecordManager.php @@ -80,6 +80,12 @@ abstract class RecordManager /** */ const TABLENAME_CONTACT_TYPES = 'oo_plugin_contacttypes'; + /** */ + const TABLENAME_FIELDCONFIG_ADDRESS_CUSTOMS_LABELS = 'oo_plugin_fieldconfig_address_customs_labels'; + + /** */ + const TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS = 'oo_plugin_fieldconfig_address_translated_labels'; + /** * * @deprecated get wpdb via DI diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php index a87023a37..4cae6e106 100644 --- a/templates.dist/address/default_detail.php +++ b/templates.dist/address/default_detail.php @@ -63,6 +63,7 @@ . ''; continue; } + echo '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; echo '
' . (is_array($value) ? esc_html(implode(', ', $value)) : esc_html($value)) . '
'; From 83a44b90c23d155f6538f6f5fcbe4dbb8b694c81 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 09:39:25 +0700 Subject: [PATCH 02/12] 53258 refactor code --- plugin/AddressList.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/AddressList.php b/plugin/AddressList.php index fe5393235..5cbcebc82 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -448,6 +448,7 @@ public function getVisibleFilterableFields(): array ->getAsRow(); $result[$field]['name'] = $field; $result[$field]['value'] = $value; + $result[$field]['label'] = $this->getFieldLabel($field); } return $result; } From 3e6e9eb43f1af40186cd2576a6e87807e19de88e Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 11:41:00 +0700 Subject: [PATCH 03/12] 53258 update unit test --- plugin/AddressList.php | 2 +- plugin/Gui/AdminPageAddressListSettings.php | 2 +- tests/TestClassAddressList.php | 4 +- ...eCollectionDecoratorCustomLabelAddress.php | 199 ++++++++++++++++++ tests/TestClassFormModelBuilderDBAddress.php | 22 ++ 5 files changed, 225 insertions(+), 4 deletions(-) create mode 100644 tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php diff --git a/plugin/AddressList.php b/plugin/AddressList.php index 5cbcebc82..52a01e53c 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -419,7 +419,7 @@ public function getFieldType($field): string private function buildFieldsCollectionForAddressCustomLabel() { $this->_pFieldsCollection = new FieldsCollection(); - $pFieldBuilderShort = $this->_pEnvironment->getContainer()->get(FieldsCollectionBuilderShort::class); + $pFieldBuilderShort = $this->_pEnvironment->getFieldsCollectionBuilderShort(); $pFieldBuilderShort->addFieldsAddressEstate($this->_pFieldsCollection); if ($this->_pDataViewAddress instanceof DataListViewAddress) { diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index dcc0d4d3b..57d1634c1 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -310,7 +310,7 @@ protected function updateValues(array $row, stdClass $pResult, $recordId = null) RecordManager::TABLENAME_FIELDCONFIG_ADDRESS => $this->prepareRelationValues (RecordManager::TABLENAME_FIELDCONFIG_ADDRESS, 'listview_address_id', $row, $recordId), RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS => $this->prepareRelationValues - (RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS, 'listview_address_id', $row, $recordId), + (RecordManager::TABLENAME_FIELDCONFIG_ADDRESS_TRANSLATED_LABELS, 'listview_address_id', $row, $recordId), ]; $pRecordManagerInsert->insertAdditionalValues($row); $result = true; diff --git a/tests/TestClassAddressList.php b/tests/TestClassAddressList.php index bdfe0ce2f..e9a3f8cb0 100644 --- a/tests/TestClassAddressList.php +++ b/tests/TestClassAddressList.php @@ -216,7 +216,7 @@ public function prepare() ->getMock(); $pFieldsCollectionNewFields = new FieldsCollection; - $pFieldsCollectionNewFields->addField(new Field('KdNr', onOfficeSDK::MODULE_ADDRESS)); + $pFieldsCollectionNewFields->addField(new Field('KdNr', onOfficeSDK::MODULE_ADDRESS, 'Kundennummer')); $pFieldsCollectionNewFields->addField(new Field('Vorname', onOfficeSDK::MODULE_ADDRESS)); $pFieldsCollectionNewFields->addField(new Field('Name', onOfficeSDK::MODULE_ADDRESS)); @@ -352,7 +352,7 @@ public function testGetVisibleFilterableFields() 'KdNr' => [ 'type' => 'varchar', 'value' => 4, - 'label' => '', + 'label' => 'Kundennummer', 'default' => null, 'length' => null, 'permittedvalues' => Array (), diff --git a/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php b/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php new file mode 100644 index 000000000..297e7fcfd --- /dev/null +++ b/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php @@ -0,0 +1,199 @@ +. + * + */ + +declare (strict_types=1); + +namespace onOffice\tests; + +use DI\Container; +use DI\ContainerBuilder; +use Generator; +use onOffice\SDK\onOfficeSDK; +use onOffice\WPlugin\Field\CustomLabel\CustomLabelRead; +use onOffice\WPlugin\Field\FieldModuleCollection; +use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorCustomLabelAddress; +use onOffice\WPlugin\Form; +use onOffice\WPlugin\Record\RecordManagerReadForm; +use onOffice\WPlugin\Types\Field; +use onOffice\WPlugin\Types\FieldsCollection; +use WP_UnitTestCase; +use wpdb; +use onOffice\WPlugin\Record\RecordManagerReadListViewAddress; + +/** + * + * @url http://www.onoffice.de + * @copyright 2003-2018, onOffice(R) GmbH + * + */ +class TestClassFieldModuleCollectionDecoratorCustomLabelAddress + extends WP_UnitTestCase +{ + /** @var RecordManagerReadListViewAddress */ + private $_pRecordManagerReadListViewAddress = null; + + /** @var CustomLabelRead */ + private $_pCustomLabelRead = null; + + /** @var FieldModuleCollection */ + private $_pFieldModuleCollection = null; + + /** @var Container */ + private $_pContainer = null; + + /** @var wpdb */ + private $_pWPDBMock = null; + + /** + * @before + */ + + public function prepare() + { + $rows = [ + (object)[ + 'customs_labels_id' => 33, + 'locale' => 'de_DE', + 'value' => 'Deutschland', + ] + ]; + $this->_pWPDBMock = $this->getMockBuilder(\wpdb::class) + ->disableOriginalConstructor() + ->setMethods(['get_results']) + ->getMock(); + $pContainerBuilder = new ContainerBuilder; + $pContainerBuilder->addDefinitions(ONOFFICE_DI_CONFIG_PATH); + $this->_pContainer = $pContainerBuilder->build(); + + $this->_pRecordManagerReadListViewAddress = $this->getMockBuilder(RecordManagerReadListViewAddress::class) + ->getMock(); + $this->_pRecordManagerReadListViewAddress->method('readFieldconfigByListviewId')->will($this->returnValueMap([ + [1, $this->getBasicFieldsArray(1)] + ])); + $this->_pRecordManagerReadListViewAddress->method('getRowByName')->will($this->returnValue( + $this->getBaseRow(1) + )); + $this->_pContainer->set(RecordManagerReadListViewAddress::class, $this->_pRecordManagerReadListViewAddress); + $pFieldsCollectionByFormIds = $this->_pContainer->get(RecordManagerReadListViewAddress::class)->readFieldconfigByListviewId(1); + + $this->_pFieldModuleCollection = new FieldsCollection(); + foreach ($pFieldsCollectionByFormIds as $pFieldsCollectionByFormId) { + $this->_pFieldModuleCollection->addField(new Field($pFieldsCollectionByFormId['fieldname'], + onOfficeSDK::MODULE_ADDRESS)); + $this->_pWPDBMock->method('get_results')->will($this->returnValue($rows)); + $this->_pCustomLabelRead = new CustomLabelRead($this->_pWPDBMock); + $this->_pCustomLabelRead->readCustomLabelByFormIdAndFieldName(1, $pFieldsCollectionByFormId['fieldname'], + 'de_DE','oo_plugin_fieldconfig_address_customs_labels','oo_plugin_fieldconfig_address_translated_labels'); + } + $this->_pContainer->set(CustomLabelRead::class, $this->_pCustomLabelRead); + } + + + /** + * + */ + + public function testGetAllFields() + { + $pDecoratorCustomLabel = new FieldModuleCollectionDecoratorCustomLabelAddress($this->_pFieldModuleCollection, + 'testListViewId1', $this->_pContainer); + $fieldCustomLabels = $pDecoratorCustomLabel->getFieldCustomLabels(); + $cloneFields = array(); + + foreach ($pDecoratorCustomLabel->getAllFields() as $key => $field) { + $cloneFields[$key] = clone $field; + $module = $cloneFields[$key]->getModule(); + $name = $cloneFields[$key]->getName(); + $label = $fieldCustomLabels[$module][$name] ?? null; + + if ($label !== null) { + $this->assertEquals($label, $cloneFields[$key]->getLabel()); + } + } + } + + /** + * + * @param int $addressId + * @return array + * + */ + + private function getBasicFieldsArray(int $addressId): array + { + $fields = [ + [ + 'fieldconfig_id' => '1', + 'listview_id' => $addressId, + 'order' => '1', + 'fieldname' => 'Test 1', + 'fieldlabel' => 'Field label 1', + 'hidden' => '0', + 'availableOptions' => '0', + ], + [ + 'fieldconfig_id' => '1', + 'listview_id' => $addressId, + 'order' => '1', + 'fieldname' => 'Test 3', + 'fieldlabel' => 'Field label 3', + 'hidden' => '0', + 'availableOptions' => '0', + ], + [ + 'fieldconfig_id' => '1', + 'listview_id' => $addressId, + 'order' => '1', + 'fieldname' => 'Test 3', + 'fieldlabel' => 'Field label 3', + 'hidden' => '0', + 'availableOptions' => '0', + ], + ]; + + return $fields; + } + + /** + * + * @param int $addressId + * @return array + * + */ + + private function getBaseRow(int $listviewId): array + { + return [ + 'listview_address_id' => $listviewId, + 'name' => 'testListViewId' . $listviewId, + 'filterId' => '0', + 'template' => 'testtemplate.php', + 'expose' => '', + 'radius' => '10', + 'fields' => [ + 'test1', + 'test2' + ], + 'filterable' => [], + 'hidden' => [], + ]; + } +} diff --git a/tests/TestClassFormModelBuilderDBAddress.php b/tests/TestClassFormModelBuilderDBAddress.php index bf04bd44c..d52da0785 100644 --- a/tests/TestClassFormModelBuilderDBAddress.php +++ b/tests/TestClassFormModelBuilderDBAddress.php @@ -125,4 +125,26 @@ public function testCreateInputModelRecordsPerPage() $this->assertInstanceOf(InputModelDB::class, $pInputModelDB); $this->assertEquals($pInputModelDB->getHtmlType(), 'number'); } + + /** + * @covers onOffice\WPlugin\Model\FormModelBuilder\FormModelBuilderDBAddress::getInputModelCustomLabelLanguageSwitch + */ + public function testGetInputModelCustomLabelLanguageSwitch() + { + $pInstance = $this->getMockBuilder(FormModelBuilderDBAddress::class) + ->disableOriginalConstructor() + ->setMethods(['readAvailableLanguageNamesUsingNativeName']) + ->getMock(); + + $inputModel = $pInstance->getInputModelCustomLabelLanguageSwitch(); + $this->assertInstanceOf(InputModelDB::class, $inputModel); + $this->assertEquals('Add custom label language', $inputModel->getLabel()); + $this->assertEquals('language-custom-label', $inputModel->getTable()); + $this->assertEquals('language', $inputModel->getField()); + + $values = $inputModel->getValuesAvailable(); + + $this->assertContains('Choose Language', $values); + $this->assertNotContains(get_locale(), $values); + } } From 95ec29f3894e5abf2c78f00f0b13a88e99811699 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 15:54:37 +0700 Subject: [PATCH 04/12] 53258 refactor code --- templates.dist/address/default_detail.php | 1 + 1 file changed, 1 insertion(+) diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php index 4cae6e106..dc7f2d529 100644 --- a/templates.dist/address/default_detail.php +++ b/templates.dist/address/default_detail.php @@ -69,6 +69,7 @@ . ''; } if(!empty($addressPlaceDiv)) { + echo '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; echo '
'.$addressPlaceDiv.'
'; } ?> From ba8ab2e6e2b1378d335d81aea79b41b68043ad52 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 17:19:38 +0700 Subject: [PATCH 05/12] 53258 refactor code --- plugin/AddressList.php | 2 +- .../Collection/FieldsCollectionBuilderShort.php | 3 ++- ...ModuleCollectionDecoratorCustomLabelAddress.php | 10 ++++++++-- ...ModuleCollectionDecoratorCustomLabelAddress.php | 5 +---- tests/TestClassFormModelBuilderDBAddress.php | 14 +++++++------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/plugin/AddressList.php b/plugin/AddressList.php index 08b5fa3ae..b8e305985 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -422,7 +422,7 @@ private function buildFieldsCollectionForAddressCustomLabel() $pFieldBuilderShort = $this->_pEnvironment->getFieldsCollectionBuilderShort(); $pFieldBuilderShort->addFieldsAddressEstate($this->_pFieldsCollection); - if ($this->_pDataViewAddress instanceof DataListViewAddress) { + if ($this->_pDataViewAddress instanceof DataListViewAddress && !empty($this->_pDataViewAddress->getName())) { $pFieldBuilderShort->addCustomLabelFieldsAddressFrontend($this->_pFieldsCollection, $this->_pDataViewAddress->getName()); } } diff --git a/plugin/Field/Collection/FieldsCollectionBuilderShort.php b/plugin/Field/Collection/FieldsCollectionBuilderShort.php index ed7ceb53b..24fd46b15 100644 --- a/plugin/Field/Collection/FieldsCollectionBuilderShort.php +++ b/plugin/Field/Collection/FieldsCollectionBuilderShort.php @@ -342,6 +342,7 @@ public function addFieldSupervisorForSearchCriteria(FieldsCollection $pFieldsCol $pFieldsCollection->merge($pFieldCollectionSupervisor); return $this; } + /** * * @param FieldsCollection $pFieldsCollection @@ -352,7 +353,7 @@ public function addFieldSupervisorForSearchCriteria(FieldsCollection $pFieldsCol * @throws UnknownFormException */ - public function addCustomLabelFieldsAddressFrontend(FieldsCollection $pFieldsCollection, $formName): self + public function addCustomLabelFieldsAddressFrontend(FieldsCollection $pFieldsCollection, string $formName): self { $pFieldsCollectionTmp = new FieldModuleCollectionDecoratorCustomLabelAddress($pFieldsCollection, $formName); $pFieldsCollection->merge($pFieldsCollectionTmp); diff --git a/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php b/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php index 55c9bbf5a..6ea29f020 100644 --- a/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php +++ b/plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php @@ -36,7 +36,7 @@ /** * * @url http://www.onoffice.de - * @copyright 2003-2021, onOffice(R) GmbH + * @copyright 2003-2024, onOffice(R) GmbH * */ class FieldModuleCollectionDecoratorCustomLabelAddress @@ -48,7 +48,13 @@ class FieldModuleCollectionDecoratorCustomLabelAddress /** @var array */ private $_fieldCustomLabels = []; - public function __construct(FieldModuleCollection $pFieldModuleCollection, $formName, Container $pContainer = null) + /** + * @param FieldModuleCollection $pFieldModuleCollection + * @param mixed $formName + * @param Container|null $pContainer + * @return void + */ + public function __construct(FieldModuleCollection $pFieldModuleCollection, string $formName, Container $pContainer = null) { parent::__construct($pFieldModuleCollection); $this->_pContainer = $pContainer ?? $this->buildContainer(); diff --git a/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php b/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php index 297e7fcfd..7d53fa4fc 100644 --- a/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php +++ b/tests/TestClassFieldModuleCollectionDecoratorCustomLabelAddress.php @@ -2,7 +2,7 @@ /** * - * Copyright (C) 2021 onOffice GmbH + * Copyright (C) 2024 onOffice GmbH * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -25,13 +25,10 @@ use DI\Container; use DI\ContainerBuilder; -use Generator; use onOffice\SDK\onOfficeSDK; use onOffice\WPlugin\Field\CustomLabel\CustomLabelRead; use onOffice\WPlugin\Field\FieldModuleCollection; use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorCustomLabelAddress; -use onOffice\WPlugin\Form; -use onOffice\WPlugin\Record\RecordManagerReadForm; use onOffice\WPlugin\Types\Field; use onOffice\WPlugin\Types\FieldsCollection; use WP_UnitTestCase; diff --git a/tests/TestClassFormModelBuilderDBAddress.php b/tests/TestClassFormModelBuilderDBAddress.php index 08639dbc8..1b96691a7 100644 --- a/tests/TestClassFormModelBuilderDBAddress.php +++ b/tests/TestClassFormModelBuilderDBAddress.php @@ -154,14 +154,14 @@ public function testGetInputModelCustomLabelLanguageSwitch() ->getMock(); $inputModel = $pInstance->getInputModelCustomLabelLanguageSwitch(); - $this->assertInstanceOf(InputModelDB::class, $inputModel); - $this->assertEquals('Add custom label language', $inputModel->getLabel()); - $this->assertEquals('language-custom-label', $inputModel->getTable()); - $this->assertEquals('language', $inputModel->getField()); + $this->assertInstanceOf(InputModelDB::class, $inputModel); + $this->assertEquals('Add custom label language', $inputModel->getLabel()); + $this->assertEquals('language-custom-label', $inputModel->getTable()); + $this->assertEquals('language', $inputModel->getField()); - $values = $inputModel->getValuesAvailable(); + $values = $inputModel->getValuesAvailable(); - $this->assertContains('Choose Language', $values); - $this->assertNotContains(get_locale(), $values); + $this->assertContains('Choose Language', $values); + $this->assertNotContains(get_locale(), $values); } } From e2215b6b47f7c92fb6cd4ed9f642dba5f35d71a2 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 17:38:01 +0700 Subject: [PATCH 06/12] 53258 refactor code --- plugin/AddressList.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/AddressList.php b/plugin/AddressList.php index b8e305985..e9ffcfa1d 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -153,7 +153,6 @@ public function __construct(DataViewAddress $pDataViewAddress = null, AddressLis { $this->_pEnvironment = $pEnvironment ?? new AddressListEnvironmentDefault(); $this->_pDataViewAddress = $pDataViewAddress ?? new DataListViewAddress(0, 'default'); - $this->buildFieldsCollectionForAddressCustomLabel(); } /** @@ -188,6 +187,7 @@ public function loadAddressesById(array $addressIds, array $fields) $this->_pDataViewAddress->setFields($fields); $this->addRawRecordsByAPICall(clone $pApiCall, $parametersRaw); + $this->buildFieldsCollectionForAddressCustomLabel(); } /** @@ -232,6 +232,7 @@ public function loadAddresses(int $inputPage = 1) $multipage = $numpages > 1; $more = true; $page = $newPage; + $this->buildFieldsCollectionForAddressCustomLabel(); } /** From 46365425e1b834586559688af8b1b77550f2c7e7 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 17:43:33 +0700 Subject: [PATCH 07/12] 53258 update unit test --- plugin/Gui/AdminPageAddressListSettings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index 527a11422..63033ff43 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -80,7 +80,6 @@ public function __construct($pageSlug) { parent::__construct($pageSlug); $this->setPageTitle(__('Edit Address List', 'onoffice-for-wp-websites')); - $this->_pFieldsCollection = $this->buildFieldsCollectionForCurrentAddress(); } /** @@ -123,6 +122,7 @@ protected function buildForms() $this->addSortableFieldsList(array(onOfficeSDK::MODULE_ADDRESS), $this->_pFormModelBuilderAddress, InputModelBase::HTML_TYPE_COMPLEX_SORTABLE_DETAIL_LIST); $this->addSearchFieldForFieldLists(onOfficeSDK::MODULE_ADDRESS, $this->_pFormModelBuilderAddress); + $this->_pFieldsCollection = $this->buildFieldsCollectionForCurrentAddress(); $this->addFormModelName(); $this->addFormModelPictureTypes(); From 4c80cb5eac363e1c56bfa557d7ba015ba7371260 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 17:44:11 +0700 Subject: [PATCH 08/12] 53258 update unit test --- tests/TestClassDatabaseChanges.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TestClassDatabaseChanges.php b/tests/TestClassDatabaseChanges.php index c1f5f94d6..a3f0d04e0 100644 --- a/tests/TestClassDatabaseChanges.php +++ b/tests/TestClassDatabaseChanges.php @@ -118,7 +118,7 @@ public function testInstall(): array $this->assertGreaterThanOrEqual(self::NUM_NEW_TABLES, count($this->_createQueries)); $dbversion = $this->_pDbChanges->getDbVersion(); - $this->assertEquals(49, $dbversion); + $this->assertEquals(50, $dbversion); return $this->_createQueries; } @@ -271,7 +271,7 @@ public function testDeleteMessageFieldApplicantSearchForm() */ public function testMaxVersion() { - $this->assertEquals(49, DatabaseChanges::MAX_VERSION); + $this->assertEquals(50, DatabaseChanges::MAX_VERSION); } From 4162e8c14f3e22a674dc72f238c7b8e9a79bc667 Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Tue, 1 Oct 2024 18:24:20 +0700 Subject: [PATCH 09/12] 53258 update deinstall --- plugin/Gui/AdminPageAddressListSettings.php | 31 +++------------------ plugin/Installer/DatabaseChanges.php | 2 ++ 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index 63033ff43..7d96d2d63 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -122,7 +122,7 @@ protected function buildForms() $this->addSortableFieldsList(array(onOfficeSDK::MODULE_ADDRESS), $this->_pFormModelBuilderAddress, InputModelBase::HTML_TYPE_COMPLEX_SORTABLE_DETAIL_LIST); $this->addSearchFieldForFieldLists(onOfficeSDK::MODULE_ADDRESS, $this->_pFormModelBuilderAddress); - $this->_pFieldsCollection = $this->buildFieldsCollectionForCurrentAddress(); + $this->_pFieldsCollection = $pFieldsCollection; $this->addFormModelName(); $this->addFormModelPictureTypes(); @@ -424,32 +424,6 @@ public function doExtraEnqueues() wp_enqueue_style('onoffice-multiselect'); } - /** - * - * @return FieldsCollection - * @throws DependencyException - * @throws NotFoundException - * @throws UnknownFieldException - */ - - private function buildFieldsCollectionForCurrentAddress(): FieldsCollection - { - $pEnvironment = new AddressListEnvironmentDefault(); - - $pBuilderShort = $pEnvironment->getFieldsCollectionBuilderShort(); - $pFieldsCollection = new FieldsCollection(); - $pBuilderShort->addFieldsAddressEstate($pFieldsCollection); - - foreach ($pFieldsCollection->getAllFields() as $pField) { - if (!in_array($pField->getModule(), [onOfficeSDK::MODULE_ADDRESS], true)) { - $pFieldsCollection->removeFieldByModuleAndName - ($pField->getModule(), $pField->getName()); - } - } - - return $pFieldsCollection; - } - /** * @return array * @throws DependencyException @@ -463,6 +437,9 @@ private function readCustomLabels(): array $pCustomLabelRead = $this->getContainer()->get(CustomLabelRead::class); $pLanguage = $this->getContainer()->get(Language::class); $currentLocale = $pLanguage->getLocale(); + if (is_null($this->_pFieldsCollection)) { + return []; + } foreach (array_chunk($this->_pFieldsCollection->getAllFields(), 100) as $pField) { $pCustomLabelModel = $pCustomLabelRead->getCustomLabelsFieldsForAdmin diff --git a/plugin/Installer/DatabaseChanges.php b/plugin/Installer/DatabaseChanges.php index b1bbe7329..fa3592cca 100644 --- a/plugin/Installer/DatabaseChanges.php +++ b/plugin/Installer/DatabaseChanges.php @@ -973,6 +973,8 @@ public function deinstall() $prefix."oo_plugin_fieldconfig_estate_customs_labels", $prefix."oo_plugin_fieldconfig_estate_translated_labels", $prefix."oo_plugin_contacttypes", + $prefix."oo_plugin_fieldconfig_address_customs_labels", + $prefix."oo_plugin_fieldconfig_address_translated_labels", ); foreach ($tables as $table) { From 1840480bc8b389af69f1dc882a2b47964449f78a Mon Sep 17 00:00:00 2001 From: "dai.trinh" Date: Wed, 2 Oct 2024 17:13:25 +0700 Subject: [PATCH 10/12] 53258 fix field address place --- css/onoffice-address-detail.css | 4 +++- templates.dist/address/default_detail.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/css/onoffice-address-detail.css b/css/onoffice-address-detail.css index 6ca37ed7a..d52fd637a 100644 --- a/css/onoffice-address-detail.css +++ b/css/onoffice-address-detail.css @@ -16,11 +16,13 @@ } .oo-address-placefieldlist { display: flex; - flex-direction: column; + width: 100%; + flex-wrap: wrap; margin-top: 0.25rem; margin-bottom: 0.25rem; } .oo-address-placefield { + width: 25%; font-size: 1rem; } .oo-address-field { diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php index dc7f2d529..a5cc3bd7e 100644 --- a/templates.dist/address/default_detail.php +++ b/templates.dist/address/default_detail.php @@ -58,6 +58,7 @@ continue; } if (in_array($field, $addressPlace)) { + $addressPlaceDiv .= '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; $addressPlaceDiv .= '
' . (is_array($value) ? esc_html(implode(', ', $value)) : esc_html($value)) . '
'; @@ -69,7 +70,6 @@ . ''; } if(!empty($addressPlaceDiv)) { - echo '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; echo '
'.$addressPlaceDiv.'
'; } ?> From cbf91647ec35bd8d1338bb5a6a121e4b6a20309a Mon Sep 17 00:00:00 2001 From: andernath Date: Tue, 8 Oct 2024 11:52:21 +0200 Subject: [PATCH 11/12] Improve styling and refactoring after CR #4468747 --- css/onoffice-address-detail.css | 19 +++++++++---------- plugin/AddressList.php | 11 +++++++---- plugin/Gui/AdminPageAddressDetail.php | 5 ----- plugin/Gui/AdminPageAddressListSettings.php | 5 ----- templates.dist/address/default_detail.php | 18 ++++-------------- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/css/onoffice-address-detail.css b/css/onoffice-address-detail.css index d52fd637a..44072f57f 100644 --- a/css/onoffice-address-detail.css +++ b/css/onoffice-address-detail.css @@ -12,24 +12,23 @@ } .oo-address-fieldlist { display: flex; + flex-direction: column; flex-wrap: wrap; } -.oo-address-placefieldlist { +.oo-address-field { display: flex; - width: 100%; flex-wrap: wrap; + font-size: 1rem; margin-top: 0.25rem; margin-bottom: 0.25rem; } -.oo-address-placefield { - width: 25%; - font-size: 1rem; +.oo-address-field-label { + margin-right: 0.5rem; + font-weight: bold; + word-break: break-word; } -.oo-address-field { - width: 25%; - font-size: 1rem; - margin-top: 0.25rem; - margin-bottom: 0.25rem; +.oo-address-field-label { + word-break: break-word; } .oo-address-estatelist { margin-bottom: 4rem; diff --git a/plugin/AddressList.php b/plugin/AddressList.php index e9ffcfa1d..1227a8cc2 100644 --- a/plugin/AddressList.php +++ b/plugin/AddressList.php @@ -380,10 +380,9 @@ public function getDataViewAddress(): DataViewAddress * @param bool $raw * @return string */ - public function getFieldLabel($field, bool $raw = false): string + public function getFieldLabel(string $field, bool $raw = false): string { $recordType = onOfficeSDK::MODULE_ADDRESS; - $label = ''; try { $label = $this->_pFieldsCollection->getFieldByModuleAndName($recordType, $field)->getLabel(); @@ -391,8 +390,12 @@ public function getFieldLabel($field, bool $raw = false): string $label = $this->_pEnvironment->getFieldnames()->getFieldLabel($field, $recordType); } if ($this->_pDataViewAddress instanceof DataAddressDetailView) { - $pLanguage = $this->_pEnvironment->getContainer()->get(Language::class)->getLocale(); - $dataView = $this->_pDataViewAddress->getCustomLabels(); + try { + $pLanguage = $this->_pEnvironment->getContainer()->get(Language::class)->getLocale(); + } catch (DependencyException | NotFoundException $e) { + return $raw ? $label : esc_html($label); + } + $dataView = $this->_pDataViewAddress->getCustomLabels(); if (!empty( $dataView[ $field ][ $pLanguage ])) { $label = $dataView[ $field ][ $pLanguage ]; } diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php index 99d5de92e..323df806a 100644 --- a/plugin/Gui/AdminPageAddressDetail.php +++ b/plugin/Gui/AdminPageAddressDetail.php @@ -347,11 +347,6 @@ public function doExtraEnqueues() wp_register_script('onoffice-custom-form-label-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true); wp_enqueue_script('onoffice-custom-form-label-js'); - $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php'; - wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath)); - wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath)); - wp_enqueue_script('onoffice-multiselect'); - wp_enqueue_style('onoffice-multiselect'); wp_register_script('oo-unsaved-changes-message', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-unsaved-changes-message.min.js', ['jquery'], '', true); diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index 7d96d2d63..29fefcb51 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -417,11 +417,6 @@ public function doExtraEnqueues() wp_register_script('onoffice-custom-form-label-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true); wp_enqueue_script('onoffice-custom-form-label-js'); - $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php'; - wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath)); - wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath)); - wp_enqueue_script('onoffice-multiselect'); - wp_enqueue_style('onoffice-multiselect'); } /** diff --git a/templates.dist/address/default_detail.php b/templates.dist/address/default_detail.php index a5cc3bd7e..79f143906 100644 --- a/templates.dist/address/default_detail.php +++ b/templates.dist/address/default_detail.php @@ -22,7 +22,6 @@ use onOffice\WPlugin\AddressList; $addressName = array('Anrede', 'Titel', 'Vorname', 'Name'); -$addressPlace = array('Strasse', 'Plz', 'Ort', 'Plz-Ort'); /* @var $pAddressList AddressList */ $currentAddressArr = $pAddressList->getRows(); foreach ($currentAddressArr as $addressId => $escapedValues) { @@ -52,25 +51,16 @@ ?>
$value) { if (in_array($field, $addressName) || empty($value)) { continue; } - if (in_array($field, $addressPlace)) { - $addressPlaceDiv .= '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; - $addressPlaceDiv .= '
' - . (is_array($value) ? esc_html(implode(', ', $value)) : esc_html($value)) - . '
'; - continue; - } - echo '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; - echo '
' + echo '
'; + echo '
' . esc_html($pAddressList->getFieldLabel($field)) . '
'; + echo '
' . (is_array($value) ? esc_html(implode(', ', $value)) : esc_html($value)) . '
'; - } - if(!empty($addressPlaceDiv)) { - echo '
'.$addressPlaceDiv.'
'; + echo '
'; } ?>
From b93bbdbb38810a2741410689b36a3df04f13a008 Mon Sep 17 00:00:00 2001 From: andernath Date: Tue, 8 Oct 2024 12:22:17 +0200 Subject: [PATCH 12/12] Revert needed js (for custom labeling) #4468747 --- plugin/Gui/AdminPageAddressDetail.php | 5 +++++ plugin/Gui/AdminPageAddressListSettings.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/plugin/Gui/AdminPageAddressDetail.php b/plugin/Gui/AdminPageAddressDetail.php index 323df806a..d6a3bb5b3 100644 --- a/plugin/Gui/AdminPageAddressDetail.php +++ b/plugin/Gui/AdminPageAddressDetail.php @@ -347,6 +347,11 @@ public function doExtraEnqueues() wp_register_script('onoffice-custom-form-label-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true); wp_enqueue_script('onoffice-custom-form-label-js'); + $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php'; + wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath)); + wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath)); + wp_enqueue_script('onoffice-multiselect'); + wp_enqueue_style('onoffice-multiselect'); wp_register_script('oo-unsaved-changes-message', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-unsaved-changes-message.min.js', ['jquery'], '', true); diff --git a/plugin/Gui/AdminPageAddressListSettings.php b/plugin/Gui/AdminPageAddressListSettings.php index 29fefcb51..43772514b 100644 --- a/plugin/Gui/AdminPageAddressListSettings.php +++ b/plugin/Gui/AdminPageAddressListSettings.php @@ -417,6 +417,11 @@ public function doExtraEnqueues() wp_register_script('onoffice-custom-form-label-js', plugin_dir_url(ONOFFICE_PLUGIN_DIR.'/index.php').'dist/onoffice-custom-form-label.min.js', ['onoffice-multiselect'], '', true); wp_enqueue_script('onoffice-custom-form-label-js'); + $pluginPath = ONOFFICE_PLUGIN_DIR.'/index.php'; + wp_register_script('onoffice-multiselect', plugins_url('dist/onoffice-multiselect.min.js', $pluginPath)); + wp_register_style('onoffice-multiselect', plugins_url('css/onoffice-multiselect.css', $pluginPath)); + wp_enqueue_script('onoffice-multiselect'); + wp_enqueue_style('onoffice-multiselect'); } /**