118 lines
3.4 KiB
PHP
118 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Marco Glietsch
|
|
* Date: 07.12.2018
|
|
* Time: 14:15
|
|
*/
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Helpers\PublishHelper;
|
|
|
|
class PublishStadtanzeiger extends command
|
|
{
|
|
protected $signature = 'publish:stadtanzeiger {--testRun=false} {--daysInFuture=0}';
|
|
|
|
protected $description = 'Veröffentlicht Posts im Stadtanzeiger';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
$daysInFuture = $this->option('daysInFuture');
|
|
$testRun = $this->option('testRun');
|
|
if(strtoupper($testRun) == 'TRUE')
|
|
{
|
|
$testRun = true;
|
|
}
|
|
else{
|
|
$testRun = false;
|
|
}
|
|
|
|
PublishHelper::publishTodayPosts(['stadtanzeiger'], $testRun, $daysInFuture);
|
|
/*
|
|
$departments = Tag::select('*')
|
|
->where('type', 'abteilung')
|
|
->orderBy('name', 'ASC')
|
|
->get();
|
|
|
|
foreach($departments as $department)
|
|
{
|
|
// Suche alle Posts der Abteilung die heute veröffentlicht werden sollen
|
|
$publications = Publication::select('*', 'posts.type')
|
|
->whereState("PENDING")
|
|
->whereIn('platform', ['stadtanzeiger'])
|
|
->where(DB::raw("DATE(`publications`.`date_to_publish`)"), DB::raw("(DATE(NOW()) + INTERVAL 2 DAY)"))
|
|
->with('post')
|
|
->orderByRaw("FIELD(posts.type, 'dienst', 'veranstaltung', 'bericht', 'einsatz')")
|
|
->join('posts as posts', function ($join)
|
|
{
|
|
$join->on('posts.id', 'publications.post_id');
|
|
})
|
|
->join('post_tag as post_tag', function ($join)
|
|
{
|
|
$join->on('post_tag.post_id', 'publications.post_id');
|
|
})
|
|
->join('tags as tags', function ($join) use ($department)
|
|
{
|
|
$join->on('tags.id', 'post_tag.tag_id')
|
|
->where('tags.type', 'abteilung')
|
|
->where('tags.id', $department->id);
|
|
})
|
|
->get();
|
|
|
|
$count = count($publications);
|
|
if($count > 0)
|
|
{
|
|
$i = 1;
|
|
$d = array();
|
|
echo "Veröffentlichungen im Stadtanzeiger für Abteilung $department->name: $count\n\n";
|
|
foreach($publications as $publication)
|
|
{
|
|
// $publication->publishIfReady();
|
|
// $publication->save();
|
|
$post = new \stdClass();
|
|
$post->type = ucfirst($publication->post->type);
|
|
$post->title = PostHelper::getSocialMediaTitle($publication->post);
|
|
$post->content = PostHelper::getSocialMediaDescription($publication->post);
|
|
if(isset($publication->post->previewDocument->filename))
|
|
{
|
|
$post->image= config('app.url')."/uploads/".$publication->post->type."/".$publication->post->id."/".$publication->post->previewDocument->filename;
|
|
}
|
|
echo "$i/$count\n";
|
|
echo "Typ: $post->type\n";
|
|
echo "Titel: $post->title\n";
|
|
echo "Beschreibung: $post->content\n";
|
|
if(isset($post->image))
|
|
{
|
|
echo "Bild: $post->image\n";
|
|
}
|
|
|
|
$d[$department->name][] = $post;
|
|
$i++;
|
|
}
|
|
|
|
// Wer soll per Email benachrichtigt werden
|
|
$users = User::select('*')
|
|
->with(['tags' => function($query) use($department){
|
|
$query->where('type', 'abteilung')
|
|
->where('name', $department->name);
|
|
}])
|
|
->orWhere('name', 'Admin')
|
|
->get();
|
|
echo count($users);
|
|
Mail::send('inc.publish.mailStadtanzeiger', ['departments' => $d], function($message) use($department){
|
|
$message->to('glietschie@gmx.de')
|
|
->from('mail@marco-glietsch.de', "Feuerwehr Eppingen - Abteilung ".$department->name)
|
|
->subject("Stadtanzeiger KW".Carbon::now()->weekOfYear);
|
|
});
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
} |