247 lines
5.4 KiB
PHP
247 lines
5.4 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: Marco Glietsch
|
|
* Date: 11.07.2018
|
|
* Time: 16:27
|
|
*/
|
|
|
|
namespace App\Helpers;
|
|
|
|
use App\Models\Tag;
|
|
use App\Models\Post;
|
|
use Carbon\Carbon;
|
|
|
|
class PostHelper
|
|
{
|
|
static function getDepartments($model)
|
|
{
|
|
$departments = array();
|
|
|
|
// Ermittle zuerst die eigentlich getagte Abteilung
|
|
foreach($model->tags as $tag)
|
|
{
|
|
if($tag->type == 'abteilung')
|
|
{
|
|
array_push($departments, $tag->name);
|
|
}
|
|
}
|
|
|
|
// Ermittle andere Abteilungen, die anhand ihres Fahrzeugs getagt wurden
|
|
foreach($model->posts as $post)
|
|
{
|
|
if($post->type == 'fahrzeug')
|
|
{
|
|
foreach($post->tags as $tag)
|
|
{
|
|
if($tag->type == 'abteilung')
|
|
{
|
|
if(!in_array($tag->name, $departments))
|
|
{
|
|
array_push($departments, $tag->name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $departments;
|
|
}
|
|
|
|
static function getDate($model, $config)
|
|
{
|
|
if(key_exists('datetime', $config))
|
|
{
|
|
if($config['datetime']['type'] == 'inputDateTimePicker')
|
|
{
|
|
if(isset($config['datetime']['datepicker']['format']))
|
|
{
|
|
return \Carbon\Carbon::createFromTimestamp(strtotime($model->datetime))->format($config['datetime']['datepicker']['format']);
|
|
}
|
|
else
|
|
{
|
|
return \Carbon\Carbon::createFromTimestamp(strtotime($model->datetime))->format('d.m.Y');
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return \Carbon\Carbon::createFromTimestamp(strtotime($model->datetime))->format('d.m.Y');
|
|
}
|
|
}
|
|
|
|
static function getTime($model, $config)
|
|
{
|
|
if(key_exists('datetime', $config))
|
|
{
|
|
if($config['datetime']['type'] == 'inputDateTimePicker')
|
|
{
|
|
if(isset($config['datetime']['time']['format']))
|
|
{
|
|
return \Carbon\Carbon::createFromTimestamp(strtotime($model->datetime))->format($config['datetime']['time']['format']);
|
|
}
|
|
else
|
|
{
|
|
return \Carbon\Carbon::createFromTimestamp(strtotime($model->datetime))->format('H.i');
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return \Carbon\Carbon::createFromTimestamp(strtotime($model->datetime))->format('H.i');
|
|
}
|
|
}
|
|
|
|
static public function getNextServiceString($model)
|
|
{
|
|
$string = '';
|
|
|
|
if(isset($model->next))
|
|
{
|
|
if($model->next->dienstart == __("general.miscellaneous") && $model->next->beschreibung != '')
|
|
{
|
|
$string .= $model->next->beschreibung;
|
|
}
|
|
else
|
|
{
|
|
$string .= $model->next->dienstart;
|
|
}
|
|
$string .= ', am '.DateHelper::toHumanDate($model->next->datetime).' um '.DateHelper::toHumanTime($model->next->datetime).' Uhr';
|
|
}
|
|
|
|
return $string;
|
|
}
|
|
|
|
static function getServiceString($model)
|
|
{
|
|
$string = '';
|
|
|
|
if($dienstart = $model->tag('dienstart')->get(0))
|
|
{
|
|
if($dienstart->name == __("general.miscellaneous") && $model->beschreibung != '')
|
|
{
|
|
$string .= $model->beschreibung;
|
|
}
|
|
else
|
|
{
|
|
$string .= $dienstart->name;
|
|
}
|
|
$string .= ','.__('general.on :date at :time', [
|
|
'date' => DateHelper::toHumanDate($model->datetime),
|
|
'time' => DateHelper::toHumanTime($model->datetime)
|
|
]);
|
|
|
|
if($model->content->beschreibung != '')
|
|
{
|
|
$string .= " ".$model->content->beschreibung;
|
|
}
|
|
}
|
|
|
|
return $string;
|
|
}
|
|
|
|
static public function getSocialMediaServiceDescription($model)
|
|
{
|
|
return PostHelper::getNextServiceString($model);
|
|
}
|
|
|
|
static public function getSocialMediaTitle($model)
|
|
{
|
|
if(!isset($model->title))
|
|
{
|
|
$model = $model[0];
|
|
}
|
|
|
|
switch($model->getAttribute('type'))
|
|
{
|
|
case 'dienst':
|
|
$year = Carbon::parse($model->datetime)->format('Y');
|
|
$department = TagHelper::getTagNameByType($model, 'abteilung');
|
|
$instance = TagHelper::getTagNameByType($model, 'instanz');
|
|
return __("general.schedule :year: :department - :instance", [
|
|
'year' => $year,
|
|
'department' => $department,
|
|
'instance' => $instance
|
|
]);
|
|
break;
|
|
|
|
default:
|
|
return $model->title;
|
|
break;
|
|
}
|
|
}
|
|
|
|
static public function getSocialMediaDescription($model)
|
|
{
|
|
switch($model->getAttribute('type'))
|
|
{
|
|
case 'dienst':
|
|
return PostHelper::getServiceString($model);
|
|
break;
|
|
|
|
case 'fahrzeug':
|
|
return __("general.Florian Eppingen :radiocall", [
|
|
'radiocall' => $model->content->funkrufname
|
|
]);
|
|
break;
|
|
|
|
default:
|
|
return strip_tags(str_replace('"', '', $model->content));
|
|
break;
|
|
}
|
|
}
|
|
|
|
static function getDocumentWebPath($model, $isThumb = false)
|
|
{
|
|
$thumb = "";
|
|
if($isThumb == true)
|
|
{
|
|
$thumb = "/thumbs";
|
|
}
|
|
|
|
$imagePath = config('app.url')."/images/placeholder-m.png";
|
|
if(isset($model->previewDocument))
|
|
{
|
|
if(isset($model->previewDocument->filename))
|
|
{
|
|
$imagePath = config('app.url')."/uploads/".$model->type."/".$model->id.$thumb."/".$model->previewDocument->filename;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch($model->type)
|
|
{
|
|
case "einsatz":
|
|
$servicetype = $model->tag('einsatzart')[0];
|
|
if(isset($servicetype->previewDocument->filename))
|
|
{
|
|
$imagePath = config('app.url')."/uploads/".$servicetype->type."/".$servicetype->id.$thumb."/".$servicetype->previewDocument->filename;
|
|
}
|
|
else
|
|
{
|
|
$imagePath = config('app.url')."/images/operation-m.png";
|
|
}
|
|
break;
|
|
|
|
case "dienst":
|
|
$imagePath = config('app.url')."/images/schedule-m.png";
|
|
break;
|
|
|
|
case "bericht":
|
|
$imagePath = config('app.url')."/images/article-m.png";
|
|
break;
|
|
|
|
case "veranstaltung":
|
|
$imagePath = config('app.url')."/images/event-m.png";
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $imagePath;
|
|
}
|
|
|
|
static function getPreviewThumbWebPath($model)
|
|
{
|
|
return PostHelper::getDocumentWebPath($model, true);
|
|
}
|
|
} |