Completed
Pull Request — master (#26)
by
unknown
06:22
created

D7Adapter::getCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Arrilot\BitrixModels\Adapters;
4
5
use Bitrix\Main\Entity\ExpressionField;
6
7
/**
8
 * Class D7Adapter
9
 *
10
 * @method \Bitrix\Main\DB\Result getList(array $parameters = [])
11
 * @method \Bitrix\Main\Entity\UpdateResult update(int $id, array $fields)
12
 * @method \Bitrix\Main\Entity\DeleteResult delete(int $id)
13
 * @method \Bitrix\Main\Entity\AddResult add(array $fields)
14
 */
15
class D7Adapter
16
{
17
    /**
18
     * Bitrix Class FQCN.
19
     *
20
     * @var string
21
     */
22
    protected $className;
23
    
24
    /**
25
     * D7Adapter constructor.
26
     *
27
     * @param $className
28
     */
29
    public function __construct($className)
30
    {
31
        $this->className = $className;
32
    }
33
34
    /**
35
     * Getter for class name.
36
     *
37
     * @return string
38
     */
39
    public function getClassName()
40
    {
41
        return $this->className;
42
    }
43
44
    /**
45
     * Handle dynamic method calls into a static calls on bitrix entity class.
46
     *
47
     * @param  string  $method
48
     * @param  array  $parameters
49
     * @return mixed
50
     */
51
    public function __call($method, $parameters)
52
    {
53
        $className = $this->className;
54
55
        return $className::$method(...$parameters);
56
    }
57
    
58
    public function getCount($filter)
59
    {
60
        $version = explode('.', SM_VERSION);
61
        if ($version[0] <= 15) {
62
            $result = call_user_func_array([$this->className, 'query'], [])->addSelect(new ExpressionField('CNT', 'COUNT(1)'))->setFilter($filter)->exec()->fetch();
63
            return $result['CNT'];
64
        } else {
65
            return $this->__call('getCount', $filter);
66
        }
67
    }
68
}
69