Media youtube, title description, CMS Info Content / Header Frontend

This commit is contained in:
Kevin Adametz 2019-12-12 20:01:01 +01:00
parent c9f3d85d4e
commit 7294ccc1d0
49 changed files with 1283 additions and 148 deletions

View file

@ -22,11 +22,7 @@ class CMSContentController extends Controller
{
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$data = [
@ -70,7 +66,7 @@ class CMSContentController extends Controller
}
public function loadModal()
public function loadModal()
{
if(Request::ajax()){
$data = Input::all();
@ -102,4 +98,5 @@ class CMSContentController extends Controller
}

View file

@ -0,0 +1,112 @@
<?php
namespace App\Http\Controllers\CMS;
use App\Http\Controllers\Controller;
use App\Models\CMSContent;
use App\Models\CMSInfo;
use App\Models\CMSInfoAvailable;
use App\Models\CMSInfoHoliday;
use App\Services\HTMLHelper;
use Input;
use Request;
use Validator;
class CMSContentInfoController extends Controller
{
/*
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
}
public function index()
{
$data = [
'days' => $this->createWeekWithDate(),
'cms_holidays' => CMSInfoHoliday::all(),
];
return view('cms.content.info.index', $data);
}
public function store()
{
$data = Input::all();
if($data['action'] === "saveAll"){
//save in CMSInfoAvailable
if(isset($data['info_availables']) && is_array($data['info_availables'])){
foreach ($data['info_availables'] as $type=>$values){
foreach ($values as $wday=>$val){
CMSInfoAvailable::setContentBySlug($type, $wday, $val);
}
}
}
//save in CMSinfoHolidays
if(isset($data['info_holidays']) && is_array($data['info_holidays'])){
foreach ($data['info_holidays'] as $id=>$val){
$content = CMSInfoHoliday::findOrFail($id);
$content->fill($val);
$content->save();
}
}
//save in CMSinfo
if(isset($data['infos']) && is_array($data['infos'])){
foreach ($data['infos'] as $slug=>$info){
$type = isset($info['type']) ? $info['type'] : "text";
$val = isset($info['val']) ? $info['val'] : "";
CMSInfo::setContentBySlug($slug, $val, $type);
}
}
}
if($data['action'] === "add_holiday"){
CMSInfoHoliday::create();
}
\Session()->flash('alert-save', '1');
return redirect(route('cms_content_infos'));
}
private function createWeekWithDate(){
$days = HTMLHelper::getDeDays();
$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>';
$now->modify('+1 day');
}
//days before now
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');
}
return $days;
}
public function delete($model, $id){
if($model === 'holiday'){
$content = CMSInfoHoliday::findOrFail($id);
$content->delete();
\Session()->flash('alert-success', __('Content gelöscht'));
}
return redirect(route('cms_content_infos'));
}
}

View file

@ -26,11 +26,6 @@ class CMSTravelGuideController extends Controller
{
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
/*

184
app/Models/CMSInfo.php Normal file
View file

@ -0,0 +1,184 @@
<?php
namespace App\Models;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\CMSInfo
*
* @property int $id
* @property string $name
* @property string $slug
* @property string $field
* @property string|null $text
* @property string|null $full_text
* @property int|null $integer
* @property float|null $decimal
* @property int $active
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo findSimilarSlugs($attribute, $config, $slug)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereDecimal($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereField($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereFullText($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereInteger($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereText($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereUpdatedAt($value)
* @mixin \Eloquent
* @property string $type
* @property int $bool
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereBool($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfo whereType($value)
*/
class CMSInfo extends Model
{
use Sluggable;
protected static $types = [
'text' => 'Text (190 Zeichen)',
'full_text' => 'Full Text (50K Zeichen)',
'integer' => 'Zahl (10 Stellen)',
'decimal' => 'Kommazahl (10,2 Stellen)',
'bool' => 'an (1) / aus (0)',
];
protected $connection = 'mysql_stern';
protected $table = 'c_m_s_infos';
protected $fillable = [
'name', 'slug', 'type', 'text', 'full_text', 'integer', 'decimal', 'bool'
];
public function sluggable()
{
return [
'slug' => [
'source' => 'name'
]
];
}
public static function getTypeOptions($setKey = false){
$options = self::$types;
$ret = "";
foreach ($options as $key => $option){
$attr = ($key == $setKey) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
}
return $ret;
}
public function getTypeName(){
return isset(self::$types[$this->type]) ? self::$types[$this->type] : '';
}
public function getPreviewContent(){
$content = $this->{$this->type};
if(strlen($content) > 40){
return substr($content, 0, 40)." ...";
}
return $content;
}
public function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);
}
public function setDecimalAttribute($value)
{
$value = $this->_format_number($value);
$value = substr($value, -13);
$this->attributes['decimal'] = (float) str_replace(',', '.', $value);
}
public function getDecimalAttribute()
{
if(isset($this->attributes['decimal'])){
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
return number_format(($this->attributes['decimal']), 2, ',', '.');
}
return "";
}
public function setIntegerAttribute($value)
{
$value = $this->_format_number($value);
$value = substr($value, -10);
$this->attributes['integer'] = (int) $value;
}
public function setBoolAttribute($value)
{
$this->attributes['bool'] = (bool) $value;
}
public static function getContentBySlug($slug){
$content = CMSInfo::whereSlug(trim($slug))->first();
if($content){
switch ($content->type){
case 'text':
return $content->text;
break;
case 'full_text':
return $content->full_text;
break;
case 'integer':
return $content->integer;
break;
case 'decimal':
return $content->decimal;
break;
case 'bool':
return $content->bool;
break;
}
}
return false;
}
public static function setContentBySlug($slug, $value, $type = "text"){
$content = CMSInfo::whereSlug(trim($slug))->first();
if(!$content) {
$content = CMSInfo::create([
'name' => $slug,
'type' => $type,
]);
}
switch ($content->type){
case 'text':
$content->text = $value;
break;
case 'full_text':
$content->full_text = $value;
break;
case 'integer':
$content->integer = $value;
break;
case 'decimal':
$content->decimal = $value;
break;
case 'bool':
$content->bool = $value;
break;
}
$content->save();
return $content;
}
}

View file

@ -0,0 +1,62 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\CMSInfoAvailable
*
* @property int $id
* @property string $type
* @property bool $active
* @property string|null $from
* @property string|null $to
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereFrom($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereTo($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereUpdatedAt($value)
* @mixin \Eloquent
* @property int $wday
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoAvailable whereWday($value)
*/
class CMSInfoAvailable extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'c_m_s_info_availables';
protected $fillable = [
'type', 'wday', 'active', 'from', 'to'
];
protected $casts = [
'active' => 'bool',
];
public static function getContentBySlug($type, $wday){
return CMSInfoAvailable::whereType($type)->whereWday($wday)->first();
}
public static function setContentBySlug($type, $wday, $values){
$content = CMSInfoAvailable::whereType($type)->whereWday($wday)->first();
if(!$content) {
$content = CMSInfoAvailable::create([
'type' => $type,
'wday' => $wday,
]);
}
$content->fill($values);
$content->save();
return $content;
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\CMSInfoHoliday
*
* @property int $id
* @property bool $local
* @property bool $phone
* @property string $from
* @property string $to
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday whereFrom($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday whereLocal($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday wherePhone($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday whereTo($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\CMSInfoHoliday whereUpdatedAt($value)
* @mixin \Eloquent
*/
class CMSInfoHoliday extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'c_m_s_info_holidays';
protected $fillable = [
'local', 'phone', 'from', 'to'
];
protected $casts = [
'local' => 'bool',
'phone' => 'bool',
];
public function getFromAttribute()
{
return isset($this->attributes['from']) ? Carbon::parse($this->attributes['from'])->format('d.m.Y') : '';
}
public function setFromAttribute($value)
{
if (!$value) {
$this->attributes['from'] = null;
} else {
$this->attributes['from'] = Carbon::parse($value)->format('Y-m-d'); //(new Carbon($value))->format('Y-m-d');
}
}
public function getToAttribute()
{
return isset($this->attributes['to']) ? Carbon::parse($this->attributes['to'])->format('d.m.Y') : '';
}
public function setToAttribute($value)
{
if (!$value) {
$this->attributes['to'] = null;
} else {
$this->attributes['to'] = Carbon::parse($value)->format('Y-m-d'); //(new Carbon($value))->format('Y-m-d');
}
}
/* //local / phone
//local / phone
$table->boolean('local')->default(true);
$table->boolean('phone')->default(true);
$table->date('from');
$table->date('to');
*/
}

View file

@ -67,7 +67,7 @@ class CmsContent extends Model
{
$value = $this->_format_number($value);
$value = substr($value, -13);
$this->attributes['decimal'] = floatval(str_replace(',', '.', $value));
$this->attributes['decimal'] = (float) str_replace(',', '.', $value);
}
public function getDecimalAttribute()

View file

@ -37,7 +37,7 @@ class HTMLHelper
private static $days = [
0 => 'Sonntag',
1=> 'Montag',
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
@ -45,6 +45,17 @@ class HTMLHelper
6 => 'Samstag',
];
public static $de_days = [
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag',
7 => 'Sonntag',
];
private static $roles = [
0 => 'Kunde',
@ -61,13 +72,19 @@ class HTMLHelper
public static function getMonth($i){
return self::$months[intval($i)];
return self::$months[$i];
}
public static function getDay($i){
return self::$days[intval($i)];
return self::$days[$i];
}
public static function getDeDays(){
return self::$de_days;
}
public static function getRoleLabel($role_id = 0, $pre = "", $post = ""){
return '<span class="badge badge-pill '.self::getLable($role_id).'">'.$pre.self::$roles[$role_id].$post.'</span>';
}
@ -130,6 +147,38 @@ class HTMLHelper
return $ret;
}
public static function createTimeRange($start = '0:00', $end = "23:30", $interval = '30 mins'){
$start_time = strtotime($start);
$end_time = strtotime($end);
$format = 'G:i';
$current = time();
$add_time = strtotime('+'.$interval, $current);
$diff = $add_time - $current;
$times = [];
while ($start_time < $end_time){
$times[] = date($format, $start_time);
$start_time += $diff;
}
$times[] = date($format, $start_time);
return $times;
}
public static function getTimeInSteps($id = false){
$times = self::createTimeRange();
$ret = '';
foreach ($times as $item){
$attr = ($item === $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$item.'" '.$attr.'>'.$item.'</option>\n';
}
return $ret;
}
public static function getRangeOptions($id = false, $range = 30, $name = "", $start=1){
$range = range($start, $range);