<?php

namespace Webkul\DamBundle\Filter;

use Oro\Bundle\FilterBundle\Datasource\FilterDatasourceAdapterInterface;
use Oro\Bundle\FilterBundle\Filter\FilterUtility as BaseFilterUtility;
use Webkul\DamBundle\Repository\AssetRepository;

/**
 * Asset filter utility
 */
class AssetUtility extends BaseFilterUtility
{
    protected $repo;

    public function __construct(AssetRepository $repo)
    {
        $this->repo = $repo;
    }

    /**
     * Apply filter
     *
     * @param FilterDatasourceAdapterInterface $ds
     * @param string                           $field
     * @param string                           $operator
     * @param mixed                            $value
     */
    public function applyFilter(FilterDatasourceAdapterInterface $ds, $field, $operator, $value)
    {
        if ("category" === $field || "categories" === $field) {
            $this->repo->applyCategoryFilter(
                $ds->getQueryBuilder(),
                $operator,
                $value
            );
        }
    }
}
