|
50 | 50 | use function array_keys; |
51 | 51 | use function array_map; |
52 | 52 | use function array_merge; |
| 53 | +use function array_values; |
53 | 54 | use function is_array; |
54 | 55 | use function serialize; |
55 | 56 | use function sprintf; |
| 57 | +use function str_replace; |
56 | 58 | use function time; |
57 | 59 | use function trigger_error; |
58 | 60 | use function trim; |
@@ -380,6 +382,7 @@ public function getAttributeSettingNames() |
380 | 382 | 'file_validFileTypes', |
381 | 383 | 'file_filesOnly', |
382 | 384 | 'file_widgetMode', |
| 385 | + 'searchable', |
383 | 386 | 'mandatory', |
384 | 387 | ] |
385 | 388 | ); |
@@ -601,4 +604,57 @@ public function getTranslatedDataFor($arrIds, $strLangCode) |
601 | 604 |
|
602 | 605 | return $values; |
603 | 606 | } |
| 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 | + } |
604 | 660 | } |
0 commit comments