-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCloneLtiToolSetting.php
78 lines (69 loc) · 2.3 KB
/
CloneLtiToolSetting.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace App\Jobs;
use App\Models\LtiTool\LtiToolSetting;
use App\Models\Organization;
use App\Notifications\CloneNotification;
use App\Repositories\LtiTool\LtiToolSettingInterface;
use App\Repositories\User\UserRepositoryInterface;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class CloneLtiToolSetting implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @var LtiToolSetting
*/
protected $ltiToolSetting;
/**
* @var SubOrganization
*/
protected $subOrganization;
/**
* @var token
*/
protected $token;
/**
* @var userId
*/
protected $userId;
/**
* Create a new job instance.
* @param LtiToolSetting $ltiToolSetting
* @param Organization $suborganization
* @param $userId
* @param $token
* @return void
*/
public function __construct(LtiToolSetting $ltiToolSetting, Organization $suborganization, $userId, $token)
{
//
$this->ltiToolSetting = $ltiToolSetting;
$this->subOrganization = $suborganization;
$this->userId = $userId;
$this->token = $token;
}
/**
* Execute the job.
* @param LtiToolSettingInterface $ltiToolSettingRepository
* @param UserRepositoryInterface $userRepository
* @return void
*/
public function handle(LtiToolSettingInterface $ltiToolSettingRepository, UserRepositoryInterface $userRepository)
{
try {
$ltiToolSettingRepository->clone($this->ltiToolSetting, $this->subOrganization, $this->userId);
$message = "Your request to clone Lti Tool Setting [" . $this->ltiToolSetting->tool_name . "] has been completed and available";
$loggedUserId = $userRepository->parseToken($this->token);
$loggedUser = User::find($loggedUserId);
$loggedUserName = rtrim($loggedUser->first_name . ' ' . $loggedUser->last_name, ' ');
$loggedUser->notify(new CloneNotification($message, 'Clone', $loggedUserName));
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
}