Пример #1
0
 /**
  * Allows for importing data into user's address book.
  * 
  * @param int $iUserId User ID
  * @param string $sSyncType Data source type. Currently, "csv" and "vcf" options are supported.
  * @param string $sTempFileName Path to the file data are imported from.
  * @param int $iParsedCount
  * @param int $iGroupId
  * @param bool $bIsShared
  *
  * @return int|false If importing is successful, number of imported entries is returned. 
  */
 public function import($iUserId, $sSyncType, $sTempFileName, &$iParsedCount, $iGroupId, $bIsShared)
 {
     $oApiUsersManager = CApi::Manager('users');
     $oAccount = $oApiUsersManager->getDefaultAccount($iUserId);
     if ($sSyncType === \EContactFileType::CSV) {
         $this->inc('helpers.' . $sSyncType . '.formatter');
         $this->inc('helpers.' . $sSyncType . '.parser');
         $this->inc('helpers.sync.' . $sSyncType);
         $sSyncClass = 'CApi' . ucfirst($this->GetManagerName()) . 'Sync' . ucfirst($sSyncType);
         if (class_exists($sSyncClass)) {
             $oSync = new $sSyncClass($this);
             return $oSync->Import($iUserId, $sTempFileName, $iParsedCount, $iGroupId, $bIsShared);
         }
     } else {
         if ($sSyncType === \EContactFileType::VCF) {
             // You can either pass a readable stream, or a string.
             $oHandler = fopen($sTempFileName, 'r');
             $oSplitter = new \Sabre\VObject\Splitter\VCard($oHandler);
             while ($oVCard = $oSplitter->getNext()) {
                 $oContact = new \CContact();
                 $oContact->InitFromVCardObject($iUserId, $oVCard);
                 if ($oAccount) {
                     $oContact->IdDomain = $oAccount->IdDomain;
                     $oContact->IdTenant = $oAccount->IdTenant;
                 }
                 $oContact->SharedToAll = $bIsShared;
                 $oContact->GroupsIds = array($iGroupId);
                 if ($this->createContact($oContact)) {
                     $iParsedCount++;
                 }
             }
             return $iParsedCount;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * @param int $iUserId
  * @param string $sSyncType
  * @param string $sTempFileName
  * @param int $iParsedCount
  * @return int | false
  */
 public function Import($iUserId, $sSyncType, $sTempFileName, &$iParsedCount)
 {
     if ($sSyncType === \EContactFileType::CSV) {
         $this->inc('helpers.' . $sSyncType . '.formatter');
         $this->inc('helpers.' . $sSyncType . '.parser');
         $this->inc('helpers.sync.' . $sSyncType);
         $sSyncClass = 'CApi' . ucfirst($this->GetManagerName()) . 'Sync' . ucfirst($sSyncType);
         if (class_exists($sSyncClass)) {
             $oSync = new $sSyncClass($this);
             return $oSync->Import($iUserId, $sTempFileName, $iParsedCount);
         }
     } else {
         if ($sSyncType === \EContactFileType::VCF) {
             // You can either pass a readable stream, or a string.
             $oHandler = fopen($sTempFileName, 'r');
             $oSplitter = new \Sabre\VObject\Splitter\VCard($oHandler);
             while ($oVCard = $oSplitter->getNext()) {
                 $oContact = new \CContact();
                 $oContact->InitFromVCardObject($iUserId, $oVCard);
                 if ($this->CreateContact($oContact)) {
                     $iParsedCount++;
                 }
             }
             return $iParsedCount;
         }
     }
     return false;
 }