mein-sterntours/app/Models/IQTravelProgram.php
2021-11-09 18:38:44 +01:00

181 lines
5.9 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use App\Services\Util;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
/**
* Class IQTravelProgram
*
* @property int $id
* @property string $name
* @property string $code
* @property int $travel_country_id
* @property string $description
* @property string $highlights
* @property string $not_included
* @property string $weekdays
* @property int $days_duration
* @property float $discount
* @property float $deposit_pro
* @property float $price_adult_total
* @property float $price_children_total
* @property string $travel_insurance
* @property bool $active
* @property Carbon $created_at
* @property Carbon $updated_at
* @property TravelCountry $travel_country
* @property Collection|IQTravelProgramItem[] $i_q_travel_program_items
* @package App\Models
* @property int|null $typ
* @property-read int|null $i_q_travel_program_items_count
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram query()
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereDaysDuration($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereDepositPro($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereDiscount($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereHighlights($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereNotIncluded($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram wherePriceAdultTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram wherePriceChildrenTotal($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereTravelCountryId($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereTravelInsurance($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereTyp($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|IQTravelProgram whereWeekdays($value)
* @mixin \Eloquent
*/
class IQTravelProgram extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'i_q_travel_programs';
protected $casts = [
'travel_country_id' => 'int',
'days_duration' => 'int',
'typ' => 'int',
'discount' => 'float',
'deposit_pro' => 'float',
'price_adult_total' => 'float',
'price_children_total' => 'float',
'active' => 'bool',
'weekdays' => 'array',
'travel_insurance' => 'array',
];
protected $fillable = [
'name',
'code',
'typ',
'travel_country_id',
'description',
'highlights',
'not_included',
'weekdays',
'days_duration',
'discount',
'deposit_pro',
'price_adult_total',
'price_children_total',
'travel_insurance',
'active'
];
public static $status_type = [
0 => '-',
4 => '--- ist noch genau zu definieren',
1 => 'individuelles Angebot',
2 => 'Reiseangebot',
3 => 'Reisekonfigurator',
];
public static $days = [
0 => 'Sonntag',
1 => 'Montag',
2 => 'Dienstag',
3 => 'Mittwoch',
4 => 'Donnerstag',
5 => 'Freitag',
6 => 'Samstag'
];
public function travel_country()
{
return $this->belongsTo(TravelCountry::class);
}
public function i_q_travel_program_items()
{
return $this->hasMany(IQTravelProgramItem::class)->orderBy('pos', 'ASC');
}
//price_adult_total
public function getPriceAdultTotalAttribute()
{
return isset($this->attributes['price_adult_total']) ? Util::_number_format($this->attributes['price_adult_total']) : null;
}
public function setPriceAdultTotalAttribute($value)
{
$this->attributes['price_adult_total'] = $value ? Util::_clean_float($value) : null;
}
public function getPriceAdultTotalRaw()
{
return isset($this->attributes['price_adult_total']) ? $this->attributes['price_adult_total'] : 0;
}
public function setPriceAdultTotalRaw($value)
{
return $this->attributes['price_adult_total'] = $value;
}
//price_children_total
public function getPriceChildrenTotalAttribute()
{
return isset($this->attributes['price_children_total']) ? Util::_number_format($this->attributes['price_children_total']) : null;
}
public function setPriceChildrenTotalAttribute($value)
{
$this->attributes['price_children_total'] = $value ? Util::_clean_float($value) : null;
}
public function getPriceChildrenTotalRaw()
{
return isset($this->attributes['price_children_total']) ? $this->attributes['price_children_total'] : 0;
}
public function setPriceChildrenTotalRaw($value)
{
return $this->attributes['price_children_total'] = $value;
}
public static function getWeekdaysOptions($weekdays = []){
if($weekdays === null){
$weekdays = [];
}
$options = range(0, 6);
$ret = '';
foreach ($options as $option){
$attr = (in_array($option, $weekdays)) ? 'selected="selected"' : '';
$ret .= '<option value="'.$option.'" '.$attr.'>'.(isset(self::$days[$option]) ? self::$days[$option] : '').'</option>\n';
}
return $ret;
}
}