mein-sterntours/app/Models/SidebarWidget.php
2019-02-14 13:49:53 +01:00

100 lines
2.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SidebarWidget extends Model
{
protected static $shows = [
'home' => 'Startseite',
'search' => 'Suche',
'default' => 'Standartseiten',
'overview' => 'Übersicht',
'program' => 'Programme',
'booking' => 'Buchungen',
'bookingconfirm' => 'Buchungsbestätigung',
];
protected static $components = [
'aboutSternToursWidget' => 'Wir: STERN TOURS',
'searchSidebarWidget' => 'Kulturreisen suchen',
'navSidebarWidget' => 'Reiseprogramme',
'topVotingWidget' => 'TOP bewertet',
'feedbacksSidebarWidget' => 'Kundenfeedback',
'travelGuideSidebarWidget' => 'Reiseführer',
'travelMagazineSidebarWidget' => 'Reisemagazin',
'offersSidebarWidget' => 'Angebote',
];
protected $connection = 'mysql_stern';
protected $table = 'sidebar_widgets';
protected $casts = ['show_at' => 'array'];
protected $fillable = [
'name', 'component', 'html', 'show_at', 'pos', 'active'
];
public static function getComponentsOptions($setKey = false){
$options = self::$components;
$ret = '<option value="">Keine Komponente laden (nur HTML)</option>\n';
foreach ($options as $key => $option){
$attr = ($key == $setKey) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
}
return $ret;
}
public static function getShowsOptions($setKey){
if(!is_array($setKey))
$setKey = [];
$options = self::$shows;
$ret = "";
foreach ($options as $key => $option){
$attr = in_array($key, $setKey) ? 'selected="selected"' : '';
$ret .= '<option value="'.$key.'" '.$attr.'>'.$option.'</option>\n';
}
return $ret;
}
public function getShowsAtString(){
$ret = "";
if($this->show_at){
foreach($this->show_at as $show_at){
if(isset(self::$shows[$show_at])){
$ret .= self::$shows[$show_at].", ";
}
}
}
return rtrim($ret, ", ");
}
/*
* public function getVotesDetailAttribute($details)
{
return json_decode($details, true);
}
then when you will call $store->votes_detail you will get the expected result.
After that you can use mutators to convert an array back to JSON when it is saved back in the DB. Define the method setVotesDetailAttribute($value) as follows:
public function setVotesDetailsAttribute($value)
{
$this->attributes['votes_detail'] = json_encode($value);
}
*/
}