Commit d73ffa85 authored by Ricardo Walter Hildebrand's avatar Ricardo Walter Hildebrand
Browse files

notificações

parent 1635ce95
Pipeline #4228 passed with stages
in 5 minutes and 54 seconds
......@@ -9,6 +9,8 @@ use App\Http\Requests\API\PaginationRequest;
use App\Http\Resources\Material as MaterialResource;
use App\Http\Resources\MaterialCollection;
use App\Http\Resources\MaterialWithTrails;
use App\Mail\NotifyMaterialPublished;
use App\Mail\NotifyMaterialUnublished;
use App\Material;
use Illuminate\Http\Request;
use Spatie\QueryBuilder\Filter;
......@@ -159,7 +161,21 @@ class MaterialController extends Controller
}
if (is_admin($user) && $request->has('published')) {
$oldPublished = $material->published;
$material->published = $request->input('published');
if ($material->exists && $oldPublished != $material->published && !empty($material->creator_id)) {
try {
if ($material->published) {
\Mail::send(new NotifyMaterialPublished($material));
} else {
\Mail::send(new NotifyMaterialUnublished($material));
}
} catch (\Exception $e) {
\Log::error($e->getMessage());
}
}
}
$material->save();
......
<?php
namespace App\Http\Controllers\API\Publish;
use App\Http\Controllers\Controller;
use App\Mail\NotifyMaterialPublish;
use App\Material;
use Illuminate\Http\Request;
class MaterialController extends Controller
{
public function store($idOrSlug)
{
$material = Material::findByIdOrSlug($idOrSlug);
abort_if(is_null($material), 404);
\Mail::send(new NotifyMaterialPublish($material));
return response()->noContent();
}
}
<?php
namespace App\Http\Controllers\Publish;
use App\Http\Controllers\Controller;
use App\Mail\NotifyTrailPublish;
use App\Trail;
use Illuminate\Http\Request;
class TrailController extends Controller
{
public function store($idOrSlug)
{
$trail = Trail::findByIdOrSlug($idOrSlug);
abort_if(is_null($trail), 404);
\Mail::send(new NotifyTrailPublish($trail));
return response()->noContent();
}
}
......@@ -6,9 +6,11 @@ use App\Events\TrailViewed;
use App\Http\Controllers\Controller;
use App\Http\Requests\API\PaginationRequest;
use App\Http\Requests\API\TrailRequest;
use App\Http\Resources\SimpleTrailCollection;
use App\Http\Resources\Trail as TrailResource;
use App\Http\Resources\TrailCollection;
use App\Http\Resources\SimpleTrailCollection;
use App\Mail\NotifyTrailPublished;
use App\Mail\NotifyTrailUnublished;
use App\Trail;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
......@@ -154,7 +156,21 @@ class TrailController extends Controller
}
if (is_admin($user) && $request->has('published')) {
$oldPublished = $trail->published;
$trail->published = $request->input('published');
if ($trail->exists && $oldPublished != $trail->published && !empty($trail->creator_id)) {
try {
if ($trail->published) {
\Mail::send(new NotifyTrailPublished($trail));
} else {
\Mail::send(new NotifyTrailUnublished($trail));
}
} catch (\Exception $e) {
\Log::error($e->getMessage());
}
}
}
$trail->save();
......
<?php
namespace App\Mail;
use App\Material;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyMaterialPublish extends Mailable
{
use Queueable, SerializesModels;
public $material;
public function __construct(Material $material)
{
$this->material = $material;
}
public function build()
{
$emails = $this->fetchEmails();
return $this->view('email.material-publish')
->to($emails)
->subject('Material para publicar');
}
private function fetchEmails()
{
$emails = [];
$users = User::where('role', User::PROFILE_ADMIN)
->get();
foreach ($users as $user) {
$emails[] = $user->email;
}
return $emails;
}
}
<?php
namespace App\Mail;
use App\Material;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyMaterialPublished extends Mailable
{
use Queueable, SerializesModels;
public $material;
public function __construct(Material $material)
{
$this->material = $material;
}
public function build()
{
$emails = $this->fetchEmails();
return $this->view('email.material-published')
->to($emails)
->subject('Material publicado');
}
private function fetchEmails()
{
$emails = [];
$this->material->load([
'creator',
]);
$email = optional($this->material->creator)->email;
if (!empty($email)) {
$emails[] = $email;
}
return $emails;
}
}
<?php
namespace App\Mail;
use App\Material;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyMaterialUnublished extends Mailable
{
use Queueable, SerializesModels;
public $material;
public function __construct(Material $material)
{
$this->material = $material;
}
public function build()
{
$emails = $this->fetchEmails();
return $this->view('email.material-unpublished')
->to($emails)
->subject('Material escondido');
}
private function fetchEmails()
{
$emails = [];
$this->material->load([
'creator',
]);
$email = optional($this->material->creator)->email;
if (!empty($email)) {
$emails[] = $email;
}
return $emails;
}
}
<?php
namespace App\Mail;
use App\Trail;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyTrailPublish extends Mailable
{
use Queueable, SerializesModels;
public $trail;
public function __construct(Trail $trail)
{
$this->trail = $trail;
}
public function build()
{
$emails = $this->fetchEmails();
return $this->view('email.trail-publish')
->to($emails)
->subject('Trilha para publicar');
}
private function fetchEmails()
{
$emails = [];
$users = User::where('role', User::PROFILE_ADMIN)
->get();
foreach ($users as $user) {
$emails[] = $user->email;
}
return $emails;
}
}
<?php
namespace App\Mail;
use App\Trail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyTrailPublished extends Mailable
{
use Queueable, SerializesModels;
public $trail;
public function __construct(Trail $trail)
{
$this->trail = $trail;
}
public function build()
{
$emails = $this->fetchEmails();
return $this->view('email.trail-published')
->to($emails)
->subject('Trilha publicada');
}
private function fetchEmails()
{
$emails = [];
$this->trail->load([
'creator',
]);
$email = optional($this->trail->creator)->email;
if (!empty($email)) {
$emails[] = $email;
}
return $emails;
}
}
<?php
namespace App\Mail;
use App\Trail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class NotifyTrailUnublished extends Mailable
{
use Queueable, SerializesModels;
public $trail;
public function __construct(Trail $trail)
{
$this->trail = $trail;
}
public function build()
{
$emails = $this->fetchEmails();
return $this->view('email.trail-unpublished')
->to($emails)
->subject('Trilha escondida');
}
private function fetchEmails()
{
$emails = [];
$this->trail->load([
'creator',
]);
$email = optional($this->trail->creator)->email;
if (!empty($email)) {
$emails[] = $email;
}
return $emails;
}
}
......@@ -37,6 +37,9 @@ Route::group(['prefix' => '/materials'], function () {
Route::post('/{idOrSlug}/issue', 'Issue\MaterialController@store');
Route::get('/{idOrSlug}/topics', 'MaterialController@topics');
Route::get('/{idOrSlug}/publish', 'Publish\MaterialController@store')
->middleware(['auth:api', 'is_partner']);
});
Route::group(['prefix' => '/trails'], function () {
......@@ -75,6 +78,9 @@ Route::group(['prefix' => '/trails'], function () {
Route::get('/{idOrSlug}/issue', 'Issue\TrailController@index')
->middleware(['auth:api', 'is_partner']);
Route::post('/{idOrSlug}/issue', 'Issue\TrailController@store');
Route::get('/{idOrSlug}/publish', 'Publish\TrailController@store')
->middleware(['auth:api', 'is_partner']);
});
Route::group(['prefix' => '/news'], function () {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment