Synchro back-office, fix on tariffs
This commit is contained in:
15
app/Contracts/Commentator.php
Normal file
15
app/Contracts/Commentator.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace BeyondCode\Comments\Contracts;
|
||||
|
||||
|
||||
interface Commentator
|
||||
{
|
||||
/**
|
||||
* Check if a comment for a specific model needs to be approved.
|
||||
* @param mixed $model
|
||||
* @return bool
|
||||
*/
|
||||
public function needsCommentApproval($model): bool;
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace App\Datatables\Admin\Core;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
|
||||
use App\Models\Admin\Core\Comment;
|
||||
use App\Models\Core\Comment;
|
||||
use App\Repositories\Core\Comments;
|
||||
|
||||
class CommentsDataTable extends DataTable
|
||||
|
||||
@@ -6,15 +6,16 @@ use Yajra\DataTables\Html\Column;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Repositories\Shop\Articles;
|
||||
|
||||
class ArticlesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'articles';
|
||||
public $sortedColumn = 1;
|
||||
public $sortedColumn = 2;
|
||||
|
||||
public function query(Article $model)
|
||||
{
|
||||
$model = $model::with('article_nature')->withCount(['categories', 'tags'])->joinRelationship('article_nature');
|
||||
$model = $model::with(['article_nature','image'])->withCount(['categories', 'tags'])->joinRelationship('article_nature');
|
||||
$model = self::filterByArticleNature($model);
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
@@ -25,10 +26,22 @@ class ArticlesDataTable extends DataTable
|
||||
return $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('thumb', function (Article $article) {
|
||||
return Articles::getThumbsSrc($article->image);
|
||||
})
|
||||
->rawColumns(['thumb','action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('article_nature.name')->title('Nature'),
|
||||
Column::make('thumb')->searchable(false),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('tags_count')->title('Tags')->class('text-right')->searchable(false),
|
||||
Column::make('categories_count')->title('Rayons')->class('text-right')->searchable(false),
|
||||
|
||||
@@ -7,7 +7,15 @@ use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
use App\Repositories\Shop\Categories;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
$data['categories'] = Categories::getTree();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\Datatables\Shop\CategoriesDataTable;
|
||||
use App\Repositories\Shop\Offers;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
public function index(CategoriesDataTable $dataTable)
|
||||
public function index()
|
||||
{
|
||||
return $dataTable->render('Shop.Categories.list');
|
||||
}
|
||||
@@ -22,8 +22,10 @@ class CategoryController extends Controller
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data = Categories::get($id);
|
||||
return view('Shop.Categories.view', $data);
|
||||
$data = self::init();
|
||||
$data['category'] = Categories::getByCategory($id)->toArray();
|
||||
$data['offers'] = Offers::getByCategory($id)->toArray();
|
||||
return view('Shop.shelve', $data);
|
||||
}
|
||||
|
||||
public function getTree()
|
||||
|
||||
@@ -7,30 +7,19 @@ use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\Categories;
|
||||
use App\Repositories\Shop\Offers;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['categories'] = Categories::getTree();
|
||||
$data['category'] = Categories::get(15)->toArray();
|
||||
$data['articles'] = Articles::getByCategory(0)->toArray();
|
||||
// dump($data);
|
||||
$data = self::init();
|
||||
$data['offers'] = Offers::getLast()->toArray();
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,68 @@
|
||||
|
||||
namespace App\Models\Core;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
use App\Repositories\Core\DateTime;
|
||||
use App\Traits\HasComments;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
use HasComments;
|
||||
|
||||
public function user()
|
||||
protected $fillable = [
|
||||
'comment',
|
||||
'user_id',
|
||||
'is_approved'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_approved' => 'boolean'
|
||||
];
|
||||
|
||||
public function scopeApproved($query)
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Core\Auth\User::class);
|
||||
return $query->where('is_approved', true);
|
||||
}
|
||||
|
||||
public function getUpdatedAtAttribute($value)
|
||||
public function commentable()
|
||||
{
|
||||
return DateTime::DateToLocale($value);
|
||||
}
|
||||
}
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function commentator()
|
||||
{
|
||||
return $this->belongsTo($this->getAuthModelName(), 'user_id');
|
||||
}
|
||||
|
||||
public function approve()
|
||||
{
|
||||
$this->update([
|
||||
'is_approved' => true,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function disapprove()
|
||||
{
|
||||
$this->update([
|
||||
'is_approved' => false,
|
||||
]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getAuthModelName()
|
||||
{
|
||||
if (config('comments.user_model')) {
|
||||
return config('comments.user_model');
|
||||
}
|
||||
|
||||
if (!is_null(config('auth.providers.users.model'))) {
|
||||
return config('auth.providers.users.model');
|
||||
}
|
||||
|
||||
throw new Exception('Could not determine the commentator model name.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@ use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
use BeyondCode\Comments\Traits\HasComments;
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
use Kirschbaum\PowerJoins\PowerJoins;
|
||||
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
use App\Traits\HasComments;
|
||||
|
||||
class Article extends Model implements HasMedia
|
||||
{
|
||||
use Categorizable, EloquentJoin, HasComments, InteractsWithMedia, Powerjoins, Taggable, SoftDeletes, UserStamps;
|
||||
@@ -44,6 +45,11 @@ class Article extends Model implements HasMedia
|
||||
return $this->hasMany(InvoiceItem::class);
|
||||
}
|
||||
|
||||
public function offers()
|
||||
{
|
||||
return $this->hasMany(Offer::class);
|
||||
}
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasMany(Price::class);
|
||||
@@ -66,6 +72,9 @@ class Article extends Model implements HasMedia
|
||||
|
||||
public function scopeByCategory($query, $category_id)
|
||||
{
|
||||
return $query->whereHas('categories', function ($query) use ($category_id) {
|
||||
$query->where('id', $category_id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $id)
|
||||
@@ -83,6 +92,11 @@ class Article extends Model implements HasMedia
|
||||
return $query->where($this->table . '.product_id', $model_id);
|
||||
}
|
||||
|
||||
public function scopeWithOffers($query)
|
||||
{
|
||||
return $query->has('Offers');
|
||||
}
|
||||
|
||||
public function registerMediaConversions(Media $media = null) : void
|
||||
{
|
||||
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_CROP, 32, 32);
|
||||
|
||||
@@ -35,4 +35,9 @@ class Category extends Model
|
||||
return $this->belongsTo(app('rinvex.categories.category'),'category_id');
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, $category_id)
|
||||
{
|
||||
return $query->where('category_id', $category_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use BeyondCode\Comments\Traits\HasComments;
|
||||
use App\Traits\HasComments;
|
||||
|
||||
class Offer extends Model
|
||||
{
|
||||
use HasComments;
|
||||
@@ -17,6 +18,11 @@ class Offer extends Model
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->article->categories();
|
||||
}
|
||||
|
||||
public function variation()
|
||||
{
|
||||
return $this->belongsTo(Variation::class);
|
||||
@@ -26,4 +32,26 @@ class Offer extends Model
|
||||
{
|
||||
return $this->belongsTo(Tariff::class);
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, $category_id)
|
||||
{
|
||||
return $query->whereHas('article.categories', function ($query) use ($category_id) {
|
||||
$query->where('category_id', $category_id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByStatus($query, $id)
|
||||
{
|
||||
return $query->where('status_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByVariation($query, $id)
|
||||
{
|
||||
return $query->where('variation_id', $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use BeyondCode\Comments\Traits\HasComments;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
use App\Traits\HasComments;
|
||||
|
||||
class PriceList extends Model
|
||||
{
|
||||
use BelongsToThrough, HasComments;
|
||||
|
||||
@@ -5,9 +5,10 @@ namespace App\Models\Shop;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||
use BeyondCode\Comments\Traits\HasComments;
|
||||
use Kirschbaum\PowerJoins\PowerJoins;
|
||||
|
||||
use App\Traits\HasComments;
|
||||
|
||||
class Tariff extends Model
|
||||
{
|
||||
use HasComments, HasRelationships, PowerJoins;
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use BeyondCode\Comments\Traits\HasComments;
|
||||
use App\Traits\HasComments;
|
||||
class Variation extends Model
|
||||
{
|
||||
use HasComments;
|
||||
|
||||
@@ -52,7 +52,7 @@ class Species
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Specie::findOrFail($id);
|
||||
return Specie::with('tags.group')->findOrFail($id);
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
|
||||
@@ -46,7 +46,7 @@ class Varieties
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variety::findOrFail($id);
|
||||
return Variety::with('tags.group')->findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserStatusTeam;
|
||||
|
||||
class UserStatusTeams
|
||||
{
|
||||
|
||||
// supprime l'association entre les équipes et le statut utilisateur donné
|
||||
public function delete_teams($id)
|
||||
{
|
||||
return UserStatusTeam::byUserStatus($id)->delete();
|
||||
}
|
||||
|
||||
// associe une équipe avec un statut utilisateur
|
||||
public function insert_team($user_status_id, $team_id)
|
||||
{
|
||||
return UserStatusTeam::create(['team_id' => $team_id, 'user_status_id' => $user_status_id]);
|
||||
}
|
||||
|
||||
// récupère les équipes d'un statut utilisateur donné
|
||||
public function select_teams_by_id($id)
|
||||
{
|
||||
return UserStatusTeam::select('team_id')->byUserStatus($id)->get();
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserStatus;
|
||||
|
||||
class UserStatuses
|
||||
{
|
||||
// compte le nombre de statut utilisateur
|
||||
public static function count()
|
||||
{
|
||||
return UserStatus::count();
|
||||
}
|
||||
|
||||
// supprime un statut utilisateur
|
||||
public static function delete($id)
|
||||
{
|
||||
return UserStatus::destroy($id);
|
||||
}
|
||||
|
||||
// ajoute un statut utilisateur
|
||||
public static function insert($name, $translated, $negociator)
|
||||
{
|
||||
return UserStatus::create(['name' => $name, 'translated' => $translated, 'negociator' => $negociator]);
|
||||
}
|
||||
|
||||
// reset le négociateur parmi les statuts
|
||||
public static function reset_negociator_status()
|
||||
{
|
||||
return UserStatus::update(['negociator' => null]);
|
||||
}
|
||||
|
||||
// récupère toutes les infos sur les statuts utilisateur
|
||||
public static function select_all()
|
||||
{
|
||||
return UserStatus::all()->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos pour un statut utilisateur donné
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return UserStatus::find($id)->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos pour un statut utilisateur donné
|
||||
public static function select_by_name($name)
|
||||
{
|
||||
return UserStatus::byName($name)->first()->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos du statut considéré comme négociant d'un contrat
|
||||
public static function select_by_negociator()
|
||||
{
|
||||
$status = UserStatus::byNegociator()->first();
|
||||
return $status ? $status->toArray() : null;
|
||||
}
|
||||
|
||||
// met à jour le statut actif/inactif d'un statut utilisateur
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return UserStatus::find($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
// met à jour les informations d'un statut utilisateur
|
||||
public static function update($id, $name, $translated, $negociator)
|
||||
{
|
||||
return UserStatus::find($id)->update(['id' => $id, 'name' => $name, 'translated' => $translated, 'negociator' => $negociator]);
|
||||
}
|
||||
|
||||
// met à jour les informations d'un statut utilisateur
|
||||
public static function update_negociator($id, $negociator)
|
||||
{
|
||||
return UserStatus::find($id)->update(['negociator' => $negociator]);
|
||||
}
|
||||
|
||||
public static function getAllUserStatuses($input)
|
||||
{
|
||||
$data = [];
|
||||
$statuses = self::select_all();
|
||||
foreach ($statuses as $status) {
|
||||
if ($status['active'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
$item = array();
|
||||
$item['id'] = $status['id'];
|
||||
$item['name'] = \App\Repositories\Translate::translateClient($status['translated']);
|
||||
array_push($data, $item);
|
||||
}
|
||||
$data = \App\Repositories\Functions::array_orderby($data, 'name', SORT_ASC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return UserStatus::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getNegociatorsOptions()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class DateTime
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
$date = today()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ class DateTime
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
$date = now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
@@ -76,6 +76,9 @@ class DateTime
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (strlen($date) == 16) {
|
||||
$date .= ':00';
|
||||
}
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
@@ -102,12 +105,12 @@ class DateTime
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
@@ -116,29 +119,45 @@ class DateTime
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y H:i:s';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d H:i:s';
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y H:i:s';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d H:i:s';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function getLocaleDateFull($date)
|
||||
public static function getLocaleDateFull($date = false)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('LLLL');
|
||||
return self::getISOFormat('LL', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleDateFullShort($date)
|
||||
public static function getLocaleDateTimeFull($date = false)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('lll');
|
||||
return self::getISOFormat('LLL', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleHour($date)
|
||||
public static function getLocaleDateFullShort($date = false)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('');
|
||||
return self::getISOFormat('ll', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleDateTimeFullShort($date = false)
|
||||
{
|
||||
return self::getISOFormat('lll', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleTime($date = false)
|
||||
{
|
||||
return self::getISOFormat('LT', $date);
|
||||
}
|
||||
|
||||
public static function getISOFormat($format, $date = false)
|
||||
{
|
||||
$date = $date ? $date : now();
|
||||
return Carbon::parse($date)->isoFormat($format);
|
||||
}
|
||||
|
||||
public static function relativeTime()
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Media
|
||||
{
|
||||
public static function getImages($model)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
}
|
||||
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($model, $file)
|
||||
{
|
||||
return $model->addMedia($file)->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return "1";
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$images = json_decode($image['responsive_images'], true);
|
||||
/*
|
||||
$urls = $images['medialibrary_original']['urls'];
|
||||
|
||||
$img = $urls[count($urls)-1];
|
||||
$src = "storage/$id/responsive-images/$img";
|
||||
*/
|
||||
return $src ?? null;
|
||||
}
|
||||
}
|
||||
99
app/Repositories/Core/Medias.php
Normal file
99
app/Repositories/Core/Medias.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Medias
|
||||
{
|
||||
|
||||
public static function getImage($model, $conversion = 'normal', $collection = 'images')
|
||||
{
|
||||
$img = $model->getMedia($collection)->first();
|
||||
return $img ? $img->getUrl($conversion) : false;
|
||||
}
|
||||
|
||||
public static function getImages($model)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
}
|
||||
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($model, $file, $collection = 'images')
|
||||
{
|
||||
return $model->addMedia($file)->sanitizingFileName(function ($fileName) {
|
||||
return str_replace(['#', '/', '\\', ' '], '-', $fileName);
|
||||
})->toMediaCollection($collection);
|
||||
}
|
||||
|
||||
public static function deleteImages($model, $collection = 'images')
|
||||
{
|
||||
$ret = $model->clearMediaCollection($collection);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function buildURL($image, $conversion = '')
|
||||
{
|
||||
return self::getPath($image) . self::getConversion($image, $conversion);
|
||||
}
|
||||
|
||||
public static function getPath($image)
|
||||
{
|
||||
$model = basename(str_replace('\\', '/', $image->model_type));
|
||||
return '/storage/' . $model . '/' . $image->collection_name . '/' . $image->id;
|
||||
}
|
||||
|
||||
public static function getConversion($image, $conversion = '')
|
||||
{
|
||||
// return $conversion ? '/conversions/' . $image->name . '-' . $conversion . self::getExtension($image->file_name) : $image->file_name;
|
||||
return $conversion ? '/conversions/' . $image->name . '-' . $conversion . '.jpg' : $image->file_name;
|
||||
}
|
||||
|
||||
public static function getExtension($filename)
|
||||
{
|
||||
return '.' . pathinfo($filename, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$filename = $image['name'] . '-thumb' . self::getExtension($image['file_name']);
|
||||
|
||||
return "/storage/$id/conversions/$filename";
|
||||
}
|
||||
|
||||
public static function getPreviewSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$filename = $image['name'] . '-preview' . self::getExtension($image['file_name']);
|
||||
|
||||
return "/storage/$id/conversions/$filename";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace App\Repositories\Shop;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Media;
|
||||
use App\Repositories\Core\Medias;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
@@ -74,7 +74,7 @@ class Articles
|
||||
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$article = Article::with('product.tags.group')->findOrFail($id);
|
||||
$product_type = $article->product_type;
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
@@ -245,26 +245,31 @@ class Articles
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
return Media::storeImages($article, $files);
|
||||
return Medias::storeImages($article, $files);
|
||||
}
|
||||
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return Media::storeImage($article, $file);
|
||||
return Medias::storeImage($article, $file);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
return Media::getImages(self::get($id));
|
||||
return Medias::getImages(self::get($id));
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
return Media::getThumbSrc($image);
|
||||
return Medias::getThumbSrc($image);
|
||||
}
|
||||
|
||||
public static function getPreviewSrc($image)
|
||||
{
|
||||
return Medias::getPreviewSrc($image);
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
return Medias::deleteImage(self::get($id), $index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ class Categories
|
||||
return Category::with('CategoryTree')->find($id);
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Category::byCategory($category_id)->first();
|
||||
}
|
||||
|
||||
public static function getTree()
|
||||
{
|
||||
return CategoryTrees::getTree();
|
||||
|
||||
@@ -6,14 +6,15 @@ use App\Models\Shop\Offer;
|
||||
|
||||
class Offers
|
||||
{
|
||||
public static function getOptions()
|
||||
|
||||
public static function getLast()
|
||||
{
|
||||
return Offer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Offer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
return Offer::with(['article.image'])->byCategory($category_id)->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -29,6 +29,12 @@ class Tags
|
||||
return Tag::orderBy('order', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getFullname($id)
|
||||
{
|
||||
$tag = Tag::with('group')->find($id);
|
||||
return $tag->group->name . '-' . $tag->name;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Tag::find($id);
|
||||
|
||||
11
app/Traits/CanComment.php
Normal file
11
app/Traits/CanComment.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait CanComment
|
||||
{
|
||||
public function needsCommentApproval($model): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
36
app/Traits/HasComments.php
Normal file
36
app/Traits/HasComments.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Contracts\Commentator;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use App\Models\Core\Comment;
|
||||
|
||||
trait HasComments
|
||||
{
|
||||
public function comments()
|
||||
{
|
||||
return $this->morphMany(Comment::class, 'commentable');
|
||||
}
|
||||
|
||||
public function comment(string $comment)
|
||||
{
|
||||
return $this->commentAsUser(auth()->user(), $comment);
|
||||
}
|
||||
|
||||
public function commentAsUser(?Model $user, string $comment)
|
||||
{
|
||||
|
||||
$comment = new Comment([
|
||||
'comment' => $comment,
|
||||
'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
|
||||
'user_id' => is_null($user) ? null : $user->getKey(),
|
||||
'commentable_id' => $this->getKey(),
|
||||
'commentable_type' => get_class(),
|
||||
]);
|
||||
|
||||
return $this->comments()->save($comment);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user