91 public static function addResultToData($data = array(), $result = array(), $referenceKey)
93 if (empty($result) || !isset($referenceKey))
98 foreach ($result as $item)
100 if (isset($data[$item[$referenceKey]]))
102 $data[$item[$referenceKey]] += $item;
120 if (!isset($mainKey))
124 foreach ($data as $item)
126 $result[$item[$mainKey]] = $item;
129 $result[$item[$mainKey]][$keyRename] = $result[$item[$mainKey]][$mainKey];
130 unset($result[$item[$mainKey]][$mainKey]);
156 $photoSaveResults = array();
159 case 'PRODUCT_MAIN_PHOTO':
160 $uploadServerMethod =
'photos.getMarketUploadServer';
161 $saveMethod =
'photos.saveMarketPhoto';
162 $keyReference =
'BX_ID';
163 $keyPhotoVk =
'PHOTO_MAIN_VK_ID';
164 $keyPhotoBx =
'PHOTO_MAIN_BX_ID';
167 case 'PRODUCT_PHOTOS':
168 $uploadServerMethod =
'photos.getMarketUploadServer';
169 $saveMethod =
'photos.saveMarketPhoto';
170 $keyReference =
'PHOTO_BX_ID';
171 $keyPhotoVk =
'PHOTO_VK_ID';
172 $keyPhotoBx =
'PHOTO_BX_ID';
176 $uploadServerMethod =
'photos.getMarketAlbumUploadServer';
177 $saveMethod =
'photos.saveMarketAlbumPhoto';
178 $keyReference =
'SECTION_ID';
179 $keyPhotoVk =
'PHOTO_VK_ID';
180 $keyPhotoBx =
'PHOTO_BX_ID';
189 foreach ($data as $item)
192 if (!array_key_exists($keyPhotoBx, $item) || empty($item[$keyPhotoBx]))
196 $getServerParams = array(
"group_id" => str_replace(
"-",
"", $vkGroupId));
197 if ($uploadType ==
'PRODUCT_MAIN_PHOTO')
198 $getServerParams += self::setUploadServerMainPhotoParams($item[$keyPhotoBx]);
200 $uploadServer = $this->api->run($uploadServerMethod, $getServerParams);
202 $this->logger->addLog(
"Get photo upload server", [
203 'PARAMS' => $getServerParams,
204 'RESULT' => $uploadServer,
206 $uploadServer = $uploadServer[
"upload_url"];
210 $this->logger->addLog(
"Upload photo HTTP before", array(
211 "UPLOAD_TYPE" => $uploadType,
212 "ITEM" => array_key_exists(
"BX_ID", $item) ?
213 $item[
"BX_ID"].
': '.$item[
"NAME"] :
214 $item[
"SECTION_ID"].
': '.$item[
"TITLE"],
215 "PHOTO_BX_ID" => array_key_exists(
"PHOTO_MAIN_BX_ID", $item) ? $item[
"PHOTO_MAIN_BX_ID"] : $item[
"PHOTO_BX_ID"],
216 "PHOTO_URL" => array_key_exists(
"PHOTO_MAIN_URL", $item) ? $item[
"PHOTO_MAIN_URL"] : $item[
"PHOTO_URL"],
217 "PHOTOS" => $item[
"PHOTOS"]
219 $responseHttp = $this->uploadPhotoHttp($item, $uploadServer, $uploadType, $timer);
222 $photoSaveParams = array(
223 "group_id" => str_replace(
'-',
'', $vkGroupId),
224 "photo" => $responseHttp[
"photo"],
225 "server" => $responseHttp[
"server"],
226 "hash" => $responseHttp[
"hash"],
230 if ($saveMethod ==
"photos.saveMarketPhoto")
232 if (isset($responseHttp[
"crop_hash"]) && $responseHttp[
"crop_hash"])
233 $photoSaveParams[
"crop_hash"] = $responseHttp[
"crop_hash"];
234 if (isset($responseHttp[
"crop_data"]) && $responseHttp[
"crop_data"])
235 $photoSaveParams[
"crop_data"] = $responseHttp[
"crop_data"];
238 $responsePhotoSave = $this->api->run($saveMethod, $photoSaveParams);
241 $photoSaveResults[] = array(
242 $keyReference => $item[$keyReference],
243 $keyPhotoVk => $responsePhotoSave[0][
"id"],
249 return $photoSaveResults;