Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Raoul Dzoukou committed Jan 10, 2024
1 parent 32673f5 commit cc7c208
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/SelectManagers/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Dam\SelectManagers;

use Atro\ORM\DB\RDB\Mapper;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\SelectManagers\Base;
Expand Down Expand Up @@ -41,8 +42,9 @@ public function filterLinkedWithAssetCategory(QueryBuilder $qb, IEntity $relEnti

$ids = $this->getEntityManager()->getRepository('AssetCategory')->getChildrenRecursivelyArray($assetCategoryId);
$ids = array_merge($ids, [$assetCategoryId]);
$qb->andWhere("EXISTS (SELECT asset_id FROM `asset_category_asset` WHERE asset_id=$tableAlias.id AND deleted=0 AND asset_category_id IN (:categoryIds))");
$qb->andWhere("EXISTS (SELECT asset_id FROM asset_category_asset WHERE asset_id=$tableAlias.id AND deleted=:false AND asset_category_id IN (:categoryIds))");
$qb->setParameter('categoryIds', $ids, Mapper::getParameterType($ids));
$qb->setParameter('false', false, ParameterType::BOOLEAN);
}

protected function boolFilterOnlyPrivate(array &$result): void
Expand All @@ -58,12 +60,15 @@ protected function boolFilterOnlyPublic(array &$result): void
public function filterOnlyPublic(QueryBuilder $qb, IEntity $relEntity, array $params, Mapper $mapper): void
{
$tableAlias = $mapper->getQueryConverter()->getMainTableAlias();
$qb->andWhere("EXISTS (SELECT e_attachment.id FROM `attachment` e_attachment WHERE e_attachment.id=$tableAlias.file_id AND e_attachment.private=0 AND deleted=0)");
$qb->andWhere("EXISTS (SELECT e_attachment.id FROM attachment e_attachment WHERE e_attachment.id=$tableAlias.file_id AND e_attachment.private=:false AND deleted=:false)");
$qb->setParameter('false', false, ParameterType::BOOLEAN);
}

public function filterOnlyPrivate(QueryBuilder $qb, IEntity $relEntity, array $params, Mapper $mapper): void
{
$tableAlias = $mapper->getQueryConverter()->getMainTableAlias();
$qb->andWhere("EXISTS (SELECT e_attachment.id FROM `attachment` e_attachment WHERE e_attachment.id=$tableAlias.file_id AND e_attachment.private=1 AND deleted=0)");
$qb->andWhere("EXISTS (SELECT e_attachment.id FROM attachment e_attachment WHERE e_attachment.id=$tableAlias.file_id AND e_attachment.private=:true AND deleted=:false)");
$qb->setParameter('true', true, ParameterType::BOOLEAN);
$qb->setParameter('false', false, ParameterType::BOOLEAN);
}
}

0 comments on commit cc7c208

Please sign in to comment.