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/ilovecveti.ru/bitrix/modules/sproduction.datasync/lib/ |
Upload File : |
<?php namespace SProduction\Datasync; use Bitrix\Main, Bitrix\Main\Entity, Bitrix\Main\Type, Bitrix\Main\Localization\Loc; Loc::loadMessages(__FILE__); /** * Class IblocksProfilesTable * * Fields: * <ul> * <li> id int mandatory * <li> sort int mandatory * <li> active string(4) mandatory * <li> options string mandatory * <li> filter string mandatory * <li> statuses string mandatory * <li> props string mandatory * <li> contact string mandatory * <li> neworder string mandatory * </ul> * * @package SProduction\Datasync **/ class IblocksProfilesTable extends Main\Entity\DataManager { /** * Returns DB table name for entity. * * @return string */ public static function getTableName() { return 'sprod_datasync_iblocks_profiles'; } /** * Returns entity map definition. * * @return array */ public static function getMap() { return array( new Entity\IntegerField('id', [ 'primary' => true, 'autocomplete' => true, 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_ID_FIELD'), ]), new Entity\StringField('sort', [ 'required' => true, 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_SORT_FIELD'), ]), new Entity\StringField('active', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_ACTIVE_FIELD'), 'values' => ['', 'N', 'Y'], ]), new Entity\IntegerField('store_iblock_id', [ 'required' => true, 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_STORE_IBLOCK_ID_FIELD'), ]), new Entity\IntegerField('crm_iblock_id', [ 'required' => true, 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_CRM_IBLOCK_ID_FIELD'), ]), new Entity\StringField('options', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_OPTIONS_FIELD'), ]), new Entity\StringField('base', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_BASE_FIELD'), ]), new Entity\StringField('props', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_PROPS_FIELD'), ]), new Entity\StringField('catalog', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_CATALOG_FIELD'), ]), new Entity\StringField('other', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_OTHER_FIELD'), ]), new Entity\StringField('sync', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_SYNC_FIELD'), ]), new Entity\StringField('sync_process', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_SYNC_PROCESS_FIELD'), ]), new Entity\DateField('date_create', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_DATE_CREATE_FIELD'), ]), new Entity\DateField('date_update', [ 'title' => Loc::getMessage('SP_DS_PROFILES_ENTITY_DATE_UPDATE_FIELD'), 'default_value' => function () { return new Type\DateTime(); }, ]), ); } public static function add(array $fields) { if (!$fields['sort']) { $fields['sort'] = 1; } if (!$fields['date_create']) { $fields['date_create'] = new Type\DateTime(); } foreach ($fields as $code => $values) { if (in_array($code, ['options', 'base', 'props', 'catalog', 'other', 'sync', 'sync_process'])) { $fields[$code] = serialize($values); } } $res = parent::add($fields); return $res; } public static function update($id, array $fields) { foreach ($fields as $code => $values) { if (in_array($code, ['options', 'base', 'props', 'catalog', 'other', 'sync', 'sync_process'])) { $fields[$code] = serialize($values); } } $res = parent::update($id, $fields); return $res; } public static function getList(array $params=[]) { $list = []; if (!empty($params['select'])) { $params['select'][] = 'store_iblock_id'; } $result = parent::getList($params); while ($item = $result->fetch()) { foreach ($item as $code => $values) { switch ($code) { case 'options': case 'base': case 'props': case 'catalog': case 'other': case 'sync': case 'sync_process': $values = unserialize($values); $values = is_array($values) ? $values : []; $item[$code] = $values; break; } } // Get name from iblock name $iblock = \Bitrix\Iblock\IblockTable::getByPrimary($item['store_iblock_id'], [ 'select' => ['NAME'], ])->fetch(); $item['name'] = $iblock['NAME']; $list[] = $item; } return $list; } public static function getById($id) { $fields = false; $result = parent::getById($id); if ($result[0]) { $fields = $result[0]; } return $fields; } /** * @param $iblock_id * * @return array */ public static function getByIblockId($iblock_id) { $fields = []; $result = self::getList([ 'filter' => [ 'store_iblock_id' => $iblock_id, ], ]); if (!empty($result)) { $fields = $result[0]; } return $fields; } }