コード例 #1
0
 function Delete($arParams)
 {
     global $DB, $USER;
     $iblockId = $arParams['iblockId'];
     $ownerType = $arParams['ownerType'];
     $ownerId = $arParams['ownerId'];
     $ID = $arParams['id'];
     $userId = $arParams['userId'];
     if ($USER) {
         $ownerName = $USER->GetFullName();
     } else {
         $rs = CUser::GetByID($userId);
         if ($arUser = $rs->Fetch()) {
             $name = trim($arUser['NAME'] . ' ' . $arUser['LAST_NAME']);
         }
     }
     $pathToUserCalendar = $arParams['pathToUserCalendar'];
     $arFilter = array("ID" => $ID, "IBLOCK_ID" => $iblockId);
     if ($arParams['bCheckPermissions'] !== false) {
         $arFilter[$ownerType == 'USER' ? "CREATED_BY" : "SOCNET_GROUP_ID"] = $ownerId;
     }
     $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID", "XML_ID", "IBLOCK_ID", "PROPERTY_PRIVATE", "PROPERTY_ACCESSIBILITY", "PROPERTY_IMPORTANCE", "PROPERTY_PARENT", "PROPERTY_LOCATION", "NAME", "DETAIL_TEXT", "IBLOCK_SECTION_ID", "ACTIVE_FROM", "ACTIVE_TO", "CREATED_BY", "PROPERTY_BXDAVEX_LABEL", "PROPERTY_BXDAVCD_LABEL"));
     if ($arElement = $rsElement->Fetch()) {
         $DB->StartTransaction();
         // PROPERTY_PARENT_VALUE - id of parent iblock element in meeting
         if (strlen($arElement["PROPERTY_PARENT_VALUE"]) > 0 && $arParams['bJustDel'] !== true) {
             if ($ownerType == 'USER') {
                 $rsHost = CIBlockElement::GetList(array(), array("=ID" => $arElement["PROPERTY_PARENT_VALUE"], "CREATED_BY" => $arElement['CREATED_BY']), false, false, array("ID", "IBLOCK_ID"));
                 // Owner delete mirror of the original event in the personal calendar
                 if ($arHost = $rsHost->Fetch()) {
                     CECEvent::Delete(array('bCheckPermissions' => false, 'id' => intVal($arHost['ID']), 'iblockId' => intVal($arHost['IBLOCK_ID']), 'ownerType' => '', 'ownerId' => 0, 'userId' => $userId, 'pathToUserCalendar' => $arParams['pathToUserCalendar'], 'pathToGroupCalendar' => $arParams['pathToGroupCalendar'], 'userIblockId' => $arParams['userIblockId'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                     $this->ClearCache($this->cachePath . 'events/' . $arHost['IBLOCK_ID'] . '/');
                     return true;
                 }
             }
             // If no exchange
             CIBlockElement::SetPropertyValues($arElement["ID"], $arElement["IBLOCK_ID"], CEventCalendar::GetConfirmedID($iblockId, "N"), "CONFIRMED");
         } else {
             if ($arParams['bSyncDAV'] !== false) {
                 // Exchange
                 if (CEventCalendar::IsExchangeEnabled() && $ownerType == 'USER' && strlen($arElement['PROPERTY_BXDAVEX_LABEL_VALUE']) > 0) {
                     $eventXmlId = $arElement['XML_ID'];
                     $exchRes = CDavExchangeCalendar::DoDeleteItem($ownerId, $eventXmlId);
                     if ($exchRes !== true) {
                         return CEventCalendar::CollectExchangeErros($exchRes);
                     }
                 }
                 if (CEventCalendar::IsCalDAVEnabled() && $ownerType == 'USER' && strlen($arElement['PROPERTY_BXDAVCD_LABEL_VALUE']) > 0) {
                     $connectionId = CECCalendar::GetCalDAVConnectionId($iblockId, $arElement['IBLOCK_SECTION_ID']);
                     $calendarCalDAVXmlId = CECCalendar::GetCalDAVXmlId($iblockId, $arElement['IBLOCK_SECTION_ID']);
                     $DAVRes = CDavGroupdavClientCalendar::DoDeleteItem($connectionId, $calendarCalDAVXmlId, $arElement['XML_ID']);
                     if ($DAVRes !== true) {
                         return CEventCalendar::CollectCalDAVErros($DAVRes);
                     }
                 }
             }
             if (strlen($arElement["PROPERTY_LOCATION_VALUE"]) > 0) {
                 $loc = CEventCalendar::ParseLocation($arElement["PROPERTY_LOCATION_VALUE"]);
                 if ($loc['mrid'] == $arParams['VMiblockId'] && $loc['mrevid'] > 0) {
                     CEventCalendar::ReleaseVR(array('mrevid' => $loc['mrevid'], 'mrid' => $loc['mrid'], 'VMiblockId' => $arParams['VMiblockId'], 'allowVideoMeeting' => $arParams['allowVideoMeeting']));
                 } elseif ($loc['mrid'] > 0 && $loc['mrevid'] > 0) {
                     CEventCalendar::ReleaseMR(array('mrevid' => $loc['mrevid'], 'mrid' => $loc['mrid'], 'RMiblockId' => $arParams['RMiblockId'], 'allowResMeeting' => $arParams['allowResMeeting']));
                 }
             }
             $arGuests = CECEvent::GetGuests($arParams['userIblockId'], $ID);
             $obElement = new CIBlockElement();
             foreach ($arGuests as $guest_id => $arCalendarEvent) {
                 $res = CECEvent::Delete(array('id' => $arCalendarEvent["ID"], 'iblockId' => $arParams['userIblockId'], 'ownerType' => "USER", 'ownerId' => $guest_id, 'userId' => $userId, 'bJustDel' => true));
                 if ($userId == $guest_id) {
                     continue;
                 }
                 if ($arCalendarEvent["PROPERTY_VALUES"]["CONFIRMED"] != "N") {
                     // Send message
                     CEventCalendar::SendInvitationMessage(array('type' => "cancel", 'email' => $arCalendarEvent["CREATED_BY"]["EMAIL"], 'name' => $arCalendarEvent['NAME'], "from" => $arCalendarEvent["ACTIVE_FROM"], "to" => $arCalendarEvent["ACTIVE_TO"], "desc" => $arCalendarEvent['DETAIL_TEXT'], "pathToUserCalendar" => $pathToUserCalendar, "guestId" => $guest_id, "guestName" => $arCalendarEvent["CREATED_BY"]["FULL_NAME"], "userId" => $userId, "ownerName" => $ownerName));
                 }
             }
             if ($ownerType != 'USER') {
                 CEventCalendar::ClearCache('event_calendar/events/' . $arParams['userIblockId'] . '/');
             }
             // Deleting
             if (!CIBlockElement::Delete($ID)) {
                 $DB->Rollback();
                 return '[ECD1]' . GetMessage('EC_EVENT_ERROR_DEL');
             }
         }
         // log changes for socnet
         /*			if($this->bSocNetLog && $ownerType && !$arElement["PROPERTY_PRIVATE_VALUE"] && !$arParams['dontLogEvent'])
         			{
         				CEventCalendar::SocNetLog(
         					array(
         						'target' => 'delete_event',
         						'id' => $ID,
         						'name' => $arElement['NAME'],
         						'desc' => $arElement['DETAIL_TEXT'],
         						'from' => $arElement['ACTIVE_FROM'],
         						'to' => $arElement['ACTIVE_TO'],
         						'calendarId' => $arElement['IBLOCK_SECTION_ID'],
         						'accessibility' => $arElement["PROPERTY_ACCESSIBILITY_VALUE"],
         						'importance' => $arElement["PROPERTY_IMPORTANCE_VALUE"],
         						'pathToGroupCalendar' =>  $arParams["pathToGroupCalendar"],
         						'pathToUserCalendar' =>  $arParams["pathToUserCalendar"],
         						'iblockId' => $iblockId,
         						'ownerType' => $ownerType,
         						'ownerId' => $ownerId
         					)
         				);
         			}*/
         $DB->Commit();
     } else {
         return '[ECD2]' . GetMessage('EC_EVENT_NOT_FOUND');
     }
     return true;
 }