all of filter

This commit is contained in:
Yuri Kuznetsov
2021-09-23 17:03:20 +03:00
parent 67efbdc6e9
commit fc7dba6c91
3 changed files with 91 additions and 5 deletions
@@ -72,6 +72,7 @@ class Checker
'isNotLinked',
'linkedWith',
'notLinkedWith',
'linkedWithAll',
'isUserFromTeams',
];
@@ -1151,4 +1151,67 @@ class ItemGeneralConverter implements ItemConverter
throw new Error("Bad where item. Not supported relation type.");
}
protected function processLinkedWithAll(QueryBuilder $queryBuilder, string $attribute, $value): array
{
$link = $attribute;
if (!$this->ormDefs->getEntity($this->entityType)->hasRelation($link)) {
throw new Error("Not existing link '{$link}' in where item.");
}
if (is_null($value) || !$value && !is_array($value)) {
throw new Error("Bad where item. Empty value.");
}
if (!is_array($value)) {
$value = [$value];
}
$defs = $this->ormDefs->getEntity($this->entityType)->getRelation($link);
$relationType = $defs->getType();
if ($relationType === Entity::MANY_MANY) {
$key = $defs->getForeignMidKey();
$whereList = [];
foreach ($value as $targetId) {
$sq = QueryBuilder::create()
->from($this->entityType)
->select('id')
->leftJoin($link)
->where([
$link . 'Middle.' . $key => $targetId,
])
->build();
$whereList[] = ['id=s' => $sq->getRaw()];
}
return $whereList;
}
if ($relationType === Entity::HAS_MANY) {
$whereList = [];
foreach ($value as $targetId) {
$sq = QueryBuilder::create()
->from($this->entityType)
->select('id')
->leftJoin($link)
->where([
$link . '.id' => $targetId,
])
->build();
$whereList[] = ['id=s' => $sq->getRaw()];
}
return $whereList;
}
throw new Error("Bad where item. Not supported relation type.");
}
}
+27 -5
View File
@@ -56,7 +56,7 @@ define('views/fields/link-multiple', 'views/fields/base', function (Dep) {
sortable: false,
searchTypeList: ['anyOf', 'isEmpty', 'isNotEmpty', 'noneOf'],
searchTypeList: ['anyOf', 'isEmpty', 'isNotEmpty', 'noneOf', 'allOf'],
selectFilterList: null,
@@ -173,7 +173,7 @@ define('views/fields/link-multiple', 'views/fields/base', function (Dep) {
},
handleSearchType: function (type) {
if (~['anyOf', 'noneOf'].indexOf(type)) {
if (~['anyOf', 'noneOf', 'allOf'].indexOf(type)) {
this.$el.find('div.link-group-container').removeClass('hidden');
}
else {
@@ -499,7 +499,27 @@ define('views/fields/link-multiple', 'views/fields/base', function (Dep) {
return data;
}
else if (type === 'noneOf') {
if (type === 'allOf') {
var idList = this.ids || [];
var data = {
type: 'linkedWithAll',
value: idList,
data: {
type: type,
nameHash: this.nameHash,
},
};
if (!idList.length) {
data.value = null;
}
return data;
}
if (type === 'noneOf') {
var data = {
type: 'notLinkedWith',
value: this.ids || [],
@@ -511,7 +531,8 @@ define('views/fields/link-multiple', 'views/fields/base', function (Dep) {
return data;
}
else if (type === 'isEmpty') {
if (type === 'isEmpty') {
var data = {
type: 'isNotLinked',
data: {
@@ -521,7 +542,8 @@ define('views/fields/link-multiple', 'views/fields/base', function (Dep) {
return data;
}
else if (type === 'isNotEmpty') {
if (type === 'isNotEmpty') {
var data = {
type: 'isLinked',
data: {