Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
relation.php
1<?php
3
4
7
9{
10 protected $sourceEntityTypeId = 0;
11 protected $sourceEntityId = 0;
12
14 protected $destinationEntityId = 0;
15
16 public function __construct($sourceEntityTypeId, $sourceEntityId, $destinationEntityTypeId, $destinationEntityId)
17 {
18 if(!is_int($sourceEntityTypeId))
19 {
21 }
22
23 if(!is_int($sourceEntityId))
24 {
26 }
27
28 if(!is_int($destinationEntityTypeId))
29 {
31 }
32
33 if(!is_int($destinationEntityId))
34 {
36 }
37
38 $this->sourceEntityTypeId = $sourceEntityTypeId;
39 $this->sourceEntityId = $sourceEntityId;
40
41 $this->destinationEntityTypeId = $destinationEntityTypeId;
42 $this->destinationEntityId = $destinationEntityId;
43 }
44
45 public function save()
46 {
47 // region multiple relation
48 Entity\B24IntegrationBindTable::upsert(
49 [
50 'SRC_ENTITY_TYPE_ID' => $this->sourceEntityTypeId,
51 'SRC_ENTITY_ID' => $this->sourceEntityId,
52 'DST_ENTITY_TYPE_ID' => $this->destinationEntityTypeId,
53 'DST_ENTITY_ID' => $this->destinationEntityId
54 ]
55 );
56 // endregion
57 // region single relation
58 Entity\B24IntegrationRelationTable::upsert(
59 [
60 'SRC_ENTITY_TYPE_ID' => $this->sourceEntityTypeId,
61 'SRC_ENTITY_ID' => $this->sourceEntityId,
62 'DST_ENTITY_TYPE_ID' => $this->destinationEntityTypeId,
63 'DST_ENTITY_ID' => $this->destinationEntityId
64 ]
65 );
66 // endregion
67
68 return new Result();
69 }
70
71 public static function getBySourceEntity($entityTypeId, $entityId)
72 {
73 $dbResult = Entity\B24IntegrationRelationTable::getList([
74 'filter' => [
75 '=SRC_ENTITY_TYPE_ID' => $entityTypeId,
76 '=SRC_ENTITY_ID' => $entityId
77 ]
78 ]);
79
80 $results = [];
81 while($fields = $dbResult->fetch())
82 {
83 $results[] = $fields;
84 }
85 return $results;
86 }
87
88 public static function getByEntity($sourceEntityTypeId, $sourceEntityId, $destinationEntityTypeId, $destinationEntityId='')
89 {
90 $filter = [];
91 if($sourceEntityTypeId<>'')
92 $filter['=SRC_ENTITY_TYPE_ID'] = $sourceEntityTypeId;
93 if($sourceEntityId<>'')
94 $filter['=SRC_ENTITY_ID'] = $sourceEntityId;
95 if($destinationEntityTypeId<>'')
96 $filter['=DST_ENTITY_TYPE_ID'] = $destinationEntityTypeId;
97 if($destinationEntityId<>'')
98 $filter['=DST_ENTITY_ID'] = $destinationEntityId;
99
100
101 return Entity\B24IntegrationRelationTable::getRow([
102 'filter' => [$filter]
103 ]);
104 }
105
106 public static function createFromArray(array $data)
107 {
108 $item = new Relation(
109 $data['SRC_ENTITY_TYPE_ID'],
110 $data['SRC_ENTITY_ID'],
111 $data['DST_ENTITY_TYPE_ID'],
112 $data['DST_ENTITY_ID']
113 );
114
115 return $item;
116 }
117
118 public function getSourceEntityTypeId()
119 {
120 return $this->sourceEntityTypeId;
121 }
122 public function getSourceEntityId()
123 {
124 return $this->sourceEntityId;
125 }
127 {
128 return $this->destinationEntityTypeId;
129 }
130 public function getDestinationEntityId()
131 {
132 return $this->destinationEntityId;
133 }
134
135 public function setDestinationEntityId($entityId)
136 {
137 if(!is_int($entityId))
138 {
139 $entityId = (int)$entityId;
140 }
141
142 $this->destinationEntityId = $entityId;
143 }
144}
__construct($sourceEntityTypeId, $sourceEntityId, $destinationEntityTypeId, $destinationEntityId)
Definition relation.php:16
static getBySourceEntity($entityTypeId, $entityId)
Definition relation.php:71
static getByEntity($sourceEntityTypeId, $sourceEntityId, $destinationEntityTypeId, $destinationEntityId='')
Definition relation.php:88