private function _createAlbumPhoto(array $albums, array $albumThumbs) { $photoData = []; $data = []; foreach ($albums as $key => $album) { sleep(1); $data = $this->_vkObject->api('photos.get', 'GET', ['owner_id' => '-' . self::VK_GROUP_ID, 'album_id' => $album['album_id'], 'rev' => 0, 'extended' => 0]); if (isset($data, $data['response'], $data['response'][0])) { $photoData = []; $this->_setLog(['mess' => 'find (' . count($data['response']) . ') photo in album: ' . $album['title'] . '_' . $album['description']]); foreach ($data['response'] as $response) { $pname = $album['title'] . '_' . $album['description'] . '_' . $response['text']; $pname = 'krasotka_me_' . self::_get_in_translate_to_en($pname) . '_' . $response['pid']; $pname = preg_replace('/(\\.|\\/|<.*>| )/', '_', $pname); $mainPhoto = 0; if ($albumThumbs[$key] == $response['pid']) { $mainPhoto = 1; } $photoData[] = ['album_id' => $response['aid'], 'photo_id' => $response['pid'], 'vk_photo' => isset($response['src_xbig']) ? $response['src_xbig'] : $response['src_big'], 'photo_name' => $pname . '.jpg', 'text' => $response['text'], 'vk_created' => (int) $response['created'], 'main_photo' => $mainPhoto, 'created_at' => time(), 'updated_at' => time()]; } if ($photoData && $photoData[0]) { $isInsert = Yii::$app->db->createCommand()->batchInsert(Photos::tableName(), array_keys($photoData[0]), $photoData)->execute(); if ($isInsert) { foreach ($photoData as $p_data) { $path = Yii::getAlias('@fullMediaDir/' . $p_data['album_id'] . '/' . $p_data['photo_name']); if (!is_dir(dirname($path))) { mkdir(dirname($path), 0777, true); } $image = file_get_contents($p_data['vk_photo']); file_put_contents($path, $image); } $this->_setLog(['mess' => 'save in path: ' . $path]); } } $this->_setLog(['mess' => 'Left (' . (count($albums) - ($key + 1)) . ')']); } } }