Created
December 17, 2018 11:35
-
-
Save VSeryoga/3bb3bea015cc87824d1834945fa67851 to your computer and use it in GitHub Desktop.
Добавление карточки в блок на сайтах Битрикс 24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$dealId = false; | |
$dealId = str_replace('DEAL_', '', $_REQUEST['document_id'][2]); | |
function query($param){ | |
$appParams = array( | |
'halt' => 0, | |
'cmd' => $param | |
); | |
$appRequestUrl = 'https://.....bitrix24.ru/rest/134....../batch?'.http_build_query($appParams); | |
$curl = curl_init(); | |
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); | |
curl_setopt($curl,CURLOPT_URL,$appRequestUrl); | |
curl_setopt($curl,CURLOPT_POST,true); | |
curl_setopt($curl,CURLOPT_HEADER,false); | |
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,0); | |
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,0); | |
$out=curl_exec($curl); | |
curl_close($curl); | |
$result = json_decode($out, 1); | |
// echo '<pre>'; | |
// print_r($result); | |
// writeToLog2($appParams); | |
return $result; | |
} | |
function writeToLog($req, $title = '') { | |
$log = "\n------------------------\n"; | |
$log .= date("Y.m.d G:i:s") . "\n"; | |
$log .= (strlen($title) > 0 ? $title : 'DEBUG') . "\n"; | |
$log .= print_r($req, 1); | |
$log .= print_r($req2, 1); | |
$log .= "\n------------------------\n"; | |
file_put_contents(getcwd() . '/log.log', $log, FILE_APPEND); | |
return true; | |
} | |
writeToLog($_REQUEST); | |
// TEST | |
// $dealId = 206; | |
echo "<pre>"; | |
if($dealId){ | |
//Сделка | |
$param['deal'] = 'crm.deal.get?' | |
.http_build_query(array( | |
'id' => $dealId | |
)); | |
$param['contact'] = 'crm.contact.get?' | |
.http_build_query(array( | |
'id' => '$result[deal][CONTACT_ID]' | |
)); | |
$param['page'] = 'landing.landing.getList?' | |
.http_build_query(array( | |
'lid' => 1, | |
'params' => [ | |
'filter' => [ | |
'CODE' => '$result[deal][UF_CRM_1544790833]', | |
'FOLDER_ID' => 28 | |
] | |
] | |
)); | |
// $param['page2'] = 'landing.landing.getList?' | |
// .http_build_query(array( | |
// 'lid' => 1, | |
// 'params' => [ | |
// 'filter' => [ | |
// 'CODE' => 'test', | |
// 'FOLDER_ID' => 28 | |
// ] | |
// ] | |
// )); | |
$param['block'] = 'landing.block.getlist?' | |
.http_build_query(array( | |
'lid' => '$result[page][0][ID]', | |
'params' => ['edit_mode' => 1] | |
)); | |
// $param['block2'] = 'landing.block.getlist?' | |
// .http_build_query(array( | |
// 'lid' => '$result[page2][0][ID]', | |
// 'params' => ['edit_mode' => 1] | |
// )); | |
$param['city'] = 'crm.contact.userfield.list?' | |
.http_build_query(array( | |
'order' => ['ID' => 'ASC'], | |
'filter' => ['FIELD_NAME' => 'UF_CRM_1543870862'] | |
)); | |
$result = query($param); | |
$contact = $result['result']['result']['contact']; | |
$arBlock = $result['result']['result']['block']; | |
$lid = $result['result']['result']['block'][0]['lid']; | |
$city = $result['result']['result']['city']; | |
foreach ($arBlock as $key => $value) { | |
if($value['code'] == 'repo_314'){ | |
$blockId = $value['id']; | |
} | |
} | |
foreach ($city[0]['LIST'] as $key => $value) { | |
$arCity[$value['ID']] = $value['VALUE']; | |
} | |
// echo $blockId; | |
// echo "<br>".$lid; | |
// print_r($contact); | |
// print_r($arCity); | |
$text = '<div class="landing-block-card col-sm-6 col-md-3"> | |
<div class="landing-block-node-text-container g-px-25--lg g-px-40--xl"> | |
<div class="landing-block-node-img-container">'; | |
if($contact['UF_CRM_1545038042']){ | |
$text .= '<img alt="'.$contact['NAME'].'" class="landing-block-node-img img-fluid" style="height:175px;width:175px;border-radius: 87px;" src="'.$contact['UF_CRM_1545038042'].'">'; | |
} | |
$text .= ' | |
</div> | |
<h3 class="landing-block-node-title g-font-size-17 g-font-size-18--lg g-color-black g-font-roboto g-font-weight-700 g-mt-20 g-mb-10">'.$contact['NAME'].'</h3> | |
<p class="landing-block-node-text g-font-size-16 g-font-roboto g-color-black g-font-weight-400 g-mb-16">'.$contact['UF_CRM_1529421785'].'<br>'; | |
if($contact['UF_CRM_1543870862']){ | |
$text .= '<span style="color: rgb(158, 158, 158);">Родной город: '.$arCity[$contact['UF_CRM_1543870862']].'</span><br>'; | |
} | |
$text .= '</p></div>'; | |
// echo $text; | |
$param = []; | |
//Добавляем блок | |
$param['add'] = 'landing.block.addCard?'. | |
(http_build_query(array( | |
'lid' => $lid, | |
'block' => $blockId, | |
'selector' => '.landing-block-card', | |
'content' => $text | |
) | |
)); | |
$param['public'] = 'landing.landing.publication?'. | |
(http_build_query(array( | |
'lid' => $lid, | |
) | |
)); | |
$result = query($param); | |
print_r($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment