示例#1
0
 /**
  * Генерация создания
  *
  * generateAddCode
  * @param array $IblockTypeId
  * @return bool|string
  */
 public function generateAddCode($IblockTypeId)
 {
     $iBlock = new \CIBlock();
     $CIblockType = new \CIBlockType();
     $lang = new \CLanguage();
     $return = array();
     $dbIblockType = $CIblockType->GetByID($IblockTypeId);
     if ($arIblockType = $dbIblockType->GetNext()) {
         $Iblock = new \CIBlock();
         $dbIblock = $Iblock->GetList(array(), array('TYPE' => $IblockTypeId, 'CHECK_PERMISSIONS' => 'N'));
         while ($arIblock = $dbIblock->GetNext()) {
             $IblockProperty = new \CIBlockProperty();
             $dbIblockProperty = $IblockProperty->GetList(array(), array('IBLOCK_CODE' => $arIblock['CODE'], 'CHECK_PERMISSIONS' => 'N'));
             while ($arIblockProperty = $dbIblockProperty->GetNext()) {
                 $dbPropertyValues = \CIBlockPropertyEnum::GetList(array(), array("IBLOCK_ID" => $arIblockProperty['IBLOCK_ID'], "CODE" => $arIblockProperty['CODE']));
                 while ($arPropertyValues = $dbPropertyValues->Fetch()) {
                     $arIblockProperty['VALUES'][$arPropertyValues['ID']] = $arPropertyValues;
                 }
                 Helper::unsetFields(array('ID', '~ID', 'IBLOCK_ID', '~IBLOCK_ID'), $arIblockProperty);
                 $arIblockProperty['IBLOCK_CODE'] = $arIblock['CODE'];
                 foreach ($arIblockProperty as $k => $v) {
                     if (strstr($k, "~") || is_null($v)) {
                         unset($arIblockProperty[$k]);
                     }
                 }
                 if (isset($arIblockProperty['LINK_IBLOCK_ID'])) {
                     $res = $iBlock->GetList(array(), array("ID" => $arIblockProperty['LINK_IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'N'));
                     if ($ar_res = $res->GetNext()) {
                         unset($arIblockProperty['LINK_IBLOCK_ID']);
                         $arIblockProperty['LINK_IBLOCK_CODE'] = $ar_res['CODE'];
                     }
                 }
                 $return[] = $this->getMethodContent('Bim\\Db\\Iblock\\IblockPropertyIntegrate', 'Add', array($arIblockProperty));
             }
             foreach ($arIblock as $k => $v) {
                 if (strstr($k, "~") || $k == 'ID') {
                     unset($arIblock[$k]);
                 }
             }
             $return[] = $this->getMethodContent('Bim\\Db\\Iblock\\IblockIntegrate', 'Add', array($arIblock));
         }
         foreach ($arIblockType as $k => $v) {
             if (strstr($k, "~") || is_null($v)) {
                 unset($arIblockType[$k]);
             }
         }
         $rsLang = $lang->GetList($by = "lid", $order = "desc");
         while ($arLang = $rsLang->Fetch()) {
             $arTypeLang = $CIblockType->GetByIDLang($IblockTypeId, $arLang['LID']);
             $arIblockType["LANG"][$arLang['LID']] = array('NAME' => $arTypeLang['NAME'], 'SECTION_NAME' => $arTypeLang['SECTION_NAME'], 'ELEMENT_NAME' => $arTypeLang['ELEMENT_NAME']);
         }
         $return[] = $this->getMethodContent('Bim\\Db\\Iblock\\IblockTypeIntegrate', 'Add', array($arIblockType));
         $return = array_reverse($return);
         return implode(PHP_EOL, $return);
     } else {
         return false;
     }
 }
示例#2
0
 /**
  * Метод создания инфоблока.
  *
  * @param $input
  * @return bool
  * @throws \Exception
  */
 public static function Add($input)
 {
     $iBlock = new CIBlock();
     if (isset($input['SORT'])) {
         if (!is_int($input['SORT'])) {
             if (intval($input['SORT'])) {
                 $input['SORT'] = intval($input['SORT']);
             } else {
                 $input['SORT'] = 500;
             }
         }
     } else {
         $input['SORT'] = 500;
     }
     # default values
     $defaultValue = array('ACTIVE' => 'Y', 'LIST_PAGE_URL' => '#SITE_DIR#/' . $input['IBLOCK_TYPE_ID'] . '/index.php?ID=#IBLOCK_ID#', 'SECTION_PAGE_URL' => '#SITE_DIR#/' . $input['IBLOCK_TYPE_ID'] . '/list.php?SECTION_ID=#ID#', 'DETAIL_PAGE_URL' => '#SITE_DIR#/' . $input['IBLOCK_TYPE_ID'] . '/detail.php?ID=#ID#', 'INDEX_SECTION' => 'Y', 'INDEX_ELEMENT' => 'Y', 'PICTURE' => array('del' => null, 'MODULE_ID' => 'iblock'), 'DESCRIPTION' => '', 'DESCRIPTION_TYPE' => 'text', 'EDIT_FILE_BEFORE' => '', 'EDIT_FILE_AFTER' => '', 'WORKFLOW' => 'N', 'BIZPROC' => 'N', 'SECTION_CHOOSER' => 'L', 'LIST_MODE' => '', 'FIELDS' => array(), 'ELEMENTS_NAME' => 'Элементы', 'ELEMENT_NAME' => 'Элемент', 'ELEMENT_ADD' => 'Добавить элемент', 'ELEMENT_EDIT' => 'Изменить элемент', 'ELEMENT_DELETE' => 'Удалить элемент', 'SECTIONS_NAME' => 'Разделы', 'SECTION_NAME' => 'Раздел', 'SECTION_ADD' => 'Добавить раздел', 'SECTION_EDIT' => 'Изменить раздел', 'SECTION_DELETE' => 'Удалить раздел', 'RIGHTS_MODE' => 'S', 'GROUP_ID' => array(2 => 'R', 1 => 'X'), 'VERSION' => 1);
     if (!strlen($input['CODE'])) {
         throw new BimException('Not found iblock code');
     }
     $iblockDbRes = $iBlock->GetList(array(), array('CODE' => $input['CODE'], 'CHECK_PERMISSIONS' => 'N'));
     if ($iblockDbRes !== false && $iblockDbRes->SelectedRowsCount()) {
         throw new BimException('Iblock with code = "' . $input['CODE'] . '" already exist.');
     }
     foreach ($defaultValue as $defaultName => $defaultValue) {
         if (!isset($input[$defaultName]) || empty($input[$defaultName])) {
             $input[$defaultName] = $defaultValue;
         }
     }
     // Перегоняем имена групп (если были изменены при накатывании миграции) в идентификаторы групп
     $arGroups = Helper::getUserGroups();
     foreach ($input['GROUP_ID'] as $groupCode => $right) {
         $groupId = Helper::getUserGroupId($groupCode, $arGroups);
         if ($groupId != null && strlen($groupId) > 0) {
             $input['GROUP_ID'][$groupId] = $input['GROUP_ID'][$groupCode];
             unset($input['GROUP_ID'][$groupCode]);
         }
     }
     $ID = $iBlock->Add($input);
     if ($ID) {
         return $ID;
     } else {
         throw new BimException($iBlock->LAST_ERROR);
     }
 }
示例#3
0
 /**
  * Установка групп пользователей
  *
  * @param $id : ID Информационного блока
  * @param $item : Формируемый массив
  */
 private function setUserGroupId($id, &$item)
 {
     $item['GROUP_ID'] = $this->iblock->GetGroupPermissions($id);
     $arGroups = Helper::getUserGroups();
     foreach ($item['GROUP_ID'] as $groupId => $right) {
         $groupCode = Helper::getUserGroupCode($groupId, $arGroups);
         if ($groupCode != null && strlen($groupCode) > 0) {
             $item['GROUP_ID'][$groupCode] = $item['GROUP_ID'][$groupId];
             unset($item['GROUP_ID'][$groupId]);
         }
     }
 }