本文整理汇总了PHP中api_Utils::CsvToArray方法的典型用法代码示例。如果您正苦于以下问题:PHP api_Utils::CsvToArray方法的具体用法?PHP api_Utils::CsvToArray怎么用?PHP api_Utils::CsvToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类api_Utils
的用法示例。
在下文中一共展示了api_Utils::CsvToArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Import
/**
* @param int $iUserId
* @param string $sTempFileName
* @param int $iParsedCount
* @param int $iGroupId
* @param bool $bIsShared
* @return int
*/
public function Import($iUserId, $sTempFileName, &$iParsedCount, $iGroupId, $bIsShared)
{
$iCount = -1;
$iParsedCount = 0;
if (file_exists($sTempFileName)) {
$aCsv = api_Utils::CsvToArray($sTempFileName);
if (is_array($aCsv)) {
$oApiUsersManager = CApi::Manager('users');
$oAccount = $oApiUsersManager->GetDefaultAccount($iUserId);
$iCount = 0;
foreach ($aCsv as $aCsvItem) {
set_time_limit(30);
$this->oParser->Reset();
$oContact = new CContact();
$oContact->IdUser = $iUserId;
$this->oParser->SetContainer($aCsvItem);
$aParameters = $this->oParser->GetParameters();
foreach ($aParameters as $sPropertyName => $mValue) {
if ($oContact->IsProperty($sPropertyName)) {
$oContact->{$sPropertyName} = $mValue;
}
}
if (0 === strlen($oContact->FullName)) {
$oContact->FullName = trim($oContact->FirstName . ' ' . $oContact->LastName);
}
if (0 !== strlen($oContact->HomeEmail)) {
$oContact->PrimaryEmail = \EPrimaryEmailType::Home;
$oContact->ViewEmail = $oContact->HomeEmail;
} else {
if (0 !== strlen($oContact->BusinessEmail)) {
$oContact->PrimaryEmail = \EPrimaryEmailType::Business;
$oContact->ViewEmail = $oContact->BusinessEmail;
} else {
if (0 !== strlen($oContact->OtherEmail)) {
$oContact->PrimaryEmail = \EPrimaryEmailType::Other;
$oContact->ViewEmail = $oContact->OtherEmail;
}
}
}
if (strlen($oContact->BirthdayYear) === 2) {
$oDt = DateTime::createFromFormat('y', $oContact->BirthdayYear);
$oContact->BirthdayYear = $oDt->format('Y');
}
$iParsedCount++;
$oContact->__SKIP_VALIDATE__ = true;
if ($oAccount) {
$oContact->IdDomain = $oAccount->IdDomain;
$oContact->IdTenant = $oAccount->IdTenant;
}
$oContact->SharedToAll = $bIsShared;
$oContact->GroupsIds = array($iGroupId);
if ($this->oApiContactsManager->CreateContact($oContact)) {
$iCount++;
}
unset($oContact, $aParameters, $aCsvItem);
}
}
}
return $iCount;
}
示例2: Import
/**
* @param int $iUserId
* @param string $sTempFileName
* @param int $iParsedCount
* @return int
*/
public function Import($iUserId, $sTempFileName, &$iParsedCount)
{
$iCount = -1;
$iParsedCount = 0;
if (file_exists($sTempFileName)) {
$aCsv = api_Utils::CsvToArray($sTempFileName);
if (is_array($aCsv)) {
$iCount = 0;
foreach ($aCsv as $aCsvItem) {
set_time_limit(30);
$this->oParser->Reset();
$oContact = new CContact();
$oContact->IdUser = $iUserId;
$this->oParser->SetContainer($aCsvItem);
$aParameters = $this->oParser->GetParameters();
foreach ($aParameters as $sPropertyName => $mValue) {
if ($oContact->IsProperty($sPropertyName)) {
$oContact->{$sPropertyName} = $mValue;
}
}
if (0 === strlen($oContact->FullName)) {
$oContact->FullName = trim($oContact->FirstName . ' ' . $oContact->LastName);
}
$iParsedCount++;
$oContact->__SKIP_VALIDATE__ = true;
if ($this->oApiContactsManager->CreateContact($oContact)) {
$iCount++;
}
unset($oContact, $aParameters, $aCsvItem);
}
}
}
return $iCount;
}