PHP code example of fibit / bitrix-entity-helper

1. Go to this page and download the library: Download fibit/bitrix-entity-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fibit / bitrix-entity-helper example snippets




use \Fibit\EntityHelper as EH;

EH::getClass(1);
// Результат: \Bitrix\Iblock\Elements\ElementOffersTable

EH::getClass("Data");
// Результат: \DataTable

EH::getClass(new \Bitrix\Main\UserTable);
// Результат: \Bitrix\Main\UserTable

use \Fibit\EntityHelper as EH;

EH::getQuery(
  new \Bitrix\Main\UserTable,
  array(
    "select" => array("SHORT_NAME", "EMAIL"),
    "filter" => array("=ACTIVE" => "Y"),
    "order" => array("LAST_ACTIVITY_DATE" => "DESC"),
    "limit" => 100,
  )
);

use \Fibit\EntityHelper as EH;

EH::getRows(
  new \Bitrix\Main\UserTable,
  array(
    "select" => array("SHORT_NAME", "EMAIL"),
    "filter" => array("=ACTIVE" => "Y"),
    "order" => array("LAST_ACTIVITY_DATE" => "DESC"),
    "limit" => 100,
  )
);

Array(
  [result] => Array(
    [0] => Array(
      [SHORT_NAME] => Иванов И.
      [EMAIL] => [email protected]
    )
    [1] => Array(
      [SHORT_NAME] => Петров П.
      [EMAIL] => [email protected]
    )
    ...
    [99] => Array(
      [SHORT_NAME] => Сидоров С.
      [EMAIL] => [email protected]
    )
  )
  [count] => 100
  [nav] => 
  [time] => 0.010181903839111
)

use \Fibit\EntityHelper as EH;

$data = EH::getRows(
  new \Bitrix\Main\UserTable,
  array(
    "count_total" => true,
    ...
    "limit" => 20
  )
);

<?$APPLICATION->IncludeComponent(
  "bitrix:main.pagenavigation",
  "",
  array(
    "NAV_OBJECT" => $data["nav"],
    "SEF_MODE" => "N"
  ),
  true
);

use \Fibit\EntityHelper as EH;

EH::getRows(
  "Operations",
  array(
    "select" => array("UF_MEMBER", "EF_SUM"),
    "filter" => array(
      "><UF_DATETIME" => array(
        "01.01.2024 00:00:00",
        "01.01.2024 23:59:59"
      )
    ),
    "runtime" => array(
      new \Bitrix\Main\Entity\ExpressionField(
        "EF_SUM",
        "SUM(%s)",
        "UF_SUM"
      )
    )
  )
);

Array(
  [result] => Array(
    [0] => Array(
      [UF_MEMBER] => Иванов И.
      [EF_SUM] => 200
    )
    [1] => Array(
      [UF_MEMBER] => Петров П.
      [EF_SUM] => 100
    )
  )
  [count] => 2
  [nav] => 
  [time] => 0.020122900039128
)

use \Fibit\EntityHelper as EH;

EH::getRow(
  new \Bitrix\Main\UserTable,
  array(
    "select" => array("SHORT_NAME", "EMAIL"),
  )
);

Array(
  [result] => Array(
    [SHORT_NAME] => Иванов И.
    [EMAIL] => [email protected]
  )
  [time] => 0.0097489356994629
)

use \Fibit\EntityHelper as EH;

EH::addRow(
  "Data",
  array(
    "UF_NAME" => "Row 1",
    "UF_XML_ID" => "row-1",
  )
);

Array(
  [result] => 1 // ID элемента
  [time] => 0.005182203839221
)

use \Fibit\EntityHelper as EH;

EH::updRow(
  "Data",
  1, // ID обновляемого элемента
  array(
    "UF_NAME" => "Row 2",
  )
);

Array(
  [result] => 1 // ID элемента
  [time] => 0.004221103835001
)

use \Fibit\EntityHelper as EH;

EH::delRow(
  "Data",
  1, // ID удаляемого элемента
);

Array(
  [result] => true
  [time] => 0.001111100000001
)