public function Execute() { if (!CModule::IncludeModule("intranet")) { return CBPActivityExecutionStatus::Closed; } $calendarIblockId = COption::GetOptionInt("intranet", 'iblock_calendar', 0); if ($calendarIblockId <= 0) { return CBPActivityExecutionStatus::Closed; } $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $arCalendarUser = CBPHelper::ExtractUsers($this->CalendarUser, $documentId); foreach ($arCalendarUser as $calendarUser) { $Params = array('iblockId' => $calendarIblockId, 'ownerType' => "USER", 'ownerId' => $calendarUser, 'cacheTime' => 0, 'pageUrl' => false, 'allowSuperpose' => false, 'allowResMeeting' => false, 'allowVideoMeeting' => false, 'userIblockId' => $calendarIblockId); $EC = new CEventCalendar(); $EC->Init($Params); $sectionId = $EC->GetSectionIDByOwnerId($calendarUser, 'USER', $calendarIblockId); if ($sectionId <= 0) { $sectionId = CEventCalendar::CreateSectionForOwner($calendarUser, "USER", $calendarIblockId); } $arGuestCalendars = $EC->GetCalendars(array('sectionId' => $sectionId, 'iblockId' => $calendarIblockId, 'ownerType' => 'USER', 'ownerId' => $calendarUser, 'bOwner' => true, 'forExport' => true, 'bOnlyID' => true)); $arParams = array('iblockId' => $calendarIblockId, 'ownerType' => "USER", 'ownerId' => $calendarUser, 'sectionId' => $sectionId, 'bNew' => true, 'name' => $this->CalendarName, 'desc' => $this->CalendarDesrc, 'dateFrom' => cutZeroTime($this->CalendarFrom), 'dateTo' => cutZeroTime($this->CalendarTo), 'isMeeting' => false, 'prop' => array('PERIOD_TYPE' => 'NONE', 'ACCESSIBILITY' => 'busy', 'IMPORTANCE' => 'normal', 'PRIVATE' => false), 'userId' => $calendarUser, 'userIblockId' => $calendarIblockId, 'location' => array('new' => '', 'change' => true)); if (count($arGuestCalendars) > 0) { $arParams["calendarId"] = $arGuestCalendars[0]; } $EC->SaveEvent($arParams); } if (isset($EC)) { $EC->ClearCache($EC->cachePath . 'events/' . $calendarIblockId . '/'); } return CBPActivityExecutionStatus::Closed; }
public static function AddEvent($MEETING_ID, $arFields, $arParams = array()) { global $USER; $EventID = false; if (self::IsNewCalendar()) { $arEventFields = array('ID' => $arFields['EVENT_ID'], 'CAL_TYPE' => 'user', 'OWNER_ID' => $arFields['OWNER_ID'], 'DT_FROM' => $arFields['DATE_START'], 'DT_TO' => ConvertTimeStamp(MakeTimeStamp($arFields['DATE_START']) + $arFields['DURATION'], 'FULL'), 'NAME' => $arFields['TITLE'], 'DESCRIPTION' => CCalendar::ParseHTMLToBB($arFields['DESCRIPTION']), 'IS_MEETING' => true, 'MEETING_HOST' => $arFields['OWNER_ID'], 'MEETING' => array('HOST_NAME' => CCalendar::GetUserName($arFields['OWNER_ID'])), 'ATTENDEES' => array_keys($arFields['USERS'])); if ($arFields['CURRENT_STATE'] == CMeeting::STATE_CLOSED) { $arEventFields['DT_TO'] = MakeTimeStamp($arFields['DATE_FINISH']) > MakeTimeStamp($arFields['DATE_START']) ? $arFields['DATE_FINISH'] : $arEventFields['DT_TO']; } $matches = array(); if (preg_match('/^mr_([\\d]+)_([\\d]+)$/', $arFields["PLACE"], $matches)) { $arEventFields['LOCATION'] = 'ECMR_' . $matches[2]; if ($arFields['EVENT_ID'] > 0) { $arCurrentEvent = CCalendarEvent::GetById($arFields['EVENT_ID']); if ($arCurrentEvent['LOCATION']) { $res = CCalendar::ParseLocation($arCurrentEvent['LOCATION']); if ($res['mrevid']) { $arEventFields['LOCATION'] .= '_' . $res['mrevid']; } } } } else { $arEventFields['LOCATION'] = $arFields['PLACE']; } if (isset($arFields['REINVITE'])) { $arEventFields['MEETING']['REINVITE'] = $arFields['REINVITE']; } else { $arEventFields['MEETING']['REINVITE'] = false; } if (isset($arFields['NOTIFY'])) { $arEventFields['MEETING']['NOTIFY'] = $arFields['NOTIFY']; } $EventID = CCalendar::SaveEvent(array('arFields' => $arEventFields, 'userId' => $arFields['OWNER_ID'], 'autoDetectSection' => true, 'autoCreateSection' => true)); } elseif (!$arFields['EVENT_ID']) { $iblockId = $arParams['CALENDAR_IBLOCK_ID'] ? $arParams['CALENDAR_IBLOCK_ID'] : COption::GetOptionInt('intranet', 'iblock_calendar', 0, SITE_ID); $obCalendar = new CEventCalendar(); $obCalendar->Init(array('ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => true, 'iblockId' => $iblockId, 'userIblockId' => $iblockId, 'bCache' => false, 'pathToUserCalendar' => '/company/personal/user/#user_id#/calendar/')); $guestCalendarId = false; $guestSection = $obCalendar->GetSectionIDByOwnerId($USER->GetID(), 'USER', $iblockId); $arGuestCalendars = array(); if (!$guestSection) { $guestSection = $obCalendar->CreateSectionForOwner($USER->GetID(), "USER", $iblockId); } $arGuestCalendars = $obCalendar->GetCalendars(array('sectionId' => $guestSection, 'iblockId' => $iblockId, 'ownerType' => 'USER', 'ownerId' => $USER->GetID(), 'bOwner' => 1, 'forExport' => true, 'bOnlyID' => true)); if (count($arGuestCalendars) > 0) { $arUserSet = $obCalendar->GetUserSettings(array('static' => false, 'userId' => $USER->GetID())); if ($arUserSet && isset($arUserSet['MeetCalId']) && in_array($arUserSet['MeetCalId'], $arGuestCalendars)) { $guestCalendarId = intVal($arUserSet['MeetCalId']); } else { $guestCalendarId = $arGuestCalendars[0]; } } //$bGroup = $arParams['GROUP_ID'] > 0; $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true)); $arEventFields = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'RMiblockId' => self::__getRMIblockID(), 'allowResMeeting' => true, 'bNew' => true, 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->iblockId, 'calendarId' => $guestCalendarId, 'sectionId' => $guestSection, 'dateFrom' => $arFields['DATE_START'], 'dateTo' => $arFields['DATE_FINISH'] ? $arFields['DATE_FINISH'] : ConvertTimeStamp(MakeTimeStamp($arFields['DATE_START']) + $arFields['DURATION'], 'FULL'), 'name' => $arFields['TITLE'], 'desc' => $arFields['DESCRIPTION'], 'prop' => array(), 'isMeeting' => true, 'guests' => array_keys($arFields['USERS']), 'notDisplayCalendar' => true); if ($EventID = $obCalendar->SaveEvent($arEventFields)) { CEventCalendar::ClearCache('/event_calendar/events/' . $arEventFields['iblockId'] . '/'); CEventCalendar::ClearCache('/event_calendar/events/' . $arEventFields['userIblockId'] . '/'); } } if ($EventID) { self::Update($MEETING_ID, array('EVENT_ID' => $EventID)); } return $EventID; }