mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-09-28 18:13:06 -04:00
236 lines
7.0 KiB
PHP
236 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\LaraBuilder\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Modules\LaraBuilder\Facades\Settings;
|
|
|
|
class OptionBuilderController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Foundation\Application
|
|
*/
|
|
public function index()
|
|
{
|
|
$sections = [];
|
|
|
|
$dir_files = glob(base_path().'/Modules/LaraBuilder/Fields/*');
|
|
if (! empty($dir_files)) {
|
|
foreach ($dir_files as $file) {
|
|
|
|
$setting = include $file;
|
|
if (
|
|
! empty($setting['section'])
|
|
&& ! empty($setting['section']['id'])
|
|
&& empty($setting['section']['tabs'])
|
|
&& ! array_key_exists($setting['section']['id'], $sections)
|
|
) {
|
|
$sections[$setting['section']['id']] = $setting['section'];
|
|
$sections[$setting['section']['id']]['fields'] = $setting['fields'] ?? [];
|
|
} elseif (
|
|
! empty($setting['section'])
|
|
&& ! empty($setting['section']['id'])
|
|
&& ! empty($setting['section']['tabs'])
|
|
&& ! array_key_exists($setting['section']['id'], $sections)
|
|
) {
|
|
$sections[$setting['section']['id']] = $setting['section'];
|
|
if (! empty($setting['fields'])) {
|
|
foreach ($setting['fields'] as $field) {
|
|
$sections[$setting['section']['id']]['fields'][$field['tab_id'] ?? __('option_builder.tab')][] = $field;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return view('larabuilder::optionbuilder.index', compact('sections'));
|
|
}
|
|
|
|
/**
|
|
* Update key values for particular Group
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function updateSettings(Request $request)
|
|
{
|
|
|
|
$data = $request->all();
|
|
parse_str($data['data'], $form_data);
|
|
parse_str($data['env_data'], $env_data);
|
|
if (! empty($form_data) && ! empty($data['section_key'])) {
|
|
unset($form_data['_method']);
|
|
unset($form_data['_token']);
|
|
Settings::resetSection($data['section_key']);
|
|
if (! empty($env_data)) {
|
|
setEnvironmentValue($env_data);
|
|
}
|
|
foreach ($form_data as $field => $value) {
|
|
if (isset($value) && ! is_null($value)) {
|
|
Settings::set($data['section_key'], $field, $value);
|
|
}
|
|
}
|
|
|
|
return response()->json(['success' => [
|
|
'title' => __('larabuilder::option_builder.success_title'),
|
|
'type' => 'success',
|
|
'message' => __('larabuilder::option_builder.setting_updated'),
|
|
]]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* reset section settings
|
|
*
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function resetSettings(Request $request)
|
|
{
|
|
|
|
$data = $request->all();
|
|
if (! empty($data) && ! empty($data['section_key'])) {
|
|
|
|
if (! empty($data['reset_all'])) {
|
|
Settings::resetSection();
|
|
} else {
|
|
Settings::resetSection($data['section_key']);
|
|
}
|
|
|
|
return response()->json(['success' => [
|
|
'type' => 'success',
|
|
'title' => __('larabuilder::option_builder.success_title'),
|
|
'message' => __('larabuilder::option_builder.reset_settings'),
|
|
]]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update file upload
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function uploadFiles(Request $request)
|
|
{
|
|
$arr = [];
|
|
$data = $request->all();
|
|
$extensions = ! empty($data['extensions']) ? $data['extensions'] : '.*';
|
|
|
|
if ($extensions != '*') {
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
'files.*' => 'mimes:'.$extensions,
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return response()->json([
|
|
'title' => __('larabuilder::option_builder.error_title'),
|
|
'type' => 'error',
|
|
'message' => $validator->errors()->all(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
if (! empty($data['files'])) {
|
|
foreach ($data['files'] as $file) {
|
|
if (is_file($file)) {
|
|
$ext = $file->guessExtension();
|
|
$type = 'file';
|
|
$thumbnail = $ext == 'mp4' ? 'modules/larabuilder/vendor/optionbuilder/images/mp4-placeholder.jpg' : 'modules/larabuilder/vendor/optionbuilder/images/file-preview.png';
|
|
$orgName = $file->getClientOriginalName();
|
|
$size = filesize($file);
|
|
$fileName = rand(1, 9999).date('m-d-Y_hia').$file->getClientOriginalName();
|
|
$filepath = $file->storeAs('optionbuilder/uploads', $fileName, 'public');
|
|
|
|
if (str_starts_with($file->getMimeType(), 'image')) {
|
|
$type = 'image';
|
|
$thumbnail = 'storage/'.$filepath;
|
|
}
|
|
|
|
$arr[] = [
|
|
'type' => $type,
|
|
'name' => $orgName,
|
|
'path' => $filepath,
|
|
'mime' => $ext,
|
|
'size' => $size,
|
|
'thumbnail' => asset($thumbnail),
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
return response()->json([
|
|
'type' => 'success',
|
|
'files' => $arr,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return Renderable
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('optionbuilder::create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @return Renderable
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return Renderable
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return view('optionbuilder::show');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return Renderable
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return view('optionbuilder::edit');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param int $id
|
|
* @return Renderable
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return Renderable
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|