-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitrix-section.php
80 lines (64 loc) · 2.06 KB
/
bitrix-section.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
Получение данных секций из инфоблоков
Указываются ID через STD_IN (с новой строки), и/или через перечисление в параметрах
*/
namespace Bitrixcli;
require(__DIR__ . '/lib/cli-cms.php');
class SectionCli extends BitrixCli {
protected $ids = array(), $item;
public static $cliParams = array(
'noVal' // без значения
=> array(),
'val' // со значением
=> array('i' => 'ID', 'v' => 'view', 'f' => 'format'),
'optionVal' // с необязательным значением
=> array(),
)
;
public function __construct($BitrixCMS) {
if(!\CModule::IncludeModule('iblock')) throw new Exception('Can not include iblock');
parent::__construct($BitrixCMS);
}
public function run() {
try {
$this->getParms();
$this->outputElements();
} catch (Exception $e) {
$this->error($e);
}
}
protected function getParms() {
$ids = $this->getCliIdParms();
$this->ids = array_merge($this->ids, $ids);
$ids = $this->getStdinIntParms();
$this->ids = array_merge($this->ids, $ids);
$this->ids = array_filter(array_unique($this->ids));
if(count($this->ids) == 0) throw new Exception('No ids', 1);
}
protected function outputElements() {
$view = $this->getViewFormat();
foreach($this->ids as $id) {
$this->getSection($id);
if(isset($this->item)) {
$DataView = new DataView($this->item);
$DataView->view($view);
}
}
}
protected function getSection($id) {
unset($this->item);
$arSort = array('SORT' => 'ASC');
$arSelect = array('*');
$arNavStartParams = false;
$arFilter = array('id' => $id);
$rs = \CIBlockSection::GetList($arSort, $arFilter, $bIncCnt = true, $arSelect, $arNavStartParams);
if($rs->SelectedRowsCount() == 0) {
$this->warning('Can not find section by ID: ' . $id);
} else {
$this->item = $rs->Fetch();
}
}
}
$SectionCli = new SectionCli($BitrixCMS);
$SectionCli->run();