|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelRealtimeChat\Repositories\Team; |
|
4
|
|
|
use App\Events\JoinNotificationEvenHandler; |
|
|
|
|
|
|
5
|
|
|
class DbTeamRepository implements TeamRepository { |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @param int $id channel_name_id |
|
9
|
|
|
* @return Arr returns array of teams aligned to user or admin |
|
|
|
|
|
|
10
|
|
|
*/ |
|
11
|
|
|
public function getTeams($id) {// |
|
12
|
|
View Code Duplication |
if (\Session::get("role") == 1) { |
|
|
|
|
|
|
13
|
|
|
$teams = \DB::table('channels') |
|
14
|
|
|
->select('team_channels.id', 'channels.channel_name', 'team_channels.channel_view_name', 'channels.author_id', "team_channels.created_at", 'team_channels.team_channel_id','team_heads.user_id') |
|
15
|
|
|
->leftJoin('team_channels', 'channels.id', '=', 'team_channels.channel_name_id') |
|
16
|
|
|
->leftJoin('team_heads', 'team_heads.team_id', '=', 'team_channels.id') |
|
17
|
|
|
->where('team_channels.id', '!=', '') |
|
18
|
|
|
->where('channels.id', '=', $id)->distinct()->get(); |
|
19
|
|
|
} |
|
20
|
|
|
else { |
|
21
|
|
|
$teams = \DB::table('team_channels') |
|
22
|
|
|
->select('team_channels.channel_view_name', 'team_channels.team_channel_id', 'team_channels.id', 'team_channels.created_at','team_heads.user_id') |
|
23
|
|
|
->leftJoin('team_channel_users', 'team_channel_users.team_channel_name_id', '=', 'team_channels.id') |
|
24
|
|
|
->leftJoin('team_heads', 'team_heads.team_id', '=', 'team_channels.id') |
|
25
|
|
|
->where('team_channel_users.user_id', '=', \Auth::user()->id)->distinct()->get(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
return $teams; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param int $id team_id |
|
33
|
|
|
* @return Arr returns array of members aligned to a team |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getMembers($id) { |
|
36
|
|
|
$teamId = $id; |
|
37
|
|
|
$teamArr = array(); |
|
38
|
|
|
$teamMembers = \DB::table('users') |
|
39
|
|
|
->select('users.first_name', 'users.id', 'users.last_name') |
|
40
|
|
|
->leftJoin('team_channel_users', 'team_channel_users.user_id', '=', 'users.id') |
|
41
|
|
|
->where('team_channel_users.team_channel_name_id', '=', $teamId)->get(); |
|
42
|
|
|
foreach ($teamMembers as $memeber) { |
|
43
|
|
|
$teamArr[] = $memeber["first_name"] . "_" . $memeber["last_name"] . "_" . $memeber["id"]; |
|
44
|
|
|
} |
|
45
|
|
|
return $teamArr; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getTeamDecodedId($id) { |
|
49
|
|
|
$team = \DB::table('team_channels') |
|
50
|
|
|
->select('id') |
|
51
|
|
|
->where('team_channel_id', '=', $id)->first(); |
|
52
|
|
|
return $team['id']; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getTeamName($id) { |
|
56
|
|
|
$team = \DB::table('team_channels') |
|
57
|
|
|
->select('team_channels.channel_view_name',\DB::raw('CONCAT(users.first_name, " ", users.last_name) AS full_name')) |
|
58
|
|
|
->leftJoin('team_heads', 'team_heads.team_id', '=', 'team_channels.id') |
|
59
|
|
|
->leftJoin('users', 'users.id', '=', 'team_heads.user_id') |
|
60
|
|
|
->where('team_channels.id', '=', $id)->first(); |
|
61
|
|
|
return $team['channel_view_name']."_".$team['full_name']; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function updateTeamName($id) { |
|
65
|
|
|
$name = \Input::get('name'); |
|
|
|
|
|
|
66
|
|
|
if(empty($name)) |
|
67
|
|
|
return "empty"; |
|
68
|
|
|
try { |
|
69
|
|
|
//validate for duplicates |
|
70
|
|
|
$data = \DB::table('team_channels') |
|
71
|
|
|
->select('team_channels.channel_view_name') |
|
72
|
|
|
->where('channel_view_name', '=', $name)->first(); |
|
73
|
|
|
if (count($data) == 0) { |
|
74
|
|
|
//perform update |
|
75
|
|
|
\DB::table('team_channels') |
|
76
|
|
|
->where('id', $id) |
|
77
|
|
|
->update(['channel_view_name' => $name]); |
|
78
|
|
|
} else |
|
79
|
|
|
return "exists"; |
|
80
|
|
|
} catch (\Exception $e) { |
|
81
|
|
|
//coudnt update |
|
82
|
|
|
return "false"; |
|
83
|
|
|
} |
|
84
|
|
|
return "true"; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function updateTeamHead($id) { |
|
88
|
|
|
$userId = \Input::get('userId'); |
|
89
|
|
|
if (empty($userId)) |
|
90
|
|
|
return "empty"; |
|
91
|
|
|
try { |
|
92
|
|
|
|
|
93
|
|
|
//perform update |
|
94
|
|
|
\DB::table('team_heads') |
|
95
|
|
|
->where('team_id', $id) |
|
96
|
|
|
->update(['user_id' => $userId]); |
|
97
|
|
|
} catch (\Exception $e) { |
|
98
|
|
|
//coudnt update |
|
99
|
|
|
return "false"; |
|
100
|
|
|
} |
|
101
|
|
|
return "true"; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function updateNewMemberJoinNotification($team_id,$user_id){ |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* |
|
108
|
|
|
* Get all team details where the user is a memeber |
|
109
|
|
|
* |
|
110
|
|
|
* |
|
111
|
|
|
* |
|
112
|
|
|
*/ |
|
113
|
|
|
$teamArr = array(); |
|
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
$details= $this->getUserDetails($user_id); |
|
116
|
|
|
|
|
117
|
|
|
$teamMembers =\DB::table('users') |
|
118
|
|
|
->select('users.first_name','users.last_name', 'users.id','team_channels.channel_view_name','team_channels.team_channel_id','team_channels.id as team_id_decoded') |
|
119
|
|
|
->leftJoin('team_channel_users', 'team_channel_users.user_id', '=', 'users.id') |
|
120
|
|
|
->leftJoin('team_channels', 'team_channel_users.team_channel_name_id', '=', 'team_channels.id') |
|
121
|
|
|
->where('team_channel_users.team_channel_name_id', '=', $team_id)->get(); |
|
122
|
|
|
|
|
123
|
|
|
foreach ($teamMembers as $memeber) { |
|
124
|
|
|
//insert notification |
|
125
|
|
|
$lastId = \DB::table('invitation_notification')->insertGetId( |
|
|
|
|
|
|
126
|
|
|
['team_id' => $team_id, "team_user" => $memeber["id"],'new_user'=>$user_id] |
|
127
|
|
|
); |
|
128
|
|
|
//Publish data to redis |
|
129
|
|
|
$channelId = $memeber["id"] . "_" . $memeber["team_channel_id"]; |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
$teamChannelId = $memeber["team_channel_id"]; |
|
132
|
|
|
|
|
133
|
|
|
$data = array( |
|
134
|
|
|
'room' =>$memeber["id"] . "_" . $memeber["team_channel_id"], |
|
135
|
|
|
'message' => array('new_user_id'=>$user_id,'new_user_channel_id' => $user_id."_".$teamChannelId,'user_id' =>$memeber["id"] ,'name'=>$details['first_name']." ".$details['last_name'],'team_name'=>$memeber['channel_view_name'],'team_id'=>$memeber['team_id_decoded']) |
|
136
|
|
|
); |
|
137
|
|
|
// print_r($data); |
|
138
|
|
|
\Event::fire(\JoinNotificationEventHandler::EVENT, array(json_encode($data))); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
public function getUserDetails($user_id){ |
|
146
|
|
|
$details =\DB::table('users') |
|
147
|
|
|
->select('users.first_name','users.last_name') |
|
148
|
|
|
->where('id', '=', $user_id) |
|
149
|
|
|
->first(); |
|
150
|
|
|
return $details; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths