diff options
author | Camil Staps | 2016-09-05 22:30:47 +0200 |
---|---|---|
committer | Camil Staps | 2016-09-05 22:30:47 +0200 |
commit | fc5cef0efddbb1141b0a371108a23fc7f6e8d860 (patch) | |
tree | 8b3e62b50e5f856c57af477a78a51567d6e859f2 /app/Verb.php | |
parent | User creation and authentication (diff) |
Vote on verb suggestions
Diffstat (limited to 'app/Verb.php')
-rw-r--r-- | app/Verb.php | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/app/Verb.php b/app/Verb.php index 28e22ea..aa0db26 100644 --- a/app/Verb.php +++ b/app/Verb.php @@ -22,14 +22,38 @@ use Illuminate\Database\Eloquent\Model; class Verb extends Model { - protected $table = 'verbs'; - public $timestamps = false; - protected $fillable = ['verb', 'root', 'stem', 'tense', 'person', 'gender', 'number']; + protected $table = 'verbs'; + public $timestamps = false; + protected $fillable = ['verb', 'root', 'stem', 'tense', 'person', 'gender', 'number']; - public function otherParsings() - { - return self::where('verb', $this->verb)->get() - ->filter(function($v){return $v->verb === $this->verb;}); - } + const ACCEPTED_VOTE_COUNT = 1; -}
\ No newline at end of file + public function actions() { + return $this->hasMany('HebrewParseTrainer\VerbAction'); + } + + public function otherParsings() { + return self::where('verb', $this->verb)->get() + ->filter(function($v){return $v->verb === $this->verb;}); + } + + public function voteCount() { + $votes = $this->actions()->where('kind', VerbAction::KIND_VOTE)->get(); + $total = 0; + foreach ($votes as $vote) + $total += $vote->vote_weight; + return $total; + } + + public function userVote(User $user) { + $votes = $this->actions() + ->where('kind', VerbAction::KIND_VOTE) + ->where('user_id', $user->id) + ->get(); + foreach ($votes as $vote) { + return $vote->vote_weight; + } + return 0; + } + +} |