Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
section.php
1<?php
2
4
9
16class Section extends DataSource implements \Iterator
17{
18 protected $sections;
19 protected $resSections;
20 protected $currentKey = 0;
21 protected $currentRecord = array();
22
23 protected $vk;
24 protected $exportId;
25
28
29 protected $startPosition = 0;
30
37 {
38 $this->vk = Vk\Vk::getInstance();
39
40 if (!$this->vk->isActive())
41 throw new SystemException("Vk is not active!" . __METHOD__);
42
43 if (!isset($exportId) || $exportId == '')
44 throw new ArgumentNullException("EXPORT_ID");
45
46 if (!Loader::includeModule('iblock'))
47 throw new SystemException("Can't include module \"IBlock\"! " . __METHOD__);
48
49 $this->exportId = $exportId;
50
51// get list of sections to export IDs
52 $sectionsList = new Vk\SectionsList($this->exportId);
53 $preparedSections = $sectionsList->getSectionsToAlbumsExport();
54 $this->sectionsToExport = $preparedSections["SECTIONS"];
55 $this->sectionsAliases = $preparedSections["ALIASES"];
56 unset($preparedSections);
57
58// CHECK is empty list
59 if (empty($this->sectionsToExport))
60 {
61 $logger = new Vk\Logger($this->exportId);
62 $logger->addError('EMPTY_SECTIONS_LIST');
63 }
64
66 }
67
68
74 private function createSectionsDbObject()
75 {
76 return \CIBlockSection::GetList(
77 array("ID" => "ASC"),
78 array("ID" => $this->sectionsToExport, "ACTIVE" => "Y", "GLOBAL_ACTIVE" => "Y", "CHECK_PERMISSIONS" => "N"),
79 true,
80 array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "NAME", "PICTURE", "DETAIL_PICTURE", "LEFT_MARGIN", "RIGHT_MARGIN", "DESCRIPTION"),
81 false
82 );
83 }
84
85
86
92 protected function setStartPosition($startPosition)
93 {
95 {
96 $this->startPosition = intval($startPosition);
97// we can use two condition in filter on ID: in array and >=startPostion.
98// therefore prepare array of sections to export like a >=
99 foreach ($this->sectionsToExport as $key => $section)
100 {
101 if ($key < $startPosition)
102 unset($this->sectionsToExport[$key]);
103 }
104 }
105 }
106
111 public function current()
112 {
114 }
115
120 public function key()
121 {
122 return $this->currentKey;
123 }
124
128 public function next()
129 {
130 $this->currentKey++;
131 $this->currentRecord = $this->nextItem();
132 }
133
139 private function nextItem()
140 {
141 $currItem = NULL;
142// only if album exist and not empty
143 if ($obCurrItem = $this->resSections->GetNextElement(true, false))
144 {
145 $currItem = $obCurrItem->GetFields();
146 if ($currItem["ELEMENT_CNT"] > 0)
147// put album alias from map. Better do it here and not getting map (only for it value) in converter
148 $currItem["TO_ALBUM_ALIAS"] = isset($this->sectionsAliases[$currItem["ID"]]) ?
149 $this->sectionsAliases[$currItem["ID"]] : false;
150 }
151
152 return $currItem;
153 }
154
158 public function rewind()
159 {
160 $this->currentKey = 0;
161 $this->resSections = $this->createSectionsDbObject();
162 $this->currentRecord = $this->nextItem();
163 }
164
169 public function valid()
170 {
171 return is_array($this->currentRecord);
172 }
173}