本文整理汇总了PHP中CIBlockElement::SetElementSection方法的典型用法代码示例。如果您正苦于以下问题:PHP CIBlockElement::SetElementSection方法的具体用法?PHP CIBlockElement::SetElementSection怎么用?PHP CIBlockElement::SetElementSection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIBlockElement
的用法示例。
在下文中一共展示了CIBlockElement::SetElementSection方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: riseEvent
/**
* Запускает событие по атрибутам модели
* @param string $eventName
* @return bool
*/
public function riseEvent($eventName)
{
if ($eventName == 'afterSave') {
$val = $this->getValue();
if (!empty($val)) {
$current = is_array($val) ? array_map('intval', $val) : array(intval($val));
} else {
$current = array();
}
sort($current);
$inDb = $this->getSectionsId();
if ($inDb !== $current) {
if (!\CModule::IncludeModule('iblock')) {
throw new \bxar\Exception('Iblock module is not installed');
}
\CIBlockElement::SetElementSection($this->getModel()->getAttribute('id')->getValue(), !empty($current) ? $current : null);
}
$this->_sections = null;
}
}
示例2: Update
//.........这里部分代码省略.........
while ($arProp = $props->Fetch()) {
if (!array_key_exists($arProp["VALUE"], $arDup)) {
$arFields["PROPERTY_VALUES"][$arProp["ID"]][$arProp['PROPERTY_VALUE_ID']] = array("VALUE" => $arProp["VALUE"], "DESCRIPTION" => $arProp["DESCRIPTION"]);
$arDup[$arProp["VALUE"]] = true;
//This is cure for files duplication bug
}
}
}
}
} else {
if (array_key_exists("PREVIEW_PICTURE", $arFields)) {
CFile::SaveForDB($arFields, "PREVIEW_PICTURE", "iblock");
}
if (array_key_exists("DETAIL_PICTURE", $arFields)) {
CFile::SaveForDB($arFields, "DETAIL_PICTURE", "iblock");
}
}
unset($arFields["IBLOCK_ID"]);
unset($arFields["WF_NEW"]);
unset($arFields["IBLOCK_SECTION_ID"]);
$bTimeStampNA = false;
if (is_set($arFields, "TIMESTAMP_X") && ($arFields["TIMESTAMP_X"] === NULL || $arFields["TIMESTAMP_X"] === false)) {
$bTimeStampNA = true;
unset($arFields["TIMESTAMP_X"]);
}
$strUpdate = $DB->PrepareUpdate("b_iblock_element", $arFields, "iblock");
if (strlen($strUpdate) > 0) {
$strUpdate .= ", ";
}
$strSql = "UPDATE b_iblock_element SET " . $strUpdate . ($bTimeStampNA ? "TIMESTAMP_X=TIMESTAMP_X" : "TIMESTAMP_X=now()") . " WHERE ID=" . $ID;
$DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
if (array_key_exists("PROPERTY_VALUES", $arFields) && is_array($arFields["PROPERTY_VALUES"]) && count($arFields["PROPERTY_VALUES"]) > 0) {
CIBlockElement::SetPropertyValues($ID, $ar_element["IBLOCK_ID"], $arFields["PROPERTY_VALUES"]);
}
if (is_set($arFields, "IBLOCK_SECTION")) {
CIBlockElement::SetElementSection($ID, $arFields["IBLOCK_SECTION"], false, $arIBlock["RIGHTS_MODE"] === "E" ? $arIBlock["ID"] : 0);
}
if ($arIBlock["RIGHTS_MODE"] === "E") {
$obElementRights = new CIBlockElementRights($arIBlock["ID"], $ID);
if (array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"])) {
$obElementRights->SetRights($arFields["RIGHTS"]);
}
}
if (array_key_exists("IPROPERTY_TEMPLATES", $arFields)) {
$ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arIBlock["ID"], $ID);
$ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
}
if ($bUpdateSearch) {
CIBlockElement::UpdateSearch($ID, true);
}
if ($bWorkFlow) {
CIBlockElement::WF_CleanUpHistoryCopies($ID);
}
//Restore saved values
if ($SAVED_PREVIEW_PICTURE !== false) {
$arFields["PREVIEW_PICTURE_ID"] = $arFields["PREVIEW_PICTURE"];
$arFields["PREVIEW_PICTURE"] = $SAVED_PREVIEW_PICTURE;
} else {
unset($arFields["PREVIEW_PICTURE"]);
}
if ($SAVED_DETAIL_PICTURE !== false) {
$arFields["DETAIL_PICTURE_ID"] = $arFields["DETAIL_PICTURE"];
$arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE;
} else {
unset($arFields["DETAIL_PICTURE"]);
}
if ($arIBlock["FIELDS"]["LOG_ELEMENT_EDIT"]["IS_REQUIRED"] == "Y") {
$USER_ID = is_object($USER) ? intval($USER->GetID()) : 0;
$arEvents = GetModuleEvents("main", "OnBeforeEventLog", true);
if (empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID)) === false) {
$rsElement = CIBlockElement::GetList(array(), array("=ID" => $ID, "CHECK_PERMISSIONS" => "N", "SHOW_NEW" => "Y"), false, false, array("ID", "NAME", "LIST_PAGE_URL", "CODE"));
$arElement = $rsElement->GetNext();
$res = array("ID" => $ID, "CODE" => $arElement["CODE"], "NAME" => $arElement["NAME"], "ELEMENT_NAME" => $arIBlock["ELEMENT_NAME"], "USER_ID" => $USER_ID, "IBLOCK_PAGE_URL" => $arElement["LIST_PAGE_URL"]);
CEventLog::Log("IBLOCK", "IBLOCK_ELEMENT_EDIT", "iblock", $arIBlock["ID"], serialize($res));
}
}
$Result = true;
/************* QUOTA *************/
$_SESSION["SESS_RECOUNT_DB"] = "Y";
/************* QUOTA *************/
}
$arFields["ID"] = $ID;
$arFields["IBLOCK_ID"] = $ar_element["IBLOCK_ID"];
$arFields["RESULT"] =& $Result;
if (isset($arFields["PREVIEW_PICTURE"]) && $arFields["PREVIEW_PICTURE"]["COPY_FILE"] == "Y" && $arFields["PREVIEW_PICTURE"]["copy"]) {
@unlink($arFields["PREVIEW_PICTURE"]["tmp_name"]);
@rmdir(dirname($arFields["PREVIEW_PICTURE"]["tmp_name"]));
}
if (isset($arFields["DETAIL_PICTURE"]) && $arFields["DETAIL_PICTURE"]["COPY_FILE"] == "Y" && $arFields["DETAIL_PICTURE"]["copy"]) {
@unlink($arFields["DETAIL_PICTURE"]["tmp_name"]);
@rmdir(dirname($arFields["DETAIL_PICTURE"]["tmp_name"]));
}
foreach (GetModuleEvents("iblock", "OnAfterIBlockElementUpdate", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array(&$arFields));
}
if (defined("BX_COMP_MANAGED_CACHE")) {
$GLOBALS["CACHE_MANAGER"]->ClearByTag("iblock_id_" . $arIBlock["ID"]);
}
return $Result;
}
示例3: CIBlockElement
$obElement = new CIBlockElement();
/*Build filter*/
$arFilter = array("IBLOCK_ID" => $arIBlock["ID"], "CHECK_PERMISSIONS" => $arParams["CAN_EDIT"] || $arParams["SOCNET_GROUP_ID"] ? "N" : "Y");
if ($_POST["action_all_rows_" . $arResult["GRID_ID"]] == "Y") {
if (!$arResult["ANY_SECTION"]) {
$arFilter["SECTION_ID"] = $arResult["SECTION_ID"];
}
} else {
$arFilter["=ID"] = $_POST["ID"];
}
/*Take action*/
if ($_POST["action_button_" . $arResult["GRID_ID"]] == "section") {
if (!$arResult["IS_SOCNET_GROUP_CLOSED"] && ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockSectionRights::UserHasRightTo($arIBlock["ID"], $_POST["section_to_move"], "section_element_bind"))) {
$rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID"));
while ($arElement = $rsElements->Fetch()) {
$obElement->SetElementSection($arElement["ID"], array($_POST["section_to_move"]), false, $arIBlock["RIGHTS_MODE"] == "E" ? $arIBlock["ID"] : 0);
}
}
} elseif ($_POST["action_button_" . $arResult["GRID_ID"]] == "delete" && isset($_POST["ID"]) && is_array($_POST["ID"])) {
$rsElements = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID"));
while ($arElement = $rsElements->Fetch()) {
if (!$arResult["IS_SOCNET_GROUP_CLOSED"] && ($lists_perm >= CListPermissions::CAN_WRITE || CIBlockElementRights::UserHasRightTo($arIBlock["ID"], $arElement["ID"], "element_delete"))) {
$DB->StartTransaction();
$APPLICATION->ResetException();
if (!$obElement->Delete($arElement["ID"])) {
$DB->Rollback();
if ($ex = $APPLICATION->GetException()) {
$strError = GetMessage("CC_BLL_DELETE_ERROR") . " " . $ex->GetString();
} else {
$strError = GetMessage("CC_BLL_DELETE_ERROR") . " " . GetMessage("CC_BLL_UNKNOWN_ERROR");
}
示例4: Add
//.........这里部分代码省略.........
if (!isset($arFields["CREATED_BY"]) || intval($arFields["CREATED_BY"]) <= 0) {
$arFields["CREATED_BY"] = intval($USER->GetID());
}
if (!isset($arFields["MODIFIED_BY"]) || intval($arFields["MODIFIED_BY"]) <= 0) {
$arFields["MODIFIED_BY"] = intval($USER->GetID());
}
}
$arFields["~TIMESTAMP_X"] = $arFields["~DATE_CREATE"] = $DB->CurrentTimeFunction();
foreach (GetModuleEvents("iblock", "OnIBlockElementAdd", true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($arFields));
}
$IBLOCK_SECTION_ID = $arFields["IBLOCK_SECTION_ID"];
unset($arFields["IBLOCK_SECTION_ID"]);
$ID = $DB->Add("b_iblock_element", $arFields, array("DETAIL_TEXT", "SEARCHABLE_CONTENT"), "iblock");
if (array_key_exists("PREVIEW_PICTURE", $arFields)) {
$arFields["PREVIEW_PICTURE_ID"] = $arFields["PREVIEW_PICTURE"];
$arFields["PREVIEW_PICTURE"] = $SAVED_PREVIEW_PICTURE;
}
if (array_key_exists("DETAIL_PICTURE", $arFields)) {
$arFields["DETAIL_PICTURE_ID"] = $arFields["DETAIL_PICTURE"];
$arFields["DETAIL_PICTURE"] = $SAVED_DETAIL_PICTURE;
}
if (CIBlockElement::GetIBVersion($arFields["IBLOCK_ID"]) == 2) {
$DB->Query("INSERT INTO b_iblock_element_prop_s" . $arFields["IBLOCK_ID"] . "(IBLOCK_ELEMENT_ID)VALUES(" . $ID . ")");
}
if (!isset($arFields["XML_ID"]) || strlen($arFields["XML_ID"]) <= 0) {
$arFields["XML_ID"] = $ID;
$DB->Query("UPDATE b_iblock_element SET XML_ID = " . $ID . " WHERE ID = " . $ID);
}
if (is_set($arFields, "PROPERTY_VALUES")) {
CIBlockElement::SetPropertyValues($ID, $arFields["IBLOCK_ID"], $arFields["PROPERTY_VALUES"]);
}
if (is_set($arFields, "IBLOCK_SECTION")) {
CIBlockElement::SetElementSection($ID, $arFields["IBLOCK_SECTION"], true, $arIBlock["RIGHTS_MODE"] === "E" ? $arIBlock["ID"] : 0, $IBLOCK_SECTION_ID);
}
if ($arIBlock["RIGHTS_MODE"] === "E") {
$obElementRights = new CIBlockElementRights($arIBlock["ID"], $ID);
if (!is_set($arFields, "IBLOCK_SECTION") || empty($arFields["IBLOCK_SECTION"])) {
$obElementRights->ChangeParents(array(), array(0));
}
if (array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"])) {
$obElementRights->SetRights($arFields["RIGHTS"]);
}
}
if (array_key_exists("IPROPERTY_TEMPLATES", $arFields)) {
$ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arIBlock["ID"], $ID);
$ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
}
if ($bUpdateSearch) {
CIBlockElement::UpdateSearch($ID);
}
\Bitrix\Iblock\PropertyIndex\Manager::updateElementIndex($arIBlock["ID"], $ID);
if (!isset($arFields["WF_PARENT_ELEMENT_ID"]) && $arIBlock["FIELDS"]["LOG_ELEMENT_ADD"]["IS_REQUIRED"] == "Y") {
$USER_ID = is_object($USER) ? intval($USER->GetID()) : 0;
$arEvents = GetModuleEvents("main", "OnBeforeEventLog", true);
if (empty($arEvents) || ExecuteModuleEventEx($arEvents[0], array($USER_ID)) === false) {
$rsElement = CIBlockElement::GetList(array(), array("=ID" => $ID), false, false, array("LIST_PAGE_URL", "NAME", "CODE"));
$arElement = $rsElement->GetNext();
$res = array("ID" => $ID, "CODE" => $arElement["CODE"], "NAME" => $arElement["NAME"], "ELEMENT_NAME" => $arIBlock["ELEMENT_NAME"], "USER_ID" => $USER_ID, "IBLOCK_PAGE_URL" => $arElement["LIST_PAGE_URL"]);
CEventLog::Log("IBLOCK", "IBLOCK_ELEMENT_ADD", "iblock", $arIBlock["ID"], serialize($res));
}
}
if ($bWorkFlow && intval($arFields["WF_PARENT_ELEMENT_ID"]) <= 0) {
// It is completly new element - so make it copy
unset($arFields["WF_NEW"]);
$arFields["WF_PARENT_ELEMENT_ID"] = $ID;
示例5: OnBeforePrologHandler
//.........这里部分代码省略.........
$strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$intValueID];
if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) {
$arNewEnumList[] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID];
} else {
$strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$intValueID];
$intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]);
if ($intValueKey !== false) {
$arNewEnumList[] = $intValueKey;
}
}
}
if (isset($intValueID)) {
unset($intValueID);
}
if (!empty($arNewEnumList)) {
$arDestSect[$arOneUserField['FIELD_NAME']] = $arNewEnumList;
}
} else {
$strValueXmlID = $arOldUFEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]];
if (array_key_exists($strValueXmlID, $arUFEnumCache[$arOneUserField['FIELD_NAME']])) {
$arDestSect[$arOneUserField['FIELD_NAME']] = $arUFEnumCache[$arOneUserField['FIELD_NAME']][$strValueXmlID];
} else {
$strValueName = $arOldUFNameEnumCache[$arOneUserField['FIELD_NAME']][$arDestSect[$arOneUserField['FIELD_NAME']]];
$intValueKey = array_search($strValueName, $arUFNameEnumCache[$arOneUserField['FIELD_NAME']]);
if ($intValueKey !== false) {
$arDestSect[$arOneUserField['FIELD_NAME']] = $intValueKey;
}
}
}
}
}
} else {
$arDestSect[$arOneUserField['FIELD_NAME']] = false;
}
}
}
if (isset($arOneUserField)) {
unset($arOneUserField);
}
}
$intNewID = $sc->Add($arDestSect);
if (!$intNewID) {
CASDiblock::$error .= '[' . $ID . '] ' . $sc->LAST_ERROR . "\n";
}
}
}
}
$successRedirect = true;
}
unset($_REQUEST['action']);
if (isset($_REQUEST['action_button'])) {
unset($_REQUEST['action_button']);
}
if ($successRedirect) {
LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button', 'asd_ib_dest', 'asd_sect_dest', 'ID')));
}
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'asd_remove' && $IBLOCK_ID > 0 && isset($_REQUEST['find_section_section']) && check_bitrix_sessid() && CASDIblockRights::IsIBlockDisplay($IBLOCK_ID)) {
$intSectionID = (int) $_REQUEST['find_section_section'];
if ($intSectionID > 0) {
$strCurPage = $GLOBALS['APPLICATION']->GetCurPage();
$bElemPage = $strCurPage == '/bitrix/admin/iblock_element_admin.php' || $strCurPage == '/bitrix/admin/cat_product_admin.php';
$bMixPage = $strCurPage == '/bitrix/admin/iblock_list_admin.php';
if ($bElemPage || $bMixPage) {
foreach ($_REQUEST['ID'] as $eID) {
if ($bMixPage) {
if (substr($eID, 0, 1) != 'E') {
continue;
}
$ID = (int) substr($eID, 1);
} else {
$ID = (int) $eID;
}
if ($ID <= 0) {
continue;
}
if (CASDIblockRights::IsElementEdit($IBLOCK_ID, $ID)) {
$arSectionList = array();
$rsSections = CIBlockElement::GetElementGroups($ID, true);
while ($arSection = $rsSections->Fetch()) {
$arSection['ID'] = (int) $arSection['ID'];
if ($arSection['ID'] != $intSectionID) {
$arSectionList[] = $arSection['ID'];
}
}
CIBlockElement::SetElementSection($ID, $arSectionList, false);
$successRedirect = true;
}
}
}
}
unset($_REQUEST['action']);
if (isset($_REQUEST['action_button'])) {
unset($_REQUEST['action_button']);
}
if ($successRedirect) {
LocalRedirect($GLOBALS['APPLICATION']->GetCurPageParam('', array('action', 'action_button')));
}
}
}
示例6: workWithDropped
protected function workWithDropped(array $droppedSection, $downloadedSectionId)
{
$this->abortIfNeeded();
$droppedElementQuery = CIBlockElement::GetList(array(), array('CHECK_PERMISSIONS' => 'N', 'INCLUDE_SUBSECTIONS' => 'Y', 'SECTION_ID' => $droppedSection['ID'], 'IBLOCK_ID' => $droppedSection['IBLOCK_ID']));
if (!$droppedElementQuery) {
//empty spaces
return true;
}
while ($droppedElement = $droppedElementQuery->Fetch()) {
$this->abortIfNeeded();
//prepare
$this->uniqualizeElement($droppedElement, $downloadedSectionId);
//move to new life
CIBlockElement::SetElementSection($droppedElement['ID'], array($downloadedSectionId));
static::$countConvertElements++;
}
//empty spaces
return true;
}
示例7: UpdateCategory
/**
* <p>Метод обновляет привязки Wiki-страницы к категориям. Динамичный метод.</p>
*
*
* @param int $ID Идентификатор Wiki-страницы
*
* @param int $IBLOCK_ID Идентификатор Инфо.блока
*
* @param array $arCats Массив наименований категорий страницы
*
* @return void
*
* <h4>Example</h4>
* <pre>
* <?<br>
* // Обновим категории страницы с идентификатором 13 из инфо.блока с идентификатором 2
* $arCats = array('Категория 1', 'Категория 2');
* $ID = 13;
* $IBLOCK_ID = 2;
*
* $CWiki = new CWiki();
* $CWiki->UpdateCategory($ID, $IBLOCK_ID, $arCats);<br>?>
* </pre>
*
*
* <h4>See Also</h4>
* <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/GetCategory.php">CWiki::GetCategory</a> </li>
* </ul><a name="examples"></a>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/UpdateCategory.php
* @author Bitrix
*/
public function UpdateCategory($ID, $IBLOCK_ID, $arCats)
{
$this->CleanCacheById($ID, $IBLOCK_ID);
$arFilter = array('IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
$arElement = self::GetElementById($ID, $arFilter);
$bCategoryPage = false;
$sCatName = '';
$arCatsID = array();
if (CWikiUtils::IsCategoryPage($arElement['~NAME'], $sCatName)) {
$bCategoryPage = true;
}
if ($bCategoryPage) {
// get current category
$arFilter = array('NAME' => $sCatName, 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
if (CWikiSocnet::IsSocNet()) {
$arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder;
$arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder;
}
$rsCurCats = CIBlockSection::GetList(array(), $arFilter);
$arCurCat = $rsCurCats->GetNext();
if (empty($arCurCat)) {
$CIB_S = new CIBlockSection();
$_arFields = array();
$_arFields['IBLOCK_ID'] = $IBLOCK_ID;
$_arFields['ACTIVE'] = 'Y';
$_arFields['NAME'] = $sCatName;
$_arFields['XML_ID'] = $sCatName;
if (CWikiSocnet::IsSocNet()) {
$_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
}
$iCurCatID = $CIB_S->Add($_arFields);
if ($iCurCatID != false) {
$arCatsID[] = $iCurCatID;
}
} else {
$iCurCatID = $arCurCat['ID'];
$arCatsID[] = $arCurCat['ID'];
}
// Page bind only to this category
CIBlockElement::SetElementSection($ID, $arCatsID);
$CIB_S = new CIBlockSection();
if (!empty($arCats)) {
// Nova create a category if it still has no
$arFilter = array('NAME' => $arCats[0], 'IBLOCK_ID' => $IBLOCK_ID, 'CHECK_PERMISSIONS' => 'N');
if (CWikiSocnet::IsSocNet()) {
$arFilter['>LEFT_BORDER'] = CWikiSocnet::$iCatLeftBorder;
$arFilter['<RIGHT_BORDER'] = CWikiSocnet::$iCatRightBorder;
}
$rsCats = CIBlockSection::GetList(array(), $arFilter);
$arCat = $rsCats->GetNext();
if (empty($arCat)) {
$_arFields = array();
$_arFields['IBLOCK_ID'] = $IBLOCK_ID;
$_arFields['ACTIVE'] = 'Y';
$_arFields['NAME'] = CWikiUtils::htmlspecialcharsback($arCats[0]);
$_arFields['XML_ID'] = CWikiUtils::htmlspecialcharsback($arCats[0]);
$_arFields['CHECK_PERMISSIONS'] = 'N';
if (CWikiSocnet::IsSocNet()) {
$_arFields['IBLOCK_SECTION_ID'] = CWikiSocnet::$iCatId;
}
$iCatID = $CIB_S->Add($_arFields);
} else {
$iCatID = $arCat['ID'];
}
$_arFields = array();
$_arFields['IBLOCK_ID'] = $IBLOCK_ID;
//.........这里部分代码省略.........
示例8: COPY
//.........这里部分代码省略.........
}
if ($arTo['parent_id'] == $this->GetMetaID('TRASH')) {
$arCheckTrashElement = $arFrom[$arFrom['is_dir'] ? 'dir_array' : 'element_array'];
if ($this->_parse_webdav_info($arCheckTrashElement) && !isset($arCheckTrashElement['PROPS']['BX:']['UNDELETE'])) {
return $this->ThrowAccessDenied("BAD_NAME", __LINE__);
}
}
if ($arFrom["is_file"]) {
$el = new CIBlockElement();
if ($arTo["item_id"] && $arTo['item_id'] !== $arFrom['item_id']) {
$this->_ib_elm_delete($arTo['item_id']);
// TODO: need to check permissions ?
}
//drop == true if this action is @move@
//is file
if ($drop) {
$actionRename = $arFrom['parent_id'] == $arTo['parent_id'];
$arFields = array("NAME" => $arTo["basename"], "MODIFIED_BY" => $GLOBALS['USER']->GetID(), "IBLOCK_SECTION_ID" => $arTo["parent_id"]);
$this->_onEvent($arFrom['parent_id'] != $arTo['parent_id'] ? 'Move' : 'Rename', $arFrom['element_id'], 'FILE', array('TO' => $arFrom['parent_id'] != $arTo['parent_id'] ? $arTo["parent_id"] : $arTo["basename"]));
//from symlink move. Not rename!!!!
if (!$actionRename && (!empty($arFrom['is_symlink']) || !empty($arTo['is_symlink']))) {
$targetIblockId = $this->IBLOCK_ID;
if (!empty($arTo['is_symlink'])) {
$targetIblockId = $arTo['symlink_section_data']['IBLOCK_ID'];
}
//move and don't delete item
if (self::_move_from_iblock_to_iblock($arFrom['item_id'], $targetIblockId, $arTo['parent_id'], false, true)) {
$statusSymlinkDelete = $this->DELETE(array("element_id" => $arFrom['item_id']));
}
} else {
if ($this->workflow == 'workflow') {
if ($arTo["parent_id"] != $arFrom["parent_id"]) {
$arFields["WF_COMMENTS"] = GetMessage("WD_FILE_IS_MOVED");
$el->SetElementSection($arFrom["item_id"], $arTo["parent_id"]);
// TODO: need to check permissions ???
} else {
$arFields["WF_COMMENTS"] = GetMessage("WD_FILE_IS_RENAMED");
}
if ($arTo["parent_id"] != $arFrom["parent_id"] && $arTo["basename"] != $arFrom["element_name"]) {
$arFields["WF_COMMENTS"] = GetMessage("WD_FILE_IS_MOVED_AND_RENAMED");
}
}
if ($this->workflow == 'bizproc' || $this->workflow == 'bizproc_limited') {
$this->AddDocumentToHistory($arFrom['item_id'], $arFrom['element_name']);
}
$el->Update($arFrom["item_id"], $arFields, $this->workflow == 'workflow', true, false, false);
// TODO: need to check permissions ???
$arCacheCleanID[] = 'element' . $arFrom["item_id"];
if ($this->workflow == 'bizproc' || $this->workflow == 'bizproc_limited') {
$db_res2 = CIBlockElement::GetList(array(), array("WF_PARENT_ELEMENT_ID" => $arFrom["item_id"], "SHOW_HISTORY" => "Y"), false, false, array("ID"));
if ($db_res2 && ($res2 = $db_res2->Fetch())) {
do {
$res = $el->Update($res2["ID"], array("IBLOCK_SECTION_ID" => $arFields["IBLOCK_SECTION_ID"]), false, true, false, false);
$arCacheCleanID[] = 'element' . $res2["ID"];
} while ($res2 = $db_res2->Fetch());
}
}
}
} else {
//from symlink copy
if (!empty($arFrom['is_symlink']) || !empty($arTo['is_symlink'])) {
$targetIblockId = $this->IBLOCK_ID;
if (!empty($arTo['is_symlink'])) {
$targetIblockId = $arTo['symlink_section_data']['IBLOCK_ID'];
}
//move and don't delete item
示例9: save
/**
* Сохраняет запись
* @return bool
*/
public function save()
{
if (!\CModule::IncludeModule('iblock') || !$this->validate() || !$this->riseEvent('beforeSave')) {
return false;
}
$ib = new \CIBlockElement();
//собираем поля элемента
$arFields = array();
$arProperties = array();
foreach ($this->getAttributes() as $key => $attr) {
if (strpos($key, 'property_') === 0) {
$arProperties[$attr->getParam('id')] = $attr->getValueToDb();
} elseif ($key !== 'id') {
$arFields[strtoupper($key)] = $attr->getValueToDb();
}
}
//записываем поля элемента
if (!$this->isNew()) {
$id = $this->getAttribute('id')->getValue();
/* меняем местами обновление свойств инфоблока и стандартных полей, для правильного срабатывания событий, fix at 30/09/2016 */
//отдельно обновляем пользовательские свойства, чтобы не перезаписывать те, которы не были обновлены
//если обновлять свойства вместе с основными параметрами, будут возникать дубли, поэтому свойства сохраняем отдельно
if (!empty($arProperties)) {
\CIBlockElement::SetPropertyValuesEx($id, $this->getAttribute('iblock_id')->getValue(), $arProperties);
}
//при обновлении элемента сначала записываем базовые поля
$res = $ib->Update($id, $arFields);
if (!$res) {
throw new Exception($ib->LAST_ERROR);
}
$this->riseEvent('afterSave');
} else {
//при вставке нового элемента записываем сразу все пользовательские свойства
if (!empty($arProperties)) {
$arFields['PROPERTY_VALUES'] = $arProperties;
}
$new = $ib->Add($arFields);
if ($new) {
$this->getAttribute('id')->setValue($new);
$this->riseEvent('afterSave');
} else {
throw new Exception($ib->LAST_ERROR);
}
}
if (isset($arFields['IBLOCK_SECTION_ID']) && is_array($arFields['IBLOCK_SECTION_ID'])) {
\CIBlockElement::SetElementSection($this->getAttribute('id')->getValue(), $arFields['IBLOCK_SECTION_ID']);
}
return true;
}