Skip to content

Instantly share code, notes, and snippets.

@s2ar
s2ar / file.info.php
Last active June 21, 2016 11:08
bitrix. Get file info
<?php
function formatBytes($bytes, $precision = 2)
{
$base = log($bytes, 1024);
$suffixes = array('', 'Кбайт', 'Мбайт', 'Гбайт', 'Тбайт');
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
}
if(is_numeric($aProps['cr_pdf']['VALUE'])){
@s2ar
s2ar / bitrix highloadblock getList.php
Last active December 4, 2018 08:31
bitrix highloadblock getList
<?php
if(!CModule::IncludeModule('highloadblock')) die();
use Bitrix\Highloadblock as HL;
use Bitrix\Main\Entity;
$hlblock = HL\HighloadBlockTable::getById(5)->fetch();
$hlEntity = HL\HighloadBlockTable::compileEntity($hlblock);
$entDataClass = $hlEntity->getDataClass();
@s2ar
s2ar / bitrix.select.elements.php
Last active December 15, 2016 09:42
bitrix.select elements
<?php
use Bitrix\Main\Loader;
if(!Loader::includeModule("iblock")) die();
$aFilter = array("IBLOCK_ID"=>25, "ACTIVE"=>"Y");
$rPart = CIBlockElement::GetList(array('sort'=>'ASC'), $aFilter, false, false, array());
while($oPart = $rPart->GetNextElement()):
$aPart = $oPart->GetFields();
$aPart['PROP'] = $oPart->GetProperties();
@s2ar
s2ar / bitrix.select sections.php
Last active April 23, 2016 08:25
bitrix.select sections
<?php
$aFilter = Array('IBLOCK_ID'=>9, 'DEPTH_LEVEL'=>1,"UF_SECTION_REF" => $sectionID);
$rSect = CIBlockSection::GetList(Array('SORT'=>'ASC'), $aFilter, false, array('UF_*'));
$aSections = array();
while($aSect = $rSect->GetNext()) {
$aSections[] = $aSect;
}
@s2ar
s2ar / bitrix.get.property.enum1.php
Last active April 23, 2016 08:26
bitrix.get property enum
<?php
$aPropList = array();
$rEnum = CIBlockProperty::GetPropertyEnum($propID, Array('SORT'=>'ASC'), Array("IBLOCK_ID"=>2));
while($aEnum = $rEnum->Fetch()){
$aPropList[] = array('id'=>$aEnum['ID'], 'code'=>$aEnum['XML_ID'] ,'value'=>$aEnum['VALUE']);
}
@s2ar
s2ar / Bitrix.application.request.php
Last active April 23, 2016 08:24
Bitrix Application Request
<?php
use Bitrix\Main\Application;
$request = Application::getInstance()->getContext()->getRequest();
$value = $request->get("some_name");
$value = $request["some_name"];
$value = $request->getQuery("some_name"); // получение GET-параметра
$value = $request->getPost("some_name"); // получение POST-параметра
$value = $request->getFile("some_name"); // получение загруженного файла
@s2ar
s2ar / urlrewrite.php
Last active April 23, 2016 08:23
Bitrix.urlrewrite
<?php
array(
"CONDITION" => "#^/weather/([^/]+)/([^/]+)/($|index\\.php|\\?.*)#",
"RULE" => "COUNTRY_CODE=$1&CITY_CODE=$2",
"ID" => "",
"PATH" => "/weather/city.php",
),
/*
/weather/russia/moscow/ => /weather/city.php?COUNTRY_CODE=russia&CITY_CODE=moscow
@s2ar
s2ar / bitrix.highload iblock element.php
Last active April 23, 2016 08:23
bitrix.highload iblock element
<?php
use Bitrix\Main\Application;
use Bitrix\Highloadblock\HighloadBlockTable;
use Bitrix\Main\Loader;
Loader::includeModule('highloadblock');
Loader::includeModule('iblock');
$hlBlockId = 2;
@s2ar
s2ar / JS.checked.number.js
Last active April 19, 2016 05:55
JS. checked number
/*
-9007199254740990 to 9007199254740990
*/
function isInt(n) {
return +n === n && !(n % 1);
}
/*
-128 to 127
@s2ar
s2ar / bitrix запись в журнал событий.php
Last active April 23, 2016 08:22
bitrix запись в журнал событий
<?php
AddEventHandler('main', 'OnEventLogGetAuditTypes', 'ASD_OnEventLogGetAuditTypes');
function ASD_OnEventLogGetAuditTypes()
{
return array('MY_OWN_TYPE' => '[MY_OWN_TYPE] Мой собственный тип');
}
CEventLog::Add(array(
"SEVERITY" => "SECURITY",