63 $entityTypeID = isset($data[
'ENTITY_TYPE_ID']) ? (int)$data[
'ENTITY_TYPE_ID'] : \CCrmOwnerType::Undefined;
64 $entityID = isset($data[
'ENTITY_ID']) ? (int)$data[
'ENTITY_ID'] : 0;
65 $providerID = isset($data[
'PROVIDER_ID']) ? (int)$data[
'PROVIDER_ID'] : 0;
66 $dateUpdate = isset($data[
'DATE_UPDATE']) ? $data[
'DATE_UPDATE']:
null;
67 $currency = isset($data[
'CURRENCY']) ? $data[
'CURRENCY'] :
null;
68 $status = isset($data[
'STATUS']) ? $data[
'STATUS'] :
null;
69 $xmlId = isset($data[
'XML_ID']) ? $data[
'XML_ID'] :
null;
70 $amount = isset($data[
'AMOUNT']) ? (double)$data[
'AMOUNT'] : 0.0;
72 $now = Main\Type\DateTime::createFromTimestamp(time() + \CTimeZone::GetOffset());
75 'ENTITY_TYPE_ID' => $entityTypeID,
76 'ENTITY_ID' => $entityID,
77 'DATE_UPDATE' => $dateUpdate,
78 'TIMESTAMP_X' => $now,
79 'PROVIDER_ID' => $providerID,
80 'CURRENCY' => $currency,
96 public static function upsert(array $data)
98 $result =
new Main\Entity\AddResult();
99 $connection = Main\Application::getConnection();
101 static::checkFields($result,
null, $data);
102 if($result->isSuccess() ==
false)
107 $updateFields = $insertFields = static::upsertPrepareParams($data);
109 $queries = $connection->getSqlHelper()->prepareMerge(
110 static::getTableName(),
119 foreach($queries as $query)
121 $connection->queryExecute($query);
125 $connection->getInsertedId());
138 public static function modify(array $items)
140 $connection = Main\Application::getConnection();
141 $sqlHelper = $connection->getSqlHelper();
143 $r = static::checkModifyFields($items);
144 if($r->isSuccess() ==
false)
161 foreach ($names as $name)
163 $duplicate[] = $name.
' = VALUES('.$name.
')';
166 foreach ($items as $item)
168 $fields = static::upsertPrepareParams($item);
171 $fields[
'ENTITY_TYPE_ID'],
172 $fields[
'ENTITY_ID'],
173 $sqlHelper->convertToDbDateTime($fields[
'DATE_UPDATE']),
174 $sqlHelper->convertToDbDateTime($fields[
'TIMESTAMP_X']),
175 $fields[
'PROVIDER_ID'],
176 '\''.$sqlHelper->forSql($fields[
'CURRENCY']).
'\'',
177 '\''.$sqlHelper->forSql($fields[
'STATUS']).
'\'',
178 '\''.$sqlHelper->forSql($fields[
'XML_ID']).
'\'',
179 '\''.$fields[
'AMOUNT'].
'\''
181 $values[] =
'('.implode(
',', $valuesData).
')';
185 INSERT INTO '.static::getTableName().
'
186 ('.implode(
', ', $names).
')
187 VALUES '.implode(
',', $values).
'
188 ON DUPLICATE KEY UPDATE
189 '.implode(
', ', $duplicate).
'