|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Arrilot\BitrixModels\Queries; |
|
4
|
|
|
|
|
5
|
|
|
abstract class OldCoreQuery extends BaseQuery |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Query select. |
|
9
|
|
|
* |
|
10
|
|
|
* @var array |
|
11
|
|
|
*/ |
|
12
|
|
|
public $select = ['FIELDS', 'PROPS']; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Fetch method and parameters. |
|
16
|
|
|
* |
|
17
|
|
|
* @var array |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $fetchUsing; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Constructor. |
|
23
|
|
|
* |
|
24
|
|
|
* @param object $bxObject |
|
25
|
|
|
* @param string $modelName |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct($bxObject, $modelName) |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct($bxObject, $modelName); |
|
30
|
|
|
|
|
31
|
|
|
$this->fetchUsing($modelName::$fetchUsing); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Set fetch using from string or array. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string|array $methodAndParams |
|
38
|
|
|
* @return $this |
|
39
|
|
|
*/ |
|
40
|
|
|
public function fetchUsing($methodAndParams) |
|
41
|
|
|
{ |
|
42
|
|
|
// simple case |
|
43
|
|
|
if (is_string($methodAndParams) || empty($methodAndParams['method'])) { |
|
44
|
|
|
$this->fetchUsing = in_array($methodAndParams, ['GetNext', 'getNext']) |
|
45
|
|
|
? ['method' => 'GetNext', 'params' => [true, true]] |
|
46
|
|
|
: ['method' => 'Fetch']; |
|
47
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
// complex case |
|
52
|
|
|
if (in_array($methodAndParams['method'], ['GetNext', 'getNext'])) { |
|
53
|
|
|
$bTextHtmlAuto = isset($methodAndParams['params'][0]) ? $methodAndParams['params'][0] : true; |
|
54
|
|
|
$useTilda = isset($methodAndParams['params'][1]) ? $methodAndParams['params'][1] : true; |
|
55
|
|
|
$this->fetchUsing = ['method' => 'GetNext', 'params' => [$bTextHtmlAuto, $useTilda]]; |
|
56
|
|
|
} else { |
|
57
|
|
|
$this->fetchUsing = ['method' => 'Fetch']; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Choose between Fetch() and GetNext($bTextHtmlAuto, $useTilda) and then fetch |
|
65
|
|
|
* |
|
66
|
|
|
* @param \CDBResult $rsItems |
|
67
|
|
|
* @return array|false |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function performFetchUsingSelectedMethod($rsItems) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->fetchUsing['method'] === 'GetNext' |
|
72
|
|
|
? $rsItems->GetNext($this->fetchUsing['params'][0], $this->fetchUsing['params'][1]) |
|
73
|
|
|
: $rsItems->Fetch(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|