PHPackages                             polyspirit/bitrix-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. polyspirit/bitrix-builder

ActivePackage[Utility &amp; Helpers](/categories/utility)

polyspirit/bitrix-builder
=========================

Builder classes for bitrix's IBlock and ISection

v1.2.3(3y ago)127mitPHPPHP &gt;=7.3.0

Since Jun 28Pushed 3y ago2 watchersCompare

[ Source](https://github.com/polyspirit/bitrix-builder)[ Packagist](https://packagist.org/packages/polyspirit/bitrix-builder)[ RSS](/packages/polyspirit-bitrix-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

Bitrix iBlock Builder
=====================

[](#bitrix-iblock-builder)

Builder classes for bitrix's iBlock and iSection

How to install
--------------

[](#how-to-install)

`composer require polyspirit/bitrix-builder`

How to use
----------

[](#how-to-use)

### Create instance of IBlock class

[](#create-instance-of-iblock-class)

```
use \polyspirit\Bitrix\Builder\IBlock;

// set iBlock ID as first parameter
$iBlockById = new IBlock(12);

// iBlock CODE as first parameter
$iBlockByCode = new IBlock('news');

// iBlock CODE as first parameter and site ID as second parameter
$iBlockByCodeAndSiteID = new IBlock('news', 's1');
```

### Get list of elements

[](#get-list-of-elements)

```
$iBlock = new IBlock('news');
$arResult = $iBlock->getElements();
```

### Get element detail

[](#get-element-detail)

```
$iBlock = new IBlock('news');
$arResultDetail = $iBlock->filter(['ID' => 42])->getElement();
```

Every result's element has a PROPS property, which contains all element's properties.

```
// show SOME_CODE property value
echo $arResultDetail['PROPS']['SOME_CODE']['VALUE'];
```

Also every result's element has a PICTURE\_SRC property, which contains path to DETAIL\_PICTURE by default and PREVIEW\_PICTURE if DETAIL\_PICTURE not in result's fields.

```
// show path to picture
echo $arResultDetail['PICTURE_SRC']; // /upload/resize_cache/iblock/xxx/xxx_xxx_1/some_picture.ext
```

Methods
-------

[](#methods)

### FILTER, SORT AND ETC.

[](#filter-sort-and-etc)

#### IBlock::active

[](#iblockactive)

Get only active elements.

```
public IBlock::active(): IBlock
```

```
// example:
$iBlock->active()->getElements();
```

#### IBlock::sort

[](#iblocksort)

Merge sort by default with your array.

```
public IBlock::sort(array $array): IBlock
```

```
// sort by default:
['sort' => 'ASC', 'date_active_from' => 'DESC', 'created_date' => 'DESC']
```

```
// example:
$iBlock->sort(['sort' => 'DESC', 'ID' => 'DESC'])->getElements();
```

#### IBlock::sortReset

[](#iblocksortreset)

Reset default sort value to empty array.

```
public IBlock::sortReset(): IBlock
```

```
// example:
$iBlock->sortReset()->sort(['ID' => 'DESC'])->getElements();
```

#### IBlock::filter

[](#iblockfilter)

Filter result's elements.

```
public IBlock::filter(array $array): IBlock
```

```
// example:
$iBlock->filter(['>=TIMESTAMP_X' => date('Y-m-d h:i:s', 'yesterday')])->getElements();
```

#### IBlock::fields

[](#iblockfields)

Merge fields by default with your array. If you don't use this method - all fields will be selected.

```
public IBlock::fields(array $array): IBlock
```

```
// fields by default:
['ID', 'IBLOCK_ID']

// fields by default if method is not used:
['*']
```

```
// example (select ID, IBLOCK_ID, NAME, PREVIEW_PICTURE):
$iBlock->fields(['NAME', 'PREVIEW_PICTURE'])->getElements();
```

#### IBlock::navs

[](#iblocknavs)

Navigation parameters.

```
public IBlock::navs(array $array): IBlock
```

```
$iBlock->navs(['nPageSize' => 4, 'iNumPage' => 1, 'checkOutOfRange' => true])->getElements();
```

#### IBlock::sizes

[](#iblocksizes)

Sizes for element's pictures.

```
public IBlock::sizes(array $array): IBlock
```

```
// sizes by default:
['width' => 640, 'height' => 640]
```

```
// example:
$iBlock->sizes(['width' => 1280, 'height' => 720])->getElements();
```

#### IBlock::params

[](#iblockparams)

Set all properties in one array

```
public IBlock::params(array $array): IBlock
```

```
// example:
$params = [
    'sort' => ['ID' => 'DESC'],
    'filter' => ['>=TIMESTAMP_X' => date('Y-m-d h:i:s', 'yesterday')],
    'navs' => ['nPageSize' => 4, 'iNumPage' => 1, 'checkOutOfRange' => true],
    'fields' => ['NAME', 'CODE'],
    'sizes' => ['width' => 1280, 'height' => 720]
];
$iBlock->params($params)->getElements();
```

### GET

[](#get)

#### IBlock::getElement

[](#iblockgetelement)

Get first element from result.

```
public IBlock::getElement(Closure $closure = null): array
```

```
// example:
$handler = function (&$element) {
    $element['ID_CODE'] = $element['ID'] . '|' . $element['CODE'];
}
$arDetail = $iBlock->filter(['ID' => 42])->fields(['CODE'])->getElement($handler);

echo $arDetail['ID_CODE']; // 42|ELEMENT_CODE
```

### IBlock::getElements

[](#iblockgetelements)

Get list of elements.

```
public IBlock::getElements(Closure $closure = null): array
```

```
// example:
$handler = function (&$element) {
    $element['ID_CODE'] = $element['ID'] . '|' . $element['CODE'];
}
$arResult = $iBlock->filter(['>=ID' => 42])->fields(['CODE'])->getElements($handler);

foreach ($arResult as $element) {
    echo $element['ID_CODE']; // 42|ELEMENT_CODE
}
```

### ADD &amp; MODIFY

[](#add--modify)

#### IBlock::add

[](#iblockadd)

Add a new element with fields and properties.

```
public IBlock::add(array $fields, array $props = []): int
```

```
// example:
(new IBlock('news'))->add(
    [
        'NAME' => 'Some',
        'PREVIEW_TEXT' => 'Some text'
    ],
    [
        'SOME_PROPERTY_CODE' => 42
    ]
);
```

#### IBlock::update

[](#iblockupdate)

Update element's fields and properties.

```
public IBlock::update(string|int $id, array $fields, array $props = []): bool
```

```
// example:
(new IBlock('news'))->update(
    [
        'NAME' => 'Updated name',
        'PREVIEW_TEXT' => 'Updated text'
    ],
    [
        'SOME_PROPERTY_CODE' => 24
    ]
);
```

#### IBlock::delete

[](#iblockdelete)

Delete element by id. If id parameter is not setted, the last added or updated element will be deleted.

```
public IBlock::delete(string|int|null $id = null): bool
```

```
// example:
(new IBlock('news'))->delete(42);

// or:
$iBlock = new IBlock('news');
$iBlock->add(['NAME' => 'SOME']);
$iBlock->delete();
```

### OTHER

[](#other)

#### IBlock::getObResult

[](#iblockgetobresult)

Get object

```
public IBlock::getObResult(): CIBlockResult|int
```

```
// example:
$arResult = $iBlock->filter(['>=ID' => 42])->getElements();
$obResult = $iBlock->getObResult();
```

#### IBlock::includeMeta

[](#iblockincludemeta)

Includes element's meta to page.

```
public IBlock::includeMeta(string|int $elementId): void
```

```
// example:
(new IBlock('news'))->includeMeta(42);
```

#### IBlock::getPropertySubQuery

[](#iblockgetpropertysubquery)

Get subquery for property.

```
public IBlock::getPropertySubQuery(string $propName, string $propValue): array
```

```
// example:
$subquery = $iBlock->getPropertySubQuery('SOME_CODE', 42);
$iBlock->filter([$subquery])->getElement();
```

### STATIC

[](#static)

#### IBlock::getIdByCode

[](#iblockgetidbycode)

Get subquery for property.

```
public static IBlock::getIdByCode(string $code = '', $siteId = SITE_ID): false|mixed
```

```
// example:
$id = IBlock::getIdByCode('some_iblock_code');
```

#### IBlock::getResizeImageSrc

[](#iblockgetresizeimagesrc)

Get subquery for property.

```
public static IBlock::getResizeImageSrc($pictureId, array $sizes): string
```

```
// example:
$pathToPicture = IBlock::getResizeImageSrc(42, ['width' => 1280, 'height' => 720]);
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1419d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73b54fafee35611310995a916eb6ff334b7508a35549d0a3ce4229310f6bd86a?d=identicon)[polyspirit](/maintainers/polyspirit)

---

Top Contributors

[![polyspirit](https://avatars.githubusercontent.com/u/26325911?v=4)](https://github.com/polyspirit "polyspirit (20 commits)")

### Embed Badge

![Health badge](/badges/polyspirit-bitrix-builder/health.svg)

```
[![Health](https://phpackages.com/badges/polyspirit-bitrix-builder/health.svg)](https://phpackages.com/packages/polyspirit-bitrix-builder)
```

###  Alternatives

[grasmash/composerize-drupal

Convert a non-Composer managed Drupal application into a Composer-managed application.

12819.4k1](/packages/grasmash-composerize-drupal)[neutron/signal-handler

A library to ease the use of signal handling.

13101.4k2](/packages/neutron-signal-handler)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
