vsmov 1.0.0

This commit is contained in:
Clemencia John
2026-04-15 21:11:19 -07:00
parent 311c74228c
commit 68260d170a
147 changed files with 12113 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\ActorRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Actor;
/**
* Class ActorCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class ActorCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Actor::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/actor');
CRUD::setEntityNameStrings('actor', 'actors');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Actor::class);
CRUD::addColumn(['name' => 'name', 'label' => 'Tên', 'type' => 'text']);
CRUD::addColumn(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text']);
CRUD::addColumn(['name' => 'gender', 'label' => 'Giới tính', 'type' => 'text']);
CRUD::addColumn(['name' => 'image', 'label' => 'Ảnh', 'type' => 'image']);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Actor::class);
CRUD::setValidation(ActorRequest::class);
CRUD::addField(['name' => 'name', 'label' => 'Tên', 'type' => 'text']);
CRUD::addField(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text']);
CRUD::addField(['name' => 'image', 'label' => 'Ảnh', 'type' => 'upload']);
CRUD::addField([
'name' => 'gender',
'label' => "Giới tính",
'type' => 'select_from_array',
'options' => ['male' => 'Nam', 'female' => 'Nữ', 'other' => 'Khác'],
'allows_null' => false,
'default' => 'one',
],);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->model);
}
}

View File

@@ -0,0 +1,56 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Illuminate\Routing\Controller;
use Vsmov\Core\Models\Movie;
use Vsmov\Core\Models\Episode;
use Vsmov\Core\Models\Theme;
use Vsmov\Core\Models\User;
class AdminController extends Controller
{
protected $data = []; // the information we send to the view
/**
* Create a new controller instance.
*/
public function __construct()
{
$this->middleware(backpack_middleware());
}
/**
* Show the admin dashboard.
*
* @return \Illuminate\Http\Response
*/
public function dashboard()
{
$this->data['title'] = trans('backpack::base.dashboard'); // set the page title
$this->data['breadcrumbs'] = [
trans('backpack::crud.admin') => backpack_url('dashboard'),
trans('backpack::base.dashboard') => false,
];
$this->data['count_movies'] = Movie::count();
$this->data['count_episodes'] = Episode::count();
$this->data['count_episodes_error'] = Episode::where('has_report', true)->count();
$this->data['count_themes'] = Theme::count();
$this->data['count_users'] = User::count();
$this->data['top_view_day'] = Movie::orderBy('view_day', 'desc')->limit(15)->get();
$this->data['top_view_week'] = Movie::orderBy('view_week', 'desc')->limit(15)->get();
$this->data['top_view_month'] = Movie::orderBy('view_month', 'desc')->limit(15)->get();
return view(backpack_view('dashboard'), $this->data);
}
/**
* Redirect to the dashboard.
*
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
*/
public function redirect()
{
// The '/admin' route is not to be used as a page, because it breaks the menu's active state.
return redirect(backpack_url('dashboard'));
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\CatalogRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Catalog;
/**
* Class CatalogCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class CatalogCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Catalog::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/catalog');
CRUD::setEntityNameStrings('catalog', 'catalogs');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Catalog::class);
CRUD::addButtonFromModelFunction('line', 'open_view', 'openView', 'beginning');
CRUD::column('name')->label('Tên')->type('text');
CRUD::column('slug')->label('Đường dẫn tĩnh')->type('text');
CRUD::column('paginate')->label('Item per page')->type('number');
CRUD::column('value')->label('Value')->type('text');
CRUD::column('seo_title')->label('SEO Title')->type('text');
CRUD::column('seo_des')->label('SEO Description')->type('text');
CRUD::column('seo_key')->label('SEO Keyword')->type('text');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Catalog::class);
CRUD::setValidation(CatalogRequest::class);
CRUD::field('name')->label('Tên')->type('text');
CRUD::field('slug')->label('Đường dẫn tĩnh')->type('text');
CRUD::field('paginate')->label('Paginate')->hint('Item per page')->type('number');
CRUD::field('value')->label('Value')->hint('relation_tables,relation_field,relation_value|find_by_field_1,find_by_fiel_2,...,find_by_field_n|value_1,value_2,...,value_n|sort_by_field|sort_algo')->type('text');
CRUD::field('seo_title')->label('SEO Title')->type('text');
CRUD::field('seo_des')->label('SEO Description')->type('textarea');
CRUD::field('seo_key')->label('SEO Keyword')->type('text');
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\CategoryRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Category;
/**
* Class CategoryCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class CategoryCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Category::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/category');
CRUD::setEntityNameStrings('category', 'categories');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Category::class);
CRUD::column('name')->label('Tên')->type('text');
CRUD::column('slug')->label('Đường dẫn tĩnh')->type('text');
CRUD::column('seo_title')->label('SEO Title')->type('text');
CRUD::column('seo_des')->label('SEO Description')->type('text');
CRUD::column('seo_key')->label('SEO Keyword')->type('text');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Category::class);
CRUD::setValidation(CategoryRequest::class);
CRUD::field('name')->label('Tên')->type('text');
CRUD::field('slug')->label('Đường dẫn tĩnh')->type('text');
CRUD::field('seo_title')->label('SEO Title')->type('text');
CRUD::field('seo_des')->label('SEO Description')->type('textarea');
CRUD::field('seo_key')->label('SEO Keyword')->type('text');
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\DirectorRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Director;
/**
* Class DirectorCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class DirectorCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Director::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/director');
CRUD::setEntityNameStrings('director', 'directors');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Director::class);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
CRUD::addColumn(['name' => 'name', 'label' => 'Tên', 'type' => 'text']);
CRUD::addColumn(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text']);
CRUD::addColumn(['name' => 'gender', 'label' => 'Giới tính', 'type' => 'text']);
CRUD::addColumn(['name' => 'image', 'label' => 'Ảnh', 'type' => 'image']);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Director::class);
CRUD::setValidation(DirectorRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
CRUD::addField(['name' => 'name', 'label' => 'Tên', 'type' => 'text']);
CRUD::addField(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text']);
CRUD::addField(['name' => 'image', 'label' => 'Ảnh', 'type' => 'upload']);
CRUD::addField([
'name' => 'gender',
'label' => "Giới tính",
'type' => 'select_from_array',
'options' => ['male' => 'Nam', 'female' => 'Nữ', 'other' => 'Khác'],
'allows_null' => false,
'default' => 'one',
],);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
}

View File

@@ -0,0 +1,120 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\Request;
use Vsmov\Core\Models\Episode;
/**
* Class EpisodeCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class EpisodeCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation {
store as backpackStore;
}
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation {
update as backpackUpdate;
}
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use \Vsmov\Core\Traits\Operations\BulkDeleteOperation {
bulkDelete as traitBulkDelete;
}
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Episode::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/episode');
CRUD::setEntityNameStrings('Episode', 'episodes');
$this->crud->addButtonFromModelFunction('line', 'open_episode', 'openEpisode', 'beginning');
$this->crud->denyAccess('create');
$this->crud->denyAccess('delete');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Episode::class);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number','tab'=>'Thông tin phim']);
*/
$this->crud->enableExportButtons();
$this->crud->addClause('where', 'has_report', true);
CRUD::addColumn([
'name' => 'movie', 'label' => 'Phim', 'type' => 'relationship',
'searchLogic' => function ($query, $column, $searchTerm) {
$query->orWhereHas('movie', function ($movie) use ($searchTerm) {
$movie->where('name', 'like', '%' . $searchTerm . '%')
->orWhere('origin_name', 'like', '%' . $searchTerm . '%');
});
}
]);
CRUD::addColumn(['name' => 'name', 'label' => 'Tập', 'type' => 'text']);
CRUD::addColumn(['name' => 'type', 'label' => 'Type', 'type' => 'text']);
CRUD::addColumn(['name' => 'link', 'label' => 'Link', 'type' => 'textarea']);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
abort(404);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
CRUD::addField(['name' => 'type', 'label' => 'Type', 'type' => 'select_from_array', 'options' => config('vsmov.episodes.types')]);
CRUD::addField(['name' => 'link', 'label' => 'Nguồn phát', 'type' => 'url']);
CRUD::addField(['name' => 'has_report', 'label' => 'Đánh dấu đang lỗi', 'type' => 'checkbox']);
CRUD::addField(['name' => 'report_message', 'label' => 'Report message', 'type' => 'textarea']);
}
public function bulkDelete()
{
$this->crud->hasAccessOrFail('bulkDelete');
$entries = request()->input('entries', []);
$deletedEntries = [];
foreach ($entries as $key => $id) {
if ($entry = $this->crud->model->find($id)) {
$deletedEntries[] = $entry->update(['has_report' => 0, 'report_message' => '']);
}
}
return $deletedEntries;
}
}

View File

@@ -0,0 +1,126 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\CoreHttp\Requests\MenuRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Menu;
/**
* Class MenuCrudController
* @package Vsmov\CoreHttp\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class MenuCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ReorderOperation;
use \Vsmov\Core\Traits\Operations\BulkDeleteOperation {
bulkDelete as traitBulkDelete;
}
public function setup()
{
$this->crud->setModel(Menu::class);
$this->crud->setRoute(config('backpack.base.route_prefix') . '/menu');
$this->crud->setEntityNameStrings('menu item', 'menu items');
$this->crud->enableReorder('name', 2);
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Menu::class);
$this->crud->addColumn([
'name' => 'name',
'label' => 'Label',
]);
$this->crud->addColumn([
'label' => 'Parent',
'type' => 'select',
'name' => 'parent_id',
'entity' => 'parent',
'attribute' => 'name',
'model' => Menu::class,
]);
$this->crud->addColumn([
'name' => 'link',
'label' => 'Link',
'type' => 'url',
]);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Menu::class);
$this->crud->addField([
'name' => 'name',
'label' => 'Label',
]);
$this->crud->addField([
'label' => 'Parent',
'type' => 'select',
'name' => 'parent_id',
'entity' => 'parent',
'attribute' => 'name',
Menu::class
]);
$this->crud->addField([
'name' => ['type', 'link', 'internal_link'],
'label' => 'Type',
'type' => 'page_or_link',
]);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
public function bulkDelete()
{
$this->crud->hasAccessOrFail('bulkDelete');
$entries = request()->input('entries', []);
$deletedEntries = [];
foreach ($entries as $key => $id) {
if ($entry = $this->crud->model->find($id)) {
$deletedEntries[] = $entry->delete();
}
}
return $deletedEntries;
}
}

View File

@@ -0,0 +1,409 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\MovieRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Vsmov\Core\Models\Actor;
use Vsmov\Core\Models\Director;
use Vsmov\Core\Models\Movie;
use Vsmov\Core\Models\Region;
use Vsmov\Core\Models\Studio;
use Vsmov\Core\Models\Category;
use Vsmov\Core\Models\Tag;
/**
* Class MovieCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class MovieCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation {
store as backpackStore;
}
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation {
update as backpackUpdate;
}
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation {
destroy as traitDestroy;
}
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
use \Vsmov\Core\Traits\Operations\BulkDeleteOperation {
bulkDelete as traitBulkDelete;
}
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Movie::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/movie');
CRUD::setEntityNameStrings('movie', 'movies');
CRUD::setCreateView('vsmov::movies.create',);
CRUD::setUpdateView('vsmov::movies.edit',);
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Movie::class);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number','tab'=>'Thông tin phim']);
*/
$this->crud->addFilter([
'name' => 'status',
'type' => 'select2',
'label' => 'Tình trạng'
], function () {
return [
'trailer' => 'Sắp chiếu',
'ongoing' => 'Đang chiếu',
'completed' => 'Hoàn thành'
];
}, function ($val) {
$this->crud->addClause('where', 'status', $val);
});
$this->crud->addFilter([
'name' => 'type',
'type' => 'select2',
'label' => 'Định dạng'
], function () {
return [
'single' => 'Phim lẻ',
'series' => 'Phim bộ'
];
}, function ($val) {
$this->crud->addClause('where', 'type', $val);
});
$this->crud->addFilter([
'name' => 'category_id',
'type' => 'select2',
'label' => 'Thể loại'
], function () {
return Category::all()->pluck('name', 'id')->toArray();
}, function ($value) { // if the filter is active
$this->crud->query = $this->crud->query->whereHas('categories', function ($query) use ($value) {
$query->where('id', $value);
});
});
$this->crud->addFilter([
'name' => 'region_id',
'type' => 'select2',
'label' => 'Quốc gia'
], function () {
return Region::all()->pluck('name', 'id')->toArray();
}, function ($value) { // if the filter is active
$this->crud->query = $this->crud->query->whereHas('regions', function ($query) use ($value) {
$query->where('id', $value);
});
});
$this->crud->addFilter([
'name' => 'other',
'type' => 'select2',
'label' => 'Thông tin'
], function () {
return [
'thumb_url-' => 'Thiếu ảnh thumb',
'poster_url-' => 'Thiếu ảnh poster',
'trailer_url-' => 'Thiếu trailer',
'language-vietsub' => 'Vietsub',
'language-thuyết minh' => 'Thuyết minh',
'language-lồng tiếng' => 'Lồng tiếng',
];
}, function ($values) {
$value = explode("-", $values);
$field = $value[0];
$val = $value[1];
if ($field === 'language') {
$this->crud->query->where($field, 'like', '%' . $val . '%');
} else {
$this->crud->query->where($field, '')->orWhere($field, NULL)->orWhere($field, 'like', '%img.vsmov%')->orWhere($field, 'like', '%img.hiephanhthienha%');
}
});
$this->crud->addFilter(
[
'type' => 'simple',
'name' => 'is_recommended',
'label' => 'Đề cử'
],
false,
function () {
$this->crud->addClause('where', 'is_recommended', true);
}
);
$this->crud->addFilter(
[
'type' => 'simple',
'name' => 'is_shown_in_theater',
'label' => 'Chiếu rạp'
],
false,
function () {
$this->crud->addClause('where', 'is_shown_in_theater', true);
}
);
CRUD::addButtonFromModelFunction('line', 'open_view', 'openView', 'beginning');
CRUD::addColumn([
'name' => 'name',
'origin_name' => 'origin_name',
'publish_year' => 'publish_year',
'status' => 'status',
'movie_type' => 'type',
'episode_current' => 'episode_current',
'label' => 'Thông tin',
'type' => 'view',
'view' => 'vsmov::movies.columns.column_movie_info',
'searchLogic' => function ($query, $column, $searchTerm) {
$query->where('name', 'like', '%' . $searchTerm . '%')->orWhere('origin_name', 'like', '%' . $searchTerm . '%');
// $query->whereRaw("MATCH(name, origin_name) AGAINST(? IN BOOLEAN MODE)", [$searchTerm]);
}
]);
CRUD::addColumn([
'name' => 'thumb_url', 'label' => 'Ảnh thumb', 'type' => 'image',
'height' => '100px',
'width' => '68px',
]);
CRUD::addColumn(['name' => 'categories', 'label' => 'Thể loại', 'type' => 'relationship',]);
CRUD::addColumn(['name' => 'regions', 'label' => 'Khu vực', 'type' => 'relationship',]);
CRUD::addColumn(['name' => 'updated_at', 'label' => 'Cập nhật lúc', 'type' => 'datetime', 'format' => 'DD/MM/YYYY HH:mm:ss']);
// CRUD::addColumn(['name' => 'user_name', 'label' => 'Cập nhật bởi', 'type' => 'text',]);
CRUD::addColumn(['name' => 'view_total', 'label' => 'Lượt xem', 'type' => 'number',]);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Movie::class);
CRUD::setValidation(MovieRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
CRUD::addField(['name' => 'name', 'label' => 'Tên phim', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-6'
], 'attributes' => ['placeholder' => 'Tên'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'origin_name', 'label' => 'Tên gốc', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-6'
], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text', 'tab' => 'Thông tin phim']);
CRUD::addField([
'name' => 'thumb_url', 'label' => 'Ảnh Thumb', 'type' => 'ckfinder', 'preview' => ['width' => 'auto', 'height' => '340px'], 'tab' => 'Thông tin phim'
]);
CRUD::addField(['name' => 'poster_url', 'label' => 'Ảnh Poster', 'type' => 'ckfinder', 'preview' => ['width' => 'auto', 'height' => '340px'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'content', 'label' => 'Nội dung', 'type' => 'summernote', 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'notify', 'label' => 'Thông báo / ghi chú', 'type' => 'text', 'attributes' => ['placeholder' => 'Tuần này hoãn chiếu'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'showtimes', 'label' => 'Lịch chiếu phim', 'type' => 'text', 'attributes' => ['placeholder' => '21h tối hàng ngày'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'trailer_url', 'label' => 'Trailer Youtube URL', 'type' => 'text', 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'episode_time', 'label' => 'Thời lượng tập phim', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-4'
], 'attributes' => ['placeholder' => '45 phút'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'episode_current', 'label' => 'Tập phim hiện tại', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-4'
], 'attributes' => ['placeholder' => '5'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'episode_total', 'label' => 'Tổng số tập phim', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-4'
], 'attributes' => ['placeholder' => '12'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'language', 'label' => 'Ngôn ngữ', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-4'
], 'attributes' => ['placeholder' => 'Tiếng Việt'], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'quality', 'label' => 'Chất lượng', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-4'
], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'publish_year', 'label' => 'Năm xuất bản', 'type' => 'text', 'wrapperAttributes' => [
'class' => 'form-group col-md-4'
], 'tab' => 'Thông tin phim']);
CRUD::addField(['name' => 'type', 'label' => 'Định dạng', 'type' => 'radio', 'options' => ['single' => 'Phim lẻ', 'series' => 'Phim bộ'], 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'status', 'label' => 'Tình trạng', 'type' => 'radio', 'options' => ['trailer' => 'Sắp chiếu', 'ongoing' => 'Đang chiếu', 'completed' => 'Hoàn thành'], 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'categories', 'label' => 'Thể loại', 'type' => 'checklist', 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'regions', 'label' => 'Khu vực', 'type' => 'checklist', 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'directors', 'label' => 'Đạo diễn', 'type' => 'select2_relationship_tags', 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'actors', 'label' => 'Diễn viên', 'type' => 'select2_relationship_tags', 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'tags', 'label' => 'Tags', 'type' => 'select2_relationship_tags', 'tab' => 'Phân loại']);
CRUD::addField(['name' => 'studios', 'label' => 'Studios', 'type' => 'select2_relationship_tags', 'tab' => 'Phân loại']);
CRUD::addField([
'name' => 'episodes',
'type' => 'view',
'view' => 'vsmov::movies.inc.episode',
'tab' => 'Danh sách tập phim'
],);
CRUD::addField(['name' => 'update_handler', 'label' => 'Trình cập nhật', 'type' => 'select_from_array', 'options' => collect(config('vsmov.updaters', []))->pluck('name', 'handler')->toArray(), 'tab' => 'Cập nhật']);
CRUD::addField(['name' => 'update_identity', 'label' => 'ID cập nhật', 'type' => 'text', 'tab' => 'Cập nhật']);
CRUD::addField(['name' => 'is_shown_in_theater', 'label' => 'Phim chiếu rạp', 'type' => 'boolean', 'tab' => 'Khác']);
CRUD::addField(['name' => 'is_copyright', 'label' => 'Có bản quyền phim', 'type' => 'boolean', 'tab' => 'Khác']);
CRUD::addField(['name' => 'is_sensitive_content', 'label' => 'Cảnh báo nội dung người lớn', 'type' => 'boolean', 'tab' => 'Khác']);
CRUD::addField(['name' => 'is_recommended', 'label' => 'Đề cử', 'type' => 'boolean', 'tab' => 'Khác']);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
CRUD::addField(['name' => 'timestamps', 'label' => 'Cập nhật thời gian', 'type' => 'checkbox', 'tab' => 'Cập nhật']);
}
public function store(Request $request)
{
$this->getTaxonamies($request);
return $this->backpackStore();
}
public function update(Request $request)
{
$this->getTaxonamies($request);
return $this->backpackUpdate();
}
protected function getTaxonamies(Request $request)
{
$actors = request('actors', []);
$directors = request('directors', []);
$tags = request('tags', []);
$studios = request('studios', []);
$actor_ids = [];
foreach ($actors as $actor) {
$actor_ids[] = Actor::firstOrCreate([
'name_md5' => md5($actor)
], [
'name' => $actor
])->id;
}
$director_ids = [];
foreach ($directors as $director) {
$director_ids[] = Director::firstOrCreate([
'name_md5' => md5($director)
], [
'name' => $director
])->id;
}
$tag_ids = [];
foreach ($tags as $tag) {
$tag_ids[] = Tag::firstOrCreate([
'name_md5' => md5($tag)
], [
'name' => $tag
])->id;
}
$studio_ids = [];
foreach ($studios as $studio) {
$studio_ids[] = Studio::firstOrCreate([
'name_md5' => md5($studio)
], [
'name' => $studio
])->id;
}
$request['actors'] = $actor_ids;
$request['directors'] = $director_ids;
$request['tags'] = $tag_ids;
$request['studios'] = $studio_ids;
}
// protected function setupDeleteOperation()
// {
// $this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
// }
public function deleteImage($movie)
{
// Delete images
if ($movie->thumb_url && !filter_var($movie->thumb_url, FILTER_VALIDATE_URL) && file_exists(public_path($movie->thumb_url))) {
unlink(public_path($movie->thumb_url));
}
if ($movie->poster_url && !filter_var($movie->poster_url, FILTER_VALIDATE_URL) && file_exists(public_path($movie->poster_url))) {
unlink(public_path($movie->poster_url));
}
return true;
}
public function destroy($id)
{
$this->crud->hasAccessOrFail('delete');
$movie = Movie::find($id);
$this->deleteImage($movie);
// get entry ID from Request (makes sure its the last ID for nested resources)
$id = $this->crud->getCurrentEntryId() ?? $id;
$res = $this->crud->delete($id);
if ($res) {
}
return $res;
}
public function bulkDelete()
{
$this->crud->hasAccessOrFail('bulkDelete');
$entries = request()->input('entries', []);
$deletedEntries = [];
foreach ($entries as $key => $id) {
if ($entry = $this->crud->model->find($id)) {
$this->deleteImage($entry);
$deletedEntries[] = $entry->delete();
}
}
return $deletedEntries;
}
}

View File

@@ -0,0 +1,157 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Illuminate\Support\Facades\Route;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Support\Facades\Artisan;
use Vsmov\Core\Models\Plugin;
use Prologue\Alerts\Facades\Alert;
class PluginController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(Plugin::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/plugin');
CRUD::setEntityNameStrings('plugin', 'plugins');
$this->crud->denyAccess('update');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
if (!backpack_user()->hasPermissionTo('Browse plugin')) {
abort(403);
}
CRUD::column('name')->label('Plugin')->type('text');
CRUD::column('version')->label('Version')->type('text');
$this->crud->addButtonFromModelFunction('line', 'editBtn', 'editBtn', 'beginning');
$this->crud->addButtonFromModelFunction('line', 'openBtn', 'openBtn', 'beginning');
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$plugin = $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId());
$fields = $plugin->options;
CRUD::addField(['name' => 'fields', 'type' => 'hidden', 'value' => collect($fields)->implode('name', ',')]);
foreach ($fields as $field) {
CRUD::addField($field);
}
}
public function show($id)
{
/** @var Plugin */
$plugin = Plugin::findOrFail($id);
return $plugin->open();
}
/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Contracts\View\View
*/
public function edit($id)
{
if (!backpack_user()->hasPermissionTo('Update plugin')) {
abort(403);
}
$id = $this->crud->getCurrentEntryId() ?? $id;
$this->data['entry'] = $this->crud->getEntryWithLocale($id);
$this->crud->setOperationSetting('fields', $this->getUpdateFields());
$this->data['crud'] = $this->crud;
$this->data['saveAction'] = $this->crud->getSaveAction();
$this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.edit') . ' ' . $this->crud->entity_name;
$this->data['id'] = $id;
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
return view($this->crud->getEditView(), $this->data);
}
/**
* Update the specified resource in the database.
*
* @return array|\Illuminate\Http\RedirectResponse
*/
public function update($plugin)
{
if (!backpack_user()->hasPermissionTo('Update plugin')) {
abort(403);
}
// execute the FormRequest authorization and validation, if one is required
$request = $this->crud->validateRequest();
// register any Model Events defined on fields
$this->crud->registerFieldEvents();
// update the row in the db
$item = $this->crud->update(
$request->get($this->crud->model->getKeyName()),
[
'value' => request()->only(explode(',', request('fields')))
]
);
$this->data['entry'] = $this->crud->entry = $item;
// show a success message
Alert::success(trans('backpack::crud.update_success'))->flash();
return redirect(backpack_url('plugin'));
}
/**
* Get all fields needed for the EDIT ENTRY form.
*
* @param int $id The id of the entry that is being edited.
* @return array The fields with attributes, fake attributes and values.
*/
public function getUpdateFields($id = false)
{
$fields = $this->crud->fields();
$entry = ($id != false) ? $this->getEntry($id) : $this->crud->getCurrentEntry();
$options = $entry->value ?? [];
foreach ($options as $k => $v) {
$fields[$k]['value'] = $v;
}
if (!array_key_exists('id', $fields)) {
$fields['id'] = [
'name' => $entry->getKeyName(),
'value' => $entry->getKey(),
'type' => 'hidden',
];
}
return $fields;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Prologue\Alerts\Facades\Alert;
class QuickActionController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function delete_cache()
{
Artisan::call('optimize:clear');
Alert::success("Xóa cache thành công")->flash();
return back();
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\RegionRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Region;
/**
* Class RegionCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class RegionCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Region::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/region');
CRUD::setEntityNameStrings('region', 'regions');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Region::class);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->label('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
CRUD::column('name')->label('Tên khu vực')->type('text');
CRUD::column('slug')->label('Đường dẫn tĩnh')->type('text');
CRUD::column('seo_title')->label('SEO Title')->type('text');
CRUD::column('seo_des')->label('SEO Description')->type('text');
CRUD::column('seo_key')->label('SEO Keyword')->type('text');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Region::class);
CRUD::setValidation(RegionRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->label('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
CRUD::field('name')->label('Tên khu vực')->type('text');
CRUD::field('slug')->label('Đường dẫn tĩnh')->type('text');
CRUD::field('seo_title')->label('SEO Title')->type('text');
CRUD::field('seo_des')->label('SEO Description')->type('textarea');
CRUD::field('seo_key')->label('SEO Keyword')->type('text');
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
}

View File

@@ -0,0 +1,163 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Backpack\Settings\app\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL as LARURL;
use Illuminate\Support\Facades\File;
use Carbon\Carbon;
use Vsmov\Core\Models\Actor;
use Vsmov\Core\Models\Catalog;
use Vsmov\Core\Models\Category;
use Vsmov\Core\Models\Director;
use Vsmov\Core\Models\Movie;
use Vsmov\Core\Models\Region;
use Vsmov\Core\Models\Studio;
use Vsmov\Core\Models\Tag;
use Prologue\Alerts\Facades\Alert;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\SitemapIndex;
use Spatie\Sitemap\Tags\Url;
class SiteMapController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setRoute(config('backpack.base.route_prefix') . '/sitemap');
CRUD::setEntityNameStrings('site map', 'site map');
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupCreateOperation()
{
CRUD::addField(['name' => 'sitemap', 'type' => 'custom_html', 'value' => 'Sitemap sẽ được lưu tại đường dẫn: <i>' . url('/sitemap.xml') . '</i>']);
$this->crud->addSaveAction([
'name' => 'save_and_new',
'redirect' => function ($crud, $request, $itemId) {
return $crud->route;
},
'button_text' => 'Tạo sitemap',
]);
$this->crud->setOperationSetting('showSaveActionChange', false);
}
public function render_styles()
{
$xml = view('vsmov::sitemap/styles', [
'title' => Setting::get('site_homepage_title'),
'domain' => LARURL::to('/')
])->render();
file_put_contents(public_path('main-sitemap.xsl'), $xml);
return;
}
public function add_styles($file_name)
{
$path = public_path($file_name);
if(file_exists($path)) {
$content = file_get_contents($path);
$content = str_replace('?'.'>', '?'.'>'.'<'.'?'.'xml-stylesheet type="text/xsl" href="'. LARURL::to('/') .'/main-sitemap.xsl"?'.'>', $content);
file_put_contents($path, $content);
}
}
public function store(Request $request)
{
$this->render_styles();
if (!File::isDirectory('sitemap')) File::makeDirectory('sitemap', 0777, true, true);
$sitemap_index = SitemapIndex::create();
$sitemap_page = Sitemap::create();
$sitemap_page->add(Url::create('/')
->setLastModificationDate(now())
->setChangeFrequency(Url::CHANGE_FREQUENCY_HOURLY)
->setPriority(1));
Catalog::chunkById(100, function ($catalogs) use ($sitemap_page) {
foreach ($catalogs as $catalog) {
$sitemap_page->add(
Url::create($catalog->getUrl())
->setLastModificationDate(now())
->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY)
->setPriority(0.9)
);
}
});
$sitemap_page->writeToFile(public_path('sitemap/page-sitemap.xml'));
$this->add_styles('sitemap/page-sitemap.xml');
$sitemap_index->add('sitemap/page-sitemap.xml');
$sitemap_categories = Sitemap::create();
Category::chunkById(100, function ($categoires) use ($sitemap_categories) {
foreach ($categoires as $category) {
$sitemap_categories->add(
Url::create($category->getUrl())
->setLastModificationDate(now())
->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY)
->setPriority(0.8)
);
}
});
$sitemap_categories->writeToFile(public_path('sitemap/categories-sitemap.xml'));
$this->add_styles('sitemap/categories-sitemap.xml');
$sitemap_index->add('sitemap/categories-sitemap.xml');
$sitemap_regions = Sitemap::create();
Region::chunkById(100, function ($regions) use ($sitemap_regions) {
foreach ($regions as $region) {
$sitemap_regions->add(
Url::create($region->getUrl())
->setLastModificationDate(now())
->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY)
->setPriority(0.8)
);
}
});
$sitemap_regions->writeToFile(public_path('sitemap/regions-sitemap.xml'));
$this->add_styles('sitemap/regions-sitemap.xml');
$sitemap_index->add('sitemap/regions-sitemap.xml');
$chunk = 0;
Movie::chunkById(200, function ($movies) use ($sitemap_index, &$chunk) {
$chunk++;
$sitemap_movies = null;
$sitemap_movies = Sitemap::create();
foreach ($movies as $movie) {
$sitemap_movies->add(
Url::create($movie->getUrl())
->setLastModificationDate($movie->updated_at)
->setChangeFrequency(Url::CHANGE_FREQUENCY_DAILY)
->setPriority(0.7)
);
}
$sitemap_movies->writeToFile(public_path("sitemap/movies-sitemap{$chunk}.xml"));
$this->add_styles("sitemap/movies-sitemap{$chunk}.xml");
$sitemap_index->add("sitemap/movies-sitemap{$chunk}.xml");
});
$sitemap_index->writeToFile(public_path('sitemap.xml'));
$this->add_styles("sitemap.xml");
Alert::success("Đã tạo thành công sitemap tại thư mục public")->flash();
return back();
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Vsmov\Core\Requests\StudioRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Studio;
/**
* Class StudioCrudController
* @package Vsmov\Core\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class StudioCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Studio::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/studio');
CRUD::setEntityNameStrings('studio', 'studios');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Studio::class);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
CRUD::addColumn(['name' => 'name', 'label' => 'Tên', 'type' => 'text']);
CRUD::addColumn(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text']);
CRUD::addColumn(['name' => 'image', 'label' => 'Ảnh', 'type' => 'image']);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Studio::class);
CRUD::setValidation(StudioRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
CRUD::addField(['name' => 'name', 'label' => 'Tên', 'type' => 'text']);
CRUD::addField(['name' => 'slug', 'label' => 'Đường dẫn tĩnh', 'type' => 'text']);
CRUD::addField(['name' => 'image', 'label' => 'Ảnh', 'type' => 'upload']);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Vsmov\Core\Models\Tag;
use Vsmov\Core\Requests\TagRequest;
/**
* Class TagCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class TagCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\Vsmov\Core\Models\Tag::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/tag');
CRUD::setEntityNameStrings('tag', 'tags');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
$this->authorize('browse', Tag::class);
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
CRUD::addColumn(['name' => 'name', 'type' => 'text']);
CRUD::addColumn(['name' => 'slug', 'type' => 'text']);
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
$this->authorize('create', Tag::class);
CRUD::setValidation(TagRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
CRUD::addField(['name' => 'name', 'type' => 'text']);
CRUD::addField(['name' => 'slug', 'type' => 'text']);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->authorize('update', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
$this->setupCreateOperation();
}
protected function setupDeleteOperation()
{
$this->authorize('delete', $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId()));
}
}

View File

@@ -0,0 +1,252 @@
<?php
namespace Vsmov\Core\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Illuminate\Support\Facades\Route;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Illuminate\Http\Request;
use Vsmov\Core\Models\Theme;
use Prologue\Alerts\Facades\Alert;
class ThemeManagementController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(Theme::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/theme');
CRUD::setEntityNameStrings('theme', 'themes');
$this->crud->denyAccess('update');
}
/**
* Define which routes are needed for this operation.
*
* @param string $name Name of the current entity (singular). Used as first URL segment.
* @param string $routeName Prefix of the route name.
* @param string $controller Name of the current CrudController.
*/
protected function setupManagementRoutes($segment, $routeName, $controller)
{
Route::post($segment . '/{id}/active', [
'as' => $routeName . '.active',
'uses' => $controller . '@active',
'operation' => 'update',
]);
Route::post($segment . '/{id}/reset', [
'as' => $routeName . '.reset',
'uses' => $controller . '@reset',
'operation' => 'update',
]);
Route::post($segment . '/{id}/delete', [
'as' => $routeName . '.delete',
'uses' => $controller . '@delete',
'operation' => 'update',
]);
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
foreach (config('themes', []) as $key => $theme) {
Theme::updateOrCreate([
'name' => $key,
], [
'display_name' => $theme['display_name'] ?? $theme['name'],
'preview_image' => $theme['preview_image'] ?: '',
'author' => $theme['author'] ?: '',
'package_name' => $theme['package_name'],
]);
}
CRUD::addColumn(['name' => 'display_name', 'type' => 'text']);
CRUD::addColumn(['name' => 'preview_image', 'type' => 'image']);
CRUD::addColumn(['name' => 'version', 'type' => 'text']);
$this->crud->addButtonFromModelFunction('line', 'editBtn', 'editBtn', 'beginning');
$this->crud->addButtonFromModelFunction('line', 'resetBtn', 'resetBtn', 'beginning');
$this->crud->addButtonFromModelFunction('line', 'activeBtn', 'activeBtn', 'beginning');
$this->crud->addButtonFromModelFunction('line', 'deleteBtn', 'deleteBtn', '');
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$theme = $this->crud->getEntryWithLocale($this->crud->getCurrentEntryId());
$fields = $theme->options;
CRUD::addField(['name' => 'fields', 'type' => 'hidden', 'value' => collect($fields)->implode('name', ',')]);
foreach ($fields as $field) {
CRUD::addField($field);
}
}
public function delete(Request $request, $id)
{
if (!backpack_user()->hasPermissionTo('Customize theme')) {
abort(403);
}
$theme = Theme::fromCache()->find($id);
if (is_null($theme)) {
Alert::warning("Không tìm thấy dữ liệu giao diện")->flash();
return redirect(backpack_url('theme'));
}
// delete row from db
$theme->delete();
Alert::success("Xóa giao diện thành công!")->flash();
return redirect(backpack_url('theme'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Contracts\View\View
*/
public function edit($id)
{
if (!backpack_user()->hasPermissionTo('Customize theme')) {
abort(403);
}
$id = $this->crud->getCurrentEntryId() ?? $id;
$this->data['entry'] = $this->crud->getEntryWithLocale($id);
$this->crud->setOperationSetting('fields', $this->getUpdateFields());
$this->data['crud'] = $this->crud;
$this->data['saveAction'] = $this->crud->getSaveAction();
$this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.edit') . ' ' . $this->crud->entity_name;
$this->data['id'] = $id;
// load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
return view($this->crud->getEditView(), $this->data);
}
/**
* Update the specified resource in the database.
*
* @return array|\Illuminate\Http\RedirectResponse
*/
public function update()
{
if (!backpack_user()->hasPermissionTo('Customize theme')) {
abort(403);
}
// execute the FormRequest authorization and validation, if one is required
$request = $this->crud->validateRequest();
// register any Model Events defined on fields
$this->crud->registerFieldEvents();
// update the row in the db
$item = $this->crud->update(
$request->get($this->crud->model->getKeyName()),
[
'value' => request()->only(explode(',', request('fields')))
]
);
$this->data['entry'] = $this->crud->entry = $item;
Alert::success(trans('backpack::crud.update_success'))->flash();
return redirect(backpack_url('theme'));
}
/**
* Get all fields needed for the EDIT ENTRY form.
*
* @param int $id The id of the entry that is being edited.
* @return array The fields with attributes, fake attributes and values.
*/
public function getUpdateFields($id = false)
{
$fields = $this->crud->fields();
$entry = ($id != false) ? $this->getEntry($id) : $this->crud->getCurrentEntry();
$options = $entry->value ?? [];
foreach ($options as $k => $v) {
$fields[$k]['value'] = $v;
}
if (!array_key_exists('id', $fields)) {
$fields['id'] = [
'name' => $entry->getKeyName(),
'value' => $entry->getKey(),
'type' => 'hidden',
];
}
return $fields;
}
public function reset(Request $request, $id)
{
$theme = Theme::fromCache()->find($id);
if (is_null($theme)) {
Alert::warning("Không tìm thấy dữ liệu giao diện")->flash();
return redirect(backpack_url('theme'));
}
$fields = collect($theme->options);
$theme->update([
'value' => $fields->pluck('value', 'name')->toArray()
]);
Alert::success(trans('backpack::crud.update_success'))->flash();
return redirect(backpack_url('theme'));
}
public function active($id)
{
$theme = Theme::fromCache()->find($id);
if (is_null($theme)) {
Alert::warning("Không tìm thấy dữ liệu giao diện")->flash();
return redirect(backpack_url('theme'));
}
$res = $theme->active();
if ($res) {
Alert::success(trans('backpack::crud.update_success'))->flash();
} else {
Alert::error(trans('backpack::crud.update_failed'))->flash();
}
return redirect(backpack_url('theme'));
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace Vsmov\Core\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}