Skip to content

Commit

Permalink
IP-78: As a platform admin/content manager, when a new solution is su…
Browse files Browse the repository at this point in the history
…bmitted I receive an email notification with the submission details
  • Loading branch information
PavlosIsaris committed Dec 16, 2024
1 parent 2f3067b commit 0c77a77
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
8 changes: 8 additions & 0 deletions app/BusinessLogicLayer/Solution/SolutionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ public function storeSolution(array $attributes): Solution {
public function storeSolutionFromPublicForm(array $attributes): Solution {
$solution = $this->storeSolutionWithStatus($attributes, SolutionStatusLkp::UNPUBLISHED);
$user = Auth::user();

// notify the user that their solution has been submitted
$user->notify(new \App\Notifications\SolutionSubmitted($solution));

// get the creator of the solution problem
$problem_creator = $solution->problem->creator;

// notify the creator of the solution submission
$problem_creator->notify(new \App\Notifications\SolutionSubmittedForReview($solution));

return $solution;
}

Expand Down
5 changes: 5 additions & 0 deletions app/Models/Problem/Problem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\CrowdSourcingProject\CrowdSourcingProject;
use App\Models\Solution\Solution;
use App\Models\User\User;
use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -45,6 +46,10 @@ public function project(): HasOne {
return $this->hasOne(CrowdSourcingProject::class, 'id', 'project_id');
}

public function creator(): HasOne {
return $this->hasOne(User::class, 'id', 'user_creator_id');
}

//observe this model being deleted and delete the related records
public static function boot() {
parent::boot();
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Solution/Solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function translations(): HasMany {
return $this->hasMany('App\Models\Solution\SolutionTranslation', 'solution_id', 'id');
}

public function user(): BelongsTo {
public function creator(): BelongsTo {
return $this->belongsTo(User::class, 'user_creator_id', 'id');
}

Expand Down
62 changes: 62 additions & 0 deletions app/Notifications/SolutionSubmittedForReview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace App\Notifications;

use App\Models\Solution\Solution;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SolutionSubmittedForReview extends Notification implements ShouldQueue {
use Queueable;

protected Solution $solution;

/**
* Create a new notification instance.
*/
public function __construct(Solution $solution) {
$this->solution = $solution;
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array {
return ['mail'];
}

/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage {
return (new MailMessage)
->subject('Crowdsourcing Platform | ' . __('notifications.solution_submitted') . ': ' . $this->solution->defaultTranslation->title)
->line(__('notifications.new_solution_submitted'))
->line('<div style="text-align:center; height: 200px; margin-bottom: 20px;"><img class="badgeImg" style="height: 200px; margin-bottom: 0;" src=' . asset('images/active_participation.webp') . '></div>')
->greeting(__('notifications.hello') . ' ' . $notifiable->nickname . '!')
->line(__('notifications.a_user_has_proposed_solution'))
->line('Username: ' . $this->solution->creator->nickname)
->line('Email: ' . $this->solution->creator->email)
->line('Campaign: ' . $this->solution->problem->project->defaultTranslation->name)
->line('Problem: ' . $this->solution->problem->defaultTranslation->title)
->line('Solution: ' . $this->solution->defaultTranslation->title)
->line(__('notifications.check_solution_and_review'))
->action(__('notifications.see_submitted_solutions'), route('solutions.index', ['locale' => app()->getLocale()]))
->salutation(__('notifications.thanks_message_2'));
}

/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array {
return [
//
];
}
}
6 changes: 4 additions & 2 deletions resources/lang/en/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
|--------------------------------------------------------------------------
| Notifications elements
|--------------------------------------------------------------------------
*/


'go_to_dashboard' => 'Go to Dashboard',
'thank_you_for_contribution' => 'Thank you for your contribution!',
'hello' => 'Hello!',
Expand All @@ -35,4 +33,8 @@
'ok' => 'OK',
'solution_submitted' => 'Solution Submitted',
'thanks_for_proposing_solution' => 'Thank you for proposing a solution! It will soon be reviewed by our team, and you will be notified when it is approved. Once approved, other users will be able to vote on it!',
'new_solution_submitted' => 'A new solution has been submitted.',
'a_user_has_proposed_solution' => 'A user has proposed a solution.',
'check_solution_and_review' => 'Please check the solution and review it.',
'see_submitted_solutions' => 'See Submitted Solutions',
];

0 comments on commit 0c77a77

Please sign in to comment.