199 lines
No EOL
6.8 KiB
PHP
199 lines
No EOL
6.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
|
|
use App\Models\TravelClass;
|
|
use App\Models\TravelProgram;
|
|
use App\Models\TravelProgramDraft;
|
|
|
|
class TravelProgramRepository extends BaseRepository {
|
|
|
|
|
|
public function __construct(TravelProgram $model)
|
|
{
|
|
$this->model = $model;
|
|
}
|
|
|
|
public function update($data)
|
|
{
|
|
/*if($data['id'] == "new"){
|
|
$this->model = TravelProgram::createNew();
|
|
}
|
|
else{
|
|
$this->model = $this->getById($data['id']);
|
|
}
|
|
$this->checkDraftsWeekdays($data['weekdays']);
|
|
$data['weekdays'] = $this->model->setWeekdaysFromArray($data['weekdays']);
|
|
$this->model->fill($data);
|
|
$this->model->status = isset($data['status']) ? true : false;
|
|
$this->model->save();
|
|
return $this->model;*/
|
|
}
|
|
|
|
|
|
public function updateGeneral($id, $data){
|
|
//weekdays
|
|
$this->model = TravelProgram::findOrFail($id);
|
|
|
|
$this->checkDraftsWeekdays($data['weekdays']);
|
|
$data['weekdays'] = $this->model->setWeekdaysFromArray($data['weekdays']);
|
|
|
|
$fill = [
|
|
'title' => $data['title'],
|
|
'subtitle' => $data['subtitle'],
|
|
'program_code' => $data['program_code'],
|
|
'program_type' => $data['program_type'] ? $data['program_type'] : null,
|
|
'category_id' => $data['category_id'] ? $data['category_id'] : null,
|
|
'travel_country' => $data['travel_country'] ? $data['travel_country'] : null,
|
|
'travel_agenda' => $data['travel_agenda'] ? $data['travel_agenda'] : null,
|
|
'travel_category' => $data['travel_category'] ? $data['travel_category'] : null,
|
|
'travel_company' => $data['travel_company'] ? $data['travel_company'] : null,
|
|
'status' => isset($data['status']) ? 1 : 0,
|
|
'weekdays' => $data['weekdays'],
|
|
];
|
|
$this->model->fill($fill);
|
|
$this->model->save();
|
|
return $this->model;
|
|
}
|
|
|
|
|
|
public function updateDetail($id, $data){
|
|
//weekdays
|
|
$this->model = TravelProgram::findOrFail($id);
|
|
|
|
$this->checkDraftsWeekdays($data['weekdays']);
|
|
$data['weekdays'] = $this->model->setWeekdaysFromArray($data['weekdays']);
|
|
|
|
$fill = [
|
|
'default_flight_price' => $data['default_flight_price'] ? $data['default_flight_price'] : null,
|
|
'deposit_percent' => $data['deposit_percent'] ? $data['deposit_percent'] : null,
|
|
'discount' => $data['discount'] ? $data['discount'] : null,
|
|
'discount_is_percent_value' => $data['discount_is_percent_value'] ? $data['discount_is_percent_value'] : null,
|
|
'travel_arrival_point_id' => $data['travel_arrival_point_id'] ? $data['travel_arrival_point_id'] : null,
|
|
'max_age_for_children' => $data['max_age_for_children'] ? $data['max_age_for_children'] : null,
|
|
//'url' => $data['url'] ? $data['url'] : null,
|
|
'generalnote' => $data['generalnote'] ? $data['generalnote'] : null,
|
|
'payment_conditions' => $data['payment_conditions'] ? $data['payment_conditions'] : null,
|
|
];
|
|
$this->model->fill($fill);
|
|
$this->model->save();
|
|
return $this->model;
|
|
|
|
}
|
|
|
|
public function updatePage($id, $data){
|
|
//weekdays
|
|
$this->model = TravelProgram::findOrFail($id);
|
|
if(!$this->model->page){
|
|
return $this->model;
|
|
}
|
|
$fill = [
|
|
'title' => $data['page_title'] ? $data['page_title'] : null,
|
|
'pagetitle' => $data['page_pagetitle'] ? $data['page_pagetitle'] : null,
|
|
'description' => $data['page_description'] ? $data['page_description'] : null,
|
|
'slug' => $data['page_slug'] ? $data['page_slug'] : null,
|
|
|
|
];
|
|
$this->model->page->fill($fill);
|
|
$this->model->page->save();
|
|
return $this->model;
|
|
|
|
}
|
|
/*
|
|
|
|
'profit_margin',
|
|
'program_duration',
|
|
'is_seasonal',
|
|
'youth',
|
|
'slider_info',
|
|
'organizer',
|
|
'generalnote',
|
|
'included',
|
|
'class_description',
|
|
'excluded',
|
|
'advices',
|
|
'notes',
|
|
'html_description',
|
|
'insurance_1',
|
|
'insurance_2',
|
|
'insurance_3',
|
|
'insurance_4',
|
|
'in_slider',
|
|
'show_map',
|
|
'map_html',
|
|
'map_image',
|
|
'map_image_ext',
|
|
'netto_prices_in_euro',
|
|
'text_right',
|
|
'position',
|
|
*/
|
|
|
|
public function checkDraftsWeekdays($weekdays){
|
|
if(isset($weekdays) && is_array($weekdays) && $weekdays[0] === NULL){
|
|
$weekdays = range(0, 6);
|
|
}
|
|
foreach($this->model->travel_program_drafts as $travel_program_draft){
|
|
if($travel_program_draft->weekdays !== NULL){
|
|
$wd = [];
|
|
foreach ($travel_program_draft->weekdays as $weekday){
|
|
if(in_array($weekday, $weekdays)){
|
|
$wd[] = $weekday;
|
|
}
|
|
}
|
|
if(count($wd)){
|
|
$travel_program_draft->weekdays = $wd;
|
|
}else{
|
|
$travel_program_draft->weekdays = NULL;
|
|
}
|
|
$travel_program_draft->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function updateClass($data)
|
|
{
|
|
if($data['id'] == "new"){
|
|
$travel_class = TravelClass::create([
|
|
'program_id' => $data['program_id'],
|
|
'name' => $data['name'],
|
|
'standard' => isset($data['standard']) ? true : false,
|
|
'description' => $data['description'],
|
|
]);
|
|
}else {
|
|
$travel_class = TravelClass::findOrFail($data['id']);
|
|
$travel_class->name = $data['name'];
|
|
$travel_class->standard = isset($data['standard']) ? true : false;
|
|
$travel_class->description = $data['description'];
|
|
$travel_class->save();
|
|
}
|
|
return $travel_class;
|
|
}
|
|
|
|
public function updateDraft($data)
|
|
{
|
|
if(isset($data['weekdays']) && count($data['weekdays']) > 1 && in_array(NULL, $data['weekdays'])){
|
|
$data['weekdays'] = array_filter($data['weekdays'], 'is_numeric');
|
|
sort($data['weekdays']);
|
|
}
|
|
if($data['id'] == "new"){
|
|
$travel_program_draft = TravelProgramDraft::create([
|
|
'travel_program_id' => $data['travel_program_id'],
|
|
'travel_class_id' => $data['travel_class_id'],
|
|
'draft_id' => $data['draft_id'],
|
|
'weekdays' => isset($data['weekdays']) ? $data['weekdays'] : NULL,
|
|
]);
|
|
}else{
|
|
$travel_program_draft = TravelProgramDraft::findOrFail($data['id']);
|
|
$travel_program_draft->draft_id = $data['draft_id'];
|
|
$travel_program_draft->travel_class_id = $data['travel_class_id'];
|
|
$travel_program_draft->weekdays = isset($data['weekdays']) ? $data['weekdays'] : NULL;
|
|
$travel_program_draft->save();
|
|
}
|
|
return $travel_program_draft;
|
|
}
|
|
|
|
|
|
|
|
} |