/** * Add products from order or updates existing. * * @param $orderId * * @return void */ public static function addProductsFromOrder($orderId = 0) { $orderId = (int) $orderId; if (Sale\OrderProcessingTable::hasAddedProducts($orderId)) { return; } $connection = Main\Application::getConnection(); $type = $connection->getType(); // Update existing if ($type == "mysql") { $sqlUpdate = "UPDATE b_sale_product2product p2p, b_sale_basket b, b_sale_basket b1\n\t\t\t\tSET p2p.CNT = p2p.CNT + 1\n\t\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\t\tp2p.PRODUCT_ID = b.PRODUCT_ID AND\n\t\t\t\t\tp2p.PARENT_PRODUCT_ID = b1.PRODUCT_ID"; } elseif ($type == "mssql") { $sqlUpdate = "UPDATE b_sale_product2product\n\t\t\t\tSET CNT = CNT + 1\n\t\t\t\tFROM b_sale_product2product p2p, b_sale_basket b, b_sale_basket b1\n\t\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\t\tp2p.PRODUCT_ID = b.PRODUCT_ID AND\n\t\t\t\t\tp2p.PARENT_PRODUCT_ID = b1.PRODUCT_ID"; } else { $sqlUpdate = "UPDATE b_sale_product2product\n\t\t\t\tSET CNT = CNT + 1\n\t\t\t\tWHERE ID IN (\n\t\t\t\t\tSELECT p2p.ID FROM b_sale_product2product p2p, b_sale_basket b, b_sale_basket b1\n\t\t\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\t\t\tp2p.PRODUCT_ID = b.PRODUCT_ID AND\n\t\t\t\t\t\tp2p.PARENT_PRODUCT_ID = b1.PRODUCT_ID\n\t\t\t\t\t)"; } $connection->query($sqlUpdate); // Insert new $sqlInsert = "INSERT INTO b_sale_product2product (PRODUCT_ID, PARENT_PRODUCT_ID, CNT)\n\t\t\tSELECT b.PRODUCT_ID, b1.PRODUCT_ID, 1\n\t\t\tFROM b_sale_basket b, b_sale_basket b1\n\t\t\tWHERE b.ORDER_ID = b1.ORDER_ID AND\n\t\t\t\tb.ORDER_ID = {$orderId} AND\n\t\t\t\tb.ID <> b1.ID AND\n\t\t\t\tNOT EXISTS (SELECT 1 FROM b_sale_product2product d WHERE d.PRODUCT_ID = b.PRODUCT_ID AND d.PARENT_PRODUCT_ID = b1.PRODUCT_ID)"; $connection->query($sqlInsert); Sale\OrderProcessingTable::markProductsAdded($orderId); if (defined("BX_COMP_MANAGED_CACHE")) { $app = Main\Application::getInstance(); $app->getTaggedCache()->clearByTag('sale_product_buy'); } }
public static function deleteByDeliveryIdClassName($deliveryId, $className) { $con = \Bitrix\Main\Application::getConnection(); $sqlHelper = $con->getSqlHelper(); $strSql = "DELETE FROM " . self::getTableName() . " WHERE DELIVERY_ID=" . $sqlHelper->forSql($deliveryId) . " AND CLASS_NAME='" . $sqlHelper->forSql($className) . "'"; $con->queryExecute($strSql); }
public static function Set($user_id, $page_last_date, $page_size, $page_num = 1, $site_id = SITE_ID, $group_code = '**', $traffic_avg = false, $traffic_cnt = false) { global $DB; $user_id = intval($user_id); $page_size = intval($page_size); $page_num = intval($page_num); $traffic_avg = intval($traffic_avg); $traffic_cnt = intval($traffic_cnt); if ($user_id <= 0 || $page_size <= 0 || strlen($page_last_date) <= 0) { return false; } $page_last_date = new \Bitrix\Main\Type\DateTime($page_last_date); $connection = \Bitrix\Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $arInsertFields = array("USER_ID" => $user_id, "SITE_ID" => $DB->ForSQL($site_id), "GROUP_CODE" => $DB->ForSQL($group_code), "PAGE_SIZE" => $page_size, "PAGE_NUM" => $page_num, "PAGE_LAST_DATE" => $page_last_date); $arUpdateFields = array("PAGE_LAST_DATE" => $page_last_date); if ($traffic_cnt) { $arInsertFields["TRAFFIC_AVG"] = $arUpdateFields["TRAFFIC_AVG"] = $traffic_avg; $arInsertFields["TRAFFIC_CNT"] = $arUpdateFields["TRAFFIC_CNT"] = $traffic_cnt; $arInsertFields["TRAFFIC_LAST_DATE"] = $arUpdateFields["TRAFFIC_LAST_DATE"] = new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction()); } $merge = $helper->prepareMerge("b_sonet_log_page", array("USER_ID", "SITE_ID", "GROUP_CODE", "PAGE_SIZE", "PAGE_NUM"), $arInsertFields, $arUpdateFields); if ($merge[0] != "") { $connection->query($merge[0]); if ($traffic_cnt) { CSocNetLogFollow::checkAutoUnfollow($traffic_cnt, $traffic_avg, $user_id); } } }
function clearValues() { $connection = \Bitrix\Main\Application::getConnection(); $connection->query("\n\t\t\tDELETE FROM b_iblock_element_iprop\n\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t"); $connection->query("\n\t\t\tDELETE FROM b_iblock_section_iprop\n\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t"); $connection->query("\n\t\t\tDELETE FROM b_iblock_iblock_iprop\n\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t"); }
public static function getMap() { global $DB, $DBType; $connection = Main\Application::getConnection(); $helper = $connection->getSqlHelper(); return array('ID' => array('data_type' => 'integer', 'primary' => true, 'autocomplete' => true), 'LID' => array('data_type' => 'string', 'required' => true, 'validation' => array(__CLASS__, 'validateLid')), 'FUSER_ID' => array('data_type' => 'integer', 'required' => true), new Main\Entity\ReferenceField('FUSER', 'Bitrix\\Sale\\Internals\\Fuser', array('=this.FUSER_ID' => 'ref.ID'), array('join_type' => 'INNER')), new Main\Entity\ReferenceField('USER', 'Bitrix\\Main\\User', array('=this.ID' => 'FUSER.USER_ID')), 'ORDER_ID' => array('data_type' => 'integer'), new Main\Entity\ReferenceField('ORDER', 'Bitrix\\Sale\\Internals\\Order', array('=this.ORDER_ID' => 'ref.ID')), 'PRODUCT_ID' => array('data_type' => 'integer', 'required' => true), 'PRODUCT' => array('data_type' => 'Product', 'reference' => array('=this.PRODUCT_ID' => 'ref.ID')), 'PRODUCT_PRICE_ID' => array('data_type' => 'integer'), 'NAME' => array('data_type' => 'string'), new Main\Entity\ExpressionField('NAME_WITH_IDENT', $helper->getConcatFunction("%s", "' ['", "%s", "']'"), array('NAME', 'PRODUCT_ID')), 'PRICE' => array('data_type' => 'float'), 'CURRENCY' => array('data_type' => 'string', 'required' => true, 'validation' => array(__CLASS__, 'validateCurrency')), 'BASE_PRICE' => array('data_type' => 'float'), 'VAT_INCLUDED' => array('data_type' => 'boolean', 'values' => array('Y', 'N')), 'DATE_INSERT' => array('data_type' => 'datetime'), 'DATE_INS' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'DATE_INSERT')), 'DATE_UPDATE' => array('data_type' => 'datetime'), 'DATE_UPD' => array('data_type' => 'datetime', 'expression' => array($DB->datetimeToDateFunction('%s'), 'DATE_UPDATE')), 'WEIGHT' => array('data_type' => 'float'), 'QUANTITY' => array('data_type' => 'float', 'required' => true), 'DELAY' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'SUMMARY_PRICE' => array('data_type' => 'float', 'expression' => array('(%s * %s)', 'QUANTITY', 'PRICE')), 'CAN_BUY' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'MODULE' => array('data_type' => 'string'), 'PRODUCT_PROVIDER_CLASS' => array('data_type' => 'string'), 'NOTES' => array('data_type' => 'string'), 'DETAIL_PAGE_URL' => array('data_type' => 'string'), 'DISCOUNT_PRICE' => array('data_type' => 'float'), 'CATALOG_XML_ID' => array('data_type' => 'string'), 'PRODUCT_XML_ID' => array('data_type' => 'string'), 'DISCOUNT_NAME' => array('data_type' => 'string', 'validation' => array(__CLASS__, 'validateDiscountName')), 'DISCOUNT_VALUE' => array('data_type' => 'string', 'validation' => array(__CLASS__, 'validateDiscountValue')), 'DISCOUNT_COUPON' => array('data_type' => 'string', 'validation' => array(__CLASS__, 'validateDiscountCoupon')), 'VAT_RATE' => array('data_type' => 'float'), 'VAT_RATE_PRC' => array('data_type' => 'float', 'expression' => array('100 * %s', 'VAT_RATE')), 'SUBSCRIBE' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'N_SUBSCRIBE' => array('data_type' => 'integer', 'expression' => array('CASE WHEN %s = \'Y\' THEN 1 ELSE 0 END', 'SUBSCRIBE')), 'RESERVED' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'RESERVE_QUANTITY' => array('data_type' => 'float'), 'BARCODE_MULTI' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'CUSTOM_PRICE' => array('data_type' => 'boolean', 'values' => array('N', 'Y')), 'DIMENSIONS' => array('serialized' => true, 'data_type' => 'string'), 'TYPE' => array('data_type' => 'integer'), 'SET_PARENT_ID' => array('data_type' => 'integer'), 'MEASURE_CODE' => array('data_type' => 'integer'), 'MEASURE_NAME' => array('data_type' => 'string'), 'CALLBACK_FUNC' => array('data_type' => 'string'), 'ORDER_CALLBACK_FUNC' => array('data_type' => 'string'), 'CANCEL_CALLBACK_FUNC' => array('data_type' => 'string'), 'PAY_CALLBACK_FUNC' => array('data_type' => 'string'), 'RECOMMENDATION' => array('data_type' => 'string'), 'ALL_PRICE' => array('data_type' => 'float', 'expression' => array('(%s + %s)', 'QUANTITY', 'DISCOUNT_PRICE')), 'SUMMARY_PURCHASING_PRICE' => array('data_type' => 'float', 'expression' => array('(%s) * %s', 'PRODUCT.PURCHASING_PRICE_IN_SITE_CURRENCY', 'QUANTITY')), 'GROSS_PROFIT' => array('data_type' => 'float', 'expression' => array('(%s) - (%s)', 'SUMMARY_PRICE', 'SUMMARY_PURCHASING_PRICE')), 'PROFITABILITY' => array('data_type' => 'float', 'expression' => array('CASE WHEN %s is NULL OR %s=0 THEN NULL ELSE (%s) * 100 / (%s) END', 'SUMMARY_PURCHASING_PRICE', 'SUMMARY_PURCHASING_PRICE', 'GROSS_PROFIT', 'SUMMARY_PURCHASING_PRICE')), 'SHIPMENT_ITEM' => array('data_type' => 'ShipmentItem', 'reference' => array('=ref.BASKET_ID' => 'this.ID')), 'SHIPMENT' => array('data_type' => 'Shipment', 'reference' => array('=ref.ID' => 'this.SHIPMENT_ITEM.ORDER_DELIVERY_ID')), 'PAYMENT' => array('data_type' => 'Payment', 'reference' => array('=ref.ORDER_ID' => 'this.ORDER_ID'))); }
public static function upsert(array $data) { $connection = Main\Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $entityTypeID = isset($data['ENTITY_TYPE_ID']) ? (int) $data['ENTITY_TYPE_ID'] : 0; $entityID = isset($data['ENTITY_ID']) ? (int) $data['ENTITY_ID'] : 0; $typeID = isset($data['TYPE_ID']) ? (int) $data['TYPE_ID'] : 0; $address1 = isset($data['ADDRESS_1']) && $data['ADDRESS_1'] !== '' ? "'{$sqlHelper->forSql($data['ADDRESS_1'], 255)}'" : 'NULL'; $address2 = isset($data['ADDRESS_2']) && $data['ADDRESS_2'] !== '' ? "'{$sqlHelper->forSql($data['ADDRESS_2'], 255)}'" : 'NULL'; $city = isset($data['CITY']) && $data['CITY'] !== '' ? "'{$sqlHelper->forSql($data['CITY'], 128)}'" : 'NULL'; $postalCode = isset($data['POSTAL_CODE']) && $data['POSTAL_CODE'] !== '' ? "'{$sqlHelper->forSql($data['POSTAL_CODE'], 16)}'" : 'NULL'; $region = isset($data['REGION']) && $data['REGION'] !== '' ? "'{$sqlHelper->forSql($data['REGION'], 128)}'" : 'NULL'; $province = isset($data['PROVINCE']) && $data['PROVINCE'] !== '' ? "'{$sqlHelper->forSql($data['PROVINCE'], 128)}'" : 'NULL'; $country = isset($data['COUNTRY']) && $data['COUNTRY'] !== '' ? "'{$sqlHelper->forSql($data['COUNTRY'], 128)}'" : 'NULL'; $countryCode = isset($data['COUNTRY_CODE']) && $data['COUNTRY_CODE'] !== '' ? "'{$sqlHelper->forSql($data['COUNTRY_CODE'], 100)}'" : 'NULL'; if ($connection instanceof Main\DB\MysqlCommonConnection) { $connection->queryExecute("INSERT INTO b_crm_addr(ENTITY_TYPE_ID, ENTITY_ID, TYPE_ID, ADDRESS_1, ADDRESS_2, CITY, POSTAL_CODE, REGION, PROVINCE, COUNTRY, COUNTRY_CODE)\n\t\t\t\t\tVALUES({$entityTypeID}, {$entityID}, {$typeID}, {$address1}, {$address2}, {$city}, {$postalCode}, {$region}, {$province}, {$country}, {$countryCode})\n\t\t\t\t\tON DUPLICATE KEY UPDATE ADDRESS_1 = {$address1}, ADDRESS_2 = {$address2}, CITY = {$city}, POSTAL_CODE = {$postalCode}, REGION = {$region}, PROVINCE = {$province}, COUNTRY = {$country}, COUNTRY_CODE = {$countryCode}"); } elseif ($connection instanceof Main\DB\MssqlConnection) { $dbResult = $connection->query("SELECT 'X' FROM b_crm_addr WHERE ENTITY_TYPE_ID = {$entityTypeID} AND ENTITY_ID = {$entityID} AND TYPE_ID = {$typeID}"); if (is_array($dbResult->fetch())) { $connection->queryExecute("UPDATE b_crm_addr SET ADDRESS_1 = {$address1}, ADDRESS_2 = {$address2}, CITY = {$city}, POSTAL_CODE = {$postalCode}, REGION = {$region}, PROVINCE = {$province}, COUNTRY = {$country}, COUNTRY_CODE = {$countryCode}\n\t\t\t\t\t\tWHERE ENTITY_TYPE_ID = {$entityTypeID} AND ENTITY_ID = {$entityID} AND TYPE_ID = {$typeID}"); } else { $connection->queryExecute("INSERT INTO b_crm_addr(ENTITY_TYPE_ID, ENTITY_ID, TYPE_ID, ADDRESS_1, ADDRESS_2, CITY, POSTAL_CODE, REGION, PROVINCE, COUNTRY, COUNTRY_CODE)\n\t\t\t\t\t\tVALUES({$entityTypeID}, {$entityID}, {$typeID}, {$address1}, {$address2}, {$city}, {$postalCode}, {$region}, {$province}, {$country}, {$countryCode})"); } } elseif ($connection instanceof Main\DB\OracleConnection) { $connection->queryExecute("MERGE INTO b_crm_addr USING (SELECT {$entityTypeID} ENTITY_TYPE_ID, {$entityID} ENTITY_ID, {$typeID} TYPE_ID FROM dual)\n\t\t\t\tsource ON\n\t\t\t\t(\n\t\t\t\t\tsource.ENTITY_TYPE_ID = b_crm_addr.ENTITY_TYPE_ID\n\t\t\t\t\tAND source.ENTITY_ID = b_crm_addr.ENTITY_ID\n\t\t\t\t\tAND source.TYPE_ID = b_crm_addr.TYPE_ID\n\t\t\t\t)\n\t\t\t\tWHEN MATCHED THEN\n\t\t\t\t\tUPDATE SET b_crm_addr.ADDRESS_1 = {$address1},\n\t\t\t\t\t\tb_crm_addr.ADDRESS_2 = {$address2},\n\t\t\t\t\t\tb_crm_addr.CITY = {$city},\n\t\t\t\t\t\tb_crm_addr.POSTAL_CODE = {$postalCode},\n\t\t\t\t\t\tb_crm_addr.REGION = {$region},\n\t\t\t\t\t\tb_crm_addr.PROVINCE = {$province},\n\t\t\t\t\t\tb_crm_addr.COUNTRY = {$country},\n\t\t\t\t\t\tb_crm_addr.COUNTRY_CODE = {$countryCode}\n\t\t\t\tWHEN NOT MATCHED THEN\n\t\t\t\t\tINSERT (ENTITY_TYPE_ID, ENTITY_ID, TYPE_ID, ADDRESS_1, ADDRESS_2, CITY, POSTAL_CODE, REGION, PROVINCE, COUNTRY, COUNTRY_CODE)\n\t\t\t\t\tVALUES({$entityTypeID}, {$entityID}, {$typeID}, {$address1}, {$address2}, {$city}, {$postalCode}, {$region}, {$province}, {$country}, {$countryCode})"); } else { $dbType = $connection->getType(); throw new Main\NotSupportedException("The '{$dbType}' is not supported in current context"); } }
/** * @return void */ public static function upsert(array $data) { $connection = Main\Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $srcTypeID = isset($data['SRC_TYPE_ID']) ? (int) $data['SRC_TYPE_ID'] : 0; $dstTypeID = isset($data['DST_TYPE_ID']) ? (int) $data['DST_TYPE_ID'] : 0; $dateField = new DatetimeField('D'); $lastUpdated = $sqlHelper->convertToDb(new DateTime(), $dateField); $data = isset($data['DATA']) ? $sqlHelper->forSql($data['DATA']) : ''; if ($connection instanceof Main\DB\MysqlCommonConnection) { $connection->queryExecute("INSERT INTO b_crm_conv_map(SRC_TYPE_ID, DST_TYPE_ID, LAST_UPDATED, DATA)\n\t\t\t\t\tVALUES({$srcTypeID}, {$dstTypeID}, {$lastUpdated}, '{$data}')\n\t\t\t\t\tON DUPLICATE KEY UPDATE LAST_UPDATED = {$lastUpdated}, DATA = '{$data}'"); } elseif ($connection instanceof Main\DB\MssqlConnection) { $dbResult = $connection->query("SELECT 'X' FROM b_crm_conv_map WHERE SRC_TYPE_ID = {$srcTypeID} AND DST_TYPE_ID = {$dstTypeID}"); if (is_array($dbResult->fetch())) { $connection->queryExecute("UPDATE b_crm_conv_map SET LAST_UPDATED = {$lastUpdated}, DATA = '{$data}'\n\t\t\t\t\t\tWHERE SRC_TYPE_ID = {$srcTypeID} AND DST_TYPE_ID = {$dstTypeID}"); } else { $connection->queryExecute("INSERT INTO b_crm_conv_map(SRC_TYPE_ID, DST_TYPE_ID, LAST_UPDATED, DATA)\n\t\t\t\t\t\tVALUES({$srcTypeID}, {$dstTypeID}, {$lastUpdated}, '{$data}')"); } } elseif ($connection instanceof Main\DB\OracleConnection) { $connection->queryExecute("MERGE INTO b_crm_conv_map USING (SELECT {$srcTypeID} SRC_TYPE_ID, {$dstTypeID} DST_TYPE_ID FROM dual)\n\t\t\t\tsource ON\n\t\t\t\t(\n\t\t\t\t\tsource.SRC_TYPE_ID = b_crm_conv_map.SRC_TYPE_ID\n\t\t\t\t\tAND source.DST_TYPE_ID = b_crm_conv_map.DST_TYPE_ID\n\t\t\t\t)\n\t\t\t\tWHEN MATCHED THEN\n\t\t\t\t\tUPDATE SET b_crm_conv_map.LAST_UPDATED = {$lastUpdated},\n\t\t\t\t\tb_crm_conv_map.DATA = '{$data}'\n\t\t\t\tWHEN NOT MATCHED THEN\n\t\t\t\t\tINSERT (SRC_TYPE_ID, DST_TYPE_ID, LAST_UPDATED, DATA)\n\t\t\t\t\tVALUES({$srcTypeID}, {$dstTypeID}, {$lastUpdated}, '{$data}')"); } else { $dbType = $connection->getType(); throw new Main\NotSupportedException("The '{$dbType}' is not supported in current context"); } }
/** * @param string $dbName * @return array List of all sites & their params */ public static function getList($dbName = false) { if (!$dbName) { $connection = \Bitrix\Main\Application::getConnection(); $dbName = $connection->getDbName(); } $result = array(); $shellAdapter = new ShellAdapter(); $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-sites -o json -a list -d " . $dbName); $sitesData = $shellAdapter->getLastOutput(); if ($execRes) { $arData = json_decode($sitesData, true); if (isset($arData["params"])) { $result = $arData["params"]; } $rsSite = \Bitrix\Main\SiteTable::getList(); while ($site = $rsSite->fetch()) { foreach ($result as $siteId => $siteInfo) { $docRoot = strlen($site["DOC_ROOT"]) > 0 ? $site["DOC_ROOT"] : \Bitrix\Main\Application::getDocumentRoot(); if ($siteInfo["DocumentRoot"] == $docRoot) { $result[$siteId]["NAME"] = $site["NAME"] . " (" . $site["LID"] . ") "; } else { $result[$siteId]["NAME"] = $siteId; } } } } return $result; }
/** * Deletes all records with mapEntityId. * @param string $mapEntityId Map entity id. */ public static function deleteByMapEntityId($mapEntityId) { $con = \Bitrix\Main\Application::getConnection(); $sqlHelper = $con->getSqlHelper(); $tableName = self::getTableName(); $strSql = "DELETE FROM " . $tableName . " " . "WHERE ENTITY_ID=" . $sqlHelper->forSql($mapEntityId); $con->queryExecute($strSql); }
/** * Fills descendants simple rights by simple rights of object. * @internal * @param int $objectId Id of object. */ public static function fillDescendants($objectId) { $tableName = static::getTableName(); $pathTableName = ObjectPathTable::getTableName(); $connection = Application::getConnection(); $objectId = (int) $objectId; $connection->queryExecute("\n\t\t\tINSERT INTO {$tableName} (OBJECT_ID, ACCESS_CODE)\n\t\t\tSELECT path.OBJECT_ID, sright.ACCESS_CODE FROM {$pathTableName} path\n\t\t\t\tINNER JOIN {$tableName} sright ON sright.OBJECT_ID = path.PARENT_ID\n\t\t\tWHERE path.PARENT_ID = {$objectId}\n\t\t"); }
function UnInstallDB() { Loader::includeModule($this->MODULE_ID); // Drop PersonTable Application::getConnection(\Adelshin\Person\PersonTable::getConnectionName())->queryExecute('drop table if exists ' . Base::getInstance('\\Adelshin\\Person\\PersonTable')->getDBTableName()); // Drop GroupTable Application::getConnection(\Adelshin\Person\GroupsTable::getConnectionName())->queryExecute('drop table if exists ' . Base::getInstance('\\Adelshin\\Person\\GroupsTable')->getDBTableName()); Option::delete($this->MODULE_ID); }
/** * Deletes rows by filter. * @param array $filter Filter does not look like filter in getList. It depends by current implementation. * @internal * @return void */ public static function deleteBatch(array $filter) { $tableName = static::getTableName(); $connection = Application::getConnection(); if (!empty($filter['ACCESS_CODE'])) { $accessCode = $connection->getSqlHelper()->forSql($filter['ACCESS_CODE']); $connection->queryExecute("DELETE FROM {$tableName} WHERE ACCESS_CODE = '{$accessCode}'"); } }
public static function getActiveUsersCount() { $sql = "SELECT COUNT(ID) " . "FROM b_user " . "WHERE ACTIVE = 'Y' " . " AND LAST_LOGIN IS NOT NULL"; if (ModuleManager::isModuleInstalled("intranet")) { $sql = "SELECT COUNT(U.ID) " . "FROM b_user U " . "WHERE U.ACTIVE = 'Y' " . " AND U.LAST_LOGIN IS NOT NULL " . " AND EXISTS(" . " SELECT 'x' " . " FROM b_utm_user UF, b_user_field F " . " WHERE F.ENTITY_ID = 'USER' " . " AND F.FIELD_NAME = 'UF_DEPARTMENT' " . " AND UF.FIELD_ID = F.ID " . " AND UF.VALUE_ID = U.ID " . " AND UF.VALUE_INT IS NOT NULL " . " AND UF.VALUE_INT <> 0" . " )"; } $connection = Application::getConnection(); return $connection->queryScalar($sql); }
public static function deleteByShipmentId($shipmentId) { if (intval($shipmentId) > 0) { $con = \Bitrix\Main\Application::getConnection(); $sqlHelper = $con->getSqlHelper(); $strSql = "DELETE FROM " . self::getTableName() . " WHERE SHIPMENT_ID=" . $sqlHelper->forSql($shipmentId); $con->queryExecute($strSql); } }
public static function clean() { $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $tableName = static::getTableName(); $deleteBorder = $sqlHelper->addSecondsToDateTime(-static::TTL, $sqlHelper->getCurrentDateTimeFunction()); $connection->queryExecute("DELETE FROM {$tableName} WHERE TIMESTAMP_X < {$deleteBorder}"); return __CLASS__ . "::clean();"; }
function clearValues() { $connection = \Bitrix\Main\Application::getConnection(); $sectionList = \Bitrix\Iblock\SectionTable::getList(array("select" => array("LEFT_MARGIN", "RIGHT_MARGIN"), "filter" => array("=ID" => $this->section_id))); $section = $sectionList->fetch(); if ($section) { $connection->query("\n\t\t\t\tDELETE FROM b_iblock_element_iprop\n\t\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\tAND ELEMENT_ID in (\n\t\t\t\t\tSELECT BSE.IBLOCK_ELEMENT_ID\n\t\t\t\t\tFROM b_iblock_section_element BSE\n\t\t\t\t\tINNER JOIN b_iblock_section BS ON BSE.IBLOCK_SECTION_ID = BS.ID AND BSE.ADDITIONAL_PROPERTY_ID IS NULL\n\t\t\t\t\tWHERE BS.IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\t\tAND BS.LEFT_MARGIN <= " . $section["RIGHT_MARGIN"] . "\n\t\t\t\t\tAND BS.RIGHT_MARGIN >= " . $section["LEFT_MARGIN"] . "\n\t\t\t\t)\n\t\t\t"); $connection->query("\n\t\t\t\tDELETE FROM b_iblock_section_iprop\n\t\t\t\tWHERE IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\tAND SECTION_ID in (\n\t\t\t\t\tSELECT BS.ID\n\t\t\t\t\tFROM b_iblock_section BS\n\t\t\t\t\tWHERE BS.IBLOCK_ID = " . $this->iblock_id . "\n\t\t\t\t\tAND BS.LEFT_MARGIN <= " . $section["RIGHT_MARGIN"] . "\n\t\t\t\t\tAND BS.RIGHT_MARGIN >= " . $section["LEFT_MARGIN"] . "\n\t\t\t\t)\n\t\t\t"); } }
/** * Delete modules by discount. * * @param int $discount Discount id. * @return void */ public static function deleteByDiscount($discount) { $discount = (int) $discount; if ($discount <= 0) { return; } $conn = Application::getConnection(); $helper = $conn->getSqlHelper(); $conn->queryExecute('delete from ' . $helper->quote(self::getTableName()) . ' where ' . $helper->quote('DISCOUNT_ID') . ' = ' . $discount); }
public static function catchCatalogBasket($id, $arFields) { global $APPLICATION; // alter b_sale_basket - add recommendation, update it here if (!static::isOn()) { return; } // get product id by offer id $productInfo = \CCatalogSKU::GetProductInfo($arFields['PRODUCT_ID']); if (!empty($productInfo['ID'])) { $realProductId = $productInfo['ID']; } else { $realProductId = $arFields['PRODUCT_ID']; } // select site user id & recommendation id $siteUserId = 0; $recommendationId = ''; // first, try to find in cookies $recommendationCookie = $APPLICATION->get_cookie(static::getCookieLogName()); if (!empty($recommendationCookie)) { $recommendations = static::decodeProductLog($recommendationCookie); if (is_array($recommendations) && isset($recommendations[$realProductId])) { $recommendationId = $recommendations[$realProductId][0]; } } if (empty($recommendationId)) { // ok then, lets see in views history //if(\COption::GetOptionString("sale", "encode_fuser_id", "N") == "Y") if (!is_numeric($arFields['FUSER_ID'])) { $filter = array('CODE' => $arFields['FUSER_ID']); } else { $filter = array('ID' => $arFields['FUSER_ID']); } $result = \CSaleUser::getList($filter); if (!empty($result)) { $siteUserId = $result['USER_ID']; // select recommendation id $fuser = $result['ID']; $viewResult = CatalogViewedProductTable::getList(array('select' => array('RECOMMENDATION'), 'filter' => array('=FUSER_ID' => $fuser, '=PRODUCT_ID' => $arFields['PRODUCT_ID']), 'order' => array('DATE_VISIT' => 'DESC')))->fetch(); if (!empty($viewResult['RECOMMENDATION'])) { $recommendationId = $viewResult['RECOMMENDATION']; } } } // prepare data $data = array('product_id' => $realProductId, 'user_id' => $siteUserId, 'bx_user_id' => static::getBxUserId(), 'domain' => Context::getCurrent()->getServer()->getHttpHost(), 'recommendation' => $recommendationId, 'date' => date(DATE_ISO8601)); CounterDataTable::add(array('TYPE' => 'basket', 'DATA' => $data)); // update basket with recommendation id if (!empty($recommendationId)) { $conn = Application::getConnection(); $helper = $conn->getSqlHelper(); $conn->query("UPDATE " . $helper->quote('b_sale_basket') . " SET RECOMMENDATION='" . $helper->forSql($recommendationId) . "' WHERE ID=" . (int) $id); } }
public static function checkUserLinks($socservUserId) { $dbRes = UserTable::getByPrimary($socservUserId); $arUser = $dbRes->fetch(); if ($arUser) { $sql = "\nSELECT sul.ID, su_link.USER_ID\nFROM " . self::getTableName() . " sul\nLEFT JOIN " . SocservUserTable::getTableName() . " su_link ON sul.LINK_UID=su_link.XML_ID\nWHERE (1=1)\nAND sul.SOCSERV_USER_ID='" . $arUser['ID'] . "'\nAND su_link.EXTERNAL_AUTH_ID='" . $arUser['EXTERNAL_AUTH_ID'] . "'\nAND sul.LINK_USER_ID IS NULL\n"; $connection = \Bitrix\Main\Application::getConnection(); return $connection->query($sql); } else { return false; } }
public static function getMap() { $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $map = parent::getMap(); $map['TYPE']['validation'] = array(__CLASS__, 'validateType'); $map[] = new ExpressionField('HAS_SUBFOLDERS', 'CASE WHEN EXISTS( SELECT \'x\' FROM b_disk_object_path p INNER JOIN b_disk_object o ON o.ID=p.OBJECT_ID AND o.TYPE=2 WHERE p.PARENT_ID = %1$s AND p.DEPTH_LEVEL = 1) THEN 1 ELSE 0 END', array('REAL_OBJECT_ID'), array('data_type' => 'boolean')); return $map; }
/** * Construct object */ public function __construct() { $this->MODULE_NAME = Loc::getMessage('CORE_MODULE_NAME_CITFACT_TOOLS'); $this->MODULE_DESCRIPTION = Loc::getMessage('CORE_MODULE_DESCRIPTION_CITFACT_TOOLS'); $this->PARTNER_NAME = Loc::getMessage('PARTNER_NAME_CITFACT'); $this->PARTNER_URI = Loc::getMessage('PARTNER_NAME_CITFACT'); $this->MODULE_PATH = $this->getModulePath(); $arModuleVersion = array(); include $this->MODULE_PATH . '/install/version.php'; $this->MODULE_VERSION = $arModuleVersion['VERSION']; $this->MODULE_VERSION_DATE = $arModuleVersion['VERSION_DATE']; $this->connection = Application::getConnection(); }
public static function getDBColumnType($userField) { $connection = Application::getConnection(); if ($connection instanceof MysqlCommonConnection) { return 'int(11)'; } if ($connection instanceof OracleConnection) { return 'number(18)'; } if ($connection instanceof MssqlConnection) { return 'int'; } throw new NotSupportedException("The '{$connection->getType()}' is not supported in current context"); }
/** * Deletes old objects from recently used log by user. * @param int $userId User id. * @return void */ public static function deleteOldObjects($userId) { $offset = self::MAX_COUNT_FOR_USER - 1; $connection = Application::getConnection(); if ($connection instanceof MysqlCommonConnection) { $connection->queryExecute("\n\t\t\t\tDELETE t\n\t\t\t\tFROM\n\t\t\t\t b_disk_recently_used AS t\n\t\t\t JOIN\n\t\t\t\t( SELECT ID\n\t\t\t\t FROM b_disk_recently_used\n\t\t\t\t WHERE USER_ID = {$userId}\n\t\t\t\t ORDER BY ID DESC\n\t\t\t\t LIMIT 1 OFFSET {$offset}\n\t\t\t\t) tlimit ON t.ID < tlimit.ID AND t.USER_ID = {$userId}\n\t\t\t"); } else { $id = static::getList(array('select' => array('ID'), 'filter' => array('USER_ID' => $userId), 'order' => array('ID' => 'DESC'), 'limit' => 1, 'offset' => $offset))->fetch(); $id = !empty($id['ID']) ? (int) $id['ID'] : null; if ($id) { $connection->queryExecute("\n\t\t\t\t\tDELETE FROM b_disk_recently_used WHERE ID < {$id} AND USER_ID = {$userId}\n\t\t\t\t"); } } }
public static function synchronize($ownerID, array $data) { if (!is_int($ownerID)) { $ownerID = (int) $ownerID; } if ($ownerID <= 0) { throw new Main\ArgumentException('Owner ID must be greater than zero.', 'ownerID'); } $connection = Main\Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $dateField = new DatetimeField('D'); $start = $sqlHelper->convertToDb(isset($data['START_DATE']) ? $data['START_DATE'] : null, $dateField); $end = $sqlHelper->convertToDb(isset($data['END_DATE']) ? $data['END_DATE'] : null, $dateField); $userID = isset($data['RESPONSIBLE_ID']) ? (int) $data['RESPONSIBLE_ID'] : 0; Main\Application::getConnection()->queryExecute("UPDATE b_crm_deal_stage_history\n\t\t\t\tSET START_DATE = {$start}, END_DATE = {$end}, RESPONSIBLE_ID = {$userID} WHERE OWNER_ID = {$ownerID}"); }
public static function deleteBySiteId($siteId) { if (empty($siteId)) { throw new \Bitrix\Main\ArgumentNullException("siteId"); } $result = new \Bitrix\Main\Entity\DeleteResult(); // event PRE // delete $connection = \Bitrix\Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $tableName = static::getEntity()->getDBTableName(); $sql = "DELETE FROM " . $tableName . " WHERE SITE_ID = '" . $helper->forSql($siteId) . "'"; $connection->queryExecute($sql); // event POST return $result; }
public static function getCurrentTemplateId($siteId) { $cacheFlags = Config\Configuration::getValue("cache_flags"); $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0; $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION"; $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates"); if ($ttl === false) { $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } else { $managedCache = Application::getInstance()->getManagedCache(); if ($managedCache->read($ttl, "b_site_template")) { $arSiteTemplateBySite = $managedCache->get("b_site_template"); } else { $arSiteTemplateBySite = array(); $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $arSiteTemplateBySite[$record['SITE_ID']][] = $record; } $managedCache->set("b_site_template", $arSiteTemplateBySite); } if (is_array($arSiteTemplateBySite[$siteId])) { foreach ($arSiteTemplateBySite[$siteId] as $record) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } } return ".default"; }
public static function deleteByEntity($entityTypeID, $entityID) { if (!is_int($entityTypeID)) { $entityTypeID = (int) $entityTypeID; } if (!\CCrmOwnerType::IsDefined($entityTypeID)) { throw new Main\ArgumentException("Is not defined or invalid", 'entityTypeID'); } if (!is_int($entityID)) { $entityID = (int) $entityID; } if ($entityID <= 0) { throw new Main\ArgumentException("Must be greater than zero", 'entityID'); } $connection = Main\Application::getConnection(); $connection->queryExecute("DELETE FROM b_crm_dp_index_mismatch WHERE ENTITY_TYPE_ID = {$entityTypeID} AND L_ENTITY_ID = {$entityID}"); $connection->queryExecute("DELETE FROM b_crm_dp_index_mismatch WHERE ENTITY_TYPE_ID = {$entityTypeID} AND R_ENTITY_ID = {$entityID}"); }
/** * @param mixed $value значение параметра по которому инициализируется объект * @param string $param параметр * @param int $iblockId инфоблок * @throws \Exception */ public function __construct($value, $param = 'id', $iblockId = null) { $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $value = $sqlHelper->forSql($value); if ($iblockId > 0) { $iblockId = " AND IBLOCK_ID = " . intval($iblockId); } if (!isset($this->allowedParamsFrom[$param])) { throw new \Exception("Param {$param} not allowed"); } $param = $this->allowedParamsFrom[$param]; $res = $connection->query("SELECT * FROM b_iblock_element WHERE `{$param}`='{$value}' {$iblockId} LIMIT 1")->fetch(); if (!$res || !$res['ID']) { return; } $this->params = $res; }
/** * Returns entity map definition. * * @return array */ public static function getMap() { global $DB, $USER; $maxLock = Main\Config\Option::get('sale', 'MAX_LOCK_TIME', 60); $userID = is_object($USER) ? (int) $USER->getID() : 0; $connection = Main\Application::getConnection(); $helper = $connection->getSqlHelper(); $lockStatusExpression = ''; if ($DB->type == 'MYSQL') { $lockStatusExpression = "if(DATE_LOCK is null, 'green', if(DATE_ADD(DATE_LOCK, interval " . $maxLock . " MINUTE)<now(), 'green', if(LOCKED_BY=" . $userID . ", 'yellow', 'red')))"; } elseif ($DB->type == 'MSSQL') { $lockStatusExpression = "case when DATE_LOCK is null then 'green' else case when dateadd(minute, " . $maxLock . ", DATE_LOCK)<getdate() then 'green' else case when LOCKED_BY=" . $userID . " then 'yellow' else 'red' end end end"; } elseif ($DB->type == 'ORACLE') { $lockStatusExpression = "DECODE(DATE_LOCK, NULL, 'green', DECODE(SIGN(1440*(SYSDATE-DATE_LOCK)-" . $maxLock . "), 1, 'green', decode(LOCKED_BY," . $userID . ",'yellow','red')))"; } return array(new Main\Entity\IntegerField('ID', array('autocomplete' => true, 'primary' => true)), new Main\Entity\StringField('LID'), new Main\Entity\StringField('ACCOUNT_NUMBER', array('size' => 100)), new Main\Entity\StringField('TRACKING_NUMBER'), new Main\Entity\IntegerField('PAY_SYSTEM_ID'), new Main\Entity\IntegerField('DELIVERY_ID'), new Main\Entity\DatetimeField('DATE_INSERT'), new Main\Entity\ExpressionField('DATE_INSERT_FORMAT', static::replaceDateTime(), array('DATE_INSERT')), new Main\Entity\DatetimeField('DATE_UPDATE'), new Main\Entity\ExpressionField('DATE_UPDATE_SHORT', $DB->datetimeToDateFunction('%s'), array('DATE_UPDATE')), new Main\Entity\ExpressionField('PRODUCTS_QUANT', '(SELECT SUM(b_sale_basket.QUANTITY) FROM b_sale_basket WHERE b_sale_basket.ORDER_ID = %s)', array('ID')), new Main\Entity\StringField('PERSON_TYPE_ID'), new Main\Entity\IntegerField('USER_ID', array('required' => true)), new Main\Entity\ReferenceField('USER', '\\Bitrix\\Main\\User', array('=this.USER_ID' => 'ref.ID'), array('join_type' => 'INNER')), new Main\Entity\BooleanField('PAYED', array('values' => array('N', 'Y'), 'default_value' => 'N')), new Main\Entity\DatetimeField('DATE_PAYED'), new Main\Entity\IntegerField('EMP_PAYED_ID'), new Main\Entity\BooleanField('DEDUCTED', array('values' => array('N', 'Y'), 'default_value' => 'N')), new Main\Entity\DatetimeField('DATE_DEDUCTED'), new Main\Entity\IntegerField('EMP_DEDUCTED_ID'), new Main\Entity\StringField('REASON_UNDO_DEDUCTED'), new Main\Entity\StringField('STATUS_ID'), new Main\Entity\ReferenceField('STATUS', 'Bitrix\\Sale\\Internals\\StatusLang', array('=this.STATUS_ID' => 'ref.STATUS_ID', '=ref.LID' => array('?', LANGUAGE_ID))), new Main\Entity\DatetimeField('DATE_STATUS'), new Main\Entity\ExpressionField('DATE_STATUS_SHORT', $DB->datetimeToDateFunction('%s'), array('DATE_STATUS')), new Main\Entity\IntegerField('EMP_STATUS_ID'), new Main\Entity\ReferenceField('EMP_STATUS_BY', 'Bitrix\\Main\\User', array('=this.EMP_STATUS_ID' => 'ref.ID')), new Main\Entity\BooleanField('MARKED', array('values' => array('N', 'Y'), 'default_value' => 'N')), new Main\Entity\DatetimeField('DATE_MARKED'), new Main\Entity\IntegerField('EMP_MARKED_ID'), new Main\Entity\ReferenceField('EMP_MARKED_BY', 'Bitrix\\Main\\User', array('=this.EMP_MARKED_ID' => 'ref.ID')), new Main\Entity\StringField('REASON_MARKED'), new Main\Entity\FloatField('PRICE_DELIVERY'), new Main\Entity\BooleanField('ALLOW_DELIVERY', array('values' => array('N', 'Y'), 'default_value' => 'N')), new Main\Entity\DatetimeField('DATE_ALLOW_DELIVERY'), new Main\Entity\IntegerField('EMP_ALLOW_DELIVERY_ID'), new Main\Entity\FloatField('PRICE_PAYMENT'), new Main\Entity\BooleanField('RESERVED', array('values' => array('N', 'Y'), 'default_value' => 'N')), new Main\Entity\FloatField('PRICE', array('required' => true)), new Main\Entity\StringField('CURRENCY', array('required' => true, 'size' => 3)), new Main\Entity\FloatField('DISCOUNT_VALUE', array('default_value' => '0.0000')), new Main\Entity\ExpressionField('DISCOUNT_ALL', "%s + (SELECT SUM(b_sale_basket.DISCOUNT_PRICE)\n\t\t\t\t\t\tFROM b_sale_basket\n\t\t\t\t\t\tWHERE b_sale_basket.ORDER_ID = %s)", array('DISCOUNT_VALUE', 'ID')), new Main\Entity\FloatField('TAX_VALUE'), new Main\Entity\FloatField('SUM_PAID'), new Main\Entity\ExpressionField('SUM_PAID_FORREP', 'CASE WHEN %s = \'Y\' THEN %s ELSE %s END', array('PAYED', 'PRICE', 'SUM_PAID')), new Main\Entity\StringField('USER_DESCRIPTION', array('size' => 2000)), new Main\Entity\StringField('PAY_VOUCHER_NUM', array('size' => 20)), new Main\Entity\DateField('PAY_VOUCHER_DATE'), new Main\Entity\StringField('ADDITIONAL_INFO'), new Main\Entity\StringField('COMMENTS'), new Main\Entity\IntegerField('CREATED_BY'), new Main\Entity\ReferenceField('CREATED_USER', 'Bitrix\\Main\\User', array('=this.CREATED_BY' => 'ref.ID')), new Main\Entity\IntegerField('RESPONSIBLE_ID'), new Main\Entity\ReferenceField('RESPONSIBLE_BY', 'Bitrix\\Main\\User', array('=this.RESPONSIBLE_ID' => 'ref.ID')), new Main\Entity\StringField('STAT_GID'), new Main\Entity\DatetimeField('DATE_PAY_BEFORE'), new Main\Entity\DatetimeField('DATE_BILL'), new Main\Entity\IntegerField('RECURRING_ID'), new Main\Entity\IntegerField('LOCKED_BY'), new Main\Entity\ReferenceField('LOCK_USER', 'Bitrix\\Main\\User', array('=this.LOCKED_BY' => 'ref.ID')), new Main\Entity\DatetimeField('DATE_LOCK'), new Main\Entity\ExpressionField('LOCK_USER_NAME', $helper->getConcatFunction("'('", "%s", "') '", "%s", "' '", "%s"), array('LOCK_USER.LOGIN', 'LOCK_USER.NAME', 'LOCK_USER.LAST_NAME')), new Main\Entity\ExpressionField('LOCK_STATUS', $lockStatusExpression), new Main\Entity\ReferenceField('USER_GROUP', 'Bitrix\\Main\\UserGroup', array('=ref.USER_ID' => 'this.USER_ID')), new Main\Entity\ReferenceField('RESPONSIBLE', 'Bitrix\\Main\\User', array('=this.RESPONSIBLE_ID' => 'ref.ID')), new Main\Entity\ReferenceField('BASKET', 'Bitrix\\Sale\\Internals\\Basket', array('=this.ID' => 'ref.ORDER_ID'), array('join_type' => 'INNER')), new Main\Entity\ExpressionField('BASKET_PRICE_TOTAL', '(%s * %s)', array('BASKET.PRICE', 'BASKET.QUANTITY')), new Main\Entity\ReferenceField('PAYMENT', 'Bitrix\\Sale\\Internals\\Payment', array('=ref.ORDER_ID' => 'this.ID')), new Main\Entity\ReferenceField('SHIPMENT', 'Bitrix\\Sale\\Internals\\Shipment', array('=ref.ORDER_ID' => 'this.ID')), new Main\Entity\ReferenceField('PROPERTY', 'Bitrix\\Sale\\Internals\\OrderPropsValue', array('=ref.ORDER_ID' => 'this.ID'), array('join_type' => 'INNER')), new Main\Entity\BooleanField('RECOUNT_FLAG', array('values' => array('N', 'Y'))), new Main\Entity\IntegerField('AFFILIATE_ID'), new Main\Entity\StringField('DELIVERY_DOC_NUM', array('size' => 20)), new Main\Entity\DatetimeField('DELIVERY_DOC_DATE'), new Main\Entity\BooleanField('UPDATED_1C', array('values' => array('N', 'Y'))), new Main\Entity\StringField('ORDER_TOPIC'), new Main\Entity\StringField('XML_ID'), new Main\Entity\StringField('ID_1C'), new Main\Entity\StringField('VERSION_1C'), new Main\Entity\IntegerField('VERSION'), new Main\Entity\BooleanField('EXTERNAL_ORDER', array('values' => array('N', 'Y'))), new Main\Entity\IntegerField('STORE_ID'), new Main\Entity\BooleanField('CANCELED', array('values' => array('N', 'Y'), 'default_value' => 'N')), new Main\Entity\IntegerField('EMP_CANCELED_ID'), new Main\Entity\ReferenceField('EMP_CANCELED_BY', 'Bitrix\\Main\\User', array('=this.EMP_CANCELED_ID' => 'ref.ID')), new Main\Entity\DatetimeField('DATE_CANCELED'), new Main\Entity\ExpressionField('DATE_CANCELED_SHORT', $DB->datetimeToDateFunction('%s'), array('DATE_CANCELED')), new Main\Entity\StringField('REASON_CANCELED'), new Main\Entity\StringField('BX_USER_ID'), new Main\Entity\ReferenceField('ORDER_COUPONS', 'Bitrix\\Sale\\Internals\\OrderCoupons', array('=ref.ORDER_ID' => 'this.ID'), array('join_type' => 'LEFT')), new Main\Entity\ReferenceField('ORDER_DISCOUNT_DATA', 'Bitrix\\Sale\\Internals\\OrderDiscountData', array('=ref.ORDER_ID' => 'this.ID', '=ref.ENTITY_TYPE' => new Main\DB\SqlExpression('?', OrderDiscountDataTable::ENTITY_TYPE_ORDER)), array('join_type' => 'LEFT')), new Main\Entity\ExpressionField('BY_RECOMMENDATION', "(SELECT (CASE WHEN MAX(BR.RECOMMENDATION) IS NULL OR MAX(BR.RECOMMENDATION) = '' THEN 'N' ELSE 'Y' END) FROM b_sale_basket BR WHERE BR.ORDER_ID=%s GROUP BY BR.ORDER_ID)", array('ID'))); }
public static function Setmyzyavki($json) { $json1 = json_decode($json); global $USER; //Получаем объект подключения к БД $db = Application::getConnection(); //Начинаем транзакцию $db->startTransaction(); $arValue = array('UF_OPISANIE' => $json1->UF_OPISANIE, 'UF_NAME' => $json1->UF_NAME, 'UF_USER_ID' => $USER->GetID()); $result = MyzyavkiTable::add($arValue); if (!$result->isSuccess()) { $db->rollbackTransaction(); return mymanag::otvet('false', 'Повторите еще'); } if ($result->isSuccess()) { $db->commitTransaction(); return mymanag::otvet('true', 'Ваша заявку успешно принята'); } }