Skip to content

Commit 973c2ba

Browse files
committed
Merge branch 'hotfix/fix_add_search_file' into 'feature/2.3.0'
Add search file See merge request metamodels/attribute_translatedfile!50
2 parents 1753fe4 + 6e11069 commit 973c2ba

File tree

4 files changed

+319
-11
lines changed

4 files changed

+319
-11
lines changed

psalm.xml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="3"
4-
resolveFromConfigFile="true"
5-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6-
xmlns="https://getpsalm.org/schema/config"
7-
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
3+
errorLevel="3"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
88
>
99
<projectFiles>
10-
<directory name="src" />
10+
<directory name="src"/>
1111
<ignoreFiles>
1212
<directory name="src/Resources/contao/dca"/>
1313
<directory name="src/Resources/contao/languages"/>
1414
</ignoreFiles>
1515
</projectFiles>
16+
<issueHandlers>
17+
<TooManyArguments>
18+
<errorLevel type="suppress">
19+
<referencedFunction name="Doctrine\DBAL\Query\QueryBuilder::select"/>
20+
</errorLevel>
21+
</TooManyArguments>
22+
</issueHandlers>
1623
</psalm>

src/Attribute/TranslatedFile.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
use function array_keys;
5151
use function array_map;
5252
use function array_merge;
53+
use function array_values;
5354
use function is_array;
5455
use function serialize;
5556
use function sprintf;
57+
use function str_replace;
5658
use function time;
5759
use function trigger_error;
5860
use function trim;
@@ -380,6 +382,7 @@ public function getAttributeSettingNames()
380382
'file_validFileTypes',
381383
'file_filesOnly',
382384
'file_widgetMode',
385+
'searchable',
383386
'mandatory',
384387
]
385388
);
@@ -601,4 +604,57 @@ public function getTranslatedDataFor($arrIds, $strLangCode)
601604

602605
return $values;
603606
}
607+
608+
/**
609+
* Search for file names or UUIDs.
610+
* Find items if one or more files are stored (serialised array) or the parent folder has been selected.
611+
*
612+
* {@inheritdoc}
613+
*/
614+
public function searchForInLanguages($strPattern, $arrLanguages = []): ?array
615+
{
616+
$subSelect = $this->connection->createQueryBuilder();
617+
$subSelect
618+
->select('f.uuid', 'f.pid')
619+
->from('tl_files', 'f');
620+
621+
if (Validator::isUuid($uuid = str_replace('*', '', $strPattern))) {
622+
$subSelect
623+
->where(('f.uuid = :value'))
624+
->setParameter('value', StringUtil::uuidToBin($uuid));
625+
} else {
626+
$subSelect
627+
->where($subSelect->expr()->like('f.name', ':value'))
628+
->setParameter('value', str_replace(['*', '?'], ['%', '_'], $strPattern));
629+
}
630+
631+
if ([] === ($subResults = $subSelect->executeQuery()->fetchAllAssociative())) {
632+
return [];
633+
}
634+
635+
$builder = $this->connection->createQueryBuilder();
636+
$builder
637+
->select('t.item_id')
638+
->from($this->getValueTable(), 't')
639+
->where('t.att_id = :attributeId')
640+
->setParameter('attributeId', $this->get('id'));
641+
642+
$uuids = [];
643+
foreach ($subResults as $subResult) {
644+
$uuids[$subResult['pid']] = $subResult['pid'];
645+
$uuids[$subResult['uuid']] = $subResult['uuid'];
646+
}
647+
648+
$orX = [];
649+
foreach (array_values($uuids) as $key => $uuid) {
650+
$orX[] = sprintf('t.value LIKE :value_%s', $key);
651+
$builder->setParameter('value_' . $key, '%' . $uuid . '%');
652+
}
653+
$builder->andWhere($builder->expr()->or(...$orX));
654+
655+
$statement = $builder->executeQuery();
656+
657+
// Return value list as list<mixed>, parent function wants a list<string> so we make a cast.
658+
return array_map(static fn(mixed $value) => (string) $value, $statement->fetchFirstColumn());
659+
}
604660
}

src/Resources/contao/dca/tl_metamodel_dcasetting.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of MetaModels/attribute_translatedfile.
55
*
6-
* (c) 2012-2023 The MetaModels team.
6+
* (c) 2012-2024 The MetaModels team.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -18,7 +18,7 @@
1818
* @author Sven Baumann <[email protected]>
1919
* @author David Molineus <[email protected]>
2020
* @author Ingolf Steinhardt <[email protected]>
21-
* @copyright 2012-2023 The MetaModels team.
21+
* @copyright 2012-2024 The MetaModels team.
2222
* @license https://github.com/MetaModels/attribute_translatedfile/blob/master/LICENSE LGPL-3.0-or-later
2323
* @filesource
2424
* @filesource
@@ -32,5 +32,8 @@
3232
'functions' => [
3333
'mandatory',
3434
'file_widgetMode'
35+
],
36+
'overview' => [
37+
'searchable',
3538
]
3639
];

0 commit comments

Comments
 (0)