Passed
Push — master ( b831b6...96f132 )
by John
06:04 queued 21s
created

Dojo::getPassedAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Models\Eloquent\Dojo;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Dojo extends Model
9
{
10
    use SoftDeletes;
11
12
    public function phase()
13
    {
14
        return $this->belongsTo('App\Models\Eloquent\Dojo\DojoPhase', 'dojo_phase_id');
15
    }
16
17
    public function problems()
18
    {
19
        return $this->hasMany('App\Models\Eloquent\Dojo\DojoProblem', 'dojo_id');
20
    }
21
22
    public function passes()
23
    {
24
        return $this->hasMany('App\Models\Eloquent\Dojo\DojoPass', 'dojo_id');
25
    }
26
27
    public function canPass()
28
    {
29
        $tot=0;
30
        foreach($this->problems->sortBy('order') as $problem){
31
            $problem=$problem->problem;
32
            $tot+=$problem->problem_status['color']=='wemd-green-text';
33
        }
34
        return $tot>=$this->passline;
0 ignored issues
show
Bug introduced by
The property passline does not seem to exist on App\Models\Eloquent\Dojo\Dojo. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
35
    }
36
37
    public function getPassedAttribute()
38
    {
39
        return DojoPass::isPassed($this->id);
40
    }
41
42
    public function getAvailabilityAttribute()
43
    {
44
        foreach(explode(',', $this->precondition) as $dojo_id){
0 ignored issues
show
Bug introduced by
The property precondition does not seem to exist on App\Models\Eloquent\Dojo\Dojo. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
45
            if(blank($dojo_id)) continue;
46
            if(!DojoPass::isPassed($dojo_id)) return 'locked';
47
        }
48
        return $this->passed?'passed':'available';
49
    }
50
51
}
52