This commit is contained in:
Ludovic CANDELLIER
2021-08-21 19:48:21 +02:00
parent 7ec40145de
commit 9ca510086b
24 changed files with 423 additions and 65 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Datatables\Admin\Core;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Admin\Core\Comment;
use App\Repositories\Core\Comments;
class CommentsDataTable extends DataTable
{
public $model_name = 'comments';
public function __construct()
{
$this->url = route('Admin.Core.Comments.index');
}
public function query(Comment $model)
{
$model = $model::with(['user'])->select('*');
return self::buildQuery($model);
}
protected function getColumns()
{
return [
Column::make('updated_at')->title(__('date'))->width('80')->class('text-center')->searchable(false),
Column::make('user.name')->title(__('name'))->searchable(false),
Column::make('comment')->title(__('comments'))->searchable(false),
self::makeColumnButtons(),
];
}
}

View File

@@ -10,22 +10,24 @@ use Yajra\DataTables\Services\DataTable;
class ParentDataTable extends DataTable
{
public $rowReorder = true;
public $rowReorderSelector; // ['selector' => 'tr']
public $autoWidth = false;
public $colReorder = false;
public $fixedColumns = false;
public $fixedHeader = false;
public $rowReorder = false;
public $rowReorderSelector; // ['selector' => 'tr']
public $scrollCollapse = false;
public $scrollX = false;
public $scrollCollapse = true;
public $sortedColumn = 0;
public $sortedOrder = 'asc';
public $stateSave = false;
/**
* Build DataTable class.
*
* @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract
*/
* Build DataTable class.
*
* @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract
*/
public function dataTable($query)
{
return $this->modifier(datatables()->eloquent($query));
@@ -39,7 +41,7 @@ class ParentDataTable extends DataTable
/**
* Add buttons DataTable class.
*
* @param mixed $query Results from query() method.
* @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract
*/
public function addButtons($datatables)
@@ -50,15 +52,27 @@ class ParentDataTable extends DataTable
public function getHtmlButtons()
{
$buttons = '';
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-leaf-alt"></i></button>';
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-pencil-alt"></i></button>';
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
$buttons .= self::getButtonEdit();
$buttons .= self::getButtonDel();
return $buttons;
// return view('components.datatables.buttons.row_action');
}
public function getButtonEdit()
{
return '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-pencil-alt"></i></button>';
}
public function getButtonShow()
{
return '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
}
public function getButtonDel()
{
return '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
}
public function makeColumnButtons()
{
return Column::computed('action')
@@ -66,7 +80,7 @@ class ParentDataTable extends DataTable
->exportable(false)
->printable(false)
->searchable(false)
->width("74")
->width(74)
->addClass('text-center text-nowrap');
}
@@ -78,7 +92,7 @@ class ParentDataTable extends DataTable
/**
* Get query source of dataTable.
*
* @param \App\Family $model
* @param \App\Family $model
* @return \Illuminate\Database\Eloquent\Builder
*/
public function buildQuery($model)
@@ -106,24 +120,22 @@ class ParentDataTable extends DataTable
$table_id = $table_id ? $table_id : strtolower($this->model_name) . '-table';
$selector = $selector ? $selector : '#' . $this->model_name . '-filters';
return $this->builder()
->setTableId($table_id)
->parameters($this->getParameters())
->columns($this->getColumns())
->ajax(
[
->setTableId($table_id)
->parameters($this->getParameters())
->columns($this->getColumns())
->ajax([
'data' => 'function(d) { d.filters = $("' . $selector . '").serializeJSON(); }',
'url' => isset($this->url) ? $this->url : ''
]
)
->dom($this->getDom())
->orderBy($this->sortedColumn, $this->sortedOrder)
->buttons($this->getButtons());
])
->dom($this->getDom())
->orderBy($this->sortedColumn, $this->sortedOrder)
->buttons($this->getButtons());
}
public function getButtons()
{
return [
Button::make('export'),
// Button::make('export'),
Button::make('print'),
Button::make('colvis'),
Button::make('columnsToggle')
@@ -133,13 +145,14 @@ class ParentDataTable extends DataTable
public function getParameters()
{
$data = [
'pageLength' => 5,
'scrollX' => $this->scrollX,
'scrollCollapse' => $this->scrollCollapse,
'searchDelay' => 500,
'autoWidth' => $this->autoWidth,
'colReorder' => $this->colReorder,
'fixedColumns' => $this->fixedColumns,
// 'autoWidth' => false,
'fixedHeader' => $this->fixedHeader,
'pageLength' => 5,
'searchDelay' => 500,
'scrollX' => $this->scrollX,
'scrollCollapse' => $this->scrollCollapse,
'stateSave' => $this->stateSave
];
if ($this->rowReorder) {

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Http\Controllers\Admin\Core;
use Illuminate\Http\Request;
use App\Repositories\Core\Comments;
use App\Datatables\Admin\Core\CommentsDataTable;
class CommentController extends Controller
{
public function index(CommentsDataTable $dataTable, $model, $model_id)
{
$data['model'] = $model;
$data['model_id'] = $model_id;
return $dataTable->render('Admin.Core.Comment.index', $data);
}
public function create($model, $model_id)
{
$data['comment']['commentable_type'] = $model;
$data['comment']['commentable_id'] = $model_id;
return view('Admin.Core.Comments.partials.modal', $data);
}
public function edit(Request $request, $id = false)
{
$id = $id ? $id : $request->input('id');
$data = Comments::get($id);
return view('Admin.Core.Comments.partials.modal', $data);
}
public function store(Request $request)
{
$data = $request->all();
Comments::store($data);
return response()->json(['error' => 0]);
}
public function destroy(Request $request, $id = false)
{
$id = $id ? $id : $request->input('id');
Comments::destroy($id);
return response()->json(['error' => 0]);
}
}

View File

@@ -25,6 +25,7 @@ class ArticleController extends Controller
public function create()
{
$data = Articles::getMeta();
// $data['comment']['']
return view('Admin.Shop.Articles.create', $data);
}

View File

@@ -22,6 +22,8 @@ class OfferController extends Controller
public function store(Request $request)
{
dump($request->all());
exit;
$ret = Offers::store($request->all());
return redirect()->route('Admin.Shop.Offers.index');
}

View File

@@ -2,15 +2,22 @@
namespace App\Models\Core;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Venturecraft\Revisionable\RevisionableTrait;
use Wildside\Userstamps\Userstamps;
use App\Repositories\Core\DateTime;
use BeyondCode\Comments\Comment as parentComment;
class Comment extends parentComment
class Comment extends Model
{
use SoftDeletes, Userstamps;
protected $guarded = [];
}
public function user()
{
return $this->belongsTo(\App\Models\Core\Auth\User::class);
}
public function getUpdatedAtAttribute($value)
{
return DateTime::DateToLocale($value);
}
}

View File

@@ -2,23 +2,50 @@
namespace App\Repositories\Core;
use BeyondCode\Comments\Comment;
use App\Models\Core\Comment as rawComment;
use App\Repositories\Core\Auth\Users;
use App\Datatables\Admin\Core\CommentsDataTable;
class Comments
{
public static function get($id)
{
return rawComment::find($id);
}
public static function getDatatable()
{
$model = new CommentsDataTable();
return $model->html();
}
public static function getCommentsByClass($class, $id)
{
return self::getByModel(self::getModel($class, $id));
}
public static function getModel($class, $id)
{
return $$class::find($id);
}
public static function getClass($class)
{
return 'App\Models\\' . str_replace('.','\\', $class);
}
public static function getByModel($model)
{
if (!$model) {
return false;
}
return $model->comments;
return $model ? $model->comments : false;
}
public static function storeComments($model, $comments)
{
if ($comments) {
foreach ($comments as $comment) {
self::storeComment($model, $comment);
}
foreach (($comments ?? []) as $comment) {
self::storeComment($model, $comment);
}
}
@@ -27,6 +54,31 @@ class Comments
return $model->comment($comment);
}
public static function store($data)
{
$id = $data['id'] ?? false;
unset($data['_token']);
$data['commentable_type'] = Comments::getClass($data['commentable_type']);
$data['commentable_id'] = (int) $data['commentable_id'];
return $id ? self::update($data, $id) : self::create($data);
}
public static function create($data)
{
unset($data['id']);
$data['is_approved'] = true;
$data['user_id'] = Users::getId();
return rawComment::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$model = self::get($id);
$model->update($data);
return $model;
}
public static function deleteComments($model)
{
return true;

View File

@@ -6,6 +6,7 @@ use Illuminate\Support\Str;
use App\Repositories\Core\Tag;
use App\Repositories\Core\Media;
use App\Repositories\Core\Comments;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Models\Shop\Article;
@@ -37,6 +38,10 @@ class Articles
$data['article']['categories'] = self::getCategoriesByArticle($article);
$data['article']['tags'] = self::getTagsByArticle($article);
// $data['article']['prices'] = self::getPricesByArticle($article);
// $data['datatables']['comments'] = Comments::getDatatable();
$data['article']['comments'] = $article->comments;
self::getMeta($data);
return $data;
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Offer;
class Offers
{
public static function getOptions()
{
return Offer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
}
public static function getOptionsByPackage($package_id)
{
return Offer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
}
public static function getAll()
{
return Offer::orderBy('value', 'asc')->get();
}
public static function get($id)
{
return Offer::findOrFail($id);
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
public static function create($data)
{
return Offer::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return Offer::destroy($id);
}
}

View File

@@ -8,7 +8,7 @@ class Tariffs
{
public static function autocomplete($str)
{
$data = Tariff::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
$data = Tariff::where('name', 'LIKE', "%${str}%")->orWhere('ref', 'LIKE', "${str}%")->orWhere('code', 'LIKE', "${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
$export = [];
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];