Issues (17)

app/Events/TimeLogSaved.php (1 issue)

Severity
1
<?php
2
3
namespace App\Events;
4
5
use App\TimeLog;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Foundation\Events\Dispatchable;
8
use App\Notifications\ProjectIsAtFiftyPercentTime;
9
use App\Notifications\ProjectIsAtEightyPercentTime;
10
use App\Notifications\ProjectIsAtOneHundredPercentTime;
11
12
class TimeLogSaved
13
{
14
    use Dispatchable, SerializesModels;
0 ignored issues
show
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Events\TimeLogSaved: $id, $class, $connection, $relations
Loading history...
15
16
    public $timelog;
17
18
    /**
19
     * Create a new event instance.
20
     *
21
     * @return void
22
     */
23
    public function __construct(TimeLog $timelog)
24
    {
25
        $project = $timelog->project;
26
27
        // @todo only notify each user once, save spamming
28
        if ($project->percentage_taken >= 100) {
29
            $project->user->notify(new ProjectIsAtOneHundredPercentTime($project->user, $project));
30
        } elseif ($project->percentage_taken >= 80) {
31
            $project->user->notify(new ProjectIsAtEightyPercentTime($project->user, $project));
32
        } elseif ($project->percentage_taken >= 50) {
33
            $project->user->notify(new ProjectIsAtFiftyPercentTime($project->user, $project));
34
        }
35
    }
36
}
37