2020-01-26 08:47:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Velocity\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Webkul\Product\Repositories\ProductRepository;
|
|
|
|
|
use Webkul\Velocity\Repositories\ContentRepository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Content Controller
|
|
|
|
|
*
|
|
|
|
|
* @author Vivek Sharma <viveksh047@webkul.com> @vivek
|
|
|
|
|
* @author Shubham Mehrotra <shubhammehrotra.symfony@webkul.com> @shubhwebkul
|
|
|
|
|
* @copyright 2019 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class ContentController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* ProductRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var object
|
|
|
|
|
*/
|
|
|
|
|
protected $productRepository;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ContentRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var object
|
|
|
|
|
*/
|
2020-02-20 07:38:52 +00:00
|
|
|
protected $contentRepository;
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
2020-02-20 07:38:52 +00:00
|
|
|
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
|
|
|
|
|
* @param \Webkul\Velocity\Repositories\ContentRepository $contentRepository
|
2020-01-26 08:47:05 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ProductRepository $productRepository,
|
2020-02-20 07:38:52 +00:00
|
|
|
ContentRepository $contentRepository
|
2020-01-26 08:47:05 +00:00
|
|
|
) {
|
|
|
|
|
$this->productRepository = $productRepository;
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
$this->contentRepository = $contentRepository;
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Search for catalog
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function search()
|
|
|
|
|
{
|
|
|
|
|
$results = [];
|
|
|
|
|
|
|
|
|
|
$params = request()->input();
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if (isset($params['query']) && $params['query']) {
|
2020-01-26 08:47:05 +00:00
|
|
|
foreach ($this->productRepository->searchProductByAttribute(request()->input('query')) as $row) {
|
|
|
|
|
$results[] = [
|
2020-02-27 08:03:03 +00:00
|
|
|
'id' => $row->product_id,
|
|
|
|
|
'name' => $row->name,
|
|
|
|
|
];
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return response()->json($results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store()
|
|
|
|
|
{
|
|
|
|
|
$params = request()->all();
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if (isset($params['products'])) {
|
2020-01-26 08:47:05 +00:00
|
|
|
$params['products'] = json_encode($params['products']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
$this->contentRepository->create($params);
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Content Page']));
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
2020-02-20 07:38:52 +00:00
|
|
|
$content = $this->contentRepository->findOrFail($id);
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('content'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Webkul\Product\Http\Requests\ProductForm $request
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function update($id)
|
|
|
|
|
{
|
|
|
|
|
$params = request()->all();
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
if (isset($params['locale']) && isset($params[$params['locale']]['products'])) {
|
2020-01-26 08:47:05 +00:00
|
|
|
$params[$params['locale']]['products'] = json_encode($params[$params['locale']]['products']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
$content = $this->contentRepository->update($params, $id);
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', trans('admin::app.response.update-success', ['name' => 'Content']));
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
2020-02-20 07:38:52 +00:00
|
|
|
$content = $this->contentRepository->findOrFail($id);
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
try {
|
2020-02-20 07:38:52 +00:00
|
|
|
$this->contentRepository->delete($id);
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Content']));
|
|
|
|
|
|
|
|
|
|
return response()->json(['message' => true], 200);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Content']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()->json(['message' => false], 400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Mass Delete the products
|
|
|
|
|
*
|
|
|
|
|
* @return response
|
|
|
|
|
*/
|
|
|
|
|
public function massDestroy()
|
|
|
|
|
{
|
|
|
|
|
$contentIds = explode(',', request()->input('indexes'));
|
|
|
|
|
|
|
|
|
|
foreach ($contentIds as $contentId) {
|
|
|
|
|
|
2020-02-20 07:38:52 +00:00
|
|
|
$content = $this->contentRepository->find($contentId);
|
2020-01-26 08:47:05 +00:00
|
|
|
|
|
|
|
|
if (isset($content)) {
|
2020-02-20 07:38:52 +00:00
|
|
|
$this->contentRepository->delete($contentId);
|
2020-01-26 08:47:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session()->flash('success', trans('velocity::app.admin.contents.mass-delete-success'));
|
|
|
|
|
|
|
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
}
|