mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 15:06:06 +00:00
Number field type
This commit is contained in:
@@ -6,11 +6,56 @@ class NumberType extends Base
|
||||
{
|
||||
public function onRead($scope, $name, &$defs)
|
||||
{
|
||||
$defs['nextNumber'] = 2;
|
||||
$number = $this->getEntityManager()->getRepository('NextNumber')->where(array(
|
||||
'entityType' => $scope,
|
||||
'fieldName' => $name
|
||||
))->findOne();
|
||||
|
||||
$value = null;
|
||||
if (!$number) {
|
||||
$value = 1;
|
||||
} else {
|
||||
if (!$number->get('value')) {
|
||||
$value = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$value && $number) {
|
||||
$value = $number->get('value');
|
||||
}
|
||||
|
||||
$defs['nextNumber'] = $value;
|
||||
}
|
||||
|
||||
public function afterSave($scope, $name, $defs)
|
||||
{
|
||||
if (!isset($defs['nextNumber'])) return;
|
||||
|
||||
$number = $this->getEntityManager()->getRepository('NextNumber')->where(array(
|
||||
'entityType' => $scope,
|
||||
'fieldName' => $name
|
||||
))->findOne();
|
||||
|
||||
if (!$number) {
|
||||
$number = $this->getEntityManager()->getEntity('NextNumber');
|
||||
|
||||
$number->set('entityType', $scope);
|
||||
$number->set('fieldName', $name);
|
||||
}
|
||||
|
||||
$number->set('value', $defs['nextNumber']);
|
||||
$this->getEntityManager()->saveEntity($number);
|
||||
}
|
||||
|
||||
public function afterRemove($scope, $name)
|
||||
{
|
||||
$number = $this->getEntityManager()->getRepository('NextNumber')->where(array(
|
||||
'entityType' => $scope,
|
||||
'fieldName' => $name
|
||||
))->findOne();
|
||||
|
||||
if (!$number) return;
|
||||
|
||||
$this->getEntityManager()->removeEntity($number);
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ class Manager
|
||||
public function unsetContents($path, $unsets, $isJSON = true)
|
||||
{
|
||||
$currentData = $this->getContents($path);
|
||||
if ($currentData == false) {
|
||||
if (!isset($currentData) || !$currentData) {
|
||||
$GLOBALS['log']->notice('FileManager::unsetContents: File ['.$this->concatPaths($path).'] does not exist.');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -394,11 +394,18 @@ class Util
|
||||
$unsets = (array) $unsets;
|
||||
}
|
||||
|
||||
foreach($unsets as $rootKey => $unsetItem){
|
||||
if (!isset($content)) {
|
||||
$e = new \Exception;
|
||||
var_dump($e->getTraceAsString());
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
foreach ($unsets as $rootKey => $unsetItem) {
|
||||
$unsetItem = is_array($unsetItem) ? $unsetItem : (array) $unsetItem;
|
||||
|
||||
foreach($unsetItem as $unsetSett){
|
||||
if (!empty($unsetSett)){
|
||||
foreach ($unsetItem as $unsetSett) {
|
||||
if (!empty($unsetSett)) {
|
||||
$keyItems = explode('.', $unsetSett);
|
||||
$currVal = isset($content[$rootKey]) ? "\$content['{$rootKey}']" : "\$content";
|
||||
|
||||
|
||||
35
application/Espo/Entities/NextNumber.php
Normal file
35
application/Espo/Entities/NextNumber.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://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\Entities;
|
||||
|
||||
class NextNumber extends \Espo\Core\ORM\Entity
|
||||
{
|
||||
|
||||
}
|
||||
104
application/Espo/Hooks/Common/NextNumber.php
Normal file
104
application/Espo/Hooks/Common/NextNumber.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://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\Hooks\Common;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Core\Utils\Util;
|
||||
|
||||
class NextNumber extends \Espo\Core\Hooks\Base
|
||||
{
|
||||
public static $order = 10;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->addDependency('metadata');
|
||||
}
|
||||
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
}
|
||||
|
||||
protected function composeNumberAttribute(Entity $nextNumber)
|
||||
{
|
||||
$entityType = $nextNumber->get('entityType');
|
||||
$fieldName = $nextNumber->get('fieldName');
|
||||
$value = $nextNumber->get('value');
|
||||
|
||||
$prefix = $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $fieldName, 'prefix'], '');
|
||||
$padLength = $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $fieldName, 'padLength'], 0);
|
||||
|
||||
return $prefix . str_pad(strval($value), $padLength, '0', \STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function beforeSave(Entity $entity, array $options = array())
|
||||
{
|
||||
$fieldDefs = $this->getMetadata()->get(['entityDefs', $entity->getEntityType(), 'fields'], array());
|
||||
|
||||
foreach ($fieldDefs as $fieldName => $defs) {
|
||||
if (isset($defs['type']) && $defs['type'] === 'number') {
|
||||
$nextNumber = $this->getEntityManager()->getRepository('NextNumber')->where(array(
|
||||
'fieldName' => $fieldName,
|
||||
'entityType' => $entity->getEntityType()
|
||||
))->findOne();
|
||||
if (!$nextNumber) continue;
|
||||
$entity->set($fieldName, $this->composeNumberAttribute($nextNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function afterSave(Entity $entity, array $options = array())
|
||||
{
|
||||
$fieldDefs = $this->getMetadata()->get(['entityDefs', $entity->getEntityType(), 'fields'], array());
|
||||
|
||||
foreach ($fieldDefs as $fieldName => $defs) {
|
||||
if (isset($defs['type']) && $defs['type'] === 'number') {
|
||||
$nextNumber = $this->getEntityManager()->getRepository('NextNumber')->where(array(
|
||||
'fieldName' => $fieldName,
|
||||
'entityType' => $entity->getEntityType()
|
||||
))->findOne();
|
||||
if (!$nextNumber) continue;
|
||||
|
||||
$value = $nextNumber->get('value');
|
||||
if (!$value) {
|
||||
$value = 1;
|
||||
}
|
||||
$value++;
|
||||
|
||||
$nextNumber->set('value', $value);
|
||||
$this->getEntityManager()->saveEntity($nextNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"fields": {
|
||||
"entityType": {
|
||||
"type": "varchar",
|
||||
"index": true
|
||||
},
|
||||
"fieldName": {
|
||||
"type": "varchar"
|
||||
},
|
||||
"value": {
|
||||
"type": "int",
|
||||
"default": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
46
client/src/views/fields/number.js
Normal file
46
client/src/views/fields/number.js
Normal file
@@ -0,0 +1,46 @@
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2015 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://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.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/fields/number', 'views/fields/varchar', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
type: 'number',
|
||||
|
||||
validations: [],
|
||||
|
||||
inlineEditDisabled: true,
|
||||
|
||||
readOnly: true,
|
||||
|
||||
fetch: function () {
|
||||
return {};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user