CMS Info for Header, dyn. Tage, API

This commit is contained in:
Kevin Adametz 2019-12-28 20:15:25 +01:00
parent 7294ccc1d0
commit bed91c4f4a
49 changed files with 3476 additions and 1562 deletions

View file

@ -22,7 +22,7 @@ class CMSContentController extends Controller
return response()->json(['error' => "request no found"], $this->successStatus);
}
if($request['key'] != 'f6077389c9ce710e554763a5de02c8ec'){
if($request['key'] !== 'f6077389c9ce710e554763a5de02c8ec'){
return response()->json(['error' => "key"], 401);
}

View file

@ -0,0 +1,233 @@
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use App\Models\CMSInfo;
use App\Models\CMSInfoAvailable;
use App\Models\CMSInfoHoliday;
use App\Services\HTMLHelper;
class CMSContentInfoController extends Controller
{
public $successStatus = 200;
public function headerInfo()
{
$request = \Request::all();
/* if(!isset($request['url']) || !isset($request['key'])){
return response()->json(['error' => "request no found"], $this->successStatus);
}
if($request['key'] !== 'f6077389c9ce710e554763a5de02c8ec'){
return response()->json(['error' => "key"], 401);
}*/
$ret = [];
$days = HTMLHelper::getDeDays();
$locals = CMSInfoAvailable::whereType('local')->whereSpecial(false)->get();
foreach ($locals as $value){
$date = CMSInfoAvailable::getWeekWithDate($value->wday);
$ret['local'][$date['date']] = [
'day'=>$days[$value->wday],
'active' => $value->active,
'from' => $value->from,
'to' => $value->to,
];
}
$phones = CMSInfoAvailable::whereType('phone')->whereSpecial(false)->get();
foreach ($phones as $value){
$date = CMSInfoAvailable::getWeekWithDate($value->wday);
$ret['phone'][$date['date']] = [
'day'=>$days[$value->wday],
'active' => $value->active,
'from' => $value->from,
'to' => $value->to,
];
}
$specials = CMSInfoAvailable::whereSpecial(true)->get();
foreach ($specials as $special){
$ret[$special->type][$special->date] = [
'day'=>$days[$special->wday],
'active' => $special->active,
'from' => $special->from,
'to' => $special->to,
];
}
// ksort($ret);
$ret['info']['office_important_note_active'] = CMSInfo::getContentBySlug('office-important-note-active');
$ret['info']['office_important_note'] = CMSInfo::getContentBySlug('office-important-note');
$ret['info']['office_appointment'] = CMSInfo::getContentBySlug('office-appointment');
$now = \Carbon::now();
$wday = $now->dayOfWeekIso;
$ret['available']['local'] = $this->checkAvailable('local', $wday);
$ret['available']['phone'] = $this->checkAvailable('phone', $wday);
return response()->json(['success' => "content", "ret"=>$ret], $this->successStatus);
}
private function checkAvailable($type, $wday){
$contents = [];
$contents['local'] = [
1 => " keinen Eintrag",
2 => "öffnet am #day#",
3 => "schließt um #to# Uhr",
4 => "öffnet am #n-day# um #from# Uhr",
5 => "ab #from# Uhr",
];
$contents['phone'] = [
1 => " keinen Eintrag",
2 => "ab #day#",
3 => "bis #to# Uhr",
4 => "ab #n-day# um #from# Uhr",
5 => "ab #from# Uhr",
];
$now = \Carbon::now();
//holidays
if($next_date = $this->checkBetweenHoliday($type, $now)){
$content = str_replace('#day#', $next_date, $contents[$type][2]);
return ['active' => 0, 'content'=>$content];
}
$now = \Carbon::now();
$minutes = $now->hour*60 + $now->minute;
if($special = $this->checkDateforSpecial($type, $wday, $now->format("d.m.Y"))) {
if($special->active) {
$from = $special->fromMinutes();
$to = $special->toMinutes();
//open to
if($minutes >= $from && $minutes <= $to){
$content = str_replace('#to#', $special->to, $contents[$type][3]);
return ['active' => 1, 'content'=> $content];
}
//is close, but open today
if($minutes < $from && $minutes < $to) {
$content = str_replace('#from#', $special->from, $contents[$type][5]);
return ['active' => 0, 'content'=> $content];
}
}
}else{
$available = CMSInfoAvailable::getContentBySlug($type, $wday);
if(!$available){
return ['active' => 0, 'content'=> $contents[$type][1]];
}
if($available->active) {
$from = $available->fromMinutes();
$to = $available->toMinutes();
//open to
if($minutes >= $from && $minutes <= $to){
$content = str_replace('#to#', $available->to, $contents[$type][3]);
return ['active' => 1, 'content'=> $content];
}
//is close, but open today
if($minutes < $from && $minutes < $to) {
$content = str_replace('#from#', $available->from, $contents[$type][5]);
return ['active' => 0, 'content'=> $content];
}
}
}
//is next day
$next = $this->getNextActiveDay($type, $wday, $contents);
if($next){
return $next;
}
return ['active' => 0, 'content'=> $contents[$type][1]];
}
private function getNextActiveDay($type, $wday, $contents){
$days = HTMLHelper::getDeDays();
$counter = 0;
while ($counter <= 6) {
$counter++;
$wday = $wday < 7 ? $wday+1 : 1;
$w = CMSInfoAvailable::getWeekWithDate($wday);
$wDate = \Carbon::parse($w['date']);
if($next_date = $this->checkBetweenHoliday($type, $wDate)){
$content = str_replace('#day#', $next_date, $contents[$type][2]);
return ['active' => 0, 'content'=>$content];
}
if($special = $this->checkDateforSpecial($type, $wday, $wDate->format("d.m.Y"))){
if($special->active) {
$content = str_replace('#from#', $special->from, $contents[$type][4]);
$content = str_replace('#n-day#', $days[$special->wday], $content);
return ['active' => 0, 'content'=> $content];
}
}
$available = CMSInfoAvailable::getContentBySlug($type, $wday);
if(isset($available) && $available->active){
//is in holiday?
$content = str_replace('#from#', $available->from, $contents[$type][4]);
$content = str_replace('#n-day#', $days[$available->wday], $content);
return ['active' => 0, 'content'=> $content];
}
}
return false;
}
private function checkBetweenHoliday($type, \Carbon $cdate){
$holidays = CMSInfoHoliday::where($type, true)->get();
foreach ($holidays as $holiday){
//is in range?
$from = \Carbon::parse($holiday->from);
$to = \Carbon::parse($holiday->to);
if($cdate->between($from, $to)){
$to->modify('+1 day');
return $to->format("d.m.Y");
}
}
return false;
}
private function checkDateforSpecial($type, $wday, $date){
$specials = CMSInfoAvailable::whereType($type)->whereWday($wday)->whereSpecial(true)->get();
foreach ($specials as $special){
if($special->date == $date){
return $special;
}
}
}
}

View file

@ -58,7 +58,7 @@ class FewoController extends Controller
'zipcode',
'city',
'phone',
'fax',
'mobile',
'travel_nationality_id'
];

View file

@ -29,7 +29,9 @@ class CMSContentInfoController extends Controller
public function index()
{
$data = [
'days' => $this->createWeekWithDate(),
'days' => CMSInfoAvailable::getWeekWithDate(),
'specials_local' => CMSInfoAvailable::getSpecialsBy('local'),
'specials_phone' => CMSInfoAvailable::getSpecialsBy('phone'),
'cms_holidays' => CMSInfoHoliday::all(),
];
return view('cms.content.info.index', $data);
@ -52,6 +54,19 @@ class CMSContentInfoController extends Controller
}
}
//save in CMSInfoAvailable SPECIALS
if(isset($data['special_availables']) && is_array($data['special_availables'])){
foreach ($data['special_availables'] as $id=>$values){
$special_available = CMSInfoAvailable::findOrFail($id);
$cdate = \Carbon::parse($values['date']);
$values['wday'] = $cdate->dayOfWeekIso;
$special_available->fill($values)->save();
}
}
//save in CMSinfoHolidays
if(isset($data['info_holidays']) && is_array($data['info_holidays'])){
foreach ($data['info_holidays'] as $id=>$val){
@ -75,6 +90,34 @@ class CMSContentInfoController extends Controller
CMSInfoHoliday::create();
}
if($data['action'] === "add_special_available_local"){
$date = CMSInfoAvailable::getNextSpecialDateBy('local', 6);
CMSInfoAvailable::create([
'type' => 'local',
'wday' => $date->dayOfWeekIso,
'special' => true,
'active' => true,
'from' => '10:00',
'to' => '13:00',
'date' => $date->format('d.m.Y'),
]);
}
if($data['action'] === "add_special_available_phone"){
$date = CMSInfoAvailable::getNextSpecialDateBy('phone', 6);
CMSInfoAvailable::create([
'type' => 'phone',
'wday' => $date->dayOfWeekIso,
'special' => true,
'active' => true,
'from' => '10:00',
'to' => '13:00',
'date' => $date->format('d.m.Y'),
]);
}
\Session()->flash('alert-save', '1');
return redirect(route('cms_content_infos'));
}
@ -85,6 +128,7 @@ class CMSContentInfoController extends Controller
$now = \Carbon::now();
$day_of = $now->dayOfWeekIso;
//days after now
for ($i = $day_of; $i<=7; $i++){
$days[$i] = $days[$i].' <span class="text-muted">('.$now->format("d.m.Y").')</span>';
@ -92,10 +136,12 @@ class CMSContentInfoController extends Controller
}
//days before now
for ($i = 1; $i<$day_of; $i++){
$days[$i] = $days[$i].' <span class="text-muted">('.$now->format("d.m.Y").')</span>';
for ($i = 1; $i<$day_of; $i++) {
$days[$i] = $days[$i] . ' <span class="text-muted">(' . $now->format("d.m.Y") . ')</span>';
$now->modify('+1 day');
}
//add
return $days;
}
@ -106,6 +152,12 @@ class CMSContentInfoController extends Controller
$content->delete();
\Session()->flash('alert-success', __('Content gelöscht'));
}
if($model === 'special_available'){
$content = CMSInfoAvailable::findOrFail($id);
$content->delete();
\Session()->flash('alert-success', __('Content gelöscht'));
}
return redirect(route('cms_content_infos'));
}