Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/location/lib/model/ |
Upload File : |
<?php namespace Bitrix\Location\Model; use Bitrix\Main, Bitrix\Main\ORM\Fields; use Bitrix\Main\Application; use Bitrix\Main\ORM\Fields\Relations\Reference; use Bitrix\Main\ORM\Query\Join; /** * Class HierarchyTable * * Fields: * <ul> * <li> ANCESTOR_ID int mandatory * <li> DESCENDANT_ID int mandatory * <li> LEVEL int mandatory * </ul> * * @package Bitrix\Location * * DO NOT WRITE ANYTHING BELOW THIS * * <<< ORMENTITYANNOTATION * @method static EO_Hierarchy_Query query() * @method static EO_Hierarchy_Result getByPrimary($primary, array $parameters = array()) * @method static EO_Hierarchy_Result getById($id) * @method static EO_Hierarchy_Result getList(array $parameters = array()) * @method static EO_Hierarchy_Entity getEntity() * @method static \Bitrix\Location\Model\EO_Hierarchy createObject($setDefaultValues = true) * @method static \Bitrix\Location\Model\EO_Hierarchy_Collection createCollection() * @method static \Bitrix\Location\Model\EO_Hierarchy wakeUpObject($row) * @method static \Bitrix\Location\Model\EO_Hierarchy_Collection wakeUpCollection($rows) */ class HierarchyTable extends Main\Entity\DataManager { /** * Returns DB table name for entity. * * @return string */ public static function getTableName() { return 'b_location_hierarchy'; } /** * Returns entity map definition. * * @return array */ public static function getMap() { return array( (new Fields\IntegerField('ANCESTOR_ID')) ->configurePrimary(true), (new Fields\IntegerField('DESCENDANT_ID')) ->configurePrimary(true), (new Fields\IntegerField('LEVEL')) ->configureRequired(true), // References (new Reference('ANCESTOR', LocationTable::class, Join::on('this.ANCESTOR_ID', 'ref.ID'))) ->configureJoinType('inner'), (new Reference('DESCENDANT', LocationTable::class, Join::on('this.DESCENDANT_ID', 'ref.ID'))) ->configureJoinType('inner') ); } /** * @param array $data * @return Main\DB\Result * @throws Main\Db\SqlQueryException */ public static function insertBatch(array $data) { $values = []; foreach ($data as $row) { if((int)$row['ANCESTOR_ID'] <= 0 || (int)$row['DESCENDANT_ID'] <= 0) { continue; } $values[] = (int)$row['ANCESTOR_ID'].', '.(int)$row['DESCENDANT_ID'].', '.(int)$row['LEVEL']; } if(!empty($values)) { $values = '(' . implode('), (', $values) . ')'; $sql = "INSERT IGNORE INTO " . static::getTableName() . " (ANCESTOR_ID, DESCENDANT_ID, LEVEL) VALUES " . $values; Application::getConnection()->queryExecute($sql); } } /** * @param int $locationId * @throws Main\Db\SqlQueryException */ public static function deleteByLocationId(int $locationId) { $locationId = (int)$locationId; Application::getConnection()->queryExecute(" DELETE FROM ".self::getTableName()." WHERE ANCESTOR_ID=".$locationId." OR DESCENDANT_ID = ".$locationId ); } }