Skip to content

Instantly share code, notes, and snippets.

@iTeeLion
Last active October 31, 2022 13:44
Show Gist options
  • Save iTeeLion/8a9cd1529d9ed50f116f34211e172a5a to your computer and use it in GitHub Desktop.
Save iTeeLion/8a9cd1529d9ed50f116f34211e172a5a to your computer and use it in GitHub Desktop.
PHP snippets for bitrix D7 version / Примеры самых используемых конструкций в bitrix на D7
<?php
/*
* Bitrix init (paths to header/prolog/footer)
*/
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/header.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/footer.php');
/*
* Include module example
*/
\Bitrix\Main\Loader::includeModule('im');
\Bitrix\Main\Loader::includeModule('crm');
\Bitrix\Main\Loader::includeModule('sale');
\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('catalog');
/*
* Header show methods
*/
$GLOBALS['APPLICATION']->ShowTitle();
$GLOBALS['APPLICATION']->ShowHead();
$GLOBALS['APPLICATION']->ShowMeta('keywords');
$GLOBALS['APPLICATION']->ShowMeta('description');
$GLOBALS['APPLICATION']->ShowCSS();
$GLOBALS['APPLICATION']->ShowHeadStrings();
$GLOBALS['APPLICATION']->ShowHeadScripts();
$GLOBALS['APPLICATION']->ShowPanel();
$GLOBALS['APPLICATION']->RestartBuffer();
/*
* Add JS and CSS assets
*/
\Bitrix\Main\Page\Asset::getInstance()->addCss('/path/to/style.css');
\Bitrix\Main\Page\Asset::getInstance()->addJs('/path/to/script.js');
/*
* UserFields
*/
global $USER_FIELD_MANAGER;
$EntityTable = new \Bitrix\Crm\CompanyTable()
//getlist
$arUF = $USER_FIELD_MANAGER->GetUserFields($EntityTable::getUFId(), $ID);
//update
$USER_FIELD_MANAGER->Update($EntityTable::getUFId(), $ID, $arFields);
/*
* \Bitrix\Main\Mail\Event
*/
// Send email
Bitrix\Main\Mail\Event::send([
'EVENT_NAME' => 'NEW_USER',
'LID' => 's1',
'C_FIELDS' => [
'EMAIL' => 'info@mail.ru',
'USER_ID' => 1
]
]);
/*
* IM
*/
// Send message
$arMessageFields = [
'system' => 'N',
'FROM_USER_ID' => $GLOBALS['USER']->GetID(),
'TO_USER_ID' => $uid,
'MESSAGE' => $msg,
];
\CIMNotify::Add($arMessageFields);
/*
* D7 ORM example
*/
// GetList
try {
$CompanyTable = new \Bitrix\Crm\CompanyTable();
$dbRes = $CompanyTable::getList([
'select' => [],
'filter' => [],
'group' => [],
'order' => [],
'limit' => 1,
'offset' => 1,
'count_total' => true,
'runtime' => [],
]);
$rows = $dbRes->fetchAll();
while ($row = $dbRes->fetch()) {
$arUF = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields($CompanyTable::getUFId(), $item['ID']);
foreach($arUF as $field){
$item[$field['FIELD_NAME']] = $field['VALUE'];
}
$rows[] = $row;
}
} catch (\Exception $e) {
echo $e->getMessage();
}
// Add / Update
$result = BookTable::add($arFields);
// Update
$result = BookTable::update($id, $arFields);
// IBlock GetList old api adapter
function IBD7_getlist($params){
$arOrder = ($params['order'])?:[]];
$arFilter = ($params['filter'])?:[]];
$arGroupBy = ($params['group'])?:false;
$arNav = ($params['nav'])?:false;
$arSelect = ($params['select'])?:[]];
$dbRes = \CIBlockElement::GetList($arOrder, $arFilter, $arGroupBy, $arNav, $arSelect);
$arData = [];
while ($arItem = $dbRes->GetNext()) {
$arData[$arItem['ID']] = $arItem;
}
return $arData;
}
@iTeeLion
Copy link
Author

Примеры самого необходимого кода в bitrix используя ядро D7

Как подключить модуль апи битрикс без хедера
Как подключить хедер битрикс
Как подключить футер битрикс
Как подключить модуль в битрикс
Как вывести тайтл в бирикс
Как вывести хедер битрикс
Как вывести все css и js файлы подключенный в битрикс
Как вывести мета тег в битрикс
Как вывести панель админа в битрикс
Как очистить содержимое страницы перед выводом
Как подключить css файл к шаблону битрикс
Как подключить js файл к шаблону битрикс
Как получить user fileld, как получить uf свойство в битрикс
Как отправить email в битрикс
Как пользоваться orm в d7 битрикс

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment