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

53258 Custom Labels for Address Lists and Address List Detail Page in the onOffice for WP Plugin #913

Merged
18 changes: 10 additions & 8 deletions css/onoffice-address-detail.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
.oo-address-fieldlist {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.oo-address-placefieldlist {
.oo-address-field {
display: flex;
flex-direction: column;
flex-wrap: wrap;
font-size: 1rem;
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}
.oo-address-placefield {
font-size: 1rem;
.oo-address-field-label {
margin-right: 0.5rem;
font-weight: bold;
word-break: break-word;
}
.oo-address-field {
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;
Expand Down
46 changes: 43 additions & 3 deletions plugin/AddressList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -139,6 +141,10 @@ class AddressList

/** @var array */
private $_countEstates = [];

/** @var FieldsCollection */
private $_pFieldsCollection = [];

/**
*
* @param DataViewAddress $pDataViewAddress
Expand Down Expand Up @@ -185,6 +191,7 @@ public function loadAddressesById(array $addressIds, array $fields)
$this->_pDataViewAddress->setFields($fields);

$this->addRawRecordsByAPICall(clone $this->_pApiClientAction, $parametersRaw);
$this->buildFieldsCollectionForAddressCustomLabel();
}

/**
Expand Down Expand Up @@ -227,6 +234,7 @@ public function loadAddresses(int $inputPage = 1)
$multipage = $numpages > 1;
$more = true;
$page = $newPage;
$this->buildFieldsCollectionForAddressCustomLabel();
}

/**
Expand Down Expand Up @@ -404,10 +412,27 @@ 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
{
$label = $this->_pEnvironment->getFieldnames()
->getFieldLabel($field, onOfficeSDK::MODULE_ADDRESS);
$recordType = onOfficeSDK::MODULE_ADDRESS;

try {
$label = $this->_pFieldsCollection->getFieldByModuleAndName($recordType, $field)->getLabel();
} catch (UnknownFieldException $pE) {
$label = $this->_pEnvironment->getFieldnames()->getFieldLabel($field, $recordType);
}
if ($this->_pDataViewAddress instanceof DataAddressDetailView) {
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 ];
}
}

return $raw ? $label : esc_html($label);
}

Expand All @@ -424,6 +449,20 @@ public function getFieldType($field): string
return $fieldInformation['type'];
}

/**
*
*/
private function buildFieldsCollectionForAddressCustomLabel()
{
$this->_pFieldsCollection = new FieldsCollection();
$pFieldBuilderShort = $this->_pEnvironment->getFieldsCollectionBuilderShort();
$pFieldBuilderShort->addFieldsAddressEstate($this->_pFieldsCollection);

if ($this->_pDataViewAddress instanceof DataListViewAddress && !empty($this->_pDataViewAddress->getName())) {
$pFieldBuilderShort->addCustomLabelFieldsAddressFrontend($this->_pFieldsCollection, $this->_pDataViewAddress->getName());
}
}

/**
* @return string[] An array of visible fields
* @throws Field\UnknownFieldException
Expand All @@ -448,6 +487,7 @@ public function getVisibleFilterableFields(): array
->getAsRow();
$result[$field]['name'] = $field;
$result[$field]['value'] = $value;
$result[$field]['label'] = $this->getFieldLabel($field);
}
return $result;
}
Expand Down
18 changes: 18 additions & 0 deletions plugin/Field/Collection/FieldsCollectionBuilderShort.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorCustomLabelEstate;
use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorGeoPositionBackend;
use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorReadAddress;
use onOffice\WPlugin\Field\FieldModuleCollectionDecoratorCustomLabelAddress;


/**
Expand Down Expand Up @@ -341,4 +342,21 @@ 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, string $formName): self
{
$pFieldsCollectionTmp = new FieldModuleCollectionDecoratorCustomLabelAddress($pFieldsCollection, $formName);
$pFieldsCollection->merge($pFieldsCollectionTmp);
return $this;
}
}
133 changes: 133 additions & 0 deletions plugin/Field/FieldModuleCollectionDecoratorCustomLabelAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

/**
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

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-2024, onOffice(R) GmbH
*
*/
class FieldModuleCollectionDecoratorCustomLabelAddress
extends FieldModuleCollectionDecoratorAbstract
{
/** @var Container */
private $_pContainer;

/** @var array */
private $_fieldCustomLabels = [];

/**
* @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();
$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;
}

}
10 changes: 5 additions & 5 deletions plugin/Gui/AdminPageAddressDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +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');
$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);
Expand Down
Loading
Loading