diff --git a/Web/Models/Entities/Poll.php b/Web/Models/Entities/Poll.php index 6f2885b1..b88ce1a8 100644 --- a/Web/Models/Entities/Poll.php +++ b/Web/Models/Entities/Poll.php @@ -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; + } + } }