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

40398 missing field types #653

Merged
merged 23 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -568,4 +568,19 @@ body #post-body-content p.wp-clearfix:nth-child(1){

.oo-poststuff .key-of-field-block {
display: flex;
}

.oo-poststuff .custom-input-field .onoffice-input-radio {
border-radius: 4px;
width: 50%;
display: grid;
float: left;
justify-content: initial;
border: 1px solid #8c8f94;
}

.oo-poststuff .custom-input-field .onoffice-input-radio label {
display: flex;
justify-content: space-between;
margin: 10px;
}
2 changes: 1 addition & 1 deletion dist/onoffice-default-form-values.min.js

Large diffs are not rendered by default.

56 changes: 55 additions & 1 deletion js/onoffice-default-form-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,47 @@ onOffice.default_values_input_converter = function () {
onOffice.default_values_inputs_converted.push(fieldName);
var fieldDefinition = getFieldDefinition(fieldName);

if (fieldDefinition.type === "urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint") {
const parent = mainInput;
const element = document.createElement('fieldset');
const keys = Object.keys(fieldDefinition.permittedvalues).sort();
parent.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']';

element.className = 'onoffice-input-radio';
keys.forEach(k => {
const mainInputClone = parent.cloneNode(true);
const label = document.createElement('label');
onOffice.js_field_count += 1;
mainInputClone.id = 'input_radio_js_' + onOffice.js_field_count;
mainInputClone.value = k;
label.textContent = fieldDefinition.permittedvalues[k];
if (k == onOffice_loc_settings.defaultvalues[fieldName]) {
mainInputClone.checked = true;
}
label.appendChild(mainInputClone);
element.appendChild(label);
parent.parentElement.appendChild(element);
});
const labels = parent.parentElement.getElementsByTagName('label')[1];
parent.parentElement.removeChild(labels);
mainInput.remove();
return;
}

if (!fieldDefinition.rangefield &&
[
'integer', 'float', 'date', 'datetime',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:float',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:int',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:integer',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal'
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:decimal',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date',
'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint'
].indexOf(fieldDefinition.type) >= 0) {
if (fieldDefinition.type === 'date' || fieldDefinition.type === 'datetime') {
mainInput.setAttribute('type', 'text');
} else if (fieldDefinition.type === 'urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:date') {
mainInput.setAttribute('type', 'date');
}
mainInput.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']';
mainInput.value = predefinedValues[fieldName][0] || '';
Expand Down Expand Up @@ -286,6 +317,29 @@ document.addEventListener("addFieldItem", function(e) {
onOffice.js_field_count += 1;
select.options.selectedIndex = 0;
element.parentNode.replaceChild(select, element);
} else if (['urn:onoffice-de-ns:smart:2.5:dbAccess:dataType:tinyint'].indexOf(fieldDefinition.type) >= 0) {
const element = e.detail.item.querySelector('input[name^=oopluginfieldconfigformdefaultsvalues-value]');
const fieldset = document.createElement('fieldset');
const keys = Object.keys(fieldDefinition.permittedvalues).sort();
fieldset.className = 'onoffice-input-radio';
keys.forEach(function (k) {
const label = document.createElement('label');
const input = document.createElement('input');
input.name = 'oopluginfieldconfigformdefaultsvalues-value[' + fieldName + ']';
input.type = 'radio';
input.value = k;
input.className = 'onoffice-input';
onOffice.js_field_count += 1;
label.htmlFor = 'input_radio_js_' + onOffice.js_field_count;
label.textContent = fieldDefinition.permittedvalues[k];
if(k == onOffice_loc_settings.defaultvalues[fieldName]){
input.checked = true;
}
label.appendChild(input);
fieldset.appendChild(label);
});

element.parentNode.replaceChild(fieldset, element);
}

var paragraph = e.detail.item.querySelectorAll('.menu-item-settings p')[2];
Expand Down
117 changes: 117 additions & 0 deletions plugin/Field/Collection/FieldLoaderSupervisorValues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

namespace onOffice\WPlugin\Field\Collection;

use Generator;
use onOffice\SDK\onOfficeSDK;
use onOffice\WPlugin\API\APIClientActionGeneric;
use onOffice\WPlugin\API\ApiClientException;
use onOffice\WPlugin\Language;
use onOffice\WPlugin\SDKWrapper;
use onOffice\WPlugin\Types\FieldTypes;

class FieldLoaderSupervisorValues implements FieldLoader
{
/** @var SDKWrapper */
private $_pSDKWrapper;

public function __construct(SDKWrapper $_pSDKWrapper)
{
$this->_pSDKWrapper = $_pSDKWrapper;
}

/**
* @throws ApiClientException
*/
public function load(): Generator
{
$fullNameSupervisor = $this->getFullNameSupervisor();
$supervisorElementsRecord = $this->getSupervisorField();

if (empty($supervisorElementsRecord)) {
return;
}

foreach ($supervisorElementsRecord as $fieldName => $fieldProperties) {
if ($fieldName === 'benutzer') {
$fieldProperties['type'] = FieldTypes::FIELD_TYPE_SINGLESELECT;
$fieldProperties['module'] = onOfficeSDK::MODULE_SEARCHCRITERIA;
$fieldProperties['permittedvalues'] = $fullNameSupervisor;
$fieldProperties['content'] = __('Search Criteria', 'onoffice-for-wp-websites');
yield $fieldName => $fieldProperties;
}
}
}


/**
* @return array
* @throws ApiClientException
*/
private function getSupervisorField(): array
{
$parametersGetFieldList = [
'labels' => true,
'showContent' => true,
'showTable' => true,
'fieldList' => ['benutzer'],
'language' => Language::getDefault(),
'modules' => [onOfficeSDK::MODULE_ESTATE],
'realDataTypes' => true
];

$pApiClientActionFields = new APIClientActionGeneric
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'fields');
$pApiClientActionFields->setParameters($parametersGetFieldList);
$pApiClientActionFields->addRequestToQueue()->sendRequests();
$result = $pApiClientActionFields->getResultRecords();

if (empty($result[0]['elements'])) {
return [];
}

return $result[0]['elements'];
}

/**
* @return array
* @throws ApiClientException
*/
private function getFullNameSupervisor(): array
{
$pApiClientAction = new APIClientActionGeneric
($this->_pSDKWrapper, onOfficeSDK::ACTION_ID_GET, 'users');

$pApiClientAction->addRequestToQueue();
$this->_pSDKWrapper->sendRequests();
$result = $pApiClientAction->getResultRecords();
$fullNameSupervisor = [];

if (empty($result)) {
return [];
}

foreach ($result as $value) {
$fullName = '';
$firstName = $value['elements']['firstname'];
$lastName = $value['elements']['lastname'];
$userName = $value['elements']['username'];

if (!empty($firstName) && !empty($lastName)) {
$fullName = $lastName . ', ' . $firstName;
} else {
if (!empty($firstName) && empty($lastName)) {
$fullName = $firstName;
} elseif (empty($firstName) && !empty($lastName)) {
$fullName = $lastName;
} else {
$fullName = '(' .$userName . ')';
}
}

$fullNameSupervisor[$value['elements']['id']] = $fullName;
}

return $fullNameSupervisor;
}
}
18 changes: 18 additions & 0 deletions plugin/Field/Collection/FieldsCollectionBuilderShort.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,22 @@ public function addFieldsEstateGeoPositionFrontend(FieldsCollection $pFieldsColl
$pFieldsCollection->merge($pFieldsCollectionTmp);
return $this;
}

/**
* @param FieldsCollection $pFieldsCollection
* @return $this
* @throws DependencyException
* @throws NotFoundException
*/
public function addFieldSupervisorForSearchCriteria(FieldsCollection $pFieldsCollection): self
{
if (!$pFieldsCollection->containsFieldByModule(onOfficeSDK::MODULE_SEARCHCRITERIA, 'benutzer')) {
return $this;
};
$pFieldLoader = $this->_pContainer->get(FieldLoaderSupervisorValues::class);
$pFieldCollectionSupervisor = $this->_pContainer->get(FieldsCollectionBuilder::class)
->buildFieldsCollection($pFieldLoader);
$pFieldsCollection->merge($pFieldCollectionSupervisor);
return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function getConvertedMultiFields(int $formId, array $pFields): array
case FieldTypes::isDateOrDateTime($pField->getType()):
case FieldTypes::isNumericType($pField->getType()):
case $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE:
$pDataModel = $this->convertGeneric($formId, $pField, $rowData);
$pDataModels[ $pField->getName() ] = $pDataModel[0] ?? '';
break;
Expand Down Expand Up @@ -139,6 +141,8 @@ public function getConvertedMultiFieldsForAdmin(int $formId, array $pFields): ar
case FieldTypes::isDateOrDateTime($pField->getType()):
case FieldTypes::isNumericType($pField->getType()):
case $pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT:
case $pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE:
$pDataModel = $this->convertGeneric($formId, $pField, $rowData);
break;
case $pField->getType() === FieldTypes::FIELD_TYPE_MULTISELECT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ private function saveForFoundType(int $formId, Field $pField, $values)
{
$isSingleValue = FieldTypes::isDateOrDateTime($pField->getType()) ||
FieldTypes::isNumericType($pField->getType()) ||
$pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT;
$pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT ||
$pField->getType() === FieldTypes::FIELD_TYPE_SINGLESELECT ||
$pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_DATE;
$isMultiSelect = $pField->getType() === FieldTypes::FIELD_TYPE_MULTISELECT;
$isBoolean = $pField->getType() === FieldTypes::FIELD_TYPE_BOOLEAN;
$isStringType = FieldTypes::isStringType($pField->getType());
Expand Down
6 changes: 5 additions & 1 deletion plugin/Field/OutputFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public function getVisibleFilterableFields(

$allFields = array_merge($fieldsArray, array_keys($geoFields));
$valuesDefault = array_map(function($field) use ($geoFields, $pInputVariableReader) {
return $pInputVariableReader->getFieldValueFormatted($field) ?: $geoFields[$field] ?? null;
$fieldValue = $pInputVariableReader->getFieldValueFormatted($field);
if ($fieldValue === false) {
return false;
}
return $fieldValue ?: $geoFields[$field] ?? null;
}, $allFields);

$resultDefault = array_combine($allFields, $valuesDefault);
Expand Down
14 changes: 13 additions & 1 deletion plugin/Field/SearchcriteriaFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public function getFieldLabelsOfInputs(array $inputFormFields, array $listDataIn
$pFieldsCollection = new FieldsCollection();
$this->_pFieldsCollectionBuilder
->addFieldsSearchCriteria($pFieldsCollection)
->addFieldsAddressEstate($pFieldsCollection);
->addFieldsAddressEstate($pFieldsCollection)
->addFieldSupervisorForSearchCriteria($pFieldsCollection);

$pGeoFieldsCollection = new FieldModuleCollectionDecoratorGeoPositionFrontend(new FieldsCollection);
$pFieldsCollection->merge($pGeoFieldsCollection);
Expand All @@ -116,6 +117,9 @@ public function getFieldLabelsOfInputs(array $inputFormFields, array $listDataIn
$aliasedFieldName = $geoRangeFields[$name];
}
$module = onOfficeSDK::MODULE_ESTATE;
if ($name === 'benutzer') {
$module = onOfficeSDK::MODULE_SEARCHCRITERIA;
}
$pField = $pFieldsCollection->getFieldByModuleAndName($module, $aliasedFieldName);
if ($name === 'regionaler_zusatz') {
$pField = $pFieldsCollection->getFieldByModuleAndName($listDataInputs[$name], $aliasedFieldName);
Expand All @@ -141,6 +145,14 @@ public function getFieldLabelsOfInputs(array $inputFormFields, array $listDataIn
else {
$output[$pField->getLabel()] = (array_key_exists($value, $pField->getPermittedvalues()) ? $pField->getPermittedvalues()[$value] : $value);
}
} elseif (FieldTypes::FIELD_TYPE_DATATYPE_TINYINT === $pField->getType() || FieldTypes::FIELD_TYPE_BOOLEAN === $pField->getType()) {
if ($value === '') {
$output[$pField->getLabel()] = __('Not Special', 'onoffice-for-wp-websites');
} elseif ($value === '0') {
$output[$pField->getLabel()] = __('No', 'onoffice-for-wp-websites');
} elseif ($value === '1') {
$output[$pField->getLabel()] = __('Yes', 'onoffice-for-wp-websites');
}
} else {
$output[$pField->getLabel()] = $value;
}
Expand Down
9 changes: 8 additions & 1 deletion plugin/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public function __construct(string $formName, string $type, Container $pContaine
->addCustomLabelFieldsFormFrontend($pFieldsCollection, $formName)
->addFieldsAddressEstateWithRegionValues($pFieldsCollection);

if ($type === self::TYPE_INTEREST || $type === self::TYPE_APPLICANT_SEARCH) {
$pFieldBuilderShort->addFieldSupervisorForSearchCriteria($pFieldsCollection);
}

$pFormPost = FormPostHandler::getInstance($type);
FormPost::incrementFormNo();
$this->_formNo = $pFormPost->getFormNo();
Expand Down Expand Up @@ -559,7 +563,10 @@ private function getDefaultValues(): array
$pDefaultFields = $pDefaultValueRead->getConvertedMultiFields($formId, $fields);
if (count($pDefaultFields)) $values = array_merge($values, $pDefaultFields);
}
return array_filter($values);

return array_filter($values, function($value) {
return ($value === "0" || !empty($value));
});
}

/**
Expand Down
9 changes: 8 additions & 1 deletion plugin/Gui/AdminPageFormSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ private function getFieldList(): array
'0' => __('No', 'onoffice-for-wp-websites'),
'1' => __('Yes', 'onoffice-for-wp-websites'),
];
} elseif ($pField->getType() === FieldTypes::FIELD_TYPE_DATATYPE_TINYINT) {
$result[ $pField->getModule() ][ $pField->getName() ]['permittedvalues'] = [
'' => __('Not Specified', 'onoffice-for-wp-websites'),
'0' => __('No', 'onoffice-for-wp-websites'),
'1' => __('Yes', 'onoffice-for-wp-websites'),
];
}
}
return $result;
Expand Down Expand Up @@ -511,7 +517,8 @@ private function buildFieldsCollectionForCurrentForm(): FieldsCollection
if (in_array(onOfficeSDK::MODULE_SEARCHCRITERIA, $modules)) {
$pFieldsCollectionBuilder
->addFieldsSearchCriteria($pDefaultFieldsCollection)
->addFieldsSearchCriteriaSpecificBackend($pDefaultFieldsCollection);
->addFieldsSearchCriteriaSpecificBackend($pDefaultFieldsCollection)
->addFieldSupervisorForSearchCriteria($pDefaultFieldsCollection);
}

$pFieldsCollectionBuilder->addFieldsFormBackend($pDefaultFieldsCollection,$this->getType());
Expand Down
5 changes: 5 additions & 0 deletions plugin/Model/FormModelBuilder/FormModelBuilderDBForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ private function getFieldsCollection(): FieldsCollection
->addFieldsAddressEstate($pFieldsCollection)
->addFieldsSearchCriteria($pFieldsCollection)
->addFieldsFormBackend($pFieldsCollection,$this->getFormType());

if ($this->getFormType() === Form::TYPE_INTEREST || $this->getFormType() === Form::TYPE_APPLICANT_SEARCH) {
$pFieldsCollectionBuilder->addFieldSupervisorForSearchCriteria($pFieldsCollection);
}

return $pFieldsCollection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class InputModelBuilderDefaultValue
FieldTypes::FIELD_TYPE_MULTISELECT => InputModelOption::HTML_TYPE_SELECT,
FieldTypes::FIELD_TYPE_SINGLESELECT => InputModelOption::HTML_TYPE_SELECT,
FieldTypes::FIELD_TYPE_BOOLEAN => InputModelOption::HTML_TYPE_SELECT,
FieldTypes::FIELD_TYPE_DATATYPE_TINYINT => InputModelOption::HTML_TYPE_RADIO
];


Expand Down
Loading
Loading