本文整理汇总了PHP中CIBlockSection::Add方法的典型用法代码示例。如果您正苦于以下问题:PHP CIBlockSection::Add方法的具体用法?PHP CIBlockSection::Add怎么用?PHP CIBlockSection::Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIBlockSection
的用法示例。
在下文中一共展示了CIBlockSection::Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: applySnapshot
/**
* @param $data
* @param null $dbVersion
* @throws \Exception
* @return ApplyResult
*/
public function applySnapshot($data, $dbVersion = null)
{
$data = $this->handleNullValues($data);
$sec = new \CIBlockSection();
$res = new ApplyResult();
$extId = $data['ID'];
if ($dbVersion) {
$data['IBLOCK_ID'] = $this->getReferenceController()->getCurrentIdByOtherVersion($data['IBLOCK_ID'], ReferenceController::GROUP_IBLOCK, $dbVersion);
$data['IBLOCK_SECTION_ID'] && ($data['IBLOCK_SECTION_ID'] = $this->getCurrentVersionId($data['IBLOCK_SECTION_ID'], $dbVersion));
$id = $this->getCurrentVersionId($extId, $dbVersion);
} else {
$id = $extId;
}
if (!$dbVersion && !SectionTable::getList(array('filter' => array('=ID' => $id)))->fetch()) {
$addRes = SectionTable::add(array('ID' => $id, 'IBLOCK_ID' => $data['IBLOCK_ID'], 'TIMESTAMP_X' => new DateTime(), 'NAME' => $data['NAME'], 'DESCRIPTION_TYPE' => $data['DESCRIPTION_TYPE']));
if (!$addRes->isSuccess()) {
throw new \Exception('Не удалось возобновить секцию(раздел) текущей версии. ' . implode(', ', $addRes->getErrorMessages()) . "\n" . var_export($data, true));
}
}
unset($data['CREATED_BY'], $data['MODIFIED_BY']);
if ($id && ($currentData = SectionTable::getById($id)->fetch())) {
$data['PICTURE'] = $currentData['PICTURE'];
$data['DETAIL_PICTURE'] = $currentData['DETAIL_PICTURE'];
$res->setSuccess((bool) $sec->Update($id, $data));
} else {
unset($data['PICTURE'], $data['DETAIL_PICTURE']);
$res->setSuccess((bool) ($id = $sec->Add($data)));
$this->registerCurrentVersionId($id, $this->getReferenceValue($extId, $dbVersion));
}
$res->setId($id);
$res->setMessage($sec->LAST_ERROR);
return $res;
}
示例2: Add
public static function Add(&$arFields)
{
if (!CModule::IncludeModule('iblock')) {
return false;
}
if (!(isset($arFields['NAME']) && is_string($arFields['NAME']) && $arFields['NAME'] !== '')) {
self::$LAST_ERROR_CODE = self::ERR_SECTION_NAME_EMPTY;
self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_SECTION_NAME_EMPTY');
return false;
}
$catalogID = isset($arFields['CATALOG_ID']) ? intval($arFields['CATALOG_ID']) : 0;
if (!($catalogID > 0 && CCrmCatalog::Exists($catalogID))) {
$catalogID = CCrmCatalog::EnsureDefaultExists();
}
$arFields['CATALOG_ID'] = $catalogID;
$sectionFields = CCrmProductSectionDbResult::MapKeys($arFields);
$sectionFields['CHECK_PERMISSIONS'] = 'N';
$section = new CIBlockSection();
$result = $section->Add($sectionFields);
if (!(is_int($result) && $result > 0)) {
self::$LAST_ERROR_CODE = self::ERR_IBLOCK_SECTION_ADD;
self::$LAST_ERROR = $section->LAST_ERROR;
}
return $result;
}
示例3: createSection
static function createSection($name, $code, $parent_id = false)
{
$bs = new CIBlockSection();
$arFields = array("ACTIVE" => "Y", "CODE" => $code, "IBLOCK_SECTION_ID" => $parent_id, "IBLOCK_ID" => self::$IBLOCK_ID, "NAME" => $name, "SORT" => 500, "PICTURE" => "", "DESCRIPTION" => "", "DESCRIPTION_TYPE" => "html");
$result_id = $bs->Add($arFields);
return $result_id;
}
示例4: AddCategory
function AddCategory($NAME, $PARENT_ID)
{
$iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
if ($iblock_permission < "W") {
$GLOBALS["USER"]->RequiredHTTPAuthBasic();
return new CSOAPFault('Server Error', 'Unable to authorize user.');
}
$code = self::translit($NAME);
$i = 1;
while (true) {
$res = CIBlockSection::Getlist(array(), array("CODE" => $code), false, array("CODE"));
if ($res->Fetch()) {
$code = self::translit($NAME) . $i;
} else {
break;
}
$i++;
}
$arFields = array("ACTIVE" => "Y", "NAME" => $NAME, "IBLOCK_SECTION_ID" => $PARENT_ID, "IBLOCK_ID" => IBLOCK_ID, "CODE" => $code);
$ib_section = new CIBlockSection();
$result = $ib_section->Add($arFields);
if ($result > 0) {
CIBlockSection::ReSort();
return $result;
}
return new CSOAPFault('Server Error', 'Error: ' . $ib_section->LAST_ERROR);
}
示例5: onBeforeElementAddHandler
static function onBeforeElementAddHandler($arFields)
{
$IBLOCK_ID = Config\Option::get("citfact.replaceurl", "IBLOCK_ID", "");
$SECTION_ID = Config\Option::get("citfact.replaceurl", "SECTION_BREND_ID", "BRENDI");
$CODE_PROP = Config\Option::get("citfact.replaceurl", "PROPERTY_CODE_BRENDI", "BRENDI");
if ($IBLOCK_ID == $arFields["IBLOCK_ID"]) {
$propertyBrand = \CIBlockProperty::GetByID($CODE_PROP, $arFields["IBLOCK_ID"]);
if ($arResultProperty = $propertyBrand->GetNext()) {
$propertyBrandValue = \CIBlockPropertyEnum::GetByID($arFields["PROPERTY_VALUES"][$arResultProperty["ID"]][0]["VALUE"]);
}
$rqParentSection = \CIBlockSection::GetByID($SECTION_ID);
if ($arParentSection = $rqParentSection->GetNext()) {
$arFilter = array('IBLOCK_ID' => $arParentSection['IBLOCK_ID'], '>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'], '<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'], '>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']);
// выберет потомков без учета активности
$rqSectChild = \CIBlockSection::GetList(array('left_margin' => 'asc'), $arFilter);
while ($arSectChild = $rqSectChild->GetNext()) {
$arSections[$arSectChild["NAME"]] = $arSectChild["ID"];
}
}
if (array_key_exists($propertyBrandValue["VALUE"], $arSections)) {
$arFields["IBLOCK_SECTION"][] = $arSections[$propertyBrandValue["VALUE"]];
} else {
$arParams = array("replace_space" => "-", "replace_other" => "-");
$trans = \Cutil::translit($propertyBrandValue["VALUE"], "ru", $arParams);
$bs = new \CIBlockSection();
$arFieldsNewSection = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => $SECTION_ID, "IBLOCK_ID" => $IBLOCK_ID, "NAME" => $propertyBrandValue["VALUE"], "CODE" => $trans);
$resultAdd = $bs->Add($arFieldsNewSection);
$arFields["IBLOCK_SECTION"][] = $resultAdd;
}
}
return true;
}
示例6: array
function __wd_get_root_section($IBLOCK_ID, $object, $object_id)
{
$result = CIBlockWebdavSocnet::GetSectionID($IBLOCK_ID, $object, $object_id);
if (intval($result) > 0) {
return $result;
} else {
__wd_check_uf_use_bp_property($arParams["IBLOCK_ID"]);
$arFields = array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "SOCNET_GROUP_ID" => false, "IBLOCK_SECTION_ID" => 0, "UF_USE_BP" => "N");
if ($object == "user") {
$dbUser = CUser::GetByID($object_id);
$arUser = $dbUser->Fetch();
$arFields["NAME"] = trim($arUser['LAST_NAME'] . " " . $arUser['FIRST_NAME']);
$arFields["NAME"] = trim(!empty($arFields["NAME"]) ? $arFields["NAME"] : $arUser['LOGIN']);
$arFields['CREATED_BY'] = $arUser['ID'];
$arFields['MODIFIED_BY'] = $arUser['ID'];
if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E") {
$arTasks = CWebDavIblock::GetTasks();
$arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'U' . $object_id, 'TASK_ID' => $arTasks['X']));
}
} else {
/* $res = CSocNetGroup::GetByID($arResult["VARIABLES"]["group_id"]);
if (!$res)
{
$arParams["ERROR_MESSAGE"] = GetMessage("SONET_GROUP_NOT_EXISTS");
return 0;
} */
$arFields["SOCNET_GROUP_ID"] = $object_id;
//$arGroup = CSocNetGroup::GetByID($object_id);
$arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $object_id;
$dbGroup = CSocNetGroup::GetList(array(), array("ID" => (int) $object_id), false, false, array("ID", "SITE_ID", "NAME"));
if ($arGroup = $dbGroup->Fetch()) {
$arFields["NAME"] = GetMessage("SONET_GROUP_PREFIX") . $arGroup["NAME"];
}
if (CIBlock::GetArrayByID($IBLOCK_ID, "RIGHTS_MODE") === "E") {
$arTasks = CWebDavIblock::GetTasks();
$arFields['RIGHTS'] = array('n0' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_A', 'TASK_ID' => $arTasks['X']), 'n1' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_E', 'TASK_ID' => $arTasks['W']), 'n2' => array('GROUP_CODE' => 'SG' . $arFields["SOCNET_GROUP_ID"] . '_K', 'TASK_ID' => $arTasks['W']));
}
}
if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk')) {
\Bitrix\Disk\Driver::getInstance()->addGroupStorage($arFields["SOCNET_GROUP_ID"]);
}
$GLOBALS["UF_USE_BP"] = $arFields["UF_USE_BP"];
$GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $IBLOCK_ID . "_SECTION", $arFields);
$bs = new CIBlockSection();
$sectionID = $bs->Add($arFields);
if (!$sectionID) {
$arParams["ERROR_MESSAGE"] = $bs->LAST_ERROR;
return 0;
}
WDClearComponentCache(array("webdav.element.edit", "webdav.element.hist", "webdav.element.upload", "webdav.element.view", "webdav.menu", "webdav.section.edit", "webdav.section.list"));
return true;
/*
if ($ob->workflow == 'bizproc')
{
__wd_create_default_bp_user_and_groups($arBizProcParameters);
}
*/
}
}
示例7: testAdd
public function testAdd()
{
$this->_injectDutyCollector();
$ibType = \CIBlockType::GetList()->Fetch();
$ib = new \CIBlock();
$ibId = $ib->Add(array('IBLOCK_TYPE_ID' => $ibType['ID'], 'NAME' => 'New Iblock', 'SITE_ID' => 's1'));
$this->assertNotEmpty($ibId, $this->errorMessage('not create iblock id', array(':lastError' => $ib->LAST_ERROR)));
$prop = new \CIBlockProperty();
$propId = $prop->Add(array('IBLOCK_ID' => $ibId, 'CODE' => 'propCode', 'NAME' => 'Property NAME'));
$this->assertNotEmpty($propId, $this->errorMessage('not create property iblock id', array(':lastError' => $ib->LAST_ERROR)));
$sec = new \CIBlockSection();
$secId = $sec->Add(array('IBLOCK_ID' => $ibId, 'NAME' => 'Iblock Section'));
$this->assertNotEmpty($secId, $this->errorMessage('not create section iblock id', array(':lastError' => $ib->LAST_ERROR)));
// ¬ итоге должны получитс¤
// данные по добавлению »Ѕ
$this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockHandler::className()));
// данные по добавлению свойства
$this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockPropertyHandler::className()));
// данные по добавлению секции
$this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockSectionHandler::className()));
$refFixes = $this->_getCollectorFixes('reference');
// фиксаци¤ изменений
Module::getInstance()->commitDutyChanges();
// добавлены записи журнала обновлений (в базу)
/** @var $logRecords AppliedChangesLogModel[] */
$logRecords = AppliedChangesLogModel::find(array('order' => array('id' => 'desc'), 'limit' => 10));
$this->assertTrue(count($logRecords) > 3);
$iterationsCount = 0;
foreach ($logRecords as $logRecord) {
if ($logRecord->processName == Module::SPECIAL_PROCESS_FIX_REFERENCE) {
continue;
}
if ($logRecord->processName != AddProcess::className()) {
$this->throwError($this->errorMessage('last log records need been update process'), $logRecord->processName);
}
if (++$iterationsCount > 3) {
break;
}
$data = $logRecord->updateData;
switch ($logRecord->subjectName) {
case IblockHandler::className():
(!$data['iblock'] || $data['iblock']['ID'] != $ibId) && $this->throwError($this->errorMessage('iblock not registered after update', array(':actual' => $data['iblock']['ID'], ':need' => $ibId)));
break;
case IblockPropertyHandler::className():
$data['ID'] != $propId && $this->throwError($this->errorMessage('property iblock not registered after update', array(':original' => $propId, ':actual' => $data['ID'])));
break;
case IblockSectionHandler::className():
$data['ID'] != $secId && $this->throwError($this->errorMessage('section iblock not registered after update', array(':original' => $secId, ':actual' => $data['ID'])));
break;
}
}
// добавлены три вида ссылок в фиксаци¤х
$this->assertEquals(3, count($refFixes), $this->errorMessage('links expected count', array(':count' => 3)));
$this->_iblockId = $ibId;
$this->_propertyId = $propId;
$this->_sectionId = $secId;
}
示例8: executeUp
function executeUp()
{
CModule::IncludeModule('iblock');
$obj_ib_section = new CIBlockSection();
$r = $obj_ib_section->Add(array('NAME' => 'new section here', 'CODE' => 'new_section_here', 'ACTIVE' => 'N', 'IBLOCK_ID' => self::IBLOCK_ID));
if (!$r) {
throw new \Exception('Err adding section:' . $obj_ib_section->LAST_ERROR);
}
return true;
}
示例9: IblockSectionCreate
/**
* @param array $params
*/
protected function IblockSectionCreate(array $params)
{
$bs = new \CIBlockSection();
$res = $bs->Add($params);
if (!$res) {
throw new \Exception($bs->LAST_ERROR);
} else {
return $res;
}
}
示例10: EnsureProductSection
private static function EnsureProductSection($externalID, $catalogID, $arFields)
{
$section = new CIBlockSection();
$rsSections = $section->GetList(array(), array('XML_ID' => $externalID, 'IBLOCK_ID' => $catalogID), false, array('ID'));
$arSection = $rsSections->Fetch();
if (is_array($arSection)) {
return intval($arSection['ID']);
}
$sectionID = $section->Add(array('IBLOCK_ID' => $catalogID, 'ACTIVE' => 'Y', 'NAME' => $arFields['NAME'], 'IBLOCK_SECTION_ID' => 0, 'CHECK_PERMISSIONS' => 'N', 'XML_ID' => $externalID));
return $sectionID;
}
示例11: addSection
public function addSection($iblockId, $fields = array())
{
$default = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => false, "NAME" => 'section', "CODE" => '', "SORT" => 100, "PICTURE" => false, "DESCRIPTION" => '', "DESCRIPTION_TYPE" => 'text');
$fields = array_merge($default, $fields);
$fields["IBLOCK_ID"] = $iblockId;
$ib = new \CIBlockSection();
$id = $ib->Add($fields);
if ($id) {
return $id;
}
$this->throwException(__METHOD__, $ib->LAST_ERROR);
}
示例12: addSectionReview
function addSectionReview($NAME, $CODE, $IBLOCK_ID)
{
CModule::IncludeModule('iblock');
$bs = new CIBlockSection();
$arFields = array("ACTIVE" => 'Y', "IBLOCK_ID" => $IBLOCK_ID, "NAME" => $NAME, "CODE" => $CODE);
$ID = $bs->Add($arFields);
$res = $ID > 0;
if (!$res) {
echo $bs->LAST_ERROR;
}
return $ID;
}
示例13: createAlbum
/**
* Creates new section in iblock
* @param $arParams
* @param $arResult
* @param $name
* @return bool|int
*/
public static function createAlbum($arParams, $arResult, &$name)
{
if (!CModule::IncludeModule("iblock")) {
return false;
}
$name = trim($name);
$name = strlen($name) > 0 ? $name : GetMessage("P_NEW_ALBUM");
$name = strlen($name) > 0 ? $name : "New album";
$arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "IBLOCK_SECTION_ID" => $arParams["BEHAVIOUR"] == "USER" ? $arResult["GALLERY"]["ID"] : 0, "DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "UF_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "NAME" => $name);
$GLOBALS["UF_DATE"] = $arFields["UF_DATE"];
$bs = new CIBlockSection();
$GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields);
$ID = $bs->Add($arFields);
if ($ID > 0) {
CIBlockSection::ReSort($arParams["IBLOCK_ID"]);
$arPropertiesNeed = array();
// Array of properties to create
foreach ($arParams['converters'] as $val) {
if ($val['code'] == "real_picture" || $val['code'] == "thumbnail") {
continue;
}
$db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $val['code']));
if (!($db_res && ($res = $db_res->Fetch()))) {
$arPropertiesNeed[] = $val['code'];
}
}
if (count($arPropertiesNeed) > 0) {
$obProperty = new CIBlockProperty();
foreach ($arPropertiesNeed as $key) {
$res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "F", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . strToUpper($key))) > 0 ? GetMessage("P_" . strToUpper($key)) : strToUpper($key), "CODE" => strToUpper($key), "FILE_TYPE" => "jpg, gif, bmp, png, jpeg"));
}
}
// Check Public property
$arPropertiesNeed = array();
foreach (array("PUBLIC_ELEMENT", "APPROVE_ELEMENT") as $key) {
$db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $key));
if (!$db_res || !($res = $db_res->Fetch())) {
$arPropertiesNeed[] = $key;
}
}
if (count($arPropertiesNeed) > 0) {
$obProperty = new CIBlockProperty();
foreach ($arPropertiesNeed as $key) {
$obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "S", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . $key)) > 0 ? GetMessage("P_" . $key) : $key, "DEFAULT_VALUE" => "N", "CODE" => $key));
}
}
}
return $ID > 0 ? $ID : false;
}
示例14: AddDepartment
function AddDepartment($SITE_ID, $arFields)
{
if (CModule::IncludeModule('iblock')) {
global $iblockID;
$arNewFields = array("NAME" => $arFields["NAME"], "IBLOCK_SECTION_ID" => $arFields["IBLOCK_SECTION_ID"], "UF_HEAD" => $arFields["UF_HEAD"], "IBLOCK_ID" => $iblockID);
$section = new CIBlockSection();
$ID = $section->Add($arNewFields);
}
if (!$ID) {
$arErrors = preg_split("/<br>/", $section->LAST_ERROR);
return $arErrors;
} else {
return $ID;
}
}
示例15: departmentAdd
public static function departmentAdd($params)
{
if (self::canEdit()) {
CModule::IncludeModule('iblock');
$params = array_change_key_case($params, CASE_UPPER);
$arFields = array('IBLOCK_ID' => self::getDeptIblock(), 'NAME' => $params['NAME'], 'SORT' => $params['SORT'], 'IBLOCK_SECTION_ID' => $params['PARENT'], 'UF_HEAD' => $params['UF_HEAD']);
$ob = new CIBlockSection();
$section = $ob->Add($arFields);
if ($section > 0) {
return $section;
} else {
throw new Exception($ob->LAST_ERROR);
}
} else {
throw new Exception('Access denied!');
}
}