215 lines
No EOL
8.9 KiB
PHP
215 lines
No EOL
8.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* App\Models\TravelCountry
|
|
*
|
|
* @property int $id
|
|
* @property int|null $crm_id
|
|
* @property string $name
|
|
* @property string|null $html_information
|
|
* @property string|null $entry_requirements
|
|
* @property int|null $feedback_page_id
|
|
* @property int|null $is_customer_country
|
|
* @property int|null $active_frontend
|
|
* @property int|null $active_backend
|
|
* @property string|null $updated_at
|
|
* @property string|null $created_at
|
|
* @property-read \App\Models\Page|null $feedback_page
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelNationalityRequirement[] $travel_nationality_requirements
|
|
* @property-read \App\Models\TravelProgramCountry $travel_program_country
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereActiveBackend($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereActiveFrontend($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereCrmId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereEntryRequirements($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereFeedbackPageId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereHtmlInformation($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereIsCustomerCountry($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry query()
|
|
* @property string|null $slug
|
|
* @property string|null $text_before
|
|
* @property string|null $text_after
|
|
* @property string|null $contact_headline
|
|
* @property string|null $contact_text_1
|
|
* @property string|null $contact_text_2
|
|
* @property string|null $contact_text_3
|
|
* @property string|null $contact_text_4
|
|
* @property string|null $contact_footer
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactFooter($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactHeadline($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactText1($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactText2($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactText3($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactText4($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereSlug($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereTextAfter($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereTextBefore($value)
|
|
* @property array|null $contact_lands
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactLands($value)
|
|
* @property-read int|null $travel_nationality_requirements_count
|
|
* @property array|null $contact_emails
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereContactEmails($value)
|
|
* @property array|null $mail_dirs
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereMailDirs($value)
|
|
* @property string $mail_dir_name
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereMailDirName($value)
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\GeneralFile[] $general_files
|
|
* @property-read int|null $general_files_count
|
|
* @property-read \App\Models\Sym\TravelCountry|null $crm_travel_country
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TravelCountryService[] $travel_country_services
|
|
* @property-read int|null $travel_country_services_count
|
|
* @property string|null $destco
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelCountry whereDestco($value)
|
|
* @property string|null $visum_text
|
|
* @method static \Illuminate\Database\Eloquent\Builder|TravelCountry whereVisumText($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class TravelCountry extends Model
|
|
{
|
|
//use the connection to sec. Datebase sterntours
|
|
protected $connection = 'mysql_stern';
|
|
|
|
protected $table = 'travel_country';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'destco',
|
|
'slug',
|
|
'html_information',
|
|
'text_before',
|
|
'text_after',
|
|
'contact_lands',
|
|
'mail_dir_name',
|
|
'mail_dirs',
|
|
'contact_headline',
|
|
'contact_text_1',
|
|
'contact_text_2',
|
|
'contact_text_3',
|
|
'contact_text_4',
|
|
'contact_footer',
|
|
'visum_text',
|
|
'entry_requirements',
|
|
'contact_emails',
|
|
'is_customer_country',
|
|
'active_frontend',
|
|
'active_backend'
|
|
|
|
];
|
|
|
|
protected $casts = ['contact_lands' => 'array', 'mail_dirs' => 'array', 'contact_emails' => 'array'];
|
|
|
|
|
|
public $timestamps = false;
|
|
|
|
public function travel_program_country()
|
|
{
|
|
return $this->hasOne('App\Models\TravelProgramCountry', 'country_id', 'id');
|
|
}
|
|
|
|
public function feedback_page()
|
|
{
|
|
return $this->belongsTo('App\Models\Page', 'feedback_page_id', 'id');
|
|
}
|
|
|
|
public function crm_travel_country()
|
|
{
|
|
return $this->belongsTo(\App\Models\Sym\TravelCountry::class, 'crm_id', 'id');
|
|
}
|
|
|
|
public function travel_nationality_requirements()
|
|
{
|
|
return $this->hasMany('App\Models\TravelNationalityRequirement', 'travel_country_id', 'id');
|
|
}
|
|
|
|
public function general_files()
|
|
{
|
|
return $this->hasMany(GeneralFile::class, 'travel_country_id', 'id');
|
|
}
|
|
|
|
public function travel_country_services()
|
|
{
|
|
return $this->hasMany(TravelCountryService::class, 'travel_country_id', 'id')->orderBy('pos', 'DESC');
|
|
}
|
|
|
|
public function setSlugAttribute( $value ) {
|
|
if(!isset($value) || $value == ""){
|
|
$this->attributes['slug'] = Str::slug(pre_slug($this->name), '-');
|
|
}else{
|
|
$this->attributes['slug'] = Str::slug(pre_slug($value), '-');
|
|
}
|
|
}
|
|
|
|
public function getContactLandsArray(){
|
|
$ret = [];
|
|
if($this->contact_lands){
|
|
foreach ($this->contact_lands as $contact_land_id){
|
|
$travel_country = TravelCountry::where('crm_id', $contact_land_id)->first();
|
|
if($travel_country){
|
|
$ret[] = $travel_country->name;
|
|
}
|
|
}
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
public function getMailDirs($id){
|
|
return isset($this->mail_dirs[$id]) ? $this->mail_dirs[$id] : [];
|
|
}
|
|
|
|
public function getContactLandsModels(){
|
|
$ret = [];
|
|
if($this->contact_lands){
|
|
foreach ($this->contact_lands as $contact_land_id){
|
|
if($travel_country = TravelCountry::where('crm_id', $contact_land_id)->first()){
|
|
$ret[$travel_country->id] = $travel_country;
|
|
}
|
|
}
|
|
}else{
|
|
$ret[$this->id] = $this;
|
|
}
|
|
return $ret;
|
|
}
|
|
public function getNationalityRequirement($travel_nationality_id){
|
|
|
|
$model = TravelNationalityRequirement::where('travel_country_id', $this->id)->where('travel_nationality_id', $travel_nationality_id)->first();
|
|
if($model){
|
|
return $model->text;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public function setNationalityRequirement($travel_nationality_id, $text){
|
|
$model = TravelNationalityRequirement::where('travel_country_id', $this->id)->where('travel_nationality_id', $travel_nationality_id)->first();
|
|
if($model){
|
|
$model->text = $text;
|
|
$model->save();
|
|
}else{
|
|
$data = [
|
|
'travel_country_id' => $this->id,
|
|
'travel_nationality_id' => $travel_nationality_id,
|
|
'text' => $text,
|
|
];
|
|
TravelNationalityRequirement::create($data);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public static function getAsNameIdArray($empty = true, $id = 'crm_id'){
|
|
$ret = TravelCountry::get()->pluck('name', $id)->toArray();
|
|
if($empty){
|
|
$first = [null => "-"];
|
|
return $first + $ret;
|
|
}
|
|
return $ret;
|
|
}
|
|
} |