diff --git a/app/Datatables/Admin/Core/CommentsDataTable.php b/app/Datatables/Admin/Core/CommentsDataTable.php new file mode 100644 index 00000000..428e0196 --- /dev/null +++ b/app/Datatables/Admin/Core/CommentsDataTable.php @@ -0,0 +1,35 @@ +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(), + ]; + } +} diff --git a/app/Datatables/ParentDataTable.php b/app/Datatables/ParentDataTable.php index a2182e9e..4461f675 100644 --- a/app/Datatables/ParentDataTable.php +++ b/app/Datatables/ParentDataTable.php @@ -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 .= ''; - // $buttons .= ''; - $buttons .= ''; - $buttons .= ''; + $buttons .= self::getButtonEdit(); + $buttons .= self::getButtonDel(); return $buttons; // return view('components.datatables.buttons.row_action'); } + public function getButtonEdit() + { + return ''; + } + + public function getButtonShow() + { + return ''; + } + + public function getButtonDel() + { + return ''; + } + 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) { diff --git a/app/Http/Controllers/Admin/Core/CommentController.php b/app/Http/Controllers/Admin/Core/CommentController.php new file mode 100644 index 00000000..089003e4 --- /dev/null +++ b/app/Http/Controllers/Admin/Core/CommentController.php @@ -0,0 +1,46 @@ +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]); + } +} diff --git a/app/Http/Controllers/Admin/Shop/ArticleController.php b/app/Http/Controllers/Admin/Shop/ArticleController.php index 2cb878d5..19df5f56 100644 --- a/app/Http/Controllers/Admin/Shop/ArticleController.php +++ b/app/Http/Controllers/Admin/Shop/ArticleController.php @@ -25,6 +25,7 @@ class ArticleController extends Controller public function create() { $data = Articles::getMeta(); + // $data['comment'][''] return view('Admin.Shop.Articles.create', $data); } diff --git a/app/Http/Controllers/Admin/Shop/OfferController.php b/app/Http/Controllers/Admin/Shop/OfferController.php index 1649e289..3c811fb6 100644 --- a/app/Http/Controllers/Admin/Shop/OfferController.php +++ b/app/Http/Controllers/Admin/Shop/OfferController.php @@ -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'); } diff --git a/app/Models/Core/Comment.php b/app/Models/Core/Comment.php index f21dc7bf..3d72debc 100644 --- a/app/Models/Core/Comment.php +++ b/app/Models/Core/Comment.php @@ -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); + } +} \ No newline at end of file diff --git a/app/Repositories/Core/Comments.php b/app/Repositories/Core/Comments.php index fed946cf..95ed6e25 100644 --- a/app/Repositories/Core/Comments.php +++ b/app/Repositories/Core/Comments.php @@ -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; diff --git a/app/Repositories/Shop/Articles.php b/app/Repositories/Shop/Articles.php index a6c3c0ca..769534d3 100644 --- a/app/Repositories/Shop/Articles.php +++ b/app/Repositories/Shop/Articles.php @@ -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; } diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php new file mode 100644 index 00000000..7f190e60 --- /dev/null +++ b/app/Repositories/Shop/Offers.php @@ -0,0 +1,53 @@ +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); + } +} diff --git a/app/Repositories/Shop/Tariffs.php b/app/Repositories/Shop/Tariffs.php index c0598102..6f983f2f 100644 --- a/app/Repositories/Shop/Tariffs.php +++ b/app/Repositories/Shop/Tariffs.php @@ -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]; diff --git a/resources/lang/fr.json b/resources/lang/fr.json new file mode 100644 index 00000000..d45e7e5d --- /dev/null +++ b/resources/lang/fr.json @@ -0,0 +1,58 @@ +{ + "Date": "Date", + "The list of logs is empty!": "La liste des logs est vide !", + "All": "Tous", + "Emergency": "Urgence", + "Alert": "Alerte", + "Critical": "Critique", + "Error": "Erreur", + "Warning": "Avertissement", + "Notice": "Notice", + "Info": "Info", + "Debug": "Debogage", + "name": "Nom", + "gender": "Civilité", + "mr": "M.", + "mrs": "Mme", + "firstname": "Prénom", + "lastname": "Nom", + "position": "Poste", + "department": "Service", + "office": "Bureau", + "fax": "Fax", + "email": "Email", + "phone": "Téléphone", + "phone_central": "Téléphone Accueil", + "mobile": "Mobile", + "zipcode": "Code postal", + "country": "Pays", + "company": "Entreprise", + "address": "Adresse", + "street": "Rue", + "state": "Région", + "postal_address": "Adresse postale", + "city": "Ville", + "copyright": "© JardinEnvie 2021", + "records": "enregistrements", + "delay": "Délai", + "rows_on": "lignes sur", + "selection": "Sélection", + "others": "Autres", + "list": "Liste", + "active": "Actif", + "yes": "Oui", + "no": "Non", + "choose_a_file": "Choisissez un fichier", + "select_a_value": "Selectionnez une valeur", + "members_area": "Espace réservé", + "login_to_your_account": "Se connecter à votre compte", + "sign_in": "connexion", + "password_reset": "Réinitialisation du mot de passe", + "login": "Identifiant", + "password": "Mot de passe", + "updated_at": "Mis à jour", + "cancel": "Annuler", + "save": "Sauver", + "comments": "Notes internes", + "comment_add": "Ajout de Note interne" +} \ No newline at end of file diff --git a/resources/views/Admin/Core/Comments/partials/comments.blade.php b/resources/views/Admin/Core/Comments/partials/comments.blade.php index 92990695..d51f1f8b 100644 --- a/resources/views/Admin/Core/Comments/partials/comments.blade.php +++ b/resources/views/Admin/Core/Comments/partials/comments.blade.php @@ -1,11 +1,35 @@ @component('components.layout.box-collapse', ['id' => 'comments', 'title' => __('comments')]) @if (!empty($comments)) @foreach ($comments as $comment) - {!! $comment !!} +