mirror of
https://github.com/openvk/openvk
synced 2025-04-23 08:33:02 +03:00
Fix polls
This commit is contained in:
parent
ccf618a5ab
commit
499bec2a50
1 changed files with 16 additions and 2 deletions
|
@ -4,7 +4,7 @@ use openvk\Web\Models\Exceptions\TooMuchOptionsException;
|
|||
use openvk\Web\Util\DateTime;
|
||||
use \UnexpectedValueException;
|
||||
use Nette\InvalidStateException;
|
||||
use openvk\Web\Models\Repositories\Users;
|
||||
use openvk\Web\Models\Repositories\{Users, Posts};
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
use openvk\Web\Models\Exceptions\PollLockedException;
|
||||
use openvk\Web\Models\Exceptions\AlreadyVotedException;
|
||||
|
@ -165,7 +165,7 @@ class Poll extends Attachable
|
|||
|
||||
function canVote(User $user): bool
|
||||
{
|
||||
return !$this->hasEnded() && !$this->hasVoted($user);
|
||||
return !$this->hasEnded() && !$this->hasVoted($user) && !is_null($this->getAttachedPost()) && $this->getAttachedPost()->getSuggestionType() == 0;
|
||||
}
|
||||
|
||||
function vote(User $user, array $optionIds): void
|
||||
|
@ -292,4 +292,18 @@ class Poll extends Attachable
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
function getAttachedPost()
|
||||
{
|
||||
$post = DatabaseConnection::i()->getContext()->table("attachments")
|
||||
->where(
|
||||
["attachable_type" => static::class,
|
||||
"attachable_id" => $this->getId()])->fetch();
|
||||
|
||||
if(!is_null($post->target_id)) {
|
||||
return (new Posts)->get($post->target_id);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue