mirror of
https://github.com/openvk/openvk
synced 2024-12-23 09:01:15 +03:00
VKAPI: Add attachments support for Wall methods
TODO Refactor: Перенести вывод в отдельную функцию, чтоб не дублировать код
This commit is contained in:
parent
6f2bed678d
commit
1472801874
3 changed files with 75 additions and 0 deletions
|
@ -22,6 +22,32 @@ final class Wall extends VKAPIRequestHandler
|
||||||
|
|
||||||
foreach ($posts->getPostsFromUsersWall((int)$owner_id, 1, $count, $offset) as $post) {
|
foreach ($posts->getPostsFromUsersWall((int)$owner_id, 1, $count, $offset) as $post) {
|
||||||
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
||||||
|
|
||||||
|
$attachments;
|
||||||
|
foreach($post->getChildren() as $attachment)
|
||||||
|
{
|
||||||
|
if($attachment instanceof \openvk\Web\Models\Entities\Photo)
|
||||||
|
{
|
||||||
|
$attachments[] = [
|
||||||
|
"type" => "photo",
|
||||||
|
"photo" => [
|
||||||
|
"album_id" => $attachment->getAlbum()->getId(),
|
||||||
|
"date" => $attachment->getPublicationTime()->timestamp(),
|
||||||
|
"id" => $attachment->getVirtualId(),
|
||||||
|
"owner_id" => $attachment->getOwner()->getId(),
|
||||||
|
"sizes" => array([
|
||||||
|
"height" => $attachment->getDimentions()[1],
|
||||||
|
"url" => $attachment->getURL(),
|
||||||
|
"type" => "m",
|
||||||
|
"width" => $attachment->getDimentions()[0],
|
||||||
|
]),
|
||||||
|
"text" => "",
|
||||||
|
"has_tags" => false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$items[] = (object)[
|
$items[] = (object)[
|
||||||
"id" => $post->getVirtualId(),
|
"id" => $post->getVirtualId(),
|
||||||
"from_id" => $from_id,
|
"from_id" => $from_id,
|
||||||
|
@ -35,6 +61,7 @@ final class Wall extends VKAPIRequestHandler
|
||||||
"can_archive" => false, // TODO MAYBE
|
"can_archive" => false, // TODO MAYBE
|
||||||
"is_archived" => false,
|
"is_archived" => false,
|
||||||
"is_pinned" => $post->isPinned(),
|
"is_pinned" => $post->isPinned(),
|
||||||
|
"attachments" => $attachments,
|
||||||
"post_source" => (object)["type" => "vk"],
|
"post_source" => (object)["type" => "vk"],
|
||||||
"comments" => (object)[
|
"comments" => (object)[
|
||||||
"count" => $post->getCommentsCount(),
|
"count" => $post->getCommentsCount(),
|
||||||
|
@ -127,6 +154,31 @@ final class Wall extends VKAPIRequestHandler
|
||||||
$post = (new PostsRepo)->getPostById(intval($id[0]), intval($id[1]));
|
$post = (new PostsRepo)->getPostById(intval($id[0]), intval($id[1]));
|
||||||
if($post) {
|
if($post) {
|
||||||
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
$from_id = get_class($post->getOwner()) == "openvk\Web\Models\Entities\Club" ? $post->getOwner()->getId() * (-1) : $post->getOwner()->getId();
|
||||||
|
$attachments;
|
||||||
|
foreach($post->getChildren() as $attachment)
|
||||||
|
{
|
||||||
|
if($attachment instanceof \openvk\Web\Models\Entities\Photo)
|
||||||
|
{
|
||||||
|
$attachments[] = [
|
||||||
|
"type" => "photo",
|
||||||
|
"photo" => [
|
||||||
|
"album_id" => $attachment->getAlbum()->getId(),
|
||||||
|
"date" => $attachment->getPublicationTime()->timestamp(),
|
||||||
|
"id" => $attachment->getVirtualId(),
|
||||||
|
"owner_id" => $attachment->getOwner()->getId(),
|
||||||
|
"sizes" => array([
|
||||||
|
"height" => $attachment->getDimentions()[1],
|
||||||
|
"url" => $attachment->getURL(),
|
||||||
|
"type" => "m",
|
||||||
|
"width" => $attachment->getDimentions()[0],
|
||||||
|
]),
|
||||||
|
"text" => "",
|
||||||
|
"has_tags" => false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$items[] = (object)[
|
$items[] = (object)[
|
||||||
"id" => $post->getVirtualId(),
|
"id" => $post->getVirtualId(),
|
||||||
"from_id" => $from_id,
|
"from_id" => $from_id,
|
||||||
|
@ -141,6 +193,7 @@ final class Wall extends VKAPIRequestHandler
|
||||||
"is_archived" => false,
|
"is_archived" => false,
|
||||||
"is_pinned" => $post->isPinned(),
|
"is_pinned" => $post->isPinned(),
|
||||||
"post_source" => (object)["type" => "vk"],
|
"post_source" => (object)["type" => "vk"],
|
||||||
|
"attachments" => $attachments,
|
||||||
"comments" => (object)[
|
"comments" => (object)[
|
||||||
"count" => $post->getCommentsCount(),
|
"count" => $post->getCommentsCount(),
|
||||||
"can_post" => 1
|
"can_post" => 1
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Models\Entities;
|
namespace openvk\Web\Models\Entities;
|
||||||
|
use openvk\Web\Models\Entities\Album;
|
||||||
|
use openvk\Web\Models\Repositories\Albums;
|
||||||
use Chandler\Database\DatabaseConnection as DB;
|
use Chandler\Database\DatabaseConnection as DB;
|
||||||
use Nette\InvalidStateException as ISE;
|
use Nette\InvalidStateException as ISE;
|
||||||
use Nette\Utils\Image;
|
use Nette\Utils\Image;
|
||||||
|
@ -59,4 +61,16 @@ class Photo extends Media
|
||||||
|
|
||||||
return $photo;
|
return $photo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDimentions()
|
||||||
|
{
|
||||||
|
$hash = $this->getRecord()->hash;
|
||||||
|
|
||||||
|
return getimagesize($this->pathFromHash($hash));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAlbum(): ?Album
|
||||||
|
{
|
||||||
|
return (new Albums)->getAlbumByPhotoId($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php declare(strict_types=1);
|
<?php declare(strict_types=1);
|
||||||
namespace openvk\Web\Models\Repositories;
|
namespace openvk\Web\Models\Repositories;
|
||||||
use openvk\Web\Models\Entities\Album;
|
use openvk\Web\Models\Entities\Album;
|
||||||
|
use openvk\Web\Models\Entities\Photo;
|
||||||
use openvk\Web\Models\Entities\Club;
|
use openvk\Web\Models\Entities\Club;
|
||||||
use openvk\Web\Models\Entities\User;
|
use openvk\Web\Models\Entities\User;
|
||||||
use Nette\Database\Table\ActiveRow;
|
use Nette\Database\Table\ActiveRow;
|
||||||
|
@ -115,4 +116,11 @@ class Albums
|
||||||
|
|
||||||
return new Album($album);
|
return new Album($album);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAlbumByPhotoId(Photo $photo): ?Album
|
||||||
|
{
|
||||||
|
$dbalbum = DatabaseConnection::i()->getContext()->table("album_relations")->where(["media" => $photo->getId()])->fetch();
|
||||||
|
|
||||||
|
return $this->get($dbalbum->collection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue