link multiple maxCount

This commit is contained in:
Yuri Kuznetsov
2024-04-20 20:50:03 +03:00
parent b604501eba
commit a081237b2e
5 changed files with 117 additions and 19 deletions
@@ -36,20 +36,17 @@ use Espo\Core\ORM\Entity as CoreEntity;
use stdClass;
/**
* @noinspection PhpUnused
*/
class LinkMultipleType
{
private Metadata $metadata;
private Defs $defs;
private const COLUMN_TYPE_ENUM = 'enum';
private const COLUMN_TYPE_VARCHAR = 'varchar';
private const COLUMN_TYPE_BOOL = 'bool';
public function __construct(Metadata $metadata, Defs $defs)
{
$this->metadata = $metadata;
$this->defs = $defs;
}
public function __construct(private Metadata $metadata, private Defs $defs)
{}
public function checkRequired(Entity $entity, string $field): bool
{
@@ -63,6 +60,7 @@ class LinkMultipleType
return count($idList) > 0;
}
/** @noinspection PhpUnused */
public function checkPattern(Entity $entity, string $field): bool
{
/** @var ?mixed[] $idList */
@@ -93,6 +91,27 @@ class LinkMultipleType
return true;
}
/** @noinspection PhpUnused */
public function checkMaxCount(Entity $entity, string $field, ?int $maxCount): bool
{
if ($maxCount === null) {
return true;
}
$list = $entity->get($field . 'Ids');
if (!is_array($list)) {
return true;
}
if (count($list) > $maxCount) {
return false;
}
return true;
}
/** @noinspection PhpUnused */
public function checkColumnsValid(Entity $entity, string $field): bool
{
if (!$entity instanceof CoreEntity) {
@@ -54,6 +54,12 @@
".txt"
],
"tooltip": "fileAccept"
},
{
"name": "maxCount",
"type": "int",
"min": 1,
"tooltip": true
}
],
"actualFields": [
@@ -77,7 +83,8 @@
"personalData": true,
"validationList": [
"required",
"pattern"
"pattern",
"maxCount"
],
"mandatoryValidationList": [
"pattern"
@@ -5,12 +5,6 @@
"type": "bool",
"default": false
},
{
"name": "sortable",
"type": "bool",
"default": false,
"hidden": true
},
{
"name": "readOnly",
"type": "bool",
@@ -20,6 +14,11 @@
"name": "readOnlyAfterCreate",
"type": "bool"
},
{
"name": "audited",
"type": "bool",
"tooltip": true
},
{
"name": "default",
"type": "linkMultiple",
@@ -34,9 +33,16 @@
"type": "bool"
},
{
"name": "audited",
"type": "bool",
"name": "maxCount",
"type": "int",
"min": 1,
"tooltip": true
},
{
"name": "sortable",
"type": "bool",
"default": false,
"hidden": true
}
],
"actualFields": [
@@ -49,7 +55,8 @@
"validationList": [
"required",
"pattern",
"columnsValid"
"columnsValid",
"maxCount"
],
"mandatoryValidationList": [
"pattern",