settings: person name format
This commit is contained in:
@@ -35,23 +35,17 @@ class Person extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
$this->setValue('lastName', $value);
|
||||
|
||||
$firstName = $this->get('firstName');
|
||||
if (empty($firstName)) {
|
||||
$this->setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $firstName . ' ' . $value);
|
||||
}
|
||||
$name = $this->getEntityManager()->getHelper()->formatPersonName($this, 'name');
|
||||
|
||||
$this->setValue('name', $name);
|
||||
}
|
||||
|
||||
public function _setFirstName($value)
|
||||
{
|
||||
$this->setValue('firstName', $value);
|
||||
|
||||
$lastName = $this->get('lastName');
|
||||
if (empty($lastName)) {
|
||||
$this->setValue('name', $value);
|
||||
} else {
|
||||
$this->setValue('name', $value . ' ' . $lastName);
|
||||
}
|
||||
$name = $this->getEntityManager()->getHelper()->formatPersonName($this, 'name');
|
||||
|
||||
$this->setValue('name', $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class EntityManager extends Base
|
||||
{
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
$params = array(
|
||||
$params = [
|
||||
'host' => $config->get('database.host'),
|
||||
'port' => $config->get('database.port'),
|
||||
'dbname' => $config->get('database.dbname'),
|
||||
@@ -50,15 +50,16 @@ class EntityManager extends Base
|
||||
'sslCert' => $config->get('database.sslCert'),
|
||||
'sslKey' => $config->get('database.sslKey'),
|
||||
'sslCAPath' => $config->get('database.sslCAPath'),
|
||||
'sslCipher' => $config->get('database.sslCipher')
|
||||
);
|
||||
'sslCipher' => $config->get('database.sslCipher'),
|
||||
];
|
||||
|
||||
$entityManager = new \Espo\Core\ORM\EntityManager($params);
|
||||
|
||||
$entityManager->setEspoMetadata($this->getContainer()->get('metadata'));
|
||||
$entityManager->setHookManager($this->getContainer()->get('hookManager'));
|
||||
$entityManager->setHelper($this->getContainer()->get('entityManagerHelper'));
|
||||
$entityManager->setContainer($this->getContainer());
|
||||
|
||||
return $entityManager;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,11 @@ class EntityManager extends \Espo\ORM\EntityManager
|
||||
|
||||
protected $container;
|
||||
|
||||
private $repositoryClassNameHash = array();
|
||||
private $repositoryClassNameHash = [];
|
||||
|
||||
private $entityClassNameHash = array();
|
||||
private $entityClassNameHash = [];
|
||||
|
||||
private $helper;
|
||||
|
||||
public function setContainer(\Espo\Core\Container $container)
|
||||
{
|
||||
@@ -108,5 +110,14 @@ class EntityManager extends \Espo\ORM\EntityManager
|
||||
}
|
||||
return $this->entityClassNameHash[$name];
|
||||
}
|
||||
}
|
||||
|
||||
public function setHelper(Helper $helper)
|
||||
{
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
public function getHelper()
|
||||
{
|
||||
return $this->helper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM;
|
||||
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Helper
|
||||
{
|
||||
protected $config;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function formatPersonName(Entity $entity, string $field)
|
||||
{
|
||||
$format = $this->config->get('personNameFormat');
|
||||
|
||||
$first = $entity->get('first' . ucfirst($field));
|
||||
$last = $entity->get('last' . ucfirst($field));
|
||||
|
||||
switch ($format) {
|
||||
case 'lastFirst':
|
||||
if (!$first && !$last) {
|
||||
return null;
|
||||
}
|
||||
if (!$first) {
|
||||
return $last;
|
||||
}
|
||||
if (!$last) {
|
||||
return $first;
|
||||
}
|
||||
return $last . ' ' . $first;
|
||||
|
||||
default:
|
||||
if (!$first && !$last) {
|
||||
return null;
|
||||
}
|
||||
if (!$first) {
|
||||
return $last;
|
||||
}
|
||||
if (!$last) {
|
||||
return $first;
|
||||
}
|
||||
return $first . ' ' . $last;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Core\Utils\Database\Orm;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
class Base
|
||||
{
|
||||
@@ -43,11 +44,14 @@ class Base
|
||||
|
||||
private $entityDefs;
|
||||
|
||||
public function __construct(\Espo\Core\Utils\Metadata $metadata, array $ormEntityDefs, array $entityDefs)
|
||||
protected $config;
|
||||
|
||||
public function __construct(\Espo\Core\Utils\Metadata $metadata, array $ormEntityDefs, array $entityDefs, Config $config)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
$this->ormEntityDefs = $ormEntityDefs;
|
||||
$this->entityDefs = $entityDefs;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
@@ -216,20 +220,28 @@ class Base
|
||||
return $returns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Foreign field
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $entityName
|
||||
* @return string
|
||||
*/
|
||||
protected function getForeignField($name, $entityName)
|
||||
protected function getForeignField(string $name, string $entityType)
|
||||
{
|
||||
$foreignField = $this->getMetadata()->get('entityDefs.'.$entityName.'.fields.'.$name);
|
||||
$foreignField = $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $name]);
|
||||
|
||||
if ($foreignField['type'] != 'varchar') {
|
||||
if ($foreignField['type'] == 'personName') {
|
||||
return array('first' . ucfirst($name), ' ', 'last' . ucfirst($name));
|
||||
$personNameFormat = $this->config->get('personNameFormat');
|
||||
|
||||
switch ($personNameFormat) {
|
||||
case 'lastFirst':
|
||||
return [
|
||||
'last' . ucfirst($name),
|
||||
' ',
|
||||
'first' . ucfirst($name),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'first' . ucfirst($name),
|
||||
' ',
|
||||
'last' . ucfirst($name),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,9 +250,6 @@ class Base
|
||||
|
||||
/**
|
||||
* Set a value for all elements of array. So, in result all elements will have the same values
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $array
|
||||
*/
|
||||
protected function setArrayValue($inputValue, array $array)
|
||||
{
|
||||
@@ -250,5 +259,4 @@ class Base
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ class Converter
|
||||
$this->fileManager = $fileManager; //need to featue with ormHooks. Ex. isFollowed field
|
||||
$this->config = $config;
|
||||
|
||||
$this->relationManager = new RelationManager($this->metadata);
|
||||
$this->relationManager = new RelationManager($this->metadata, $config);
|
||||
|
||||
$this->metadataHelper = new \Espo\Core\Utils\Metadata\Helper($this->metadata);
|
||||
$this->databaseHelper = new \Espo\Core\Utils\Database\Helper($this->config);
|
||||
@@ -346,12 +346,8 @@ class Converter
|
||||
|
||||
/**
|
||||
* Correct fields definitions based on \Espo\Custom\Core\Utils\Database\Orm\Fields
|
||||
*
|
||||
* @param array $ormMetadata
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function correctFields($entityName, array $ormMetadata)
|
||||
protected function correctFields($entityName, array $ormMetadata) : array
|
||||
{
|
||||
$entityDefs = $this->getEntityDefs();
|
||||
|
||||
@@ -367,7 +363,7 @@ class Converter
|
||||
}
|
||||
|
||||
if (class_exists($className) && method_exists($className, 'load')) {
|
||||
$helperClass = new $className($this->metadata, $ormMetadata, $entityDefs);
|
||||
$helperClass = new $className($this->metadata, $ormMetadata, $entityDefs, $this->config);
|
||||
$fieldResult = $helperClass->process($fieldName, $entityName);
|
||||
if (isset($fieldResult['unset'])) {
|
||||
$ormMetadata = Util::unsetInArray($ormMetadata, $fieldResult['unset']);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Fields;
|
||||
|
||||
class Base extends \Espo\Core\Utils\Database\Orm\Base
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -35,7 +35,16 @@ class PersonName extends Base
|
||||
{
|
||||
protected function load($fieldName, $entityName)
|
||||
{
|
||||
$subList = ['first' . ucfirst($fieldName), ' ', 'last' . ucfirst($fieldName)];
|
||||
$format = $this->config->get('personNameFormat');
|
||||
|
||||
switch ($format) {
|
||||
case 'lastFirst':
|
||||
$subList = ['last' . ucfirst($fieldName), ' ', 'first' . ucfirst($fieldName)];
|
||||
break;
|
||||
|
||||
default:
|
||||
$subList = ['first' . ucfirst($fieldName), ' ', 'last' . ucfirst($fieldName)];
|
||||
}
|
||||
|
||||
$tableName = Util::toUnderScore($entityName);
|
||||
|
||||
|
||||
@@ -30,14 +30,17 @@
|
||||
namespace Espo\Core\Utils\Database\Orm;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Config;
|
||||
|
||||
class RelationManager
|
||||
{
|
||||
private $metadata;
|
||||
|
||||
public function __construct(\Espo\Core\Utils\Metadata $metadata)
|
||||
public function __construct(Metadata $metadata, Config $config)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
@@ -132,7 +135,7 @@ class RelationManager
|
||||
}
|
||||
|
||||
if (isset($className) && $className !== false) {
|
||||
$helperClass = new $className($this->metadata, $ormMetadata, $entityDefs);
|
||||
$helperClass = new $className($this->metadata, $ormMetadata, $entityDefs, $this->config);
|
||||
return $helperClass->process($linkName, $entityName, $foreignLink['name'], $foreignEntityName);
|
||||
}
|
||||
//END: relationDefs defined in separate file
|
||||
|
||||
@@ -179,5 +179,6 @@ return [
|
||||
'emailForceUseExternalClient' => false,
|
||||
'useWebSocket' => false,
|
||||
'auth2FAMethodList' => ['Totp'],
|
||||
'personNameFormat' => 'firstLast',
|
||||
'isInstalled' => false,
|
||||
];
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
"siteUrl": "Site URL",
|
||||
"addressPreview": "Address Preview",
|
||||
"addressFormat": "Address Format",
|
||||
"personNameFormat": "Person Name Format",
|
||||
"notificationSoundsDisabled": "Disable Notification Sounds",
|
||||
"applicationName": "Application Name",
|
||||
"calendarEntityList": "Calendar Entity List",
|
||||
@@ -138,6 +139,10 @@
|
||||
"1": "10 USD",
|
||||
"2": "$10"
|
||||
},
|
||||
"personNameFormat": {
|
||||
"firstLast": "First Last",
|
||||
"lastFirst": "Last First"
|
||||
},
|
||||
"streamEmailNotificationsTypeList": {
|
||||
"Post": "Posts",
|
||||
"Status": "Status updates",
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
[{"name": "language"}, {"name": "timeZone"}],
|
||||
[{"name": "dateFormat"}, {"name": "weekStart"}],
|
||||
[{"name": "timeFormat"}, {"name": "thousandSeparator"}],
|
||||
[{"name": "fiscalYearShift"}, {"name": "decimalMark"}],
|
||||
[{"name": "fiscalYearShift"}, {"name": "decimalMark"}],
|
||||
[{"name": "personNameFormat"}, false],
|
||||
[{"name": "addressFormat"}, {"name": "addressPreview"}],
|
||||
[{"name": "addressCountryList"}, {"name": "addressCityList"}],
|
||||
[{"name": "addressStateList"}, false]
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
"clientManager": {
|
||||
"className": "\\Espo\\Core\\Utils\\ClientManager",
|
||||
"dependencyList": ["config", "themeManager", "metadata"]
|
||||
},
|
||||
"entityManagerHelper": {
|
||||
"className": "\\Espo\\Core\\ORM\\Helper",
|
||||
"dependencyList": ["config"]
|
||||
}
|
||||
}
|
||||
@@ -453,6 +453,10 @@
|
||||
"readOnly": true,
|
||||
"view": "views/settings/fields/address-preview"
|
||||
},
|
||||
"personNameFormat": {
|
||||
"type": "enum",
|
||||
"options": ["firstLast", "lastFirst"]
|
||||
},
|
||||
"currencyFormat": {
|
||||
"type": "enumInt",
|
||||
"options": [1, 2]
|
||||
|
||||
@@ -197,8 +197,6 @@ class Settings extends \Espo\Core\Services\Base
|
||||
|
||||
if (
|
||||
(isset($data->useCache) && $data->useCache !== $this->getConfig()->get('useCache'))
|
||||
||
|
||||
(isset($data->aclStrictMode) && $data->aclStrictMode !== $this->getConfig()->get('aclStrictMode'))
|
||||
) {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
}
|
||||
@@ -211,6 +209,10 @@ class Settings extends \Espo\Core\Services\Base
|
||||
throw new Error('Cannot save settings');
|
||||
}
|
||||
|
||||
if (isset($data->personNameFormat)) {
|
||||
$this->getContainer()->get('dataManager')->clearCache();
|
||||
}
|
||||
|
||||
if (isset($data->defaultCurrency) || isset($data->baseCurrency) || isset($data->currencyRates)) {
|
||||
$this->getContainer()->get('dataManager')->rebuildDatabase([]);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
{{#if isNotEmpty}}{{translateOption salutationValue field='salutationName' scope=scope}} {{firstValue}} {{lastValue}}{{else}}
|
||||
{{#if isNotEmpty}}{{formattedValue}}
|
||||
{{else}}
|
||||
{{#if valueIsSet}}{{{translate 'None'}}}{{else}}...{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-3 col-xs-3">
|
||||
<select data-name="salutation{{ucName}}" class="form-control">
|
||||
{{options salutationOptions salutationValue field='salutationName' scope=scope}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-sm-5 col-xs-5">
|
||||
<input type="text" class="form-control" data-name="last{{ucName}}" value="{{lastValue}}" placeholder="{{translate 'Last Name'}}"{{#if lastMaxLength}} maxlength="{{lastMaxLength}}"{{/if}} autocomplete="espo-last{{ucName}}">
|
||||
</div>
|
||||
<div class="col-sm-4 col-xs-4">
|
||||
<input type="text" class="form-control" data-name="first{{ucName}}" value="{{firstValue}}" placeholder="{{translate 'First Name'}}"{{#if firstMaxLength}} maxlength="{{firstMaxLength}}"{{/if}} autocomplete="espo-first{{ucName}}">
|
||||
</div>
|
||||
</div>
|
||||
@@ -26,7 +26,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/fields/person-name', 'views/fields/varchar', function (Dep) {
|
||||
define('views/fields/person-name', 'views/fields/varchar', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
@@ -36,6 +36,8 @@ Espo.define('views/fields/person-name', 'views/fields/varchar', function (Dep) {
|
||||
|
||||
editTemplate: 'fields/person-name/edit',
|
||||
|
||||
editTemplateLastFirst: 'fields/person-name/edit-last-first',
|
||||
|
||||
data: function () {
|
||||
var data = Dep.prototype.data.call(this);
|
||||
data.ucName = Espo.Utils.upperCaseFirst(this.name);
|
||||
@@ -53,6 +55,11 @@ Espo.define('views/fields/person-name', 'views/fields/varchar', function (Dep) {
|
||||
} else if (this.mode === 'list' || this.mode === 'listLink') {
|
||||
data.isNotEmpty = !!data.firstValue || !!data.lastValue;
|
||||
}
|
||||
|
||||
if (data.isNotEmpty && this.mode == 'detail' || this.mode == 'list' || this.mode === 'listLink') {
|
||||
data.formattedValue = this.getFormattedValue();
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -83,6 +90,51 @@ Espo.define('views/fields/person-name', 'views/fields/varchar', function (Dep) {
|
||||
}
|
||||
},
|
||||
|
||||
getFormattedValue: function () {
|
||||
var salutation = this.model.get(this.salutationField);
|
||||
var first = this.model.get(this.firstField);
|
||||
var last = this.model.get(this.lastField);
|
||||
|
||||
if (salutation) {
|
||||
salutation = this.getLanguage().translateOption(salutation, 'salutationName', this.model.entityType);
|
||||
}
|
||||
|
||||
var value = '';
|
||||
|
||||
var format = this.getFormat();
|
||||
|
||||
switch (format) {
|
||||
case 'lastFirst':
|
||||
if (salutation) value += salutation;
|
||||
if (last) value += ' ' + last;
|
||||
if (first) value += ' ' + first;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (salutation) value += salutation;
|
||||
if (first) value += ' ' + first;
|
||||
if (last) value += ' ' + last;
|
||||
}
|
||||
|
||||
value = value.trim();
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
_getTemplateName: function () {
|
||||
if (this.mode == 'edit') {
|
||||
var prop = 'editTemplate' + Espo.Utils.upperCaseFirst(this.getFormat().toString());
|
||||
if (prop in this) {
|
||||
return this[prop];
|
||||
}
|
||||
}
|
||||
return Dep.prototype._getTemplateName.call(this);
|
||||
},
|
||||
|
||||
getFormat: function () {
|
||||
return this.getConfig().get('personNameFormat') || 'firstLast';
|
||||
},
|
||||
|
||||
validateRequired: function () {
|
||||
var isRequired = this.isRequired();
|
||||
|
||||
@@ -124,6 +176,6 @@ Espo.define('views/fields/person-name', 'views/fields/varchar', function (Dep) {
|
||||
data[this.firstField] = this.$first.val().trim();
|
||||
data[this.lastField] = this.$last.val().trim();
|
||||
return data;
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user