Skip to content

Commit

Permalink
KUN-8979 | (feat) search media in subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
mart-insiders committed Aug 15, 2024
1 parent a44ead7 commit 56e0462
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Kunstmaan\MediaBundle\AdminList\FilterType;

use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM\AbstractORMFilterType;
use Kunstmaan\MediaBundle\Entity\Folder;
use Symfony\Component\HttpFoundation\Request;

class SubFolderFilterType extends AbstractORMFilterType
{
public function __construct(
private Folder $folder,
string $columnName
) {
parent::__construct($columnName);
}

public function bindRequest(Request $request, array &$data, $uniqueId): void
{
$data['value'] = $request->query->get('filter_value_' . $uniqueId);
}

public function apply(array $data, $uniqueId): void
{
if (!isset($data['value']) || $data['value'] !== 'true') {
return;
}

$folders = $this->folder->fetchChildIds();
$folders[] = $this->folder->getId();

$this->queryBuilder->setParameter('folders', $folders);
}

public function getTemplate(): string
{
return '@KunstmaanAdminList/FilterType/booleanFilter.html.twig';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Kunstmaan\AdminListBundle\AdminList\Configurator\ChangeableLimitInterface;
use Kunstmaan\AdminListBundle\AdminList\FilterType\ORM;
use Kunstmaan\AdminListBundle\Traits\ChangeableLimitTrait;
use Kunstmaan\MediaBundle\AdminList\FilterType\SubFolderFilterType;
use Kunstmaan\MediaBundle\AdminList\ItemAction\MediaDeleteItemAction;
use Kunstmaan\MediaBundle\AdminList\ItemAction\MediaEditItemAction;
use Kunstmaan\MediaBundle\AdminList\ItemAction\MediaSelectItemAction;
Expand Down Expand Up @@ -77,6 +78,7 @@ public function buildFilters()
$this->addFilter('contentType', new ORM\StringFilterType('contentType'), 'media.adminlist.configurator.filter.type');
$this->addFilter('updatedAt', new ORM\NumberFilterType('updatedAt'), 'media.adminlist.configurator.filter.updated_at');
$this->addFilter('filesize', new ORM\NumberFilterType('filesize'), 'media.adminlist.configurator.filter.filesize');
$this->addFilter('subFolders', new SubFolderFilterType($this->folder, 'folder'), 'media.adminlist.configurator.filter.sub_folder');
}

/**
Expand Down Expand Up @@ -134,8 +136,8 @@ public function getEntityClass(): string

public function adaptQueryBuilder(QueryBuilder $queryBuilder)
{
$queryBuilder->andWhere('b.folder = :folder')
->setParameter('folder', $this->folder->getId())
$queryBuilder->andWhere('b.folder in (:folders)')
->setParameter('folders', [$this->folder->getId()])
->andWhere('b.deleted = :deleted')
->setParameter('deleted', false)
->orderBy('b.updatedAt', 'DESC');
Expand Down
12 changes: 12 additions & 0 deletions src/Kunstmaan/MediaBundle/Entity/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ public function setChildren($children)
return $this;
}

/**
* @return array<int>
*/
public function fetchChildIds(): array
{
$ids = $this->getChildren()->map(function (Folder $child) {
return array_merge([$child->getId()], $child->fetchChildIds());
})->toArray();

return array_merge(...$ids);
}

/**
* @return bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ media:
type: Typ
updated_at: Datum
filesize: Dateigröße (in Byte)
sub_folder: Unterordner einbeziehen
form:
remote:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ media:
type: Type
updated_at: Date
filesize: Filesize (in bytes)
sub_folder: Include subfolders

form:
remote:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ media:
type: Type
updated_at: Date
filesize: Filesize (in bytes)
sub_folder: Incluir subcarpetas
form:
remote:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ media:
type: Type
updated_at: Date
filesize: Filesize (in bytes)
sub_folder: Inclure les sous-dossiers
form:
remote:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ media:
type: Típus
updated_at: Dátum
filesize: Fájlméret (byte-ban)
sub_folder: Almappák bevonása
form:
remote:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ media:
type: Type
updated_at: Date
filesize: Filesize (in bytes)
sub_folder: Includi sottocartelle
form:
remote:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ media:
type: Type
updated_at: Datum
filesize: Bestandsformaat (in bytes)
sub_folder: In subfolders
form:
remote:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ media:
type: Typ
updated_at: Data
filesize: Rozmiar (w bajtach)
sub_folders: Uwzględnij podfoldery
form:
remote:
name:
Expand Down

0 comments on commit 56e0462

Please sign in to comment.