22 private $fieldList = [];
23 private $messageList = [];
29 $this->param = $param;
32 $this->fieldList = [
"NAME",
"ACTIVE",
"DESCRIPTION",
"SORT",
"BIZPROC",
"PICTURE"];
33 $this->messageList = [
"ELEMENTS_NAME",
"ELEMENT_NAME",
"ELEMENT_ADD",
"ELEMENT_EDIT",
"ELEMENT_DELETE",
34 "SECTIONS_NAME",
"SECTION_ADD",
"SECTION_EDIT",
"SECTION_DELETE"];
48 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE"]);
49 if ($this->param->hasErrors())
51 $this->errorCollection->add($this->param->getErrors());
56 "ID" => $this->params[
"IBLOCK_ID"] ? $this->params[
"IBLOCK_ID"] :
"",
57 "CODE" => $this->params[
"IBLOCK_CODE"] ??
"",
58 "CHECK_PERMISSIONS" =>
"N",
60 $queryObject = \CIBlock::getList([], $filter);
62 return (
bool) $queryObject->fetch();
73 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE", [
"FIELDS" => [
"NAME"]]]);
74 if ($this->param->hasErrors())
76 $this->errorCollection->add($this->param->getErrors());
80 $iblockObject = new \CIBlock();
81 $result = $iblockObject->add($this->getFields());
85 if (!empty($this->params[
"SOCNET_GROUP_ID"]) && Loader::includeModule(
"socialnetwork"))
87 \CSocNetGroup::setLastActivity($this->params[
"SOCNET_GROUP_ID"]);
93 if ($iblockObject->LAST_ERROR)
95 $this->errorCollection->setError(
new Error($iblockObject->LAST_ERROR, self::ERROR_ADD_IBLOCK));
99 $this->errorCollection->setError(
new Error(
"Unknown error", self::ERROR_ADD_IBLOCK));
113 public function get(array $navData = [])
115 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID"]);
116 if ($this->param->hasErrors())
118 $this->errorCollection->add($this->param->getErrors());
124 $filter = $this->getFilter();
126 $order = $this->getOrder();
128 $queryObject = \CIBlock::getList($order, $filter);
129 $queryObject->NavStart($navData);
130 while ($result = $queryObject->fetch())
132 $iblocks[] = $result;
135 return [$iblocks, $queryObject];
145 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE",
"IBLOCK_ID"]);
146 if ($this->param->hasErrors())
148 $this->errorCollection->add($this->param->getErrors());
152 $iblockObject = new \CIBlock;
153 if ($iblockObject->update($this->iblockId, $this->getFields()))
159 if ($iblockObject->LAST_ERROR)
161 $this->errorCollection->setError(
new Error($iblockObject->LAST_ERROR, self::ERROR_UPDATE_IBLOCK));
165 $this->errorCollection->setError(
new Error(
"Unknown error", self::ERROR_UPDATE_IBLOCK));
177 public function delete()
179 $this->param->checkRequiredInputParams([
"IBLOCK_TYPE_ID",
"IBLOCK_CODE",
"IBLOCK_ID"]);
180 if ($this->param->hasErrors())
182 $this->errorCollection->add($this->param->getErrors());
186 return \CIBlock::delete($this->iblockId);
189 private function getFilter()
192 "TYPE" => $this->params[
"IBLOCK_TYPE_ID"],
193 "ID" => ($this->params[
"IBLOCK_ID"] ? $this->params[
"IBLOCK_ID"] :
""),
194 "CODE" => ($this->params[
"IBLOCK_CODE"] ? $this->params[
"IBLOCK_CODE"] :
""),
196 "CHECK_PERMISSIONS" => ($this->params[
"SOCNET_GROUP_ID"]) ?
"N" :
"Y",
198 if ($this->params[
"SOCNET_GROUP_ID"])
200 $filter[
"=SOCNET_GROUP_ID"] = $this->params[
"SOCNET_GROUP_ID"];
204 $filter[
"SITE_ID"] = SITE_ID;
210 private function getOrder()
213 if (is_array($this->params[
"IBLOCK_ORDER"]))
215 $fieldList = [
"ID",
"IBLOCK_TYPE",
"NAME",
"ACTIVE",
"CODE",
"SORT",
"ELEMENT_CNT",
"TIMESTAMP_X"];
216 $orderList = [
"asc",
"desc"];
217 foreach ($this->params[
"IBLOCK_ORDER"] as $fieldId => $orderParam)
219 if (!in_array($orderParam, $orderList) || !in_array($fieldId, $fieldList))
223 $order[$fieldId] = $orderParam;
226 if (!isset($order[
'ID']))
228 $order[
'ID'] =
'DESC';
234 private function getFields()
237 "IBLOCK_TYPE_ID" => $this->params[
"IBLOCK_TYPE_ID"],
239 "RIGHTS_MODE" =>
"E",
240 "SITE_ID" => \CSite::getDefSite(),
242 if ($this->params[
"IBLOCK_CODE"])
244 $fields[
"CODE"] = $this->params[
"IBLOCK_CODE"];
246 if ($this->params[
"SOCNET_GROUP_ID"])
248 $fields[
"SOCNET_GROUP_ID"] = $this->params[
"SOCNET_GROUP_ID"];
251 foreach ($this->params[
"FIELDS"] as $fieldId => $fieldValue)
253 if (!in_array($fieldId, $this->fieldList))
258 if ($fieldId ==
"PICTURE")
260 $fieldValue = \CRestUtil::saveFile($fieldValue);
263 $fields[$fieldId] = $fieldValue;
266 foreach ($this->params[
"MESSAGES"] as $messageId => $messageValue)
268 if (!in_array($messageId, $this->messageList))
273 $fields[$messageId] = $messageValue;
276 $fields[
"RIGHTS"] = $this->getCurrentRights();
277 foreach ($this->getInputRight() as $rightId => $right)
279 $fields[
"RIGHTS"][$rightId] = $right;
285 private function getCurrentRights()
289 $iblockRights = new \CIBlockRights($this->iblockId);
290 $rights = $iblockRights->getRights();
291 foreach ($rights as $rightId => $right)
293 $result[$rightId] = $right;
299 private function getInputRight()
303 if (empty($this->params[
"RIGHTS"]) || !is_array($this->params[
"RIGHTS"]))
306 $this->params[
"RIGHTS"] = [];
307 $this->params[
"RIGHTS"][
"U".$USER->getID()] =
"X";
311 foreach ($this->params[
"RIGHTS"] as $rightCode => $access)
313 $result[
"n".($count++)] = [
314 "GROUP_CODE" => $rightCode,
315 "TASK_ID" => \CIBlockRights::letterToTask($access),
trait ErrorableImplementation