Ejemplo n.º 1
0
 public static function SyncCalendars($connectionType, $arCalendars, $entityType, $entityId, $siteId, $connectionId = null)
 {
     //Array(
     //	[0] => Array(
     //		[XML_ID] => calendar
     //		[NAME] => calendar
     //	)
     //	[1] => Array(
     //		[XML_ID] => AQATAGFud...
     //		[NAME] => geewgvwe 1
     //		[DESCRIPTION] => gewgvewgvw
     //		[COLOR] => #FF0000
     //		[MODIFICATION_LABEL] => af720e7c7b6a
     //	)
     //)
     $entityType = strtoupper($entityType);
     if ($entityType == "USER") {
         $iblockId = self::GetUserCalendarIBlockId($siteId);
     } else {
         $iblockId = self::GetGroupCalendarIBlockId($siteId);
     }
     $accountRootSectionId = CEventCalendar::GetAccountRootSectionId($entityId, $entityType, $iblockId);
     if (intval($accountRootSectionId) <= 0) {
         $cal = self::GetInstance();
         $accountRootSectionId = $cal->CreateSectionForOwner($entityId, $entityType, $iblockId);
     }
     $sectionObject = new CIBlockSection();
     $arCalendarNames = array();
     foreach ($arCalendars as $value) {
         $arCalendarNames[$value["XML_ID"]] = $value;
     }
     if ($connectionType == 'exchange') {
         $xmlIdField = "UF_BXDAVEX_EXCH";
     } elseif ($connectionType == 'caldav') {
         $xmlIdField = "UF_BXDAVEX_CDAV";
     } else {
         return array();
     }
     $arResult = array();
     $arCalFilter = array('IBLOCK_ID' => $iblockId, "SECTION_ID" => $accountRootSectionId, "ACTIVE" => "Y", "CHECK_PERMISSIONS" => 'N', "!" . $xmlIdField => false);
     if ($connectionType == 'caldav') {
         $arCalFilter["UF_BXDAVEX_CDAV_COL"] = $connectionId;
     }
     $dbSections = CIBlockSection::GetList(array('ID' => 'ASC'), $arCalFilter, false, array("ID", "NAME", "DESCRIPTION", "UF_USER_CAL_COL", $xmlIdField, $xmlIdField . "_LBL"));
     while ($arSection = $dbSections->Fetch()) {
         $xmlId = $arSection[$xmlIdField];
         $modificationLabel = $arSection[$xmlIdField . "_LBL"];
         if (empty($xmlId)) {
             continue;
         }
         if (!array_key_exists($xmlId, $arCalendarNames)) {
             CIBlockSection::Delete($arSection["ID"], false);
         } else {
             if ($modificationLabel != $arCalendarNames[$xmlId]["MODIFICATION_LABEL"]) {
                 $sectionObject->Update($arSection["ID"], array("NAME" => $arCalendarNames[$xmlId]["NAME"], "DESCRIPTION" => $arCalendarNames[$xmlId]["DESCRIPTION"], "UF_USER_CAL_COL" => $arCalendarNames[$xmlId]["COLOR"], "CHECK_PERMISSIONS" => "N", $xmlIdField . "_LBL" => $arCalendarNames[$xmlId]["MODIFICATION_LABEL"]));
             }
             if (empty($modificationLabel) || $modificationLabel != $arCalendarNames[$xmlId]["MODIFICATION_LABEL"]) {
                 $arResult[] = array("XML_ID" => $xmlId, "CALENDAR_ID" => array($iblockId, $accountRootSectionId, $arSection["ID"], strtolower($entityType), $entityId));
             }
             unset($arCalendarNames[$xmlId]);
         }
     }
     foreach ($arCalendarNames as $key => $value) {
         $arFields = array("IBLOCK_ID" => $iblockId, "IBLOCK_SECTION_ID" => $accountRootSectionId, "NAME" => $value["NAME"], "DESCRIPTION" => $value["DESCRIPTION"], "UF_USER_CAL_COL" => $value["COLOR"], $xmlIdField => $key, "CHECK_PERMISSIONS" => "N", $xmlIdField . "_LBL" => $value["MODIFICATION_LABEL"]);
         if ($connectionType == 'caldav') {
             $arFields["UF_BXDAVEX_CDAV_COL"] = $connectionId;
         }
         if ($entityType == 'USER') {
             $arFields["CREATED_BY"] = $entityId;
         } elseif ($entityType == 'GROUP') {
             $arFields['SOCNET_GROUP_ID'] = $entityId;
         }
         $id = $sectionObject->Add($arFields);
         $arResult[] = array("XML_ID" => $key, "CALENDAR_ID" => array($iblockId, $accountRootSectionId, $id, strtolower($entityType), $entityId));
     }
     return $arResult;
 }
Ejemplo n.º 2
0
 public function GetCalendarId($siteId, $account, $arPath)
 {
     if (is_null($arPath)) {
         return null;
     }
     if (is_null($account)) {
         if (count($arPath) == 0) {
             return null;
         }
         return array($arPath[0], isset($arPath[1]) ? $arPath[1] : 0, 0, "", 0);
     }
     $arAccount = CDavAccount::GetAccountById($account);
     if ($arAccount["TYPE"] == "user") {
         $iblockId = CEventCalendar::GetUserCalendarIBlockId($siteId);
         if ($iblockId <= 0) {
             return null;
         }
         $accountRootSectionId = CEventCalendar::GetAccountRootSectionId($arAccount["ID"], $arAccount["TYPE"], $iblockId);
         if (!$accountRootSectionId) {
             return null;
         }
         return array($iblockId, $accountRootSectionId, isset($arPath[0]) ? $arPath[0] : 0, "user", $arAccount["ID"]);
     }
     $iblockId = CEventCalendar::GetGroupCalendarIBlockId($arAccount["SITE_ID"]);
     if ($iblockId <= 0) {
         return null;
     }
     $accountRootSectionId = CEventCalendar::GetAccountRootSectionId($arAccount["ID"], $arAccount["TYPE"], $iblockId);
     if (!$accountRootSectionId) {
         return null;
     }
     return array($iblockId, $accountRootSectionId, isset($arPath[0]) ? $arPath[0] : 0, "group", $arAccount["ID"]);
 }