the browser-facing portion of osu!
at master 1.4 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Models\Forum; 7 8use App\Models\User; 9use App\Traits\Validatable; 10 11/** 12 * @property PollOption $pollOption 13 * @property int $poll_option_id 14 * @property int $topic_id 15 * @property User $user 16 * @property int $vote_user_id 17 * @property string $vote_user_ip 18 */ 19class PollVote extends Model 20{ 21 use Validatable; 22 23 protected $table = 'phpbb_poll_votes'; 24 public $timestamps = false; 25 26 public function pollOption() 27 { 28 return $this 29 ->belongsTo(PollOption::class, 'poll_option_id', 'poll_option_id') 30 ->where('topic_id', $this->topic_id); 31 } 32 33 public function user() 34 { 35 return $this->belongsTo(User::class, 'vote_user_id'); 36 } 37 38 public function validationErrorsTranslationPrefix(): string 39 { 40 return 'forum.poll_vote'; 41 } 42 43 public function isValid() 44 { 45 $this->validationErrors()->reset(); 46 47 if ($this->pollOption === null) { 48 $this->validationErrors()->add('poll_option_id', '.invalid'); 49 } 50 51 return $this->validationErrors()->isEmpty(); 52 } 53 54 public function save(array $options = []) 55 { 56 return $this->isValid() && parent::save($options); 57 } 58}