158 lines
3.8 KiB
PHP
158 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Botanic\Specie;
|
|
use App\Models\Botanic\Variety;
|
|
use App\Models\Shop\Article;
|
|
use App\Models\Shop\ArticleNature;
|
|
use App\Models\Shop\Merchandise;
|
|
use App\Repositories\Core\Medias;
|
|
use App\Traits\Model\Basic;
|
|
|
|
class ArticleNatures
|
|
{
|
|
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)
|
|
{
|
|
$type = self::get($id)->product_type ?? false;
|
|
|
|
return $type ? self::getProductTypes()[$type] : false;
|
|
}
|
|
|
|
public static function getProductTypeNameByClass($model)
|
|
{
|
|
return self::getProductTypeName(self::getProductTypeByModel($model));
|
|
}
|
|
|
|
public static function getProductTypeName($type)
|
|
{
|
|
return self::getProductTypes()[$type] ?? false;
|
|
}
|
|
|
|
public static function getProductTypeByModel($model)
|
|
{
|
|
switch ($model) {
|
|
case Specie::class:
|
|
case Variety::class:
|
|
$type = 1;
|
|
break;
|
|
case Merchandise::class:
|
|
$type = 2;
|
|
break;
|
|
default:
|
|
$type = false;
|
|
}
|
|
|
|
return $type;
|
|
}
|
|
|
|
public static function getProductTypes()
|
|
{
|
|
return ['', 'botanic', 'merchandise'];
|
|
}
|
|
|
|
public static function getOptionsByBotanic()
|
|
{
|
|
return self::getOptionsByProductType(1);
|
|
}
|
|
|
|
public static function getOptionsByMerchandise()
|
|
{
|
|
return self::getOptionsByProductType(2);
|
|
}
|
|
|
|
public static function getOptionsByProductTypeModel($model)
|
|
{
|
|
$type = self::getProductTypeByModel($model);
|
|
|
|
return self::getOptionsByProductType($type);
|
|
}
|
|
|
|
public static function getOptionsByProductType($type)
|
|
{
|
|
return self::getByProductType($type)->pluck('name', 'id')->toArray();
|
|
}
|
|
|
|
public static function getByProductType($type)
|
|
{
|
|
return ArticleNature::byProductType($type)->get();
|
|
}
|
|
|
|
public static function getByCategory($categoryId)
|
|
{
|
|
return Article::byCategory($categoryId)->select('article_nature_id')->distinct()->get();
|
|
}
|
|
|
|
public static function getNamesByIds($ids)
|
|
{
|
|
$names = ArticleNature::byIds($ids)->pluck('name')->toArray();
|
|
|
|
return array_map('strtolower', $names);
|
|
}
|
|
|
|
public static function getModel()
|
|
{
|
|
return ArticleNature::query();
|
|
}
|
|
}
|