118 lines
3.0 KiB
PHP
118 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Contracts\Mail\Mailer;
|
|
use App\Models\User;
|
|
use \Carbon\Carbon;
|
|
|
|
class MailStadtanzeiger implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected $email;
|
|
protected $template;
|
|
protected $posts;
|
|
protected $title;
|
|
protected $department;
|
|
protected $count;
|
|
protected $debug;
|
|
protected $debugText;
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($email, $template, $posts, $title, $department, $count, $debug = false, $debugText = '')
|
|
{
|
|
$this->email = $email;
|
|
$this->template = $template;
|
|
$this->posts = $posts;
|
|
$this->title = $title;
|
|
$this->department = $department;
|
|
$this->count = $count;
|
|
$this->debug = $debug;
|
|
$this->debugText = $debugText;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle(Mailer $mailer)
|
|
{
|
|
$email = $this->email;
|
|
$template = $this->template;
|
|
$posts = $this->posts;
|
|
$title = $this->title;
|
|
$department = $this->department;
|
|
$count = $this->count;
|
|
$debugText = $this->debugText;
|
|
|
|
if($this->debug)
|
|
{
|
|
echo "Sende Bericht an: Stadt Eppingen\n";
|
|
}
|
|
|
|
$users = User::select('email')
|
|
->join('user_tag as user_tag', function ($join)
|
|
{
|
|
$join->on('users.id', 'user_tag.user_id');
|
|
})
|
|
->join('tags as tags', function ($join) use($department)
|
|
{
|
|
$join->on('tags.id', 'user_tag.tag_id')
|
|
->where('tags.type', 'abteilung')
|
|
->where('tags.name', $department);
|
|
})
|
|
->join('user_tag as user_tag2', function ($join)
|
|
{
|
|
$join->on('users.id', 'user_tag2.user_id');
|
|
})
|
|
->join('tags as tags2', function ($join) use($department)
|
|
{
|
|
$join->on('tags2.id', 'user_tag2.tag_id')
|
|
->where('tags2.type', 'benachrichtigung')
|
|
->where('tags2.name', 'Veröffentlichungen');
|
|
})
|
|
->get();
|
|
|
|
$emailFrom = config('mail.from.address');
|
|
$emailCC = array();
|
|
if(count($users))
|
|
{
|
|
foreach($users as $user)
|
|
{
|
|
$emailCC[] = $user->email;
|
|
}
|
|
}
|
|
/** /
|
|
// Nur für Testzwecke //
|
|
if($department == 'Eppingen')
|
|
{
|
|
$title .= "EMPFÄNGER: ".implode(', ', $emailCC)." - ".$email." => FROM: ".$emailFrom;
|
|
$email = "m.glietsch@kortec.de";
|
|
$emailFrom = "mail@marco-glietsch.de";
|
|
$emailCC = ['glietschie@gmx.de'];
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
/**/
|
|
$mailer->send($template, ['publications' => $posts, 'debugText' => $debugText], function($message) use($email, $emailFrom, $emailCC, $department, $count, $title){
|
|
$message->to($email)
|
|
->from($emailFrom, "Feuerwehr Eppingen - Abteilung $department")
|
|
->cc($emailCC)
|
|
->subject("$title vom ".Carbon::now()->format('d.m.Y')." ($count)");
|
|
// ->subject("Feuerwehr Eppingen: Abteilung $department - $title vom ".Carbon::now()->format('d.m.Y')." ($count)");
|
|
});
|
|
}
|
|
}
|