Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
b24integrationrelationtable.php
1<?php
3
5
22class B24IntegrationRelationTable extends Main\Entity\DataManager
23{
24 public static function getTableName()
25 {
26 return 'b_sale_b24integration_relation';
27 }
28
29 public static function getMap()
30 {
31 return [
32 new Main\Entity\IntegerField('SRC_ENTITY_TYPE_ID', [ 'primary' => true ]),
33 new Main\Entity\IntegerField('SRC_ENTITY_ID', [ 'primary' => true ]),
34 new Main\Entity\IntegerField('DST_ENTITY_TYPE_ID', [ 'primary' => true ]),
35 new Main\Entity\IntegerField('DST_ENTITY_ID', [ 'primary' => true ]),
36 new Main\Entity\DatetimeField('CREATED_TIME'),
37 new Main\Entity\DatetimeField('LAST_UPDATED_TIME')
38 ];
39 }
40
41 public static function upsert(array $data)
42 {
43 $srcEntityTypeID = isset($data['SRC_ENTITY_TYPE_ID']) ? (int)$data['SRC_ENTITY_TYPE_ID'] : \CCrmOwnerType::Undefined;
44 $srcEntityID = isset($data['SRC_ENTITY_ID']) ? (int)$data['SRC_ENTITY_ID'] : 0;
45
46 $dstEntityTypeID = isset($data['DST_ENTITY_TYPE_ID']) ? (int)$data['DST_ENTITY_TYPE_ID'] : \CCrmOwnerType::Undefined;
47 $dstEntityID = isset($data['DST_ENTITY_ID']) ? (int)$data['DST_ENTITY_ID'] : 0;
48
49 $now = Main\Type\DateTime::createFromTimestamp(time() + \CTimeZone::GetOffset());
50
51 $insertFields = [
52 'SRC_ENTITY_TYPE_ID' => $srcEntityTypeID,
53 'SRC_ENTITY_ID' => $srcEntityID,
54 'DST_ENTITY_TYPE_ID' => $dstEntityTypeID,
55 'DST_ENTITY_ID' => $dstEntityID,
56 'CREATED_TIME' => $now,
57 'LAST_UPDATED_TIME' => $now
58 ];
59
60 $updateFields = [
61 'LAST_UPDATED_TIME' => $now,
62 'SRC_ENTITY_TYPE_ID' => $srcEntityTypeID,
63 'SRC_ENTITY_ID' => $srcEntityID,
64 'DST_ENTITY_TYPE_ID' => $dstEntityTypeID,
65 'DST_ENTITY_ID' => $dstEntityID
66 ];
67
68 $connection = Main\Application::getConnection();
69 $queries = $connection->getSqlHelper()->prepareMerge(
70 static::getTableName(),
71 [
72 'SRC_ENTITY_TYPE_ID',
73 'SRC_ENTITY_ID',
74 'DST_ENTITY_TYPE_ID',
75 'DST_ENTITY_ID'
76 ],
77 $insertFields,
78 $updateFields
79 );
80
81 foreach($queries as $query)
82 {
83 $connection->queryExecute($query);
84 }
85 }
86}