saving new visualizer done
This commit is contained in:
@@ -689,10 +689,168 @@ class AdminController extends Controller
|
||||
public function saveNewVisualizer(Request $request){
|
||||
$post = $request->all();
|
||||
$AdminModel = new AdminModel;
|
||||
$tmp_arr_visualizer_pattern = array();
|
||||
$template_thumbnail_path = "templates/thumbnail/";
|
||||
$template_path = "uniform-templates/";
|
||||
|
||||
foreach($post['visualizer_pattern'] as $item_visualizer){
|
||||
$arr_visualizer_pattern = explode("##", $item_visualizer);
|
||||
array_push($tmp_arr_visualizer_pattern, $arr_visualizer_pattern['0']);
|
||||
}
|
||||
|
||||
$orig_visualizer_thumbnail_filename = $request->file('visualizer_thumbnail')->getClientOriginalName();
|
||||
|
||||
$new_visualizer_thumbnail_filename = $this->generateFileName($orig_visualizer_thumbnail_filename);
|
||||
Storage::disk('uploads')->put($template_thumbnail_path . $new_visualizer_thumbnail_filename, fopen($request->file('visualizer_thumbnail'), 'r+'));
|
||||
|
||||
$final_arr_visualizer_pattern = implode(",", $tmp_arr_visualizer_pattern);
|
||||
|
||||
$data = array(
|
||||
'SportsId' => $post['sportName'],
|
||||
'Category' => $post['sport_category'],
|
||||
'Thumbnail' => $template_thumbnail_path . $new_visualizer_thumbnail_filename,
|
||||
'TemplateName' => $post['visualizer_name'],
|
||||
'Trim' => $post['numberOfTrims'],
|
||||
'PatternId' => $final_arr_visualizer_pattern,
|
||||
'WithGradient' => ($post['visualizer_format'] == "png") ? 'no' : null,
|
||||
'TemplateFormat'=> $post['visualizer_format'],
|
||||
'IsActive' => "TRUE"
|
||||
);
|
||||
|
||||
|
||||
$res_saveNewVisualizer = $AdminModel->saveNewVisualizer($data);
|
||||
|
||||
$templateCode = "TEMP-" . str_pad($res_saveNewVisualizer['lastId'], 5,'0',STR_PAD_LEFT);
|
||||
$data_to_update = array(
|
||||
'TemplateCode' => $templateCode ,
|
||||
'HashTemplateCode' => md5($templateCode)
|
||||
);
|
||||
|
||||
$res_updateVisualizer = $AdminModel->updateVisualizer($res_saveNewVisualizer['lastId'], $data_to_update);
|
||||
|
||||
$data_def_main_color = array(
|
||||
'TemplateCode' => $templateCode ,
|
||||
'RGBColor' => $post['main_body_def_color'],
|
||||
'DisplayName' => $post['main_body_label']
|
||||
);
|
||||
|
||||
$res_saveVisualizerDefaultBodyColor = $AdminModel->saveVisualizerDefaultBodyColor($data_def_main_color);
|
||||
|
||||
if($post['numberOfTrims'] != 0){
|
||||
for($i = 0; $i < $post['numberOfTrims']; $i++){
|
||||
$t = $i + 1;
|
||||
$data_def_trim_color = array(
|
||||
'TrimNumber' => $t,
|
||||
'TemplateCode' => $templateCode,
|
||||
'RGBColor' => $post['trim_def_color'][$i],
|
||||
'DisplayName' => $post['trim_label'][$i]
|
||||
);
|
||||
$AdminModel->saveVisualizerDefaultTrimColor($data_def_trim_color);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// front saving
|
||||
if(isset($post['front_visualizer'])){
|
||||
$orig_front_visualize_filename = $request->file('front_visualizer')->getClientOriginalName();
|
||||
|
||||
$new_front_visualize_filename = $this->generateFileName($orig_front_visualize_filename);
|
||||
Storage::disk('uploads')->put($template_path . $templateCode . '/DISPLAY/' . $new_front_visualize_filename, fopen($request->file('front_visualizer'), 'r+'));
|
||||
|
||||
$data_front_visualizer = array(
|
||||
'TemplateCode' => $templateCode ,
|
||||
'HashTemplateCode' => md5($templateCode),
|
||||
'Type' => $post['front_visualizer_type'],
|
||||
'Side' => "Front",
|
||||
'Path' => $template_path . $templateCode . '/DISPLAY/' . $new_front_visualize_filename,
|
||||
'TemplateFormat' => $post['visualizer_format'],
|
||||
'IsActive' => "TRUE"
|
||||
);
|
||||
|
||||
$AdminModel->saveVisualizerPath($data_front_visualizer);
|
||||
// var_dump($data_front_visualizer);
|
||||
|
||||
}
|
||||
|
||||
// back saving
|
||||
if(isset($post['back_visualizer'])){
|
||||
$orig_front_visualize_filename = $request->file('back_visualizer')->getClientOriginalName();
|
||||
|
||||
$new_back_visualize_filename = $this->generateFileName($orig_front_visualize_filename);
|
||||
Storage::disk('uploads')->put($template_path . $templateCode . '/DISPLAY/' . $new_back_visualize_filename, fopen($request->file('back_visualizer'), 'r+'));
|
||||
|
||||
$data_back_visualizer = array(
|
||||
'TemplateCode' => $templateCode ,
|
||||
'HashTemplateCode' => md5($templateCode),
|
||||
'Type' => $post['back_visualizer_type'],
|
||||
'Side' => "Back",
|
||||
'Path' => $template_path . $templateCode . '/DISPLAY/' . $new_back_visualize_filename,
|
||||
'TemplateFormat' => $post['visualizer_format'],
|
||||
'IsActive' => "TRUE"
|
||||
);
|
||||
|
||||
$AdminModel->saveVisualizerPath($data_back_visualizer);
|
||||
|
||||
}
|
||||
|
||||
// right saving
|
||||
if(isset($post['right_visualizer'])){
|
||||
$orig_right_visualize_filename = $request->file('right_visualizer')->getClientOriginalName();
|
||||
|
||||
$new_right_visualize_filename = $this->generateFileName($orig_right_visualize_filename);
|
||||
Storage::disk('uploads')->put($template_path . $templateCode . '/DISPLAY/' . $new_right_visualize_filename, fopen($request->file('right_visualizer'), 'r+'));
|
||||
|
||||
$data_right_visualizer = array(
|
||||
'TemplateCode' => $templateCode ,
|
||||
'HashTemplateCode' => md5($templateCode),
|
||||
'Type' => $post['right_visualizer_type'],
|
||||
'Side' => "Right",
|
||||
'Path' => $template_path . $templateCode . '/DISPLAY/' . $new_right_visualize_filename,
|
||||
'TemplateFormat' => $post['visualizer_format'],
|
||||
'IsActive' => "TRUE"
|
||||
);
|
||||
|
||||
$AdminModel->saveVisualizerPath($data_right_visualizer);
|
||||
|
||||
}
|
||||
|
||||
// left saving
|
||||
if(isset($post['left_visualizer'])){
|
||||
$orig_left_visualize_filename = $request->file('left_visualizer')->getClientOriginalName();
|
||||
|
||||
$new_left_visualize_filename = $this->generateFileName($orig_left_visualize_filename);
|
||||
Storage::disk('uploads')->put($template_path . $templateCode . '/DISPLAY/' . $new_left_visualize_filename, fopen($request->file('left_visualizer'), 'r+'));
|
||||
|
||||
$data_left_visualizer = array(
|
||||
'TemplateCode' => $templateCode ,
|
||||
'HashTemplateCode' => md5($templateCode),
|
||||
'Type' => $post['left_visualizer_type'],
|
||||
'Side' => "Left",
|
||||
'Path' => $template_path . $templateCode . '/DISPLAY/' . $new_left_visualize_filename,
|
||||
'TemplateFormat' => $post['visualizer_format'],
|
||||
'IsActive' => "TRUE"
|
||||
);
|
||||
|
||||
$AdminModel->saveVisualizerPath($data_left_visualizer);
|
||||
}
|
||||
|
||||
return response()->json(array(
|
||||
'success' => true,
|
||||
'message' => "Visualizer is successfully added."
|
||||
));
|
||||
|
||||
var_dump($post);
|
||||
}
|
||||
|
||||
|
||||
public function generateFileName($filename){
|
||||
|
||||
$lower_filename = str_replace(' ','-',strtolower($filename));
|
||||
$getExt = substr($lower_filename, strrpos($lower_filename, '.'));;
|
||||
$clean_filename = preg_replace("/\.[^.\s]{3,4}$/", "", $lower_filename);
|
||||
$final_filename = date('Ymd') . "-" . time().'-' . $clean_filename . "-".$getExt;
|
||||
|
||||
return $final_filename;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -258,4 +258,39 @@ class AdminModel extends Model
|
||||
->get();
|
||||
return $i;
|
||||
}
|
||||
|
||||
function saveNewVisualizer($data){
|
||||
$i = DB::table('templates')->insert($data);
|
||||
$id = DB::getPdo()->lastInsertId();
|
||||
|
||||
return array(
|
||||
'i' => $i,
|
||||
'lastId' => $id
|
||||
);
|
||||
}
|
||||
|
||||
function updateVisualizer($id, $data){
|
||||
|
||||
$i = DB::table('templates')
|
||||
->where("Id", $id)
|
||||
->update($data);
|
||||
return $i;
|
||||
}
|
||||
|
||||
function saveVisualizerDefaultBodyColor($data){
|
||||
$i = DB::table('template_body_colors')->insert($data);
|
||||
|
||||
return $i;
|
||||
}
|
||||
|
||||
function saveVisualizerDefaultTrimColor($data){
|
||||
$i = DB::table('template_trim_colors')->insert($data);
|
||||
return $i;
|
||||
}
|
||||
|
||||
function saveVisualizerPath($data){
|
||||
$i = DB::table('template_paths')->insert($data);
|
||||
return $i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user