Completed
Push — master ( 36acf6...c2375b )
by
unknown
13:20
created

searchIds()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 23
rs 8.5906
cc 5
eloc 14
nc 4
nop 3
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Autocomplete;
4
5
use Oro\Bundle\FormBundle\Autocomplete\SearchHandler;
6
use Oro\Bundle\OrganizationBundle\Provider\BusinessUnitAclProvider;
7
8
class ForecastWidgetBusinessUnitSearchHandler extends SearchHandler
9
{
10
    /** @var BusinessUnitAclProvider */
11
    protected $businessUnitAclProvider;
12
13
    /** @var string */
14
    protected $opportunityClassName;
15
16
    /**
17
     * @param string $entityName
18
     * @param array $properties
19
     * @param BusinessUnitAclProvider $businessUnitAclProvider
20
     * @param string $opportunityClassName
21
     */
22
    public function __construct(
23
        $entityName,
24
        $properties,
25
        BusinessUnitAclProvider $businessUnitAclProvider,
26
        $opportunityClassName
27
    ) {
28
        parent::__construct($entityName, $properties);
29
        $this->businessUnitAclProvider = $businessUnitAclProvider;
30
        $this->opportunityClassName = $opportunityClassName;
31
    }
32
33
    /**
34
     * @param string $search
35
     * @param int    $firstResult
36
     * @param int    $maxResults
37
     * @return array
38
     */
39
    protected function searchIds($search, $firstResult, $maxResults)
40
    {
41
        $ids = [];
42
        $allowedBusinessUnitIds = $this
43
            ->businessUnitAclProvider
44
            ->getBusinessUnitIds($this->opportunityClassName, 'VIEW');
45
46
        if (!is_array($allowedBusinessUnitIds) || count($allowedBusinessUnitIds) === 0) {
47
            return $ids;
48
        }
49
50
        $this->indexer->setIsAllowedApplyAcl(false);
0 ignored issues
show
Bug introduced by
The method setIsAllowedApplyAcl() does not seem to exist on object<Oro\Bundle\SearchBundle\Engine\Indexer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        $result   = $this->indexer->simpleSearch($search, $firstResult, $maxResults, $this->entitySearchAlias);
52
        $elements = $result->getElements();
53
54
        foreach ($elements as $element) {
55
            if (in_array($element->getRecordId(), $allowedBusinessUnitIds, true)) {
56
                $ids[] = $element->getRecordId();
57
            }
58
        }
59
60
        return $ids;
61
    }
62
}
63