Feedback in V3

This commit is contained in:
Kevin Adametz 2018-12-27 17:38:05 +01:00
parent 765d6a2f6b
commit 6e0c7e8706
19 changed files with 1141 additions and 491 deletions

View file

@ -0,0 +1,82 @@
<?php
namespace App\Http\Controllers;
use App\Models\Feedback;
use Input;
class CMSFeedbackController extends Controller
{
/*
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$data = [
'feedbacks' => Feedback::all(),//Feedback::where('lvl', 1)->get(),
];
return view('cms.feedback.index', $data);
}
public function detail($id)
{
if($id == "new") {
$feedback = new Feedback();
$id = 'new';
}else{
$feedback = Feedback::findOrFail($id);
$id = $feedback->id;
}
$data = [
'feedback' => $feedback,
'id' => $id,
];
return view('cms.feedback.detail', $data);
}
public function store($id)
{
$data = Input::all();
if($id == "new") {
$feedback = new Feedback();
}else{
$feedback = Feedback::findOrFail($id);
}
$feedback->title = $data['title'];
$feedback->status = isset($data['status']) ? true : false;
$feedback->slug = $data['slug'];
$feedback->date = $data['date'];
$feedback->content = $data['content'];
$feedback->description = $data['description'];
$feedback->pagetitle = $data['pagetitle'];
$feedback->keywords = $data['keywords'];
//parent
$feedback->save();
\Session()->flash('alert-save', '1');
return redirect(route('cms_feedback_detail', [$feedback->id]));
}
}

View file

@ -120,6 +120,12 @@ class DraftController extends Controller
foreach ($draft->draft_items as $draft_item){
$draft_item->delete();
}
foreach ($draft->travel_program_drafts as $travel_program_draft){
$travel_program_draft->delete();
}
$draft->delete();
\Session()->flash('alert-save', '1');
return redirect(route('drafts'));

74
app/Models/Feedback.php Normal file
View file

@ -0,0 +1,74 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use HTMLHelper;
class Feedback extends Page
{
protected $table = 'page';
public static function boot()
{
parent::boot();
static::addGlobalScope(function ($query) {
$query->where('model', 'feedback');
$query->orderBy('lvl', 'ASC');
$query->orderBy('date', 'DESC');
});
}
public function parent()
{
return $this->belongsTo('App\Models\Feedback', 'owner');
}
public function getParent()
{
if ($this->lvl == 2) {
$this->parent();
}
return false;
}
public function setContentAttribute($value)
{
if (!$value) {
$this->attributes['content'] = $value;
} else {
$this->attributes['content'] = HTMLHelper::filterHTML($value, ['src' => ['removeHost']], true);
}
}
public function getParentsArray(){
//lvl 0
return Page::where('model', 'feedback')->where('lvl', 1)->get()->pluck('title', 'id');
}
//$feedbacks = Feedback::where('lvl', 1)->get();
public function getDateRow()
{
return$this->attributes['date'];
}
public function getDateAttribute()
{
return isset($this->attributes['date']) ? Carbon::parse($this->attributes['date'])->format("d.m.Y") : '';
}
public function setDateAttribute($value)
{
if (!$value) {
$this->attributes['date'] = null;
} else {
$this->attributes['date'] = (new Carbon($value))->format('Y-m-d');
}
}
}

13
app/Models/Page.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Page extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'page';
}

View file

@ -172,6 +172,70 @@ class HTMLHelper
return "alle Wochentage";
}
public static function getParentBy($obj = NULL, $options, $empty=true){
$ret = "";
$setId = 0;
if($obj){
$setId = $obj->id;
}
if($empty){
$ret .= '<option value="">Non-Parent</option>\n';
}
foreach ($options as $id => $name){
$attr = ($id === $setId) ? 'selected="selected"' : '';
$ret .= '<option value="'.$id.'" '.$attr.'>'.$name.'</option>\n';
}
return $ret;
}
public static function filterHTML($html, $arg = [], $save = false){
$dom = new \DOMDocument('1.0', 'UTF-8');
//@$dom->loadHTML();
@$dom->loadHTML( mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
if(isset($arg['src'])){
if(in_array('addHost', $arg['src'])){
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$host = config('app.url_stern');
if(strpos($src, $host) === false){
$src = $host."/".ltrim($src, '/');
}
$image->setAttribute('src', $src);
}
}
if(in_array('removeHost', $arg['src'])){
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$host = config('app.url_stern');
if(strpos($src, $host) !== false){
$src = str_replace($host, '', $src);
}
$image->setAttribute('src', $src);
}
}
}
$html = $dom->saveHTML();
$html = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', $html);
if($save){
return mb_convert_encoding($html, "UTF-8", "HTML-ENTITIES");
}
return $html;
}
/*
public static function getIndustrySectorsWithoutParents($id = false, $sameId = false, $all = true){
$values = IndustrySector::where('parent_id', null)->get();

View file

@ -6,3 +6,11 @@ if (! function_exists('make_old_url')) {
return config('app.old_url').$path;
}
}
if (! function_exists('make_v2_url')) {
function make_v2_url($path)
{
return config('app.url_v2').$path;
}
}