mirror of
https://github.com/openvk/openvk
synced 2025-07-07 08:19:49 +03:00
Some fixes
Строки локализации у gifts.send теперь не костыльные и можно прикрепить до 10 аттачей к посту
This commit is contained in:
parent
545eb5e1d4
commit
da0c363524
4 changed files with 174 additions and 203 deletions
|
@ -6,7 +6,7 @@ use openvk\Web\Models\Entities\Notifications\GiftNotification;
|
||||||
|
|
||||||
final class Gifts extends VKAPIRequestHandler
|
final class Gifts extends VKAPIRequestHandler
|
||||||
{
|
{
|
||||||
function get(int $user_id, int $count = 100, int $offset = 0)
|
function get(int $user_id, int $count = 10, int $offset = 0)
|
||||||
{
|
{
|
||||||
$this->requireUser();
|
$this->requireUser();
|
||||||
|
|
||||||
|
@ -54,10 +54,17 @@ final class Gifts extends VKAPIRequestHandler
|
||||||
$this->willExecuteWriteAction();
|
$this->willExecuteWriteAction();
|
||||||
|
|
||||||
$user = (new UsersRepo)->get((int) $user_ids);
|
$user = (new UsersRepo)->get((int) $user_ids);
|
||||||
|
if(OPENVK_ROOT_CONF['openvk']['preferences']['commerce'] == false)
|
||||||
|
$this->fail(105, "Commerce is disabled on this instance");
|
||||||
|
|
||||||
if(!$user || $user->isDeleted())
|
if(!$user || $user->isDeleted())
|
||||||
$this->fail(177, "Invalid user");
|
$this->fail(177, "Invalid user");
|
||||||
|
|
||||||
$gift = (new GiftsRepo)->get($gift_id);
|
$gift = (new GiftsRepo)->get($gift_id);
|
||||||
|
|
||||||
|
if(!$gift)
|
||||||
|
$this->fail(165, "Invalid gift");
|
||||||
|
|
||||||
$price = $gift->getPrice();
|
$price = $gift->getPrice();
|
||||||
$coinsLeft = $this->getUser()->getCoins() - $price;
|
$coinsLeft = $this->getUser()->getCoins() - $price;
|
||||||
|
|
||||||
|
@ -103,128 +110,53 @@ final class Gifts extends VKAPIRequestHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
# этих методов не было в ВК, но я их добавил чтобы можно было отобразить список подарков
|
# этих методов не было в ВК, но я их добавил чтобы можно было отобразить список подарков
|
||||||
function getCategories(bool $extended = false, int $count = 10, int $offset = 0)
|
function getCategories(bool $extended = false, int $page = 1)
|
||||||
{
|
{
|
||||||
$cats = (new GiftsRepo)->getCategories(1, $count);
|
$cats = (new GiftsRepo)->getCategories($page);
|
||||||
$categ = [];
|
$categ = [];
|
||||||
$i = 1;
|
$i = 0;
|
||||||
|
|
||||||
foreach($cats as $cat) {
|
foreach($cats as $cat) {
|
||||||
if($i > $count)
|
$categ[$i] = [
|
||||||
break;
|
"name" => $cat->getName(),
|
||||||
if($i > $offset) {
|
"description" => $cat->getDescription(),
|
||||||
$categ[] = [
|
"id" => $cat->getId(),
|
||||||
"name" => $cat->getName(),
|
"thumbnail" => $cat->getThumbnailURL(),
|
||||||
"description" => $cat->getDescription(),
|
];
|
||||||
"id" => $cat->getId(),
|
if($extended == true) {
|
||||||
"thumbnail" => $cat->getThumbnailURL(),
|
$categ[$i]["localizations"] = [];
|
||||||
"localizations" => $extended == true ?
|
foreach(getLanguages() as $lang) {
|
||||||
|
$code = $lang["code"];
|
||||||
|
$categ[$i]["localizations"][$code] =
|
||||||
[
|
[
|
||||||
"en" => [
|
"name" => $cat->getName($code),
|
||||||
"name" => $cat->getName("en"),
|
"desc" => $cat->getDescription($code),
|
||||||
"desc" => $cat->getDescription("en"),
|
];
|
||||||
],
|
}
|
||||||
"ru" => [
|
|
||||||
"name" => $cat->getName("ru"),
|
|
||||||
"desc" => $cat->getDescription("ru"),
|
|
||||||
],
|
|
||||||
"uk" => [
|
|
||||||
"name" => $cat->getName("uk"),
|
|
||||||
"desc" => $cat->getDescription("uk")
|
|
||||||
],
|
|
||||||
"by" => [
|
|
||||||
"name" => $cat->getName("by"),
|
|
||||||
"desc" => $cat->getDescription("by")
|
|
||||||
],
|
|
||||||
"by_lat" => [
|
|
||||||
"name" => $cat->getName("by_lat"),
|
|
||||||
"desc" => $cat->getDescription("by_lat")
|
|
||||||
],
|
|
||||||
"pl" => [
|
|
||||||
"name" => $cat->getName("pl"),
|
|
||||||
"desc" => $cat->getDescription("pl")
|
|
||||||
],
|
|
||||||
"de" => [
|
|
||||||
"name" => $cat->getName("de"),
|
|
||||||
"desc" => $cat->getDescription("de")
|
|
||||||
],
|
|
||||||
"hy" => [
|
|
||||||
"name" => $cat->getName("hy"),
|
|
||||||
"desc" => $cat->getDescription("hy")
|
|
||||||
],
|
|
||||||
"sr_cyr" => [
|
|
||||||
"name" => $cat->getName("sr_cyr"),
|
|
||||||
"desc" => $cat->getDescription("sr_cyr")
|
|
||||||
],
|
|
||||||
"sr_lat" => [
|
|
||||||
"name" => $cat->getName("sr_lat"),
|
|
||||||
"desc" => $cat->getDescription("sr_lat")
|
|
||||||
],
|
|
||||||
"tr" => [
|
|
||||||
"name" => $cat->getName("tr"),
|
|
||||||
"desc" => $cat->getDescription("tr")
|
|
||||||
],
|
|
||||||
"kk" => [
|
|
||||||
"name" => $cat->getName("kk"),
|
|
||||||
"desc" => $cat->getDescription("kk")
|
|
||||||
],
|
|
||||||
"ru_old" => [
|
|
||||||
"name" => $cat->getName("ru_old"),
|
|
||||||
"desc" => $cat->getDescription("ru_old")
|
|
||||||
],
|
|
||||||
"eo" => [
|
|
||||||
"name" => $cat->getName("eo"),
|
|
||||||
"desc" => $cat->getDescription("eo")
|
|
||||||
],
|
|
||||||
"ru_sov" => [
|
|
||||||
"name" => $cat->getName("ru_sov"),
|
|
||||||
"desc" => $cat->getDescription("ru_sov")
|
|
||||||
],
|
|
||||||
"udm" => [
|
|
||||||
"name" => $cat->getName("udm"),
|
|
||||||
"desc" => $cat->getDescription("udm")
|
|
||||||
],
|
|
||||||
"id" => [
|
|
||||||
"name" => $cat->getName("id"),
|
|
||||||
"desc" => $cat->getDescription("id")
|
|
||||||
],
|
|
||||||
"qqx" => [
|
|
||||||
"name" => $cat->getName("qqx"),
|
|
||||||
"desc" => $cat->getDescription("qqx")
|
|
||||||
],
|
|
||||||
] : NULL];
|
|
||||||
} else {
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $categ;
|
return $categ;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGiftsInCategory(int $id, int $count = 10, int $offset = 0)
|
function getGiftsInCategory(int $id, int $page = 1)
|
||||||
{
|
{
|
||||||
$this->requireUser();
|
$this->requireUser();
|
||||||
if(!(new GiftsRepo)->getCat($id))
|
if(!(new GiftsRepo)->getCat($id))
|
||||||
$this->fail(177, "Category not found");
|
$this->fail(177, "Category not found");
|
||||||
|
|
||||||
$giftz = ((new GiftsRepo)->getCat($id))->getGifts(1, $count);
|
$giftz = ((new GiftsRepo)->getCat($id))->getGifts($page);
|
||||||
$gifts = [];
|
$gifts = [];
|
||||||
$i = 1;
|
|
||||||
|
|
||||||
foreach($giftz as $gift) {
|
foreach($giftz as $gift) {
|
||||||
if($i > $count)
|
$gifts[] = [
|
||||||
break;
|
"name" => $gift->getName(),
|
||||||
if($i > $offset) {
|
"image" => $gift->getImage(2),
|
||||||
$gifts[] = [
|
"usages_left" => (int)$gift->getUsagesLeft($this->getUser()),
|
||||||
"name" => $gift->getName(),
|
"price" => $gift->getPrice(), # голосов
|
||||||
"image" => $gift->getImage(2),
|
"is_free" => $gift->isFree()
|
||||||
"usages_left" => (int)$gift->getUsagesLeft($this->getUser()),
|
];
|
||||||
"price" => $gift->getPrice(), # голосов
|
|
||||||
"is_free" => $gift->isFree()
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $gifts;
|
return $gifts;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
namespace openvk\VKAPI\Handlers;
|
namespace openvk\VKAPI\Handlers;
|
||||||
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
||||||
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
||||||
use openvk\Web\Models\Entities\{Club};
|
use openvk\Web\Models\Entities\Club;
|
||||||
|
|
||||||
final class Groups extends VKAPIRequestHandler
|
final class Groups extends VKAPIRequestHandler
|
||||||
{
|
{
|
||||||
|
@ -292,51 +292,16 @@ final class Groups extends VKAPIRequestHandler
|
||||||
int $topics = NULL,
|
int $topics = NULL,
|
||||||
int $adminlist = NULL,
|
int $adminlist = NULL,
|
||||||
int $topicsAboveVall = NULL,
|
int $topicsAboveVall = NULL,
|
||||||
int $hideFromGlobalFeed = NULL,
|
int $hideFromGlobalFeed = NULL)
|
||||||
# дальше для совместимости с вк
|
|
||||||
int $subject = NULL,
|
|
||||||
int $access = NULL,
|
|
||||||
string $email = NULL,
|
|
||||||
string $phone = NULL,
|
|
||||||
string $rss = NULL,
|
|
||||||
int $event_start_date = NULL,
|
|
||||||
int $event_finish_date = NULL,
|
|
||||||
int $event_group_id = NULL,
|
|
||||||
int $public_category = NULL,
|
|
||||||
int $public_subcategory = NULL,
|
|
||||||
int $public_date = NULL,
|
|
||||||
int $photos = NULL,
|
|
||||||
int $video = NULL,
|
|
||||||
bool $links = NULL,
|
|
||||||
bool $events = NULL,
|
|
||||||
bool $places = NULL,
|
|
||||||
bool $contacts = NULL,
|
|
||||||
bool $wiki = NULL,
|
|
||||||
bool $messages = NULL,
|
|
||||||
bool $articles = NULL,
|
|
||||||
bool $addresses = NULL,
|
|
||||||
bool $age_limits = NULL,
|
|
||||||
bool $market = NULL,
|
|
||||||
bool $obscene_filter = NULL,
|
|
||||||
bool $obscene_stopwords = NULL,
|
|
||||||
string $obscene_words = NULL,
|
|
||||||
int $main_section = NULL,
|
|
||||||
int $secondary_section = NULL,
|
|
||||||
int $country = NULL,
|
|
||||||
int $city = NULL
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
$this->requireUser();
|
$this->requireUser();
|
||||||
$this->willExecuteWriteAction();
|
$this->willExecuteWriteAction();
|
||||||
|
|
||||||
$club = (new ClubsRepo)->get($group_id);
|
$club = (new ClubsRepo)->get($group_id);
|
||||||
|
|
||||||
if(!$club)
|
if(!$club) $this->fail(203, "Club not found");
|
||||||
$this->fail(203, "Club not found");
|
if(!$club || !$club->canBeModifiedBy($this->getUser())) $this->fail(15, "You can't modify this group.");
|
||||||
if(!$club || !$club->canBeModifiedBy($this->getUser()))
|
if(!empty($screen_name) && !$club->setShortcode($screen_name)) $this->fail(103, "Invalid shortcode.");
|
||||||
$this->fail(15, "You can't modify this group.");
|
|
||||||
if(!is_null($screen_name) && !$club->setShortcode($screen_name))
|
|
||||||
$this->fail(103, "Invalid shortcode.");
|
|
||||||
|
|
||||||
!is_null($title) ? $club->setName($title) : NULL;
|
!is_null($title) ? $club->setName($title) : NULL;
|
||||||
!is_null($description) ? $club->setAbout($description) : NULL;
|
!is_null($description) ? $club->setAbout($description) : NULL;
|
||||||
|
@ -382,8 +347,7 @@ final class Groups extends VKAPIRequestHandler
|
||||||
$filds = explode(",", $fields);
|
$filds = explode(",", $fields);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach($members as $member)
|
foreach($members as $member) {
|
||||||
{
|
|
||||||
if($i > $count) {
|
if($i > $count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -394,35 +358,95 @@ final class Groups extends VKAPIRequestHandler
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach($filds as $fild) {
|
foreach($filds as $fild) {
|
||||||
$fild == "bdate" ? $arr->items[$i]->bdate = $member->getBirthday()->format('%e.%m.%Y') : NULL;
|
switch($fild) {
|
||||||
$fild == "can_post" ? $arr->items[$i]->can_post = $club->canBeModifiedBy($member) : NULL;
|
case "bdate":
|
||||||
$fild == "can_see_all_posts" ? $arr->items[$i]->can_see_all_posts = 1 : NULL;
|
$arr->items[$i]->bdate = $member->getBirthday()->format('%e.%m.%Y');
|
||||||
$fild == "can_see_audio" ? $arr->items[$i]->can_see_audio = 0 : NULL; # lul
|
break;
|
||||||
$fild == "can_write_private_message" ? $arr->items[$i]->can_write_private_message = 0 : NULL;
|
case "can_post":
|
||||||
$fild == "common_count" ? $arr->items[$i]->common_count = 420 : NULL; # я хэзэ чё ето
|
$arr->items[$i]->can_post = $club->canBeModifiedBy($member);
|
||||||
$fild == "connections" ? $arr->items[$i]->connections = 1 : NULL;
|
break;
|
||||||
$fild == "contacts" ? $arr->items[$i]->contacts = $member->getContactEmail() : NULL;
|
case "can_see_all_posts":
|
||||||
$fild == "country" ? $arr->items[$i]->country = 1 : NULL;
|
$arr->items[$i]->can_see_all_posts = 1;
|
||||||
$fild == "domain" ? $arr->items[$i]->domain = "" : NULL;
|
break;
|
||||||
$fild == "education" ? $arr->items[$i]->education = "" : NULL;
|
case "can_see_audio":
|
||||||
$fild == "has_mobile" ? $arr->items[$i]->has_mobile = false : NULL;
|
$arr->items[$i]->can_see_audio = 0;
|
||||||
$fild == "last_seen" ? $arr->items[$i]->last_seen = $member->getOnline()->timestamp() : NULL;
|
break;
|
||||||
$fild == "lists" ? $arr->items[$i]->lists = "" : NULL;
|
case "can_write_private_message":
|
||||||
$fild == "online" ? $arr->items[$i]->online = $member->isOnline() : NULL;
|
$arr->items[$i]->can_write_private_message = 0;
|
||||||
$fild == "online_mobile" ? $arr->items[$i]->online_mobile = $member->getOnlinePlatform() == "android" || $member->getOnlinePlatform() == "iphone" || $member->getOnlinePlatform() == "mobile" : NULL;
|
break;
|
||||||
$fild == "photo_100" ? $arr->items[$i]->photo_100 = $member->getAvatarURL("tiny") : NULL;
|
case "common_count":
|
||||||
$fild == "photo_200" ? $arr->items[$i]->photo_200 = $member->getAvatarURL("normal") : NULL;
|
$arr->items[$i]->common_count = 420;
|
||||||
$fild == "photo_200_orig" ? $arr->items[$i]->photo_200_orig = $member->getAvatarURL("normal") : NULL;
|
break;
|
||||||
$fild == "photo_400_orig" ? $arr->items[$i]->photo_400_orig = $member->getAvatarURL("normal") : NULL;
|
case "connections":
|
||||||
$fild == "photo_max" ? $arr->items[$i]->photo_max = $member->getAvatarURL("original") : NULL;
|
$arr->items[$i]->connections = 1;
|
||||||
$fild == "photo_max_orig" ? $arr->items[$i]->photo_max_orig = $member->getAvatarURL() : NULL;
|
break;
|
||||||
$fild == "relation" ? $arr->items[$i]->relation = $member->getMaritalStatus() : NULL;
|
case "contacts":
|
||||||
$fild == "relatives" ? $arr->items[$i]->relatives = 0 : NULL;
|
$arr->items[$i]->contacts = $member->getContactEmail();
|
||||||
$fild == "schools" ? $arr->items[$i]->schools = 0 : NULL;
|
break;
|
||||||
$fild == "sex" ? $arr->items[$i]->sex = $member->isFemale() ? 1 : 2 : NULL;
|
case "country":
|
||||||
$fild == "site" ? $arr->items[$i]->site = $member->getWebsite() : NULL;
|
$arr->items[$i]->country = 1;
|
||||||
$fild == "status" ? $arr->items[$i]->status = $member->getStatus() : NULL;
|
break;
|
||||||
$fild == "universities" ? $arr->items[$i]->universities = 0 : NULL;
|
case "domain":
|
||||||
|
$arr->items[$i]->domain = "";
|
||||||
|
break;
|
||||||
|
case "education":
|
||||||
|
$arr->items[$i]->education = "";
|
||||||
|
break;
|
||||||
|
case "has_mobile":
|
||||||
|
$arr->items[$i]->has_mobile = false;
|
||||||
|
break;
|
||||||
|
case "last_seen":
|
||||||
|
$arr->items[$i]->last_seen = $member->getOnline()->timestamp();
|
||||||
|
break;
|
||||||
|
case "lists":
|
||||||
|
$arr->items[$i]->lists = "";
|
||||||
|
break;
|
||||||
|
case "online":
|
||||||
|
$arr->items[$i]->online = $member->isOnline();
|
||||||
|
break;
|
||||||
|
case "online_mobile":
|
||||||
|
$arr->items[$i]->online_mobile = $member->getOnlinePlatform() == "android" || $member->getOnlinePlatform() == "iphone" || $member->getOnlinePlatform() == "mobile";
|
||||||
|
break;
|
||||||
|
case "photo_100":
|
||||||
|
$arr->items[$i]->photo_100 = $member->getAvatarURL("tiny");
|
||||||
|
break;
|
||||||
|
case "photo_200":
|
||||||
|
$arr->items[$i]->photo_200 = $member->getAvatarURL("normal");
|
||||||
|
break;
|
||||||
|
case "photo_200_orig":
|
||||||
|
$arr->items[$i]->photo_200_orig = $member->getAvatarURL("normal");
|
||||||
|
break;
|
||||||
|
case "photo_400_orig":
|
||||||
|
$arr->items[$i]->photo_400_orig = $member->getAvatarURL("normal");
|
||||||
|
break;
|
||||||
|
case "photo_max":
|
||||||
|
$arr->items[$i]->photo_max = $member->getAvatarURL("original");
|
||||||
|
break;
|
||||||
|
case "photo_max_orig":
|
||||||
|
$arr->items[$i]->photo_max_orig = $member->getAvatarURL();
|
||||||
|
break;
|
||||||
|
case "relation":
|
||||||
|
$arr->items[$i]->relation = $member->getMaritalStatus();
|
||||||
|
break;
|
||||||
|
case "relatives":
|
||||||
|
$arr->items[$i]->relatives = 0;
|
||||||
|
break;
|
||||||
|
case "schools":
|
||||||
|
$arr->items[$i]->schools = 0;
|
||||||
|
break;
|
||||||
|
case "sex":
|
||||||
|
$arr->items[$i]->sex = $member->isFemale() ? 1 : 2;
|
||||||
|
break;
|
||||||
|
case "site":
|
||||||
|
$arr->items[$i]->site = $member->getWebsite();
|
||||||
|
break;
|
||||||
|
case "status":
|
||||||
|
$arr->items[$i]->status = $member->getStatus();
|
||||||
|
break;
|
||||||
|
case "universities":
|
||||||
|
$arr->items[$i]->universities = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -409,7 +409,7 @@ final class Wall extends VKAPIRequestHandler
|
||||||
if($signed == 1)
|
if($signed == 1)
|
||||||
$flags |= 0b01000000;
|
$flags |= 0b01000000;
|
||||||
|
|
||||||
if(empty($message) && !$photo && !$video)
|
if(empty($message) && empty($attachments))
|
||||||
$this->fail(100, "Required parameter 'message' missing.");
|
$this->fail(100, "Required parameter 'message' missing.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -426,32 +426,47 @@ final class Wall extends VKAPIRequestHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($attachments)) {
|
if(!empty($attachments)) {
|
||||||
$att = explode(" ", $attachments);
|
$attachmentsArr = explode(",", $attachments);
|
||||||
$attachmentType = $att[0];
|
# Аттачи такого вида: [тип][id владельца]_[id вложения]
|
||||||
# Аттачи такого вида: [тип] [id владельца]_[id вложения]
|
# Пример: photo1_1
|
||||||
# Пример: photo 1_1
|
|
||||||
|
|
||||||
$attachmentOwner = (int)explode("_", $att[1])[0];
|
if(count($attachmentsArr) > 10)
|
||||||
$attachmentId = (int)end(explode("_", $att[1]));
|
$this->fail(50, "Error: too many attachments");
|
||||||
|
|
||||||
|
foreach($attachmentsArr as $attac) {
|
||||||
|
$attachmentType = NULL;
|
||||||
|
|
||||||
$attacc = NULL;
|
if(str_contains($attac, "photo"))
|
||||||
|
$attachmentType = "photo";
|
||||||
|
elseif(str_contains($attac, "video"))
|
||||||
|
$attachmentType = "video";
|
||||||
|
else
|
||||||
|
$this->fail(205, "Unknown attachment type");
|
||||||
|
|
||||||
if($attachmentType == "photo") {
|
$attachment = str_replace($attachmentType, "", $attac);
|
||||||
$attacc = (new PhotosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId);
|
|
||||||
if(is_null($attacc))
|
|
||||||
$this->fail(100, "Photo does not exists");
|
|
||||||
if($attacc->getOwner()->getId() != $this->getUser()->getId())
|
|
||||||
$this->fail(43, "You do not have access to this photo");
|
|
||||||
|
|
||||||
$post->attach($attacc);
|
|
||||||
} elseif($attachmentType == "video") {
|
|
||||||
$attacc = (new VideosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId);
|
|
||||||
if(!$attacc)
|
|
||||||
$this->fail(100, "Video does not exists");
|
|
||||||
if($attacc->getOwner()->getId() != $this->getUser()->getId())
|
|
||||||
$this->fail(43, "You do not have access to this video");
|
|
||||||
|
|
||||||
$post->attach($attacc);
|
$attachmentOwner = (int)explode("_", $attachment)[0];
|
||||||
|
$attachmentId = (int)end(explode("_", $attachment));
|
||||||
|
|
||||||
|
$attacc = NULL;
|
||||||
|
|
||||||
|
if($attachmentType == "photo") {
|
||||||
|
$attacc = (new PhotosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId);
|
||||||
|
if(is_null($attacc))
|
||||||
|
$this->fail(100, "Photo does not exists");
|
||||||
|
if($attacc->getOwner()->getId() != $this->getUser()->getId())
|
||||||
|
$this->fail(43, "You do not have access to this photo");
|
||||||
|
|
||||||
|
$post->attach($attacc);
|
||||||
|
} elseif($attachmentType == "video") {
|
||||||
|
$attacc = (new VideosRepo)->getByOwnerAndVID($attachmentOwner, $attachmentId);
|
||||||
|
if(!$attacc)
|
||||||
|
$this->fail(100, "Video does not exists");
|
||||||
|
if($attacc->getOwner()->getId() != $this->getUser()->getId())
|
||||||
|
$this->fail(43, "You do not have access to this video");
|
||||||
|
|
||||||
|
$post->attach($attacc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -262,12 +262,12 @@ class Club extends RowModel
|
||||||
return $subbed && ($this->getOpennesStatus() === static::CLOSED ? $this->isSubscriptionAccepted($user) : true);
|
return $subbed && ($this->getOpennesStatus() === static::CLOSED ? $this->isSubscriptionAccepted($user) : true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFollowersQuery(): GroupedSelection
|
function getFollowersQuery(string $sort = "follower ASC"): GroupedSelection
|
||||||
{
|
{
|
||||||
$query = $this->getRecord()->related("subscriptions.target");
|
$query = $this->getRecord()->related("subscriptions.target");
|
||||||
|
|
||||||
if($this->getOpennesStatus() === static::OPEN) {
|
if($this->getOpennesStatus() === static::OPEN) {
|
||||||
$query = $query->where("model", "openvk\\Web\\Models\\Entities\\Club");
|
$query = $query->where("model", "openvk\\Web\\Models\\Entities\\Club")->order($sort);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -280,9 +280,9 @@ class Club extends RowModel
|
||||||
return sizeof($this->getFollowersQuery());
|
return sizeof($this->getFollowersQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFollowers(int $page = 1): \Traversable
|
function getFollowers(int $page = 1, int $perPage = 6, string $sort = "follower ASC"): \Traversable
|
||||||
{
|
{
|
||||||
$rels = $this->getFollowersQuery()->page($page, 6);
|
$rels = $this->getFollowersQuery($sort)->page($page, $perPage);
|
||||||
|
|
||||||
foreach($rels as $rel) {
|
foreach($rels as $rel) {
|
||||||
$rel = (new Users)->get($rel->follower);
|
$rel = (new Users)->get($rel->follower);
|
||||||
|
|
Loading…
Reference in a new issue