21 private $fieldList = [];
22 private $filterList = [];
23 private $selectList = [];
30 $this->param = $param;
33 $this->fieldList = [
"ID",
"CODE",
"EXTERNAL_ID",
"XML_ID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"TIMESTAMP_X",
34 "SORT",
"NAME",
"ACTIVE",
"SORT",
"PICTURE",
"DESCRIPTION",
"DESCRIPTION_TYPE",
"MODIFIED_BY",
35 "DATE_CREATE",
"CREATED_BY",
"DETAIL_PICTURE",
"SECTION_PROPERTY"];
37 $this->filterList = [
"ACTIVE",
"GLOBAL_ACTIVE",
"NAME",
"CODE",
"XML_ID",
"EXTERNAL_ID",
"SECTION_ID",
38 "DEPTH_LEVEL",
"LEFT_BORDER",
"RIGHT_BORDER",
"LEFT_MARGIN",
"RIGHT_MARGIN",
"IBLOCK_ID",
"ID",
39 "IBLOCK_ACTIVE",
"IBLOCK_NAME",
"IBLOCK_TYPE",
"IBLOCK_CODE",
"IBLOCK_XML_ID",
"IBLOCK_EXTERNAL_ID",
40 "TIMESTAMP_X",
"DATE_CREATE",
"MODIFIED_BY",
"CREATED_BY",
"SOCNET_GROUP_ID",
"MIN_PERMISSION",
41 "CHECK_PERMISSIONS",
"PERMISSIONS_BY",
"PROPERTY"];
43 $this->selectList = [
"ID",
"CODE",
"EXTERNAL_ID",
"XML_ID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"TIMESTAMP_X",
44 "SORT",
"NAME",
"ACTIVE",
"GLOBAL_ACTIVE",
"PICTURE",
"DESCRIPTION",
"DESCRIPTION_TYPE",
"LEFT_MARGIN",
45 "RIGHT_MARGIN",
"DEPTH_LEVEL",
"SEARCHABLE_CONTENT",
"SECTION_PAGE_URL",
"MODIFIED_BY",
"DATE_CREATE",
46 "CREATED_BY",
"DETAIL_PICTURE"];
61 $this->param->checkRequiredInputParams([
"IBLOCK_CODE",
"IBLOCK_ID",
"SECTION_ID",
"SECTION_CODE"]);
62 if ($this->param->hasErrors())
64 $this->errorCollection->add($this->param->getErrors());
69 "ID" => $this->sectionId,
70 "IBLOCK_ID" => $this->iblockId,
71 "CHECK_PERMISSIONS" =>
"N",
73 $queryObject = \CIBlockSection::getList([], $filter,
false, [
"ID"]);
75 return (
bool) $queryObject->fetch();
85 $this->param->checkRequiredInputParams([
"IBLOCK_CODE",
"IBLOCK_ID",
"SECTION_CODE", [
"FIELDS" => [
"NAME"]]]);
86 if ($this->param->hasErrors())
88 $this->errorCollection->add($this->param->getErrors());
92 $sectionObject = new \CIBlockSection;
93 $result = $sectionObject->add($this->getFields());
101 if ($sectionObject->LAST_ERROR)
103 $this->errorCollection->setError(
new Error($sectionObject->LAST_ERROR, self::ERROR_ADD_SECTION));
107 $this->errorCollection->setError(
new Error(
"Unknown error", self::ERROR_ADD_SECTION));
121 public function get(array $navData = [])
123 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE",
"IBLOCK_ID"]);
124 if ($this->param->hasErrors())
126 $this->errorCollection->add($this->param->getErrors());
132 $filter = $this->getFilter($this->iblockId);
134 $select = $this->getSelectList($this->params[
"SELECT"]);
136 $queryObject = \CIBlockSection::getList([], $filter,
false, $select, $navData);
137 while ($section = $queryObject->fetch())
139 $sections[] = $section;
142 return [$sections, $queryObject];
152 $this->param->checkRequiredInputParams([
"IBLOCK_CODE",
"IBLOCK_ID",
153 "SECTION_ID",
"SECTION_CODE", [
"FIELDS" => [
"NAME"]]]);
154 if ($this->param->hasErrors())
156 $this->errorCollection->add($this->param->getErrors());
160 $sectionObject = new \CIBlockSection;
161 if ($sectionObject->update($this->sectionId, $this->getFields()))
167 if ($sectionObject->LAST_ERROR)
169 $this->errorCollection->setError(
new Error($sectionObject->LAST_ERROR, self::ERROR_UPDATE_SECTION));
173 $this->errorCollection->setError(
new Error(
"Unknown error", self::ERROR_UPDATE_SECTION));
185 public function delete()
187 $this->param->checkRequiredInputParams([
"SECTION_ID",
"SECTION_CODE"]);
188 if ($this->param->hasErrors())
190 $this->errorCollection->add($this->param->getErrors());
194 $sectionObject = new \CIBlockSection;
195 if ($sectionObject->delete($this->sectionId,
false))
201 if ($sectionObject->LAST_ERROR)
203 $this->errorCollection->setError(
new Error($sectionObject->LAST_ERROR, self::ERROR_DELETE_SECTION));
207 $this->errorCollection->setError(
new Error(
"Unknown error", self::ERROR_DELETE_SECTION));
214 private function getFields()
217 "IBLOCK_ID" => $this->iblockId,
218 "CODE" => $this->params[
"SECTION_CODE"],
219 "IBLOCK_SECTION_ID" => $this->params[
"IBLOCK_SECTION_ID"] ? (int)$this->params[
"IBLOCK_SECTION_ID"] : 0,
220 "CHECK_PERMISSIONS" =>
"N"
223 foreach ($this->params[
"FIELDS"] as $fieldId => $fieldValue)
225 if (!in_array($fieldId, $this->fieldList))
230 if ($fieldId ==
"PICTURE")
232 $fieldValue = \CRestUtil::saveFile($fieldValue);
235 $fields[$fieldId] = $fieldValue;
241 private function getFilter($iblockId)
244 "IBLOCK_ID" => $iblockId,
245 "CHECK_PERMISSIONS" =>
"N",
248 if (!is_array($this->params[
"FILTER"]))
250 $this->params[
"FILTER"] = [];
253 foreach ($this->params[
"FILTER"] as $fieldId => $fieldValue)
255 if (in_array($fieldId, $this->filterList))
257 $filter[$fieldId] = $fieldValue;
264 private function getSelectList($inputSelectList)
268 if (!is_array($inputSelectList))
270 $inputSelectList = [];
273 foreach ($inputSelectList as $fieldId)
275 if (in_array($fieldId, $this->selectList))
277 $selectList[] = $fieldId;
trait ErrorableImplementation