Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'divante-filter-by-relation' into 10.1
# Conflicts: # bundles/CoreBundle/Resources/translations/en.json # models/DataObject/ClassDefinition/Data/Hotspotimage.php # models/DataObject/ClassDefinition/Data/Image.php # models/DataObject/ClassDefinition/Data/ManyToManyObjectRelation.php
- Loading branch information
Showing
16 changed files
with
289 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
models/DataObject/ClassDefinition/Data/Extension/RelationFilterConditionParser.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* @category pimcore | ||
* @date 25/06/2021 | ||
* @author Filip Szenborn <fszenborn@divante.co> | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Pimcore\Model\DataObject\ClassDefinition\Data\Extension; | ||
|
||
/** | ||
* Trait RelationFilterConditionParser | ||
* @package Pimcore\Model\DataObject\ClassDefinition\Data\Extension | ||
*/ | ||
trait RelationFilterConditionParser | ||
{ | ||
/** | ||
* Parses filter value of a relation field and creates the filter condition | ||
* @param $value | ||
* @param $operator | ||
* @param $name | ||
* @return string | ||
*/ | ||
public function getRelationFilterCondition($value, $operator, $name) | ||
{ | ||
if ($operator == '=') { | ||
$value = "'%," . $value . ",%'"; | ||
return '`' . $name . '` LIKE ' . $value . ' '; | ||
} elseif ($operator == 'LIKE') { | ||
$result = $name . " IS NULL"; | ||
$values = explode(',', (string)$value ?? ''); | ||
if (is_array($values) && !empty($values)) { | ||
$fieldConditions = []; | ||
foreach ($values as $value) { | ||
if (empty($value)) { | ||
continue; | ||
} | ||
$fieldConditions[] = '`' . $name . "` LIKE '%" . $value . "%' "; | ||
} | ||
if (!empty($fieldConditions)) { | ||
$result = '(' . implode(' AND ', $fieldConditions) . ')'; | ||
} | ||
} | ||
return $result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.