2018-11-27 04:46:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Admin\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-12-31 11:57:32 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2018-12-07 05:25:33 +00:00
|
|
|
use Webkul\Admin\Facades\Configuration;
|
2018-11-27 04:46:35 +00:00
|
|
|
use Webkul\Core\Repositories\CoreConfigRepository as CoreConfig;
|
2018-12-14 09:32:59 +00:00
|
|
|
use Webkul\Core\Tree;
|
2018-12-31 11:57:32 +00:00
|
|
|
use Webkul\Admin\Http\Requests\ConfigurationForm;
|
2019-01-31 09:48:36 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2018-11-27 04:46:35 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configuration controller
|
|
|
|
|
*
|
|
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class ConfigurationController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CoreConfigRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $coreConfig;
|
|
|
|
|
|
2018-12-14 09:32:59 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $configTree;
|
|
|
|
|
|
2018-11-27 04:46:35 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @param Webkul\Core\Repositories\CoreConfigRepository $coreConfig
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(CoreConfig $coreConfig)
|
|
|
|
|
{
|
|
|
|
|
$this->middleware('admin');
|
|
|
|
|
|
2018-12-19 09:30:40 +00:00
|
|
|
$this->coreConfig = $coreConfig;
|
|
|
|
|
|
2018-11-27 04:46:35 +00:00
|
|
|
$this->_config = request('_config');
|
|
|
|
|
|
2018-12-14 09:32:59 +00:00
|
|
|
$this->prepareConfigTree();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepares config tree
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function prepareConfigTree()
|
|
|
|
|
{
|
|
|
|
|
$tree = Tree::create();
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
foreach (config('core') as $item) {
|
2018-12-14 09:32:59 +00:00
|
|
|
$tree->add($item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tree->items = core()->sortItems($tree->items);
|
|
|
|
|
|
|
|
|
|
$this->configTree = $tree;
|
2018-11-27 04:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2018-12-18 08:11:25 +00:00
|
|
|
$slugs = $this->getDefaultConfigSlugs();
|
2018-12-14 09:32:59 +00:00
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if (count($slugs)) {
|
2018-12-26 09:16:27 +00:00
|
|
|
return redirect()->route('admin.configuration.index', $slugs);
|
2018-12-18 08:11:25 +00:00
|
|
|
}
|
2018-12-14 09:32:59 +00:00
|
|
|
|
|
|
|
|
return view($this->_config['view'], ['config' => $this->configTree]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns slugs
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function getDefaultConfigSlugs()
|
|
|
|
|
{
|
2018-12-18 08:11:25 +00:00
|
|
|
$slugs = [];
|
|
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if (! request()->route('slug')) {
|
2018-12-18 08:11:25 +00:00
|
|
|
$firstItem = current($this->configTree->items);
|
|
|
|
|
$secondItem = current($firstItem['children']);
|
|
|
|
|
|
|
|
|
|
$temp = explode('.', $secondItem['key']);
|
2018-12-14 09:32:59 +00:00
|
|
|
|
2018-12-18 08:11:25 +00:00
|
|
|
$slugs = [
|
|
|
|
|
'slug' => current($temp),
|
|
|
|
|
'slug2' => end($temp)
|
|
|
|
|
];
|
|
|
|
|
} else {
|
2019-01-15 11:54:41 +00:00
|
|
|
if (! request()->route('slug2')) {
|
2018-12-18 08:11:25 +00:00
|
|
|
$secondItem = current($this->configTree->items[request()->route('slug')]['children']);
|
|
|
|
|
|
|
|
|
|
$temp = explode('.', $secondItem['key']);
|
|
|
|
|
|
|
|
|
|
$slugs = [
|
|
|
|
|
'slug' => current($temp),
|
|
|
|
|
'slug2' => end($temp)
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-13 10:58:28 +00:00
|
|
|
|
2018-12-18 08:11:25 +00:00
|
|
|
return $slugs;
|
2018-12-07 05:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
2018-12-31 11:57:32 +00:00
|
|
|
* @param \Webkul\Admin\Http\Requests\ConfigurationForm $request
|
2018-12-07 05:25:33 +00:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2019-01-04 05:43:24 +00:00
|
|
|
public function store()
|
2018-12-07 05:25:33 +00:00
|
|
|
{
|
2018-12-31 11:57:32 +00:00
|
|
|
Event::fire('core.configuration.save.after');
|
|
|
|
|
|
2018-12-14 06:26:52 +00:00
|
|
|
$this->coreConfig->create(request()->all());
|
2018-12-07 05:25:33 +00:00
|
|
|
|
2018-12-31 11:57:32 +00:00
|
|
|
Event::fire('core.configuration.save.after');
|
|
|
|
|
|
2019-01-17 14:52:01 +00:00
|
|
|
session()->flash('success', trans('admin::app.configuration.save-message'));
|
2018-12-07 05:25:33 +00:00
|
|
|
|
2018-12-19 09:30:40 +00:00
|
|
|
return redirect()->back();
|
2018-11-27 04:46:35 +00:00
|
|
|
}
|
2019-01-31 09:48:36 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* download the file for the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function download(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$id = request()->route()->parameters()['id'];
|
|
|
|
|
|
|
|
|
|
$config = $this->coreConfig->findOneByField('id', $id);
|
|
|
|
|
|
|
|
|
|
return Storage::download($config['value']);
|
|
|
|
|
}
|
2018-11-27 04:46:35 +00:00
|
|
|
}
|