Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Работа с вебформами для внешних сервисов (1с и т.п.)
- *
- * 1. этап: получение данных и отдача json. Статус: завершен.
- */
- class ApiWebForms
- {
- public function __construct($data)
- {
- $args = [
- 'type' => FILTER_SANITIZE_STRING,
- 'form_id' => FILTER_VALIDATE_INT,
- 'limit' => FILTER_VALIDATE_INT,
- 'from' => FILTER_SANITIZE_STRING,
- 'to' => FILTER_SANITIZE_STRING,
- 'id' => FILTER_VALIDATE_INT,
- 'debug' => FILTER_VALIDATE_INT,
- ];
- $_POST = $data;
- $this->inputs = filter_input_array(INPUT_POST, $args);
- self::typeRequest();
- }
- private function typeRequest()
- {
- $type = $this->inputs['type'];
- switch ($type) {
- case 'get':
- $result = self::getForm();
- echo $result;
- break;
- // case 'set':
- // break;
- default:
- break;
- }
- }
- /**
- * Получение данных вебформ
- *
- * @return json
- */
- private function getForm()
- {
- $from = $this->inputs['from'] ? ['TIMESTAMP_1' => $this->inputs['from']] : [];
- $to = $this->inputs['to'] ? ['TIMESTAMP_2' => $this->inputs['to']] : [];
- $id = $this->inputs['id'] ? ['ID' => $this->inputs['id']] : [];
- $arFilter = array_merge($from, $to, $id);
- $limit = $this->inputs['limit'] ?? 1;
- // d($arFilter);die;
- $rsResults = CFormResult::GetList(
- $this->inputs['form_id'],
- ($by = 's_timestamp'),
- ($order = 'desc'),
- $arFilter,
- $is_filtered,
- 'N',
- $limit
- );
- while ($ar = $rsResults->Fetch()) {
- $arAnswer = CFormResult::GetDataByID(
- $ar['ID'],
- [],
- $arResult,
- $arAnswer2
- );
- $arAnswer['FORM_DATA'] = $arResult;
- // $attach = ['FILE', 'SIMPLE_FILE', 'SIMPLE_FILE_2'];
- // если прикрепили изображение
- if ($arAnswer['FILE']) {
- foreach ($arAnswer['FILE'] as $k => $v) {
- $file_url = CFile::GetPath($v['USER_FILE_ID']);
- $arAnswer['FILE'][$k]['URL'] = $file_url;
- }
- }
- if ($arResult['USER_AUTH'] == 'Y' && $arResult['USER_ID']) {
- $filter = ['ID' => $arResult['USER_ID']];
- $rsUser = CUser::GetList(
- ($by = 'date_register'),
- ($order = 'desc'),
- $filter,
- ['SELECT' => ['UF_*']]
- );
- $arUser = $rsUser->Fetch();
- unset($arUser['PASSWORD'],$arUser['CHECKWORD']);
- $arAnswer['USER_DATA'] = $arUser;
- // получаем профили покупателя по ID юзера
- $profile = Bitrix\Sale\Helpers\Admin\Blocks\OrderBuyer::getBuyerProfilesList($arUser['ID']);
- $profile_ids = array_keys($profile);
- $profile_ids = array_filter($profile_ids);
- foreach ($profile_ids as $_profile_id) {
- $inn_with_code1c = [];
- $db_propVals = CSaleOrderUserPropsValue::GetList(
- [],
- ['USER_PROPS_ID' => $_profile_id],
- false,
- false,
- ['NAME', 'PROP_CODE', 'VALUE']
- );
- while ($arPropVals = $db_propVals->Fetch()) {
- if ($arPropVals['PROP_CODE'] == 'INN') {
- $inn_with_code1c['INN'] = $arPropVals['VALUE'];
- }
- if ($arPropVals['PROP_CODE'] == 'CODE_1C') {
- $inn_with_code1c['CODE'] = $arPropVals['VALUE'];
- }
- }
- $arAnswer['INN_WITH_CODE1C'][] = $inn_with_code1c;
- }
- }
- $result[] = $arAnswer;
- }
- if ($this->inputs['debug'] == 1) {
- d($this->inputs, $result);
- } else {
- $json = json_encode($result, JSON_UNESCAPED_UNICODE);
- return $json;
- }
- }
- /**
- * Создание записи в вебформе
- */
- private function setForm()
- {
- }
- /**
- * Обновление записи в вебформе
- */
- private function updateForm()
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement