-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathCodeTrekService.php
149 lines (132 loc) · 5.7 KB
/
CodeTrekService.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace Modules\CodeTrek\Services;
use Modules\CodeTrek\Entities\CodeTrekApplicant;
use Modules\CodeTrek\Entities\CodeTrekApplicantRoundDetail;
use Modules\CodeTrek\Entities\CodeTrekCandidateFeedback;
class CodeTrekService
{
public function getCodeTrekApplicants($data = [])
{
$search = $data['name'] ?? null;
$status = $data['status'] ?? 'active';
$centre = $data['centre'] ?? null;
$sort = $data['order'] ?? null;
$roundSlug = $data['roundSlug'] ?? null;
$query = CodeTrekApplicant::where('status', $status);
$applicants = null;
if ($centre) {
$applicants = $query->where('centre_id', $centre);
}
if ($roundSlug) {
$query->where('latest_round_name', $roundSlug);
}
if ($sort == 'date') {
$applicants = $query->orderBy('start_date', 'desc');
} else {
$applicants = $query->orderBy('first_name');
}
$applicants = $query->when($search, function ($query) use ($search) {
return $query->whereRaw("CONCAT(first_name, ' ', last_name) LIKE '%{$search}%'");
})
->paginate(config('constants.pagination_size'))
->appends(request()->except('page'));
$applicantCountData = CodeTrekApplicant::whereIn('status', ['active', 'inactive', 'completed'])
->with('mentor')
->when($search, function ($applicantCountData) use ($search) {
return $applicantCountData->whereRaw("CONCAT(first_name, ' ', last_name) LIKE '%{$search}%'");
})
->when($roundSlug, function ($query) use ($roundSlug) {
return $query->where('latest_round_name', $roundSlug);
})
->groupBy('status')
->selectRaw('count(status) as total, status');
if ($centre) {
$applicantCountData = $applicantCountData->where('centre_id', $centre)->get();
} else {
$applicantCountData = $applicantCountData->get();
}
$statusCounts = [
'active' => 0,
'inactive' => 0,
'completed' => 0,
];
foreach ($applicantCountData as $data) {
$statusCounts[$data->status] = $data->total;
}
return [
'applicants' => $applicants,
'statusCounts' => $statusCounts,
];
}
public function store($data)
{
$applicant = new CodeTrekApplicant();
$applicant->first_name = $data['first_name'];
$applicant->last_name = $data['last_name'];
$applicant->email = $data['email_id'];
$applicant->phone = $data['phone'] ?? null;
$applicant->github_user_name = $data['github_username'];
$applicant->course = $data['course'] ?? null;
$applicant->start_date = $data['start_date'];
$applicant->graduation_year = $data['graduation_year'] ?? null;
$applicant->university = $data['university_name'] ?? null;
$applicant->mentor_id = $data['mentorId'];
$applicant->domain_name = $data['domain'];
$applicant->latest_round_name = config('codetrek.rounds.introductory-call.slug');
// Mail::queue(new CodetrekMailApplicant($data)); This line will be uncommented in the future when the use of the codeTrek module starts in the proper way.
$applicant->save();
$this->moveApplicantToIntroductoryRound($applicant, $data);
return $applicant;
}
public function edit($codeTrekApplicant)
{
return CodeTrekApplicant::find($codeTrekApplicant->id);
}
public function update($data, $codeTrekApplicant)
{
$applicant = CodeTrekApplicant::findOrFail($codeTrekApplicant->id);
$applicant->first_name = $data['first_name'];
$applicant->last_name = $data['last_name'];
$applicant->email = $data['email_id'];
$applicant->phone = $data['phone'] ?? null;
$applicant->github_user_name = $data['github_username'];
$applicant->course = $data['course'] ?? null;
$applicant->start_date = $data['start_date'];
$applicant->graduation_year = $data['graduation_year'] ?? null;
$applicant->university = $data['university_name'] ?? null;
$applicant->centre_id = $data['centre'] ?? null;
$applicant->mentor_id = $data['mentorId'] ?? null;
$applicant->domain_name = $data['domain'];
$applicant->save();
return $applicant;
}
public function evaluate(CodeTrekApplicant $codeTrekApplicant)
{
return CodeTrekApplicantRoundDetail::where('applicant_id', $codeTrekApplicant->id)->get();
}
public function moveApplicantToIntroductoryRound($applicant, $data)
{
$applicationRound = new CodeTrekApplicantRoundDetail();
$applicationRound->applicant_id = $applicant->id;
$applicationRound->latest_round_name = config('codetrek.rounds.introductory-call.slug');
$applicationRound->feedback = null;
$applicationRound->start_date = $data['start_date'];
$applicationRound->save();
}
public function storeCodeTrekApplicantFeedback($data)
{
$feedback = new CodeTrekCandidateFeedback();
$feedback->category_id = $data['feedback_category'];
$feedback->feedback = $data['feedback'];
$feedback->feedback_type = $data['feedback_type'];
$feedback->latest_round_name = $data['latest_round_name'];
$feedback->candidate_id = $data['candidate_id'];
$feedback->posted_by = auth()->user()->id;
$feedback->posted_on = today();
$feedback->save();
}
public function getCodeTrekApplicantFeedbacks($applicantId)
{
return CodeTrekCandidateFeedback::where('candidate_id', $applicantId)->get();
}
}