add methods to get icon on article natures
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Datatables\Admin\Shop;
|
|||||||
|
|
||||||
use App\Datatables\ParentDataTable as DataTable;
|
use App\Datatables\ParentDataTable as DataTable;
|
||||||
use App\Models\Shop\ArticleNature;
|
use App\Models\Shop\ArticleNature;
|
||||||
|
use App\Repositories\Core\Medias;
|
||||||
use App\Repositories\Shop\ArticleNatures;
|
use App\Repositories\Shop\ArticleNatures;
|
||||||
use Yajra\DataTables\Html\Column;
|
use Yajra\DataTables\Html\Column;
|
||||||
|
|
||||||
@@ -11,6 +12,8 @@ class ArticleNaturesDataTable extends DataTable
|
|||||||
{
|
{
|
||||||
public $model_name = 'article_natures';
|
public $model_name = 'article_natures';
|
||||||
|
|
||||||
|
public $sortedColumn = 1;
|
||||||
|
|
||||||
public function query(ArticleNature $model)
|
public function query(ArticleNature $model)
|
||||||
{
|
{
|
||||||
$model = $model::withCount('Articles');
|
$model = $model::withCount('Articles');
|
||||||
@@ -21,10 +24,15 @@ class ArticleNaturesDataTable extends DataTable
|
|||||||
public function modifier($datatables)
|
public function modifier($datatables)
|
||||||
{
|
{
|
||||||
$datatables
|
$datatables
|
||||||
|
->editColumn('icon', function (ArticleNature $nature) {
|
||||||
|
$logo = Medias::getImage($nature, 'thumb');
|
||||||
|
|
||||||
|
return $logo ? "<img src='{$logo}'>" : '';
|
||||||
|
})
|
||||||
->editColumn('product_type', function (ArticleNature $nature) {
|
->editColumn('product_type', function (ArticleNature $nature) {
|
||||||
return ArticleNatures::getProductTypeName($nature->product_type);
|
return ArticleNatures::getProductTypeName($nature->product_type);
|
||||||
})
|
})
|
||||||
->rawColumns(['action']);
|
->rawColumns(['icon', 'action']);
|
||||||
|
|
||||||
return parent::modifier($datatables);
|
return parent::modifier($datatables);
|
||||||
}
|
}
|
||||||
@@ -32,6 +40,7 @@ class ArticleNaturesDataTable extends DataTable
|
|||||||
protected function getColumns()
|
protected function getColumns()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Column::make('icon')->title('Icone')->width(40)->orderable(false),
|
||||||
Column::make('product_type')->title('Famille de produit')->width(140),
|
Column::make('product_type')->title('Famille de produit')->width(140),
|
||||||
Column::make('name')->title('Nom'),
|
Column::make('name')->title('Nom'),
|
||||||
Column::make('articles_count')->title('Nb Art.')->addClass('text-right')->searchable(false)->width(60),
|
Column::make('articles_count')->title('Nb Art.')->addClass('text-right')->searchable(false)->width(60),
|
||||||
|
|||||||
@@ -20,24 +20,29 @@ class ArticleNatureController extends Controller
|
|||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$ret = ArticleNatures::store($request->all());
|
$articleNature = ArticleNatures::store($request->all());
|
||||||
|
ArticleNatures::storeIcon($articleNature, $request->file('icon'));
|
||||||
|
|
||||||
return redirect()->route('Admin.Shop.ArticleNatures.index');
|
return redirect()->route('Admin.Shop.ArticleNatures.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$data['article_nature'] = ArticleNatures::get($id);
|
$data = [
|
||||||
|
'article_nature' => ArticleNatures::get($id),
|
||||||
|
];
|
||||||
|
|
||||||
return view('Admin.Shop.ArticleNatures.view', $data);
|
return view('Admin.Shop.ArticleNatures.view', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$data['article_nature'] = ArticleNatures::get($id);
|
$data = [
|
||||||
$data['product_types'] = ArticleNatures::getProductTypes();
|
'article_nature' => ArticleNatures::get($id),
|
||||||
// dump($data);
|
'product_types' => ArticleNatures::getProductTypes(),
|
||||||
// exit;
|
];
|
||||||
|
$data['article_nature']['icon'] = ArticleNatures::getIcon($id);
|
||||||
|
|
||||||
return view('Admin.Shop.ArticleNatures.edit', $data);
|
return view('Admin.Shop.ArticleNatures.edit', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ class CategoryController extends Controller
|
|||||||
]);
|
]);
|
||||||
if (count($articleNatures) === 1) {
|
if (count($articleNatures) === 1) {
|
||||||
$articleNature = $articleNatures[0];
|
$articleNature = $articleNatures[0];
|
||||||
|
} else {
|
||||||
|
$articleNature = 'semences';
|
||||||
}
|
}
|
||||||
$productTypes = Articles::getProductTypesWithOffers([
|
$productTypes = Articles::getProductTypesWithOffers([
|
||||||
'category_id' => $categoryId,
|
'category_id' => $categoryId,
|
||||||
@@ -40,35 +42,12 @@ class CategoryController extends Controller
|
|||||||
if (count($productTypes) === 1) {
|
if (count($productTypes) === 1) {
|
||||||
$productType = $productTypes[0];
|
$productType = $productTypes[0];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($articleNature) {
|
$articleNatureId = ArticleNatures::getIdBySlug($articleNature);
|
||||||
case 'semences':
|
|
||||||
$productType = 'botanic';
|
|
||||||
$articleNatureId = 1;
|
|
||||||
break;
|
|
||||||
case 'plants':
|
|
||||||
$productType = 'botanic';
|
|
||||||
$articleNatureId = 2;
|
|
||||||
break;
|
|
||||||
case 'legumes':
|
|
||||||
$productType = 'botanic';
|
|
||||||
$articleNatureId = 3;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (!($productType ?? false)) {
|
|
||||||
$productType = 'botanic';
|
|
||||||
$articleNatureId = 1;
|
|
||||||
$articleNature = 'semences';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// $productType = ArticleNatures::getProductType($articleNatureId);
|
|
||||||
// dump($productType);
|
|
||||||
// dump($articleNatureId);
|
|
||||||
// exit;
|
|
||||||
}
|
}
|
||||||
// exit;
|
|
||||||
$data = [
|
$data = [
|
||||||
'category' => Categories::getFull($categoryId),
|
'category' => Categories::getFull($categoryId),
|
||||||
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),
|
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),
|
||||||
@@ -86,8 +65,6 @@ class CategoryController extends Controller
|
|||||||
]),
|
]),
|
||||||
'tags' => TagGroups::getWithTagsAndCountOffers($categoryId),
|
'tags' => TagGroups::getWithTagsAndCountOffers($categoryId),
|
||||||
];
|
];
|
||||||
// dump($data);
|
|
||||||
// exit;
|
|
||||||
return view('Shop.Shelves.shelve', $data);
|
return view('Shop.Shelves.shelve', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,17 @@ use App\Traits\Model\HasComments;
|
|||||||
use App\Traits\Model\Imageable;
|
use App\Traits\Model\Imageable;
|
||||||
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
|
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Kirschbaum\PowerJoins\PowerJoins;
|
use Kirschbaum\PowerJoins\PowerJoins;
|
||||||
use Rinvex\Categories\Traits\Categorizable;
|
use Rinvex\Categories\Traits\Categorizable;
|
||||||
use Rinvex\Tags\Traits\Taggable;
|
use Rinvex\Tags\Traits\Taggable;
|
||||||
use Spatie\MediaLibrary\HasMedia;
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
|
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
|
||||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||||
use \Venturecraft\Revisionable\RevisionableTrait;
|
use \Venturecraft\Revisionable\RevisionableTrait;
|
||||||
use Wildside\Userstamps\Userstamps;
|
use Wildside\Userstamps\Userstamps;
|
||||||
@@ -47,22 +53,22 @@ class Article extends Model implements HasMedia
|
|||||||
'homepage',
|
'homepage',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function article_nature()
|
public function article_nature(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(ArticleNature::class);
|
return $this->belongsTo(ArticleNature::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function invoiceItems()
|
public function invoiceItems(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(InvoiceItem::class);
|
return $this->hasMany(InvoiceItem::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function offers()
|
public function offers(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Offer::class);
|
return $this->hasMany(Offer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function price_lists()
|
public function price_lists(): HasManyDeep
|
||||||
{
|
{
|
||||||
return $this->hasManyDeep(
|
return $this->hasManyDeep(
|
||||||
PriceList::class,
|
PriceList::class,
|
||||||
@@ -72,7 +78,7 @@ class Article extends Model implements HasMedia
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prices()
|
public function prices(): HasManyDeep
|
||||||
{
|
{
|
||||||
return $this->hasManyDeep(
|
return $this->hasManyDeep(
|
||||||
PriceListValue::class,
|
PriceListValue::class,
|
||||||
@@ -82,22 +88,22 @@ class Article extends Model implements HasMedia
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function product()
|
public function product(): MorphTo
|
||||||
{
|
{
|
||||||
return $this->morphTo();
|
return $this->morphTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function siblings()
|
public function siblings(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Article::class, 'name', 'name');
|
return $this->hasMany(Article::class, 'name', 'name');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tags()
|
public function tags(): MorphToMany
|
||||||
{
|
{
|
||||||
return $this->morphToMany(Tag::class, 'taggable');
|
return $this->morphToMany(Tag::class, 'taggable');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tariffs()
|
public function tariffs(): HasManyThrough
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Tariff::class, Offer::class, 'article_id', 'id', 'id', 'tariff_id');
|
return $this->hasManyThrough(Tariff::class, Offer::class, 'article_id', 'id', 'id', 'tariff_id');
|
||||||
// return $this->belongsToMany(Tariff::class, Offer::$table, 'id', 'id', 'tariff_id', 'tariff_id');
|
// return $this->belongsToMany(Tariff::class, Offer::$table, 'id', 'id', 'tariff_id', 'tariff_id');
|
||||||
|
|||||||
@@ -3,14 +3,19 @@
|
|||||||
namespace App\Models\Shop;
|
namespace App\Models\Shop;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Spatie\Image\Manipulations;
|
||||||
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||||
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
|
||||||
use \Venturecraft\Revisionable\RevisionableTrait;
|
use Venturecraft\Revisionable\RevisionableTrait;
|
||||||
use Wildside\Userstamps\Userstamps;
|
use Wildside\Userstamps\Userstamps;
|
||||||
|
|
||||||
class ArticleNature extends Model
|
class ArticleNature extends Model implements HasMedia
|
||||||
{
|
{
|
||||||
use HasRelationships, SoftDeletes, RevisionableTrait, UserStamps;
|
use HasRelationships, InteractsWithMedia, SoftDeletes, RevisionableTrait, UserStamps;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
@@ -20,7 +25,7 @@ class ArticleNature extends Model
|
|||||||
|
|
||||||
protected $keepRevisionOf = ['product_type', 'name', 'description'];
|
protected $keepRevisionOf = ['product_type', 'name', 'description'];
|
||||||
|
|
||||||
public function articles()
|
public function articles(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Article::class);
|
return $this->hasMany(Article::class);
|
||||||
}
|
}
|
||||||
@@ -49,4 +54,11 @@ class ArticleNature extends Model
|
|||||||
{
|
{
|
||||||
return $query->whereIn($this->table.'.id', $ids);
|
return $query->whereIn($this->table.'.id', $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function registerMediaConversions(Media $media = null): void
|
||||||
|
{
|
||||||
|
$this->addMediaConversion('thumb')->fit(Manipulations::FIT_MAX, 60, 32)->keepOriginalImageFormat()->nonQueued();
|
||||||
|
$this->addMediaConversion('normal')->fit(Manipulations::FIT_MAX, 360, 192)->keepOriginalImageFormat()->nonQueued();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Models\Shop;
|
namespace App\Models\Shop;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class Basket extends Model
|
class Basket extends Model
|
||||||
{
|
{
|
||||||
@@ -10,7 +11,7 @@ class Basket extends Model
|
|||||||
|
|
||||||
protected $table = 'shop_baskets';
|
protected $table = 'shop_baskets';
|
||||||
|
|
||||||
public function Offer()
|
public function Offer(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Offer::class);
|
return $this->belongsTo(Offer::class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,24 @@
|
|||||||
namespace App\Models\Shop;
|
namespace App\Models\Shop;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
|
||||||
class Categorizable extends Model
|
class Categorizable extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'categorizables';
|
protected $table = 'categorizables';
|
||||||
|
|
||||||
public function categorizable()
|
public function categorizable(): MorphTo
|
||||||
{
|
{
|
||||||
return $this->morphTo();
|
return $this->morphTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function category()
|
public function category(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Category::class);
|
return $this->belongsTo(Category::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function article()
|
public function article(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Article::class, 'categorizable_id');
|
return $this->belongsTo(Article::class, 'categorizable_id');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Models\Shop;
|
|||||||
|
|
||||||
use App\Repositories\Shop\SaleChannels;
|
use App\Repositories\Shop\SaleChannels;
|
||||||
use Cesargb\Database\Support\CascadeDelete;
|
use Cesargb\Database\Support\CascadeDelete;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Kalnoy\Nestedset\NestedSet;
|
use Kalnoy\Nestedset\NestedSet;
|
||||||
use Rinvex\Categories\Models\Category as parentCategory;
|
use Rinvex\Categories\Models\Category as parentCategory;
|
||||||
@@ -43,12 +45,12 @@ class Category extends parentCategory
|
|||||||
return $this->tags->articles;
|
return $this->tags->articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Parent()
|
public function Parent(): HasOne
|
||||||
{
|
{
|
||||||
return $this->hasOne(Category::class, 'id', 'parent_id');
|
return $this->hasOne(Category::class, 'id', 'parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function categorizables()
|
public function categorizables(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Categorizable::class);
|
return $this->hasMany(Categorizable::class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Models\Shop;
|
|||||||
|
|
||||||
use App\Notifications\ResetPassword;
|
use App\Notifications\ResetPassword;
|
||||||
use App\Notifications\VerifyEmail;
|
use App\Notifications\VerifyEmail;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
@@ -21,27 +23,27 @@ class Customer extends Authenticatable
|
|||||||
|
|
||||||
protected $casts = ['email_verified_at' => 'datetime'];
|
protected $casts = ['email_verified_at' => 'datetime'];
|
||||||
|
|
||||||
public function addresses()
|
public function addresses(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(CustomerAddress::class);
|
return $this->hasMany(CustomerAddress::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function customer_deliveries()
|
public function customer_deliveries(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(CustomerDelivery::class);
|
return $this->hasMany(CustomerDelivery::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deliveries()
|
public function deliveries(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Delivery::class, CustomerDelivery::class);
|
return $this->belongsToMany(Delivery::class, CustomerDelivery::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function invoices()
|
public function invoices(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Invoice::class);
|
return $this->hasMany(Invoice::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function orders()
|
public function orders(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Order::class);
|
return $this->hasMany(Order::class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
namespace App\Repositories\Core;
|
namespace App\Repositories\Core;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use function League\Period\interval_after;
|
|
||||||
use League\Period\Period;
|
use League\Period\Period;
|
||||||
|
|
||||||
|
use function League\Period\interval_after;
|
||||||
|
|
||||||
class DateRange
|
class DateRange
|
||||||
{
|
{
|
||||||
public static function today()
|
public static function today()
|
||||||
@@ -60,9 +61,10 @@ class DateRange
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
public static function getPeriodsLastMonthWithLabels($nb, $withActual = true)
|
||||||
{
|
{
|
||||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
$data = [];
|
||||||
|
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $withActual));
|
||||||
$labels = DateRange::getMonthNames($periods);
|
$labels = DateRange::getMonthNames($periods);
|
||||||
foreach ($labels as $label) {
|
foreach ($labels as $label) {
|
||||||
$data[$label] = $periods;
|
$data[$label] = $periods;
|
||||||
@@ -76,13 +78,12 @@ class DateRange
|
|||||||
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
public static function getPeriodsLastMonth($nb = 1, $withActual = true)
|
||||||
{
|
{
|
||||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
$end = $withActual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
$begin = $nb === 1 ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb - 1);
|
||||||
$t = self::getPeriodsbyMonth($begin, $end);
|
|
||||||
|
|
||||||
return self::getPeriodsbyMonth($begin, $end);
|
return self::getPeriodsByMonth($begin, $end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getMonthNamesByPeriods($periods)
|
public static function getMonthNamesByPeriods($periods)
|
||||||
@@ -106,20 +107,20 @@ class DateRange
|
|||||||
return $months;
|
return $months;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsLastWeek($nb = 1, $with_actual = true)
|
public static function getPeriodsLastWeek($nb = 1, $withActual = true)
|
||||||
{
|
{
|
||||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
$end = $withActual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||||
$begin = $end->copy()->subWeek($nb);
|
$begin = $end->copy()->subWeek($nb);
|
||||||
|
|
||||||
return self::getPeriodsbyWeek($begin, $end);
|
return static::getPeriodsByWeek($begin, $end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
public static function getPeriodsLastDay($nb = 1, $withActual = true)
|
||||||
{
|
{
|
||||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
$end = $withActual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||||
$begin = $end->copy()->subDay($nb);
|
$begin = $end->copy()->subDay($nb);
|
||||||
|
|
||||||
return self::getPeriodsbyDay($begin, $end);
|
return static::getPeriodsByDay($begin, $end);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function byDay()
|
public static function byDay()
|
||||||
@@ -156,6 +157,8 @@ class DateRange
|
|||||||
case 4:
|
case 4:
|
||||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [$date, $date->addMonth(6)];
|
return [$date, $date->addMonth(6)];
|
||||||
@@ -181,32 +184,38 @@ class DateRange
|
|||||||
return Carbon::now()->subDay()->startOfDay();
|
return Carbon::now()->subDay()->startOfDay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsbyMonth($begin, $end, $interval = 1)
|
public static function getPeriodsByMonth($begin, $end, $interval = 1)
|
||||||
{
|
{
|
||||||
return self::getPeriods($begin, $end, "$interval MONTH");
|
return self::getPeriods($begin, $end, "{$interval} MONTH");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsbyWeek($begin, $end, $interval = 1)
|
public static function getPeriodsByWeek($begin, $end, $interval = 1)
|
||||||
{
|
{
|
||||||
return self::getPeriods($begin, $end, "$interval WEEK");
|
return self::getPeriods($begin, $end, "{$interval} WEEK");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriodsbyDay($begin, $end, $interval = 1)
|
public static function getPeriodsByDay($begin, $end, $interval = 1)
|
||||||
{
|
{
|
||||||
return self::getPeriods($begin, $end, "$interval DAY");
|
return self::getPeriods($begin, $end, "{$interval} DAY");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
public static function getPeriods($begin, $end, $duration)
|
||||||
{
|
{
|
||||||
$period = new Period($begin, $end, $interval);
|
$range = [];
|
||||||
|
$period = new Period($begin, $end);
|
||||||
foreach ($period->getDatePeriod($duration) as $day) {
|
foreach ($period->getDatePeriod($duration) as $day) {
|
||||||
$daterange[] = interval_after($day, $duration);
|
$range[] = interval_after($day, $duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $daterange;
|
/*
|
||||||
|
foreach ($period->dateRangeForward($duration) as $day) {
|
||||||
|
$daterange[] = interval_after($day, $duration);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
return $range;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function PeriodsToCarbon($periods)
|
public static function periodsToCarbon($periods)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach ($periods as $period) {
|
foreach ($periods as $period) {
|
||||||
@@ -216,13 +225,39 @@ class DateRange
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function PeriodToCarbon($period)
|
public static function periodToCarbon($period)
|
||||||
{
|
{
|
||||||
return ['start' => self::DatePointToCarbon($period->getStartDate()), 'end' => self::DatePointToCarbon($period->getEndDate())];
|
return [
|
||||||
|
'start' => self::DatePointToCarbon($period->getStartDate()),
|
||||||
|
'end' => self::DatePointToCarbon($period->getEndDate()),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function DatePointToCarbon($date)
|
public static function datePointToCarbon($date)
|
||||||
{
|
{
|
||||||
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function convertPeriod($txt)
|
||||||
|
{
|
||||||
|
return array_values(self::convertDaterange($txt));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function convertDaterange($txt)
|
||||||
|
{
|
||||||
|
$dates = explode('-', $txt);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'start' => DateTime::convert(trim($dates[0])),
|
||||||
|
'end' => DateTime::convert(trim($dates[1])),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPeriodByLocale($start, $end)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'start' => DateTime::convert($start),
|
||||||
|
'end' => DateTime::convert($end),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Repositories\Core;
|
namespace App\Repositories\Core;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use App;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Jenssegers\Date\Date;
|
|
||||||
|
|
||||||
class DateTime
|
class DateTime
|
||||||
{
|
{
|
||||||
@@ -28,60 +28,90 @@ class DateTime
|
|||||||
return $short ? $date->shortDayName : $date->dayName;
|
return $short ? $date->shortDayName : $date->dayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function DatetoLocale($date = null)
|
public static function getDateTime()
|
||||||
|
{
|
||||||
|
return self::datetimeToLocale(date('Y-m-d H:i:s'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDate()
|
||||||
|
{
|
||||||
|
return self::dateToLocale(date('Y-m-d'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLang()
|
||||||
|
{
|
||||||
|
return App::currentLocale();
|
||||||
|
// return session('locale') ? session('locale') : 'fr';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function datetoLocale($date = null)
|
||||||
{
|
{
|
||||||
$format = self::getLocaleFormatDate();
|
$format = self::getLocaleFormatDate();
|
||||||
if (! is_null($date) && ! empty($date)) {
|
if (! is_null($date) && ! empty($date)) {
|
||||||
$date = Carbon::parse($date)->format($format);
|
$date = Carbon::parse($date)->format($format);
|
||||||
} elseif ($date == 'now') {
|
} elseif ($date === 'now') {
|
||||||
$date = today()->format($format);
|
$date = today()->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function DatetimeToLocale($date = null)
|
public static function datetimeToLocale($date = null)
|
||||||
{
|
{
|
||||||
$format = self::getLocaleFormatDatetime();
|
$format = self::getLocaleFormatDatetime();
|
||||||
if (! is_null($date) && ! empty($date)) {
|
if (! is_null($date) && ! empty($date)) {
|
||||||
$date = Carbon::parse($date)->format($format);
|
$date = Carbon::parse($date)->format($format);
|
||||||
} elseif ($date == 'now') {
|
} elseif ($date === 'now') {
|
||||||
$date = now()->format($format);
|
$date = now()->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDateTime()
|
public static function countDaysFrom($date)
|
||||||
{
|
{
|
||||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
$begin = DateTime::getCarbonTime($date);
|
||||||
|
|
||||||
|
return $begin->diffInDays(now()) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDate()
|
public static function getCarbonTime($date)
|
||||||
{
|
{
|
||||||
return self::DateToLocale(date('Y-m-d'));
|
$format = self::getLocaleFormatDatetime();
|
||||||
|
if (strlen($date) === 16) {
|
||||||
|
$date .= ':00';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ! empty($date) ? Carbon::createFromFormat($format, $date) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getLang()
|
public static function getCarbonDate($date)
|
||||||
{
|
{
|
||||||
return session('locale') ? session('locale') : 'fr';
|
$format = self::getLocaleFormatDate();
|
||||||
|
|
||||||
|
return ! empty($date) ? Carbon::createFromFormat($format, $date) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function convert($date)
|
public static function convert($date)
|
||||||
{
|
{
|
||||||
$format = self::getLocaleFormatDate();
|
return ! empty($date) ? self::getCarbonDate($date)->isoFormat('Y-MM-DD') : null;
|
||||||
|
|
||||||
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function convertTime($date)
|
public static function convertTime($date)
|
||||||
{
|
{
|
||||||
$format = self::getLocaleFormatDatetime();
|
return ! empty($date) ? self::getCarbonTime($date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||||
if (strlen($date) == 16) {
|
}
|
||||||
$date .= ':00';
|
|
||||||
}
|
|
||||||
|
|
||||||
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
public static function toLocale($date)
|
||||||
|
{
|
||||||
|
$format = self::getLocaleFormatDate();
|
||||||
|
|
||||||
|
return ! empty($date) ? Carbon::parse($date)->Format($format) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function toISO($date)
|
||||||
|
{
|
||||||
|
return ! empty($date) ? Carbon::parse($date)->isoFormat('Y-MM-DD') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function toFr($date)
|
public static function toFr($date)
|
||||||
@@ -97,7 +127,7 @@ class DateTime
|
|||||||
public static function getYearFromDate($date)
|
public static function getYearFromDate($date)
|
||||||
{
|
{
|
||||||
// return date_format(DateTime::convert($signature_date), 'Y');
|
// return date_format(DateTime::convert($signature_date), 'Y');
|
||||||
$date = DateTime::convert($date);
|
$date = self::convert($date);
|
||||||
$date = date_create($date);
|
$date = date_create($date);
|
||||||
|
|
||||||
return date_format($date, 'Y');
|
return date_format($date, 'Y');
|
||||||
@@ -118,6 +148,20 @@ class DateTime
|
|||||||
return $format;
|
return $format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function checkDateFormat($date)
|
||||||
|
{
|
||||||
|
if (preg_match("/^\d{2}\/\d{2}\/\d{4}$/", $date)) {
|
||||||
|
$day = substr($date, 0, 2);
|
||||||
|
$month = substr($date, 3, 2);
|
||||||
|
$year = substr($date, 6, 4);
|
||||||
|
if (checkdate($month, $day, $year)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getLocaleFormatDatetime()
|
public static function getLocaleFormatDatetime()
|
||||||
{
|
{
|
||||||
$locale = self::getLang();
|
$locale = self::getLang();
|
||||||
@@ -165,7 +209,8 @@ class DateTime
|
|||||||
return Carbon::parse($date)->isoFormat($format);
|
return Carbon::parse($date)->isoFormat($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function relativeTime()
|
public static function convertTimeToDate($date)
|
||||||
{
|
{
|
||||||
|
return substr($date, 0, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,66 @@ use SoftCreatR\MimeDetector\MimeDetectorException;
|
|||||||
|
|
||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
|
public static function copy($source, $target)
|
||||||
|
{
|
||||||
|
$source = self::sanitize($source);
|
||||||
|
$target = self::sanitize($target);
|
||||||
|
if (! self::checkFile($source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$dirname = self::relative(dirname($target));
|
||||||
|
self::checkDirOrCreate($dirname);
|
||||||
|
|
||||||
|
return copy($source, $target);
|
||||||
|
}
|
||||||
|
|
||||||
public static function checkDirOrCreate($dir)
|
public static function checkDirOrCreate($dir)
|
||||||
{
|
{
|
||||||
return self::checkDir($dir) ? true : self::createDir($dir);
|
return self::checkDir($dir) ? true : self::createDir($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function sanitize($filename)
|
||||||
|
{
|
||||||
|
return str_replace('\\', '/', $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function relative($filename)
|
||||||
|
{
|
||||||
|
return str_replace(self::getStorageAppPath(), '', $filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getStorageAppPath()
|
||||||
|
{
|
||||||
|
return self::sanitize(storage_path()).'/app';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getTree($path)
|
||||||
|
{
|
||||||
|
$tree = [];
|
||||||
|
|
||||||
|
$branch = [
|
||||||
|
'label' => basename($path),
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (\File::files($path) as $file) {
|
||||||
|
$branch['children'][] = basename($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (\File::directories($path) as $directory) {
|
||||||
|
$branch['children'][] = self::getTree($directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge($tree, $branch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function list($dir, $mask = '/*')
|
||||||
|
{
|
||||||
|
return glob($dir);
|
||||||
|
}
|
||||||
|
|
||||||
public static function checkDir($dir)
|
public static function checkDir($dir)
|
||||||
{
|
{
|
||||||
|
// return File::isDirectory($dir)
|
||||||
return is_dir($dir);
|
return is_dir($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,19 +78,17 @@ class File
|
|||||||
|
|
||||||
public static function createDir($dir)
|
public static function createDir($dir)
|
||||||
{
|
{
|
||||||
return mkdir($dir, '0777', true);
|
return Storage::makeDirectory($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function deleteDir($dir)
|
public static function deleteDir($dir)
|
||||||
{
|
{
|
||||||
Storage::deleteDirectory($dir);
|
return Storage::deleteDirectory($dir);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createFile($file, $content)
|
public static function createFile($file, $content)
|
||||||
{
|
{
|
||||||
Storage::put($file, $content);
|
return Storage::put($file, $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFile($file)
|
public static function getFile($file)
|
||||||
@@ -68,4 +119,27 @@ class File
|
|||||||
exit('An error occured while trying to load the given file.');
|
exit('An error occured while trying to load the given file.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function replaceInFile($path, $string, $replace)
|
||||||
|
{
|
||||||
|
set_time_limit(0);
|
||||||
|
$temp = false;
|
||||||
|
|
||||||
|
if (is_file($path) === true) {
|
||||||
|
$file = fopen($path, 'r');
|
||||||
|
$temp = tempnam('./', 'tmp');
|
||||||
|
|
||||||
|
if (is_resource($file) === true) {
|
||||||
|
while (feof($file) === false) {
|
||||||
|
file_put_contents($temp, str_replace($string, $replace, fgets($file)), FILE_APPEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $temp ? rename($temp, $path) : false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ use Carbon\Carbon;
|
|||||||
|
|
||||||
class HelperDate
|
class HelperDate
|
||||||
{
|
{
|
||||||
public static $is_debug = true;
|
|
||||||
|
|
||||||
public static function toLocaleFormat($date)
|
public static function toLocaleFormat($date)
|
||||||
{
|
{
|
||||||
if (! (! is_null($date) && ! empty($date))) {
|
if (! (! is_null($date) && ! empty($date))) {
|
||||||
@@ -24,9 +22,8 @@ class HelperDate
|
|||||||
default:
|
default:
|
||||||
$format = 'Y-m-d';
|
$format = 'Y-m-d';
|
||||||
}
|
}
|
||||||
$date = Carbon::parse($date)->format($format);
|
|
||||||
|
|
||||||
return $date;
|
return Carbon::parse($date)->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromLocale($d)
|
public static function fromLocale($d)
|
||||||
@@ -61,7 +58,7 @@ class HelperDate
|
|||||||
|
|
||||||
public static function toFrenchDate($d)
|
public static function toFrenchDate($d)
|
||||||
{
|
{
|
||||||
if ($d && $d != '0000-00-00') {
|
if ($d && $d !== '0000-00-00') {
|
||||||
return Carbon::createFromFormat('Y-m-d', $d)->format('d/m/Y');
|
return Carbon::createFromFormat('Y-m-d', $d)->format('d/m/Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
app/Repositories/Core/MediaPathGenerator.php
Normal file
31
app/Repositories/Core/MediaPathGenerator.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repositories\Core;
|
||||||
|
|
||||||
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||||
|
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator;
|
||||||
|
|
||||||
|
class MediaPathGenerator implements PathGenerator
|
||||||
|
{
|
||||||
|
public function getPath(Media $media): string
|
||||||
|
{
|
||||||
|
return $this->getBasePath($media).'/';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPathForConversions(Media $media): string
|
||||||
|
{
|
||||||
|
return $this->getBasePath($media).'/conversions/';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPathForResponsiveImages(Media $media): string
|
||||||
|
{
|
||||||
|
return $this->getBasePath($media).'/responsive-images/';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getBasePath(Media $media): string
|
||||||
|
{
|
||||||
|
$model = basename(str_replace('\\', '/', $media->model_type));
|
||||||
|
|
||||||
|
return basename($model).'/images/'.$media->getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,16 @@ class Storage
|
|||||||
return Storage2::disk('local')->has($dir);
|
return Storage2::disk('local')->has($dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function move($source, $target)
|
||||||
|
{
|
||||||
|
return Storage2::move($source, $target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function copy($source, $target)
|
||||||
|
{
|
||||||
|
return Storage2::copy($source, $target);
|
||||||
|
}
|
||||||
|
|
||||||
public static function checkFile($file)
|
public static function checkFile($file)
|
||||||
{
|
{
|
||||||
return Storage2::exists($file);
|
return Storage2::exists($file);
|
||||||
|
|||||||
@@ -7,12 +7,71 @@ use App\Models\Botanic\Variety;
|
|||||||
use App\Models\Shop\Article;
|
use App\Models\Shop\Article;
|
||||||
use App\Models\Shop\ArticleNature;
|
use App\Models\Shop\ArticleNature;
|
||||||
use App\Models\Shop\Merchandise;
|
use App\Models\Shop\Merchandise;
|
||||||
|
use App\Repositories\Core\Medias;
|
||||||
use App\Traits\Model\Basic;
|
use App\Traits\Model\Basic;
|
||||||
|
|
||||||
class ArticleNatures
|
class ArticleNatures
|
||||||
{
|
{
|
||||||
use Basic;
|
use Basic;
|
||||||
|
|
||||||
|
public static function getIconBySlug($slug, $conversion = 'normal', $collection = 'images')
|
||||||
|
{
|
||||||
|
return self::getIcon(self::getIdBySlug($slug), $conversion, $collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getIcon($id, $conversion = 'normal', $collection = 'images')
|
||||||
|
{
|
||||||
|
return Medias::getImage(self::get($id), $conversion, $collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getIdBySlug($slug)
|
||||||
|
{
|
||||||
|
switch ($slug) {
|
||||||
|
case 'semences':
|
||||||
|
$id = 1;
|
||||||
|
break;
|
||||||
|
case 'plants':
|
||||||
|
$id = 2;
|
||||||
|
break;
|
||||||
|
case 'legumes':
|
||||||
|
$id = 3;
|
||||||
|
break;
|
||||||
|
case 'marchandises':
|
||||||
|
$id = 4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$id = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getProductTypeBySlug($slug)
|
||||||
|
{
|
||||||
|
switch ($slug) {
|
||||||
|
case 'semences':
|
||||||
|
case 'plants':
|
||||||
|
case 'legumes':
|
||||||
|
$productType = 'botanic';
|
||||||
|
break;
|
||||||
|
case 'marchandises':
|
||||||
|
$productType = 'merchandise';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$productType = 'botanic';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $productType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function storeIcon($nature, $file, $collection = 'images')
|
||||||
|
{
|
||||||
|
Medias::deleteImages($nature, $collection);
|
||||||
|
|
||||||
|
return Medias::storeImage($nature, $file, $collection);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getProductType($id)
|
public static function getProductType($id)
|
||||||
{
|
{
|
||||||
$type = self::get($id)->product_type ?? false;
|
$type = self::get($id)->product_type ?? false;
|
||||||
|
|||||||
@@ -4,11 +4,14 @@
|
|||||||
'breadcrumb' => [__('shop.article_natures.title'), __('shop.article_natures.edit')]
|
'breadcrumb' => [__('shop.article_natures.title'), __('shop.article_natures.edit')]
|
||||||
])
|
])
|
||||||
|
|
||||||
@include('boilerplate::load.fileinput')
|
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
{{ Form::open(['route' => 'Admin.Shop.ArticleNatures.store', 'id' => 'article_nature-form', 'autocomplete' => 'off', 'files' => true]) }}
|
{{ Form::open([
|
||||||
|
'route' => 'Admin.Shop.ArticleNatures.store',
|
||||||
|
'id' => 'article_nature-form',
|
||||||
|
'autocomplete' => 'off',
|
||||||
|
'files' => true,
|
||||||
|
]) }}
|
||||||
<input type="hidden" name="id" value="{{ $article_nature['id'] }}">
|
<input type="hidden" name="id" value="{{ $article_nature['id'] }}">
|
||||||
@include('Admin.Shop.ArticleNatures.form')
|
@include('Admin.Shop.ArticleNatures.form')
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,41 +1,59 @@
|
|||||||
<div class="row">
|
<div class="row mb-3">
|
||||||
<div class="col-4">
|
<div class="col-8">
|
||||||
{{ Form::label('product_type', 'Famille de produit') }}
|
|
||||||
@include('components.form.select', [
|
|
||||||
'name' => 'product_type',
|
|
||||||
'value' => $article_nature['product_type'] ?? null,
|
|
||||||
'list' => $product_types ?? null,
|
|
||||||
'required' => true,
|
|
||||||
])
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-8">
|
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-12">
|
<div class="col-6">
|
||||||
|
{{ Form::label('product_type', 'Famille de produit') }}
|
||||||
|
@include('components.form.select', [
|
||||||
|
'name' => 'product_type',
|
||||||
|
'value' => $article_nature['product_type'] ?? null,
|
||||||
|
'list' => $product_types ?? null,
|
||||||
|
'required' => true,
|
||||||
|
])
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
{{ Form::label('name', 'Nom') }}
|
{{ Form::label('name', 'Nom') }}
|
||||||
@include('components.form.input', ['name' => 'name', 'value' => $article_nature['name'] ?? null, 'required' => true])
|
@include('components.form.input', [
|
||||||
|
'name' => 'name',
|
||||||
|
'value' => $article_nature['name'] ?? null,
|
||||||
|
'required' => true,
|
||||||
|
])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
{{ Form::label('description', 'Description') }}
|
{{ Form::label('description', 'Description') }}
|
||||||
@include('components.form.textarea', ['name' => 'description', 'value' => $article_nature['description'] ?? null, 'class' => 'editor', 'required' => false])
|
@include('components.form.textarea', [
|
||||||
|
'name' => 'description',
|
||||||
|
'value' => $article_nature['description'] ?? null,
|
||||||
|
'class' => 'editor',
|
||||||
|
'required' => false,
|
||||||
|
])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-4">
|
||||||
|
<x-card title="{{ __('icone') }}">
|
||||||
|
@include('components.widgets.imgUpload', [
|
||||||
|
'name' => 'icon',
|
||||||
|
'id_name' => 'icon',
|
||||||
|
'file' => $article_nature['icon'] ?? false,
|
||||||
|
])
|
||||||
|
</x-card>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@include('components.save')
|
<x-save />
|
||||||
|
|
||||||
@include('load.form.editor')
|
@include('load.form.editor')
|
||||||
|
@include('load.form.upload.fileinput')
|
||||||
@include('load.form.save')
|
@include('load.form.save')
|
||||||
|
|
||||||
@push('js')
|
@push('js')
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
initEditor();
|
initEditor();
|
||||||
|
initUploadImage();
|
||||||
initSaveForm('#article_nature-form');
|
initSaveForm('#article_nature-form');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-3">
|
<div class="col-lg-3 col-md-12">
|
||||||
@include('Shop.Customers.partials.user')
|
@include('Shop.Customers.partials.user')
|
||||||
</div>
|
</div>
|
||||||
<div class="col-9">
|
<div class="col-lg-9 col-md-12">
|
||||||
@include('Shop.Customers.partials.sale')
|
@include('Shop.Customers.partials.sale')
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
21
resources/views/components/widgets/imgUpload.blade.php
Normal file
21
resources/views/components/widgets/imgUpload.blade.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<div id="{{ $id_name ?? $name }}_preview" class="{{ ($file ?? false) ? '' : 'd-none' }}">
|
||||||
|
<img src="{{ $file ?? null }}" class="img-fluid">
|
||||||
|
@if (!($disabled ?? false))
|
||||||
|
<div class="mt-2 text-right">
|
||||||
|
<button type="button" class="btn btn-sm btn-danger img-delete"><i class="fa fa-trash"></i></button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (!($disabled ?? false))
|
||||||
|
<div id="{{ $id_name ?? $name }}_uploader" class="{{ ($file ?? false) ? 'd-none' : '' }} uploader-input">
|
||||||
|
@include('components.form.file', [
|
||||||
|
'name' => $name,
|
||||||
|
'value' => $file ?? null,
|
||||||
|
])
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,25 +1,144 @@
|
|||||||
@if(!defined('LOAD_FILEINPUT'))
|
@if(!defined('LOAD_FILEINPUT'))
|
||||||
@push('css')
|
@push('css')
|
||||||
<link rel="stylesheet" href="{!! asset('/assets/plugins/bootstrap-fileinput/css/fileinput.min.css') !!}">
|
<link rel="stylesheet" href="/assets/plugins/bootstrap-fileinput/css/fileinput.min.css">
|
||||||
@endpush
|
@endpush
|
||||||
@push('js')
|
@push('scripts')
|
||||||
<script src="{!! asset('/assets/plugins/bootstrap-fileinput/js/fileinput.min.js') !!}"></script>
|
<script src="/assets/plugins/bootstrap-fileinput/js/fileinput.min.js"></script>
|
||||||
@if(App::getLocale() !== 'en')
|
@if(App::getLocale() !== 'en')
|
||||||
<script src="{!! asset('/assets/plugins/bootstrap-fileinput/js/locales/'. App::getLocale() .'.js') !!}"></script>
|
<script src="/assets/plugins/bootstrap-fileinput/js/locales/{{ App::getLocale() }}.js"></script>
|
||||||
|
<script src="/assets/plugins/bootstrap-fileinput/themes/fas/theme.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
$.fn.fileinput.defaults.language = '{{ App::getLocale() }}';
|
$.fn.fileinput.defaults.language = '{{ App::getLocale() }}';
|
||||||
</script>
|
</script>
|
||||||
|
@endif
|
||||||
|
@component('boilerplate::minify')
|
||||||
<script>
|
<script>
|
||||||
function initUpload(selector) {
|
function UploadInit(sel, options, callbackUploaded) {
|
||||||
var selector = '.file';
|
// console.log(options);
|
||||||
$(selector).fileinput({
|
var selector = (typeof(sel) == 'undefined') ? '.fileinput' : sel;
|
||||||
|
$(selector).fileinput(options)
|
||||||
|
.on("filebatchselected", function(event, files) {
|
||||||
|
$(selector).fileinput("upload");
|
||||||
|
}).on('fileuploaded', function (event, data, previewId, index, fileId) {
|
||||||
|
// console.log('File uploaded', previewId, index, fileId);
|
||||||
|
var file = data.files[0];
|
||||||
|
// console.log(file);
|
||||||
|
var response = data.response.initialPreviewConfig.extra;
|
||||||
|
// console.log(response);
|
||||||
|
|
||||||
|
response.model = $(this).data('model');
|
||||||
|
|
||||||
|
// console.log(response);
|
||||||
|
if (typeof(callbackUploaded) !== 'undefined') {
|
||||||
|
// console.log('Callback');
|
||||||
|
eval(callbackUploaded);
|
||||||
|
}
|
||||||
|
}).on('filebatchuploadcomplete', function(event, preview, config, tags, extraData) {
|
||||||
|
console.log('File Batch Uploaded', preview, config, tags, extraData);
|
||||||
|
}).on('filebatchuploadsuccess', function(event, data) {
|
||||||
|
console.log('File batch upload success');
|
||||||
|
console.log(data);
|
||||||
|
}).on('fileuploaderror', function(event, data, msg) {
|
||||||
|
console.log('File upload error');
|
||||||
|
console.log(data);
|
||||||
|
console.log(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function UploadOptions(options) {
|
||||||
|
return {
|
||||||
|
allowedFileExtensions: (typeof(options.allowedFileExtensions) == 'undefined') ? ['doc','docx','jpg','jpeg','png','xls','xlsx','pdf'] : options.allowedFileExtensions,
|
||||||
|
browseOnZoneClick: (typeof(options.browseOnZoneClick) == 'undefined') ? true : options.browseOnZoneClick,
|
||||||
|
dropZoneEnabled: (typeof(options.dropZoneEnabled) == 'undefined') ? false : options.dropZoneEnabled,
|
||||||
|
initialPreview: (typeof(options.initialPreview) == 'undefined') ? false : options.initialPreview,
|
||||||
|
initialPreviewAsData: (typeof(options.initialPreviewAsData) == 'undefined') ? false : options.initialPreviewAsData,
|
||||||
|
maxFilesize: (typeof(options.maxFilesize) == 'undefined') ? false : options.maxFilesize,
|
||||||
|
overwriteInitial: (typeof(options.overwriteInitial) == 'undefined') ? false : options.overwriteInitial,
|
||||||
|
showCaption: (typeof(options.showCaption) == 'undefined') ? true : options.showCaption,
|
||||||
|
showPreview: (typeof(options.showPreview) == 'undefined') ? true : options.showPreview,
|
||||||
|
showRemove: (typeof(options.showRemove) == 'undefined') ? false : options.showRemove,
|
||||||
|
showUpload: (typeof(options.showUpload) == 'undefined') ? false : options.showUpload,
|
||||||
|
showUploadStats: (typeof(options.showUploadStats) == 'undefined') ? true : options.showUploadStats,
|
||||||
|
theme: (typeof(options.theme) == 'undefined') ? 'fas' : options.theme,
|
||||||
|
uploadAsync: (typeof(options.uploadAsync) == 'undefined') ? false : options.uploadAsync,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function initUpload(sel, options, callbackUploaded) {
|
||||||
|
UploadInit(sel, UploadOptions(options), callbackUploaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initUploadMultiple(sel, options, callbackUploaded) {
|
||||||
|
UploadInit(sel, Object.assign({}, UploadOptions({
|
||||||
|
uploadUrl: "/site/test-upload",
|
||||||
|
enableResumableUpload: true,
|
||||||
|
initialPreviewAsData: true,
|
||||||
|
deleteUrl: '/upload',
|
||||||
|
dropZoneEnabled: true,
|
||||||
|
overwriteInitial: false,
|
||||||
|
showCaption: false,
|
||||||
|
showPreview: true,
|
||||||
|
showRemove: true,
|
||||||
|
showUpload: false,
|
||||||
|
uploadAsync: true,
|
||||||
|
maxFileCount: 5,
|
||||||
|
}), options), callbackUploaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initRowUpload(sel, options, callbackUploaded) {
|
||||||
|
UploadInit(sel, Object.assign({}, UploadOptions({
|
||||||
|
showCaption: true,
|
||||||
|
showPreview: false,
|
||||||
|
showRemove: true,
|
||||||
|
uploadAsync: true,
|
||||||
|
}), options), callbackUploaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initPdfUpload(sel, options, callbackUploaded) {
|
||||||
|
UploadInit(sel, Object.assign({}, UploadOptions({
|
||||||
|
allowedFileExtensions: ['pdf'],
|
||||||
showCaption: false,
|
showCaption: false,
|
||||||
dropZoneEnabled: false,
|
dropZoneEnabled: false,
|
||||||
showUpload: false,
|
showUpload: false,
|
||||||
|
}), options), callbackUploaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initUploadImage(image, sel) {
|
||||||
|
var selector = (typeof(sel) == 'undefined') ? '.fileinput' : sel;
|
||||||
|
var imgs = image ? [image] : false;
|
||||||
|
initFileInputImage(imgs, selector);
|
||||||
|
|
||||||
|
$('.img-delete').click(function() {
|
||||||
|
$container = $(this).parents('.row');
|
||||||
|
// console.log($container);
|
||||||
|
$(this).closest('.row').find('.uploader-input').toggleClass('d-none');
|
||||||
|
$(this).closest('.row').find('img').toggleClass('d-none');
|
||||||
|
$(this).toggleClass('d-none');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initFileInputImage(images, sel)
|
||||||
|
{
|
||||||
|
UploadInit(sel, {
|
||||||
|
allowedFileExtensions: ['jpg', 'jpeg', 'png', 'gif'],
|
||||||
|
overwriteInitial: true,
|
||||||
|
showPreview: true,
|
||||||
|
showUpload: false,
|
||||||
|
maxFileSize: 10000,
|
||||||
|
initialPreview: images,
|
||||||
|
initialPreviewAsData: false,
|
||||||
|
theme: 'fas',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function uploadShowImage(id, image)
|
||||||
|
{
|
||||||
|
$('#' + id + '_preview').toggleClass('d-none');
|
||||||
|
$('#' + id + '_preview').find('img').attr('src', image);
|
||||||
|
$('#' + id + '_uploader').toggleClass('d-none');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@endif
|
@endcomponent
|
||||||
@endpush
|
@endpush
|
||||||
@php(define('LOAD_FILEINPUT', true))
|
@php(define('LOAD_FILEINPUT', true))
|
||||||
@endif
|
@endif
|
||||||
Reference in New Issue
Block a user