update
This commit is contained in:
@@ -4,44 +4,57 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Library\VK\Service;
|
||||
|
||||
use App\Library\VK\Entity\VkPost;
|
||||
use App\Library\VK\Mapper\PostMapper;
|
||||
use App\Library\VK\Resources\GroupResource;
|
||||
use App\Library\VK\Resources\WallResource;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Generator;
|
||||
|
||||
class VkPostImportService
|
||||
{
|
||||
public function __construct(
|
||||
private WallResource $resource,
|
||||
private PostMapper $mapper
|
||||
private WallResource $wall,
|
||||
private GroupResource $group,
|
||||
private PostMapper $mapper
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
//$result = $this->resource->get('ledstarband', 1, 100);
|
||||
$group = $this->getGroupInfo('ledstarband');
|
||||
$posts = $this->getWallPosts('ledstarband', 10);
|
||||
|
||||
foreach($posts as $item) {
|
||||
$post = $this->mapper->map($item);
|
||||
$post->setSourceName($group['name']);
|
||||
|
||||
if(! $post->isEmpty()) {
|
||||
print_r($post->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** @return Generator<int, array> */
|
||||
private function getWallPosts(string $id, int $count = 5): Generator
|
||||
{
|
||||
$result = $this->wall->get($id, $count);
|
||||
|
||||
if (empty ($result['items']) ) {
|
||||
Log::info('Post import failed: no items found');
|
||||
}
|
||||
|
||||
# echo "\nFound items: ".$result['count']."\n";
|
||||
// foreach ($result['items'] as $item) {
|
||||
// $post = $this->mapper->map($item);
|
||||
// if(! $post->isEmpty()) {
|
||||
// # print_r($post->toArray());
|
||||
// }
|
||||
// }
|
||||
|
||||
$res = $this->resource->getById('-93243530_2113');
|
||||
foreach ($res as $item) {
|
||||
$post = $this->mapper->map($item);
|
||||
if(! $post->isEmpty()) {
|
||||
print_r($post->toArray());
|
||||
}
|
||||
foreach ($result['items'] as $item) {
|
||||
yield $item;
|
||||
}
|
||||
}
|
||||
|
||||
# print_r($res);
|
||||
|
||||
private function getGroupInfo(string $groupId): ?array
|
||||
{
|
||||
$res = $this->group->getById($groupId);
|
||||
return $res[0] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user