check if user accept notifications
This commit is contained in:
@@ -97,28 +97,35 @@ class EventsController extends Controller
|
||||
return $task->users;
|
||||
})->unique('id');
|
||||
|
||||
|
||||
if (Carbon::now()->lessThanOrEqualTo($event->end)) {
|
||||
$notification = Notification::create([
|
||||
'content' => "L'événement {$event->name} a été supprimé. Vous n'y participez donc plus."
|
||||
]);
|
||||
$notification->users()->attach($participants->pluck('id'));
|
||||
$webParticipants = $participants->filter(fn($user) => $user->web_notifications);
|
||||
|
||||
if ($webParticipants->isNotEmpty()) {
|
||||
$notification = Notification::create([
|
||||
'content' => "L'événement {$event->name} a été supprimé. Vous n'y participez donc plus."
|
||||
]);
|
||||
$notification->users()->attach($webParticipants->pluck('id'));
|
||||
|
||||
foreach ($webParticipants as $user) {
|
||||
broadcast(new EventParticipationCancelled(
|
||||
$user->id,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($participants as $user) {
|
||||
broadcast(new EventParticipationCancelled(
|
||||
$user->id,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'eventName' => $event->name,
|
||||
'start' => $event->start,
|
||||
'end' => $event->end,
|
||||
];
|
||||
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'eventName' => $event->name,
|
||||
'start' => $event->start,
|
||||
'end' => $event->end,
|
||||
];
|
||||
Mail::to($user->email)->send(new EventParticipationCancelledMail($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,15 +35,14 @@ class TasksController extends Controller
|
||||
$event = Event::find($request["event_id"]);
|
||||
|
||||
$event->tasks()->create([
|
||||
"name" => $request["name"],
|
||||
"description" => $request["description"],
|
||||
"start" => $request["start"],
|
||||
"end" => $request["end"],
|
||||
"location" => $request["location"],
|
||||
"max_participants" => $request["max_participants"],
|
||||
"name" => $request["name"],
|
||||
"description" => $request["description"],
|
||||
"start" => $request["start"],
|
||||
"end" => $request["end"],
|
||||
"location" => $request["location"],
|
||||
"max_participants" => $request["max_participants"],
|
||||
]);
|
||||
|
||||
|
||||
return response()->json(['message' => "Task created"], 200);
|
||||
|
||||
} catch(\Exception $e) {
|
||||
@@ -98,27 +97,31 @@ class TasksController extends Controller
|
||||
|
||||
if($user && Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||
|
||||
$notification = Notification::create([
|
||||
'content' => "Vous avez été assigné à la tâche {$task->name} de l'événement {$event->name}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
if ($user->web_notifications) {
|
||||
$notification = Notification::create([
|
||||
'content' => "Vous avez été assigné à la tâche {$task->name} de l'événement {$event->name}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
|
||||
broadcast(new VolunteerAssignedToTask(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
broadcast(new VolunteerAssignedToTask(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $task->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new VolunteerAssignToTaskMail($data));
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $task->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new VolunteerAssignToTaskMail($data));
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['message' => "Task assigned"], 200);
|
||||
@@ -141,7 +144,6 @@ class TasksController extends Controller
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteTask(Request $request, int $id): JsonResponse {
|
||||
@@ -161,29 +163,37 @@ class TasksController extends Controller
|
||||
|
||||
if (Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||
if ($participants->isNotEmpty()) {
|
||||
$notification = Notification::create([
|
||||
'content' => "La tâche {$task->name} pour l'événement {$event->name} a été supprimée. Vous n'y participez donc plus."
|
||||
]);
|
||||
$notification->users()->attach($participants->pluck('id'));
|
||||
}
|
||||
$webParticipants = $participants->filter(fn($user) => $user->web_notifications);
|
||||
|
||||
foreach ($participants as $user) {
|
||||
broadcast(new TaskParticipationCancelled(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
if ($webParticipants->isNotEmpty()) {
|
||||
$notification = Notification::create([
|
||||
'content' => "La tâche {$task->name} pour l'événement {$event->name} a été supprimée. Vous n'y participez donc plus."
|
||||
]);
|
||||
$notification->users()->attach($webParticipants->pluck('id'));
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $event->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new TaskParticipationCancelledMail($data));
|
||||
foreach ($webParticipants as $user) {
|
||||
broadcast(new TaskParticipationCancelled(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($participants as $user) {
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $event->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new TaskParticipationCancelledMail($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +216,7 @@ class TasksController extends Controller
|
||||
try {
|
||||
$task = Task::find($id);
|
||||
if((
|
||||
$task->start !== $request["start"] || $task->end !== $request["end"]
|
||||
$task->start !== $request["start"] || $task->end !== $request["end"]
|
||||
) &&
|
||||
Carbon::now()->lessThanOrEqualTo($task->end)
|
||||
){
|
||||
@@ -216,30 +226,35 @@ class TasksController extends Controller
|
||||
$event = Event::find($task->events_id);
|
||||
|
||||
foreach ($participants as $user) {
|
||||
$notification = Notification::create([
|
||||
'content' => "La date de la tâche {$task->name} de l'événement {$event->name} à été mis à jour. Cette tâche aura maintenant lieu du {$formatedTaskStart} au {$formatedTaskEnd}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
broadcast(new TaskDateUpdated(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
FormatDate::formatDate($request["start"]),
|
||||
FormatDate::formatDate($request["end"]),
|
||||
$notification->id,
|
||||
));
|
||||
if ($user->web_notifications) {
|
||||
$notification = Notification::create([
|
||||
'content' => "La date de la tâche {$task->name} de l'événement {$event->name} à été mis à jour. Cette tâche aura maintenant lieu du {$formatedTaskStart} au {$formatedTaskEnd}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'oldStart' => $formatedTaskStart,
|
||||
'oldEnd' => $formatedTaskEnd,
|
||||
'newStart' => $request["start"],
|
||||
'newEnd' => $request["end"],
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new TaskDateUpdateMail($data));
|
||||
broadcast(new TaskDateUpdated(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
FormatDate::formatDate($request["start"]),
|
||||
FormatDate::formatDate($request["end"]),
|
||||
$notification->id,
|
||||
));
|
||||
}
|
||||
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'oldStart' => $formatedTaskStart,
|
||||
'oldEnd' => $formatedTaskEnd,
|
||||
'newStart' => $request["start"],
|
||||
'newEnd' => $request["end"],
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new TaskDateUpdateMail($data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,26 +316,31 @@ class TasksController extends Controller
|
||||
$task->users()->detach($id);
|
||||
|
||||
if ($user && Carbon::now()->lessThanOrEqualTo($task->end)) {
|
||||
$notification = Notification::create([
|
||||
'content' => "Vous avez été désassigné de la tâche {$task->name} de l'événement {$event->name}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
broadcast(new VolunteerUnassignedFromTask(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
if ($user->web_notifications) {
|
||||
$notification = Notification::create([
|
||||
'content' => "Vous avez été désassigné de la tâche {$task->name} de l'événement {$event->name}."
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $task->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new VolunteerUnassignToTaskMail($data));
|
||||
broadcast(new VolunteerUnassignedFromTask(
|
||||
$user->id,
|
||||
$task,
|
||||
$event,
|
||||
$notification->id,
|
||||
));
|
||||
}
|
||||
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'taskName' => $task->name,
|
||||
'start' => $task->start,
|
||||
'end' => $task->end,
|
||||
'eventName' => $event->name,
|
||||
];
|
||||
Mail::to($user->email)->send(new VolunteerUnassignToTaskMail($data));
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['message' => "User unassigned successfully"], 200);
|
||||
|
||||
@@ -55,27 +55,29 @@ class UserController extends Controller
|
||||
"email_notifications" => 1,
|
||||
]);
|
||||
|
||||
|
||||
$notification = Notification::create([
|
||||
'content' => "Nouvelle demande d'inscription : {$user->name} {$user->lastname}"
|
||||
]);
|
||||
$admins = User::whereIn('role', [1, 2])->get();
|
||||
$notification->users()->attach(
|
||||
$admins->pluck('id')->toArray()
|
||||
);
|
||||
|
||||
$webAdmins = $admins->filter(fn($admin) => $admin->web_notifications);
|
||||
$notification->users()->attach($webAdmins->pluck('id')->toArray());
|
||||
|
||||
broadcast(new UserCreated(
|
||||
$user,
|
||||
$notification->id,
|
||||
));
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
$data = [
|
||||
'adminName' => $admin->name,
|
||||
'adminLastname' => $admin->lastname,
|
||||
'userName' => $user->name,
|
||||
'userLastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($admin->email)->send(new RegisterMail($data));
|
||||
if ($admin->email_notifications) {
|
||||
$data = [
|
||||
'adminName' => $admin->name,
|
||||
'adminLastname' => $admin->lastname,
|
||||
'userName' => $user->name,
|
||||
'userLastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($admin->email)->send(new RegisterMail($data));
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User created successfully']);
|
||||
@@ -104,14 +106,17 @@ class UserController extends Controller
|
||||
"validate" => 1,
|
||||
"role" => 3,
|
||||
"phone" => $phone->formatInternational(),
|
||||
"web_notifications" => 1,
|
||||
"email_notifications" => 1,
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new CreateUserByAdminMail($data));
|
||||
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new CreateUserByAdminMail($data));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'User created successfully',
|
||||
@@ -123,11 +128,13 @@ class UserController extends Controller
|
||||
try {
|
||||
$user = User::find($request->user()->id);
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
return response()->json(['message' => 'User deleted successfully']);
|
||||
@@ -138,7 +145,6 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
public function getUser(Request $request, int $id): JsonResponse {
|
||||
|
||||
try {
|
||||
return response()->json(UserService::getData($id));
|
||||
} catch (ModelNotFoundException $e) {
|
||||
@@ -147,7 +153,6 @@ class UserController extends Controller
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteById(Request $request, int $id): JsonResponse {
|
||||
@@ -159,11 +164,13 @@ class UserController extends Controller
|
||||
try {
|
||||
$user = User::find($id);
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new DeleteAccountMail($data));
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
return response()->json(['message' => 'User deleted successfully']);
|
||||
@@ -183,11 +190,13 @@ class UserController extends Controller
|
||||
try {
|
||||
$userToDeactivate->update(['validate' => 0]);
|
||||
|
||||
$data = [
|
||||
'name' => $userToDeactivate->name,
|
||||
'lastname' => $userToDeactivate->lastname,
|
||||
];
|
||||
Mail::to($userToDeactivate->email)->send(new DeactivateAccountMail($data));
|
||||
if ($userToDeactivate->email_notifications) {
|
||||
$data = [
|
||||
'name' => $userToDeactivate->name,
|
||||
'lastname' => $userToDeactivate->lastname,
|
||||
];
|
||||
Mail::to($userToDeactivate->email)->send(new DeactivateAccountMail($data));
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User deactivated successfully']);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
@@ -196,13 +205,10 @@ class UserController extends Controller
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update(Request $request): JsonResponse {
|
||||
|
||||
try {
|
||||
|
||||
$phone = new PhoneNumber($request["phone"], 'FR');
|
||||
|
||||
$user = User::find($request->user()->id);
|
||||
@@ -212,12 +218,10 @@ class UserController extends Controller
|
||||
$user->save();
|
||||
|
||||
return response()->json(['message' => 'User updated successfully']);
|
||||
|
||||
} catch(\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function validate(Request $request, int $id): JsonResponse {
|
||||
@@ -234,14 +238,15 @@ class UserController extends Controller
|
||||
$user->verified_at = now();
|
||||
$user->save();
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new ValidateMail($data));
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
];
|
||||
Mail::to($user->email)->send(new ValidateMail($data));
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User validated successfully']);
|
||||
|
||||
} catch(\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
@@ -261,24 +266,27 @@ class UserController extends Controller
|
||||
|
||||
$role = GetRole::getRole($request['role']);
|
||||
|
||||
$notification = Notification::create([
|
||||
'content' => "Votre rôle à changé pour : {$role}",
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
if ($user->web_notifications) {
|
||||
$notification = Notification::create([
|
||||
'content' => "Votre rôle à changé pour : {$role}",
|
||||
]);
|
||||
$notification->users()->attach($user->id);
|
||||
|
||||
broadcast(new VolunteerRoleUpdated(
|
||||
$user->id,
|
||||
$role,
|
||||
$notification->id,
|
||||
));
|
||||
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'role' => $role,
|
||||
];
|
||||
Mail::to($user->email)->send(new UpdateRoleMail($data));
|
||||
broadcast(new VolunteerRoleUpdated(
|
||||
$user->id,
|
||||
$role,
|
||||
$notification->id,
|
||||
));
|
||||
}
|
||||
|
||||
if ($user->email_notifications) {
|
||||
$data = [
|
||||
'name' => $user->name,
|
||||
'lastname' => $user->lastname,
|
||||
'role' => $role,
|
||||
];
|
||||
Mail::to($user->email)->send(new UpdateRoleMail($data));
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'User role added successfully']);
|
||||
} catch(\Exception $e) {
|
||||
@@ -288,16 +296,12 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
public function getUsers(Request $request): JsonResponse {
|
||||
|
||||
try {
|
||||
|
||||
$users = User::where('validate', 1)
|
||||
->orderBy('verified_at', 'desc')
|
||||
->pluck('id');
|
||||
|
||||
return response()->json($users);
|
||||
|
||||
|
||||
} catch(\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
@@ -305,7 +309,6 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
public function getUserTasks(Request $request): JsonResponse {
|
||||
|
||||
try {
|
||||
return response()->json(['data' => $request->user()->tasks]);
|
||||
} catch (\Exception $e) {
|
||||
@@ -315,7 +318,6 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
public function getUserByIdTasks(Request $request, int $id): JsonResponse {
|
||||
|
||||
try {
|
||||
return response()->json(['data' => User::find($id)->tasks]);
|
||||
} catch (\Exception $e) {
|
||||
@@ -325,7 +327,6 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
public function getUserTaskById(Request $request, int $idTask): JsonResponse {
|
||||
|
||||
try {
|
||||
return response()->json(['data' => $request->user()->tasks->find($idTask)]);
|
||||
} catch (\Exception $e) {
|
||||
@@ -340,11 +341,9 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$users = User::where('validate', 0)->pluck('id');
|
||||
|
||||
return response()->json($users);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
@@ -358,7 +357,7 @@ class UserController extends Controller
|
||||
$user->save();
|
||||
|
||||
return response()->json($user);
|
||||
}catch(\Exception $e){
|
||||
} catch(\Exception $e){
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
@@ -371,10 +370,9 @@ class UserController extends Controller
|
||||
$user->save();
|
||||
|
||||
return response()->json($user);
|
||||
}catch(\Exception $e){
|
||||
} catch(\Exception $e){
|
||||
Log::info($e->getMessage());
|
||||
return response()->json(['message' => "Server error"], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user