// CRM_QUOTE_ID
$crmQuoteId = 2;
// XML_ID UF поля с CRM_QUOTE_ID в HL-блоке
$crmQuoteFieldId = 'UF_ELEMENT';
// IBLOCK PROPERTY
$iblockUserProertyCode = 'USER_ID';
$iblockUserProertyValue = 1;
$result = $entity_data_class::getList(array(
'select' => ['ELEMENT_' => 'IBLOCK_ELEMENT', 'IBLOCK_PROPERTIES.CODE', 'IBLOCK_ELEMENT_PROPERTIES.VALUE'],
'order' => [],
'filter' => [$crmQuoteFieldId => $crmQuoteId, [
'LOGIC' => 'AND',
['IBLOCK_PROPERTIES.CODE' => $iblockUserProertyCode],
['IBLOCK_ELEMENT_PROPERTIES.VALUE' => $iblockUserProertyValue]
]],
//'group' => ['ELEMENT_DATE_CREATE'],
'runtime' => [
'IBLOCK_ELEMENT' => [
'data_type' => \Bitrix\Iblock\ElementTable::class,
'reference' => ['this.'.$crmQuoteFieldId => 'ref.ID'],
'join' => 'RIGHT'
],
'IBLOCK_ELEMENT_PROPERTIES' => [
'data_type' => \Bitrix\Iblock\ElementPropertyTable::class,
'reference' => ['this.IBLOCK_ELEMENT.ID' => 'ref.IBLOCK_ELEMENT_ID'],
'join' => 'RIGHT'
],
'IBLOCK_PROPERTIES' => [
'data_type' => \Bitrix\Iblock\PropertyTable::class,
'reference' => ['this.IBLOCK_ELEMENT_PROPERTIES.IBLOCK_PROPERTY_ID' => 'ref.ID'],
'join' => 'RIGHT'
],
]
))->fetchAll();
print_r($result);
$eventManager = \Bitrix\Main\EventManager::getInstance();
$events = $eventManager->findEventHandlers('iblock', 'OnIBlockElementUpdate');
print_r($events);
public static function SendPhoneCode($phoneNumber, $smsTemplate, $siteId = null)
public static function VerifyPhoneCode($phoneNumber, $code)
<?if(!isset($arResult["SHOW_SMS_FIELD"]) || $arResult["SHOW_SMS_FIELD"] !== true):?>
<form //..............
<input type="text" required name="PHONE_NUMBER">
</form>
<?endif;?>
<?if($arResult["SHOW_SMS_FIELD"] == true):?>
<?CJSCore::Init('phone_auth');?>
<form method="post" action="<?=$arResult["AUTH_URL"]?>" name="regform">
<input type="hidden" name="SIGNED_DATA" value="<?=htmlspecialcharsbx($arResult["SIGNED_DATA"])?>" />
<div class="bx-authform-formgroup-container">
<div class="bx-authform-label-container"><span class="bx-authform-starrequired">*</span><?echo GetMessage("main_register_sms_code")?></div>
<div class="bx-authform-input-container">
<input type="text" name="SMS_CODE" maxlength="255" value="<?=htmlspecialcharsbx($arResult["SMS_CODE"])?>" autocomplete="off" />
</div>
</div>
<div class="bx-authform-formgroup-container">
<input type="submit" class="btn btn-primary" name="code_submit_button" value="<?echo GetMessage("main_register_sms_send")?>" />
</div>
</form>
<div id="bx_auth_error" style="display:none" class="alert alert-danger"></div>
<div id="bx_auth_resend"></div>
<script>
new BX.PhoneAuth({
containerId: 'bx_auth_resend',
errorContainerId: 'bx_auth_error',
interval: <?=$arResult["PHONE_CODE_RESEND_INTERVAL"]?>,
data:
<?=CUtil::PhpToJSObject([
'signedData' => $arResult["SIGNED_DATA"],
])?>,
onError:
function(response)
{
var errorNode = BX('bx_auth_error');
errorNode.innerHTML = '';
for(var i = 0; i < response.errors.length; i++)
{
errorNode.innerHTML = errorNode.innerHTML + BX.util.htmlspecialchars(response.errors[i].message) + '<br />';
}
errorNode.style.display = '';
}
});
</script>
<?endif;?>
$arResult["PHONE_CODE_RESEND_INTERVAL"] = \CUser::PHONE_CODE_RESEND_INTERVAL;
$phoneNumber = $_REQUEST['PHONE_NUMBER'] ?? null;
$signedData = $_REQUEST['SIGNED_DATA'] ?? null;
if(!empty($phoneNumber))
{
$smsTemplate = 'SMS_USER_RESTORE_PASSWORD'; // только указываешь свой шаблон (создаешь сначала в админке)
$result = \CUser::SendPhoneCode($phoneNumber, $smsTemplate, SITE_ID);
if($result->isSuccess()) {
$arResult['SIGNED_DATA'] = \Bitrix\Main\Controller\PhoneAuth::signData([
'phoneNumber' => $phoneNumber,
'smsTemplate' => $smsTemplate
]);
$arResult["SHOW_SMS_FIELD"] = true;
}
else {
$arResult['ERROR_MESSAGE'] = $result->getErrorMessages();
}
if(!empty($signedData)) {
$arResult["SIGNED_DATA"] = $signedData;
$arResult["SHOW_SMS_FIELD"] = true;
}
// verify phone code
$isNeedVerifySmsCode = $_SERVER["REQUEST_METHOD"] == "POST" && $_REQUEST["code_submit_button"] <> '' && !$USER->IsAuthorized() && !empty($signedData);
if($isNeedVerifySmsCode)
{
$smsCode = $_REQUEST['SMS_CODE'];
if(($params = \Bitrix\Main\Controller\PhoneAuth::extractData($signedData)) !== false)
{
if(($userId = CUser::VerifyPhoneCode($params['phoneNumber'], $smsCode)))
{
$USER->Authorize($userId);
}
else
{
$arResult['ERROR_MESSAGE'] = 'Error verify code'; // здесь сам ошибку придумай
$arResult["SHOW_SMS_FIELD"] = true;
$arResult["SMS_CODE"] = $smsCode;
$arResult["SIGNED_DATA"] = $signedData;
}
}
}
}
ничего плохого в процедурном подходе, если все идеи реализованы в виде простых, коротких и минимально функциональных чистых статических методах
abstract class AbstractComponentFactory implements ComponentFactoryInterface
{
public function supports(string $component): bool
{
return in_array($component, $this->getSupportedComponents());
}
abstract protected function getSupportedComponents(): array;
}
final class ComponentFactory extends AbstractComponentFactory
{
public function create(string $component): ComponentInterface
{
switch ($component) {
case 'news':
return new NewsComponent();
default:
throw new InvalidArgumentException(sprintf('No component supports the given name "%s".', $component));
}
}
protected function getSupportedComponents(): array
{
return ['news'];
}
}
final class ComponentFactory
{
public function create(string $component): ComponentInterface
{
switch ($component) {
case 'news':
return new NewsComponent();
default:
throw new InvalidArgumentException(sprintf('No component supports the given name "%s".', $component));
}
}
}
abstract class AbstractComponentFactory
{
public function modifyResult(array $result): array
{
$component = $this->create();
return $component->modifyResult($result);
}
abstract protected function create(): ComponentInterface;
}
class NewsListComponentFactory extends AbstractComponentFactory
{
protected function create(): ComponentInterface
{
return new NewsListComponent();
}
}
class NewsDetailComponentFactory extends AbstractComponentFactory
{
protected function create(): ComponentInterface
{
return new NewsDetailComponent();
}
}
class NewsListComponent implements ComponentInterface
{
public function modifyResult(array $result): array
{
return [];
}
}
class NewsDetailComponent implements ComponentInterface
{
public function modifyResult(array $result): array
{
return [];
}
}
(new NewsListComponentFactory())->modifyResult($arResult);
$component = $this->getComponent();
$arParams = $component->applyTemplateModifications();
$arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y", 'IBLOCK_SECTION_ID' => $idSections);
while ($sectRes = $dbResSect->GetNext()) {
$arSections[] = $sectRes;
}
while ($sectRes = $dbResSect->GetNext()) {
$arSections[$sectRes['ID']] = $sectRes;
}
// Находим все разделы элемента и собираем их в массив
// Собираем массив из разделов и элементов
// Получаем разделы и собираем их в массив
while ($sectRes = $dbResSect->GetNext()) {
$arSections[$sectRes['ID']] = $sectRes;
}
// Формируем массив элементов по фильтру
//......
$arFilter = array("IBLOCK_ID" => $IBLOCK_ID, 'IBLOCK_SECTION_ID' => $idSections, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y");
$res = CIBlockElement::GetList(array("ID" => "ASC"), $arFilter, false, false, $arSelect);
while ($el = $res->Fetch()) {
$arResult["ITEMS"][$el['ID']] = $el;
}
$elementIdsBySectionIds = [];
$iterator = \Bitrix\Iblock\SectionElementTable::getList([
'select' => ['IBLOCK_SECTION_ID', 'IBLOCK_ELEMENT_ID'],
'filter' => ['IBLOCK_SECTION_ID' => $idSections]
]);
while($row = $iterator->fetch()) {
$elementIdsBySectionIds[$row['IBLOCK_SECTION_ID']][$row['IBLOCK_ELEMENT_ID']] = $row['IBLOCK_ELEMENT_ID'];
}
// здесь как раз пригодятся ключи = ID
foreach($elementIdsBySectionIds as $sectionId => $elementIds) {
foreach($elementIds as $elementId) {
if(isset($arResult["ITEMS"][$elementId])) {
$arSections[$sectionId]['ITEMS'][] = $arResult["ITEMS"][$elementId];
}
}
}
$arResult = $arSections;
CModule::IncludeModule('iblock'); //Подключаем модуль "Информационные блоки"
// Параметры
$IBLOCK_ID = 7; // ID ифноблока
$idSections = array(104,105,106); // ID разделов
// Формируем список разделов по фильтру
$dbResSect = CIBlockSection::GetList(
array("SORT" => 'asc'), // Параметры сортировки
array(
"IBLOCK_ID" => $IBLOCK_ID, // ID инфоблока
"ID" => $idSections, // Массив разделов
),
false,
array("ID", "NAME", "UF_ITEMPROP") // Выбираем необходимые поля разделов.
);
// Получаем разделы и собираем их в массив
while ($sectRes = $dbResSect->GetNext()) {
$arSections[$sectRes['ID']] = $sectRes;
}
// Формируем массив элементов по фильтру
$arResult = [];
$arSelect = Array(
"ID",
"NAME",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"PROPERTY_FILE",
"PROPERTY_ITEMPROP",
);
$arFilter = array("IBLOCK_ID" => $IBLOCK_ID, 'IBLOCK_SECTION_ID' => $idSections, "ACTIVE_DATE" => "Y", "ACTIVE" => "Y");
$res = CIBlockElement::GetList(array("ID" => "ASC"), $arFilter, false, false, $arSelect);
while ($el = $res->Fetch()) {
$arResult["ITEMS"][$el['ID']] = $el;
}
$elementIdsBySectionIds = [];
$iterator = \Bitrix\Iblock\SectionElementTable::getList([
'select' => ['IBLOCK_SECTION_ID', 'IBLOCK_ELEMENT_ID'],
'filter' => ['IBLOCK_SECTION_ID' => $idSections]
]);
while($row = $iterator->fetch()) {
$elementIdsBySectionIds[$row['IBLOCK_SECTION_ID']][$row['IBLOCK_ELEMENT_ID']] = $row['IBLOCK_ELEMENT_ID'];
}
foreach($elementIdsBySectionIds as $sectionId => $elementIds) {
foreach($elementIds as $elementId) {
if(isset($arResult["ITEMS"][$elementId])) {
$arSections[$sectionId]['ITEMS'][] = $arResult["ITEMS"][$elementId];
}
}
}
$arResult = $arSections;