Add preview from father, add new features
This commit is contained in:
@@ -7,23 +7,13 @@ use App\Http\Controllers\Controller;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// return redirect('dashboard');
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,48 +11,48 @@ use App\Datatables\Botanic\FamiliesDataTable;
|
||||
class FamilyController extends Controller
|
||||
{
|
||||
|
||||
public function index(FamiliesDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Botanic.Admin.Families.list');
|
||||
}
|
||||
public function index(FamiliesDataTable $dataTable)
|
||||
{
|
||||
return $dataTable->render('Botanic.Admin.Families.list');
|
||||
}
|
||||
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Families::getTables($request->all());
|
||||
}
|
||||
public function getDatatable(Request $request)
|
||||
{
|
||||
return Families::getTables($request->all());
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
return view('Botanic.Admin.Families.create', $data);
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
return view('Botanic.Admin.Families.create', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Families::store($request);
|
||||
return redirect()->route('Botanic.Admin.Families.index');
|
||||
}
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Families::store($request);
|
||||
return redirect()->route('Botanic.Admin.Families.index');
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$data = Families::get($id);
|
||||
return view('Botanic.Admin.Families.view', $data);
|
||||
}
|
||||
public function show($id)
|
||||
{
|
||||
$data = Families::get($id);
|
||||
return view('Botanic.Admin.Families.view', $data);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$data['family'] = Families::get($id)->toArray();
|
||||
return view('Botanic.Admin.Families.edit', $data);
|
||||
}
|
||||
public function edit($id)
|
||||
{
|
||||
$data['family'] = Families::get($id)->toArray();
|
||||
return view('Botanic.Admin.Families.edit', $data);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
return Families::destroy($id);
|
||||
}
|
||||
public function destroy($id)
|
||||
{
|
||||
return Families::destroy($id);
|
||||
}
|
||||
|
||||
public function exportExcel()
|
||||
{
|
||||
return Families::exportExcel();
|
||||
}
|
||||
public function exportExcel()
|
||||
{
|
||||
return Families::exportExcel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,23 +7,23 @@ use App\Http\Controllers\Controller;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
return redirect('dashboard');
|
||||
}
|
||||
/**
|
||||
* Show the application dashboard.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return redirect('dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,27 +10,27 @@ use App\Repositories\Shop\Categories;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// $this->middleware('auth');
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,18 @@
|
||||
|
||||
namespace App\Repositories\Botanic;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Media;
|
||||
use App\Models\Botanic\Variety;
|
||||
use App\Exports\Botanic\VarietiesExport;
|
||||
|
||||
class Varieties
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Variety::with('specie');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Variety::orderBy('name')->get()->pluck('name','id')->toArray();
|
||||
@@ -30,8 +23,7 @@ class Varieties
|
||||
{
|
||||
$varieties = Variety::with('specie')->get();
|
||||
$data = [];
|
||||
foreach ($varieties as $variety)
|
||||
{
|
||||
foreach ($varieties as $variety) {
|
||||
$data[$variety->id] = (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name;
|
||||
}
|
||||
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
@@ -45,7 +37,7 @@ class Varieties
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variety::find($id);
|
||||
return Variety::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
@@ -58,8 +50,7 @@ class Varieties
|
||||
|
||||
public static function getTagsByVariety($variety)
|
||||
{
|
||||
$tags = $variety->tags;
|
||||
return $tags ? $tags->pluck('id')->toArray() : null;
|
||||
return Tag::getTagsByModel($variety);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +80,7 @@ class Varieties
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$variety = Variety::find($id);
|
||||
$variety = self::get($id);
|
||||
$ret = $variety->update($data);
|
||||
return $variety;
|
||||
}
|
||||
@@ -101,43 +92,22 @@ class Varieties
|
||||
|
||||
public static function storeTags($variety, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $variety->syncTags($tags, true);
|
||||
} else return false;
|
||||
return Tag::storeTags($variety, $tags);
|
||||
}
|
||||
|
||||
public static function storeImages($variety, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
$variety->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
}
|
||||
}
|
||||
return Media::storeImages($variety, $files);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
if ($variety) {
|
||||
$variety->getMedia();
|
||||
foreach ($variety->media as $key => $media) {
|
||||
$variety->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $variety->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$variety->getMedia();
|
||||
$ret = $variety->media[$index]->delete();
|
||||
return "1";
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
|
||||
@@ -2,113 +2,172 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use \Carbon\Carbon;
|
||||
use \League\Period\Period;
|
||||
use Carbon\Carbon;
|
||||
use League\Period\Period;
|
||||
use League\Period\Duration;
|
||||
use League\Period\Sequence;
|
||||
use League\Period\Chart\Dataset;
|
||||
use function League\Period\duration;
|
||||
use function League\Period\interval_after;
|
||||
|
||||
class DateRange
|
||||
{
|
||||
public static function getPeriodsLastMonth($nb)
|
||||
{
|
||||
$end = static::lastMonth();
|
||||
$begin = $end->copy()->subMonth($nb);
|
||||
return static::getPeriodsbyMonth($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastWeek($nb)
|
||||
{
|
||||
$end = static::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
return static::getPeriodsbyWeek($begin, $end);
|
||||
}
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
||||
{
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
||||
$labels = DateRange::getMonthNames($periods);
|
||||
foreach ($labels as $label) {
|
||||
$data[$label] = $periods;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getPeriodsLastDay($nb)
|
||||
{
|
||||
$end = static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
return static::getPeriodsbyDay($begin, $end);
|
||||
}
|
||||
public static function getAllMonthNames()
|
||||
{
|
||||
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
||||
}
|
||||
|
||||
public static function byDay()
|
||||
{
|
||||
return [Carbon::now()->startOfDay(), Carbon::now()->endOfDay()];
|
||||
}
|
||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb-1);
|
||||
$t = self::getPeriodsbyMonth($begin, $end);
|
||||
return self::getPeriodsbyMonth($begin, $end);
|
||||
}
|
||||
|
||||
public static function byWeek()
|
||||
{
|
||||
return [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()];
|
||||
}
|
||||
public static function getMonthNamesByPeriods($periods)
|
||||
{
|
||||
$months = [];
|
||||
foreach ($periods as $period) {
|
||||
$date = self::DatePointToCarbon($period->getStartDate());
|
||||
$months[] = DateTime::getMonthName($date);
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
|
||||
public static function byMonth()
|
||||
{
|
||||
return [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()];
|
||||
}
|
||||
public static function getMonthNames($periods)
|
||||
{
|
||||
$months = [];
|
||||
foreach ($periods as $period) {
|
||||
$months[] = DateTime::getMonthName($period['start']);
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
|
||||
public static function byQuarter()
|
||||
{
|
||||
return [Carbon::now()->startOfQuarter(), Carbon::now()->endOfQuarter()];
|
||||
}
|
||||
public static function getPeriodsLastWeek($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
return static::getPeriodsbyWeek($begin, $end);
|
||||
}
|
||||
|
||||
public static function bySemester()
|
||||
{
|
||||
$quarter = Carbon::now()->quarter;
|
||||
switch ($quarter) {
|
||||
case 1:
|
||||
case 2:
|
||||
$date = Carbon::now()->startOfYear();
|
||||
break;
|
||||
case 3:
|
||||
$date = Carbon::now()->startOfQuarter();
|
||||
break;
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
}
|
||||
return [$date, $date->addMonth(6)];
|
||||
}
|
||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
return static::getPeriodsbyDay($begin, $end);
|
||||
}
|
||||
|
||||
public static function byYear()
|
||||
{
|
||||
return [Carbon::now()->startOfYear(), Carbon::now()->endOfYear()];
|
||||
}
|
||||
public static function byDay()
|
||||
{
|
||||
return [Carbon::now()->startOfDay(), Carbon::now()->endOfDay()];
|
||||
}
|
||||
|
||||
public static function lastMonth()
|
||||
{
|
||||
$start = Carbon::parse('first day of last month');
|
||||
$start->addMonth()->startOfDay();
|
||||
return $start;
|
||||
}
|
||||
public static function byWeek()
|
||||
{
|
||||
return [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()];
|
||||
}
|
||||
|
||||
public static function lastWeek()
|
||||
{
|
||||
return Carbon::parse('last monday');
|
||||
}
|
||||
public static function byMonth()
|
||||
{
|
||||
return [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()];
|
||||
}
|
||||
|
||||
public static function lastDay()
|
||||
{
|
||||
return Carbon::parse('yesterday');
|
||||
}
|
||||
public static function byQuarter()
|
||||
{
|
||||
return [Carbon::now()->startOfQuarter(), Carbon::now()->endOfQuarter()];
|
||||
}
|
||||
|
||||
public static function getPeriodsbyMonth($begin, $end)
|
||||
{
|
||||
return (static::getPeriods($begin, $end, 'MONTH'));
|
||||
}
|
||||
public static function bySemester()
|
||||
{
|
||||
$quarter = Carbon::now()->quarter;
|
||||
switch ($quarter) {
|
||||
case 1:
|
||||
case 2:
|
||||
$date = Carbon::now()->startOfYear();
|
||||
break;
|
||||
case 3:
|
||||
$date = Carbon::now()->startOfQuarter();
|
||||
break;
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
}
|
||||
return [$date, $date->addMonth(6)];
|
||||
}
|
||||
|
||||
public static function getPeriodsbyWeek($begin, $end)
|
||||
{
|
||||
return (static::getPeriods($begin, $end, 'WEEK'));
|
||||
}
|
||||
public static function byYear()
|
||||
{
|
||||
return [Carbon::now()->startOfYear(), Carbon::now()->endOfYear()];
|
||||
}
|
||||
|
||||
public static function getPeriodsbyDay($begin, $end)
|
||||
{
|
||||
return (static::getPeriods($begin, $end, 'DAY'));
|
||||
}
|
||||
public static function lastMonth()
|
||||
{
|
||||
return Carbon::now()->subMonth()->startOfMonth();
|
||||
}
|
||||
|
||||
public static function lastWeek()
|
||||
{
|
||||
return Carbon::now()->subWeek()->startOfWeek();
|
||||
}
|
||||
|
||||
public static function lastDay()
|
||||
{
|
||||
return Carbon::now()->subDay()->startOfDay();
|
||||
}
|
||||
|
||||
public static function getPeriodsbyMonth($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval MONTH");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyWeek($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval WEEK");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyDay($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval DAY");
|
||||
}
|
||||
|
||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
||||
{
|
||||
$period = new Period($begin, $end);
|
||||
foreach ($period->getDatePeriod($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
}
|
||||
return $daterange;
|
||||
}
|
||||
|
||||
public static function PeriodsToCarbon($periods)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($periods as $period) {
|
||||
$data[] = self::PeriodToCarbon($period);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function PeriodToCarbon($period)
|
||||
{
|
||||
return ['start' => self::DatePointToCarbon($period->getStartDate()), 'end' => self::DatePointToCarbon($period->getEndDate())];
|
||||
}
|
||||
|
||||
public static function DatePointToCarbon($date)
|
||||
{
|
||||
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function getPeriods($begin, $end, $interval)
|
||||
{
|
||||
$period = new Period($begin, new \DateTime($end));
|
||||
foreach ($period->getDatePeriod("1 $interval") as $day) {
|
||||
$daterange[] = Period::createFromDuration($day->format('Y-m-d H:i:s'), "1 $interval");
|
||||
}
|
||||
return ($daterange);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,58 +2,146 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
use App\Repositories\Languages;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
public static function getMonthName($date, $short = true)
|
||||
{
|
||||
return $short ? self::getUltraShortMonthName($date) : $date->monthName;
|
||||
}
|
||||
|
||||
public static function convert($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y', $date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
public static function getShortMonthName($date)
|
||||
{
|
||||
return $date->shortMonthName;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y H:i', $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
public static function getUltraShortMonthName($date)
|
||||
{
|
||||
return strtoupper(Str::ascii(mb_substr($date->shortMonthName,0,3)));
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
public static function getDayName($date, $short = true)
|
||||
{
|
||||
return $short ? $date->shortDayName : $date->dayName;
|
||||
}
|
||||
|
||||
public static function toFrTime($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
||||
}
|
||||
public static function DatetoLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function FromDatetimeFr($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y H:i:s', $date) : null;
|
||||
}
|
||||
public static function DatetimeToLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function DatetimeToStamp($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
public static function getDateTime()
|
||||
{
|
||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function DatetimeToDate($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
public static function getDate()
|
||||
{
|
||||
return self::DateToLocale(date('Y-m-d'));
|
||||
}
|
||||
|
||||
public static function DatetimeToTime($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('HH:mm') : null;
|
||||
}
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
|
||||
public static function isPast($date)
|
||||
{
|
||||
return self::FromDatetimeFr($date)->isPast();
|
||||
}
|
||||
public static function convert($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
{
|
||||
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
|
||||
public static function toFrTime($date)
|
||||
{
|
||||
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function getYearFromDate($date)
|
||||
{
|
||||
// return date_format(DateTime::convert($signature_date), 'Y');
|
||||
$date = DateTime::convert($date);
|
||||
$date = date_create($date);
|
||||
return date_format($date, 'Y');
|
||||
}
|
||||
|
||||
|
||||
public static function getLocaleFormatDate()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function getLocaleFormatDatetime()
|
||||
{
|
||||
$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';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function getLocaleDateFull($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('LLLL');
|
||||
}
|
||||
|
||||
public static function getLocaleDateFullShort($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('lll');
|
||||
}
|
||||
|
||||
public static function getLocaleHour($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('');
|
||||
}
|
||||
|
||||
public static function relativeTime()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
33
app/Repositories/Core/Mailer.php
Normal file
33
app/Repositories/Core/Mailer.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Qoraiche\MailEclipse\MailEclipse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Mailer
|
||||
{
|
||||
|
||||
public static function getTemplates()
|
||||
{
|
||||
// $mailables = MailEclipse::getMailables();
|
||||
// DB::rollBack();
|
||||
// dump($mailables);
|
||||
/*
|
||||
$mailables = (null !== $mailables) ? $mailables->sortBy('name') : collect([]);
|
||||
foreach ($mailables as $mailable)
|
||||
{
|
||||
$templates[] = $mailable['name'];
|
||||
}
|
||||
|
||||
*/
|
||||
$templates = ['EventInscription','EventSaveTheDate','MatinalesBadge','MatinalesThanks','MatinalesReplays'];
|
||||
return $templates;
|
||||
}
|
||||
|
||||
public static function getTemplate($template_id)
|
||||
{
|
||||
$templates = self::getTemplates();
|
||||
return $templates[$template_id];
|
||||
}
|
||||
}
|
||||
56
app/Repositories/Core/Media.php
Normal file
56
app/Repositories/Core/Media.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Media
|
||||
{
|
||||
|
||||
public static function getImages($model) {
|
||||
if ($model) {
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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)->withResponsiveImages()->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
25
app/Repositories/Core/Tag.php
Normal file
25
app/Repositories/Core/Tag.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Tag
|
||||
{
|
||||
|
||||
public static function getTagsByModel($model)
|
||||
{
|
||||
$tags = $model->tags;
|
||||
return $tags ? $tags->pluck('id')->toArray() : null;
|
||||
}
|
||||
|
||||
public static function storeTags($model, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $model->syncTags($tags, true);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Botanic\Family;
|
||||
|
||||
class Tags
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Family::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Family::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Family::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Family::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Family::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Family::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Family::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,94 +8,157 @@ use Intervention\Image\Facades\Image as Image;
|
||||
|
||||
class Upload
|
||||
{
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->extension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
return $data;
|
||||
}
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->getClientOriginalExtension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
$data['mime'] = $file->getMimeType();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = pathinfo($uuid, PATHINFO_FILENAME);
|
||||
// $uuid = str_replace('.' . strtolower($data->filetype), '', $uuid);
|
||||
// $uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
public static function store($file, $filepath)
|
||||
{
|
||||
return $file->store($filepath);
|
||||
}
|
||||
public static function storeByVar($var, $path, $public = false)
|
||||
{
|
||||
// check if filename exists
|
||||
// store
|
||||
// Storage::disk('local')->put('file.txt', 'Contents');
|
||||
// $path = Storage::putFile('avatars', $request->file('avatar'));
|
||||
// $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3');
|
||||
// $path = $request->file('avatar')->storePublicly('avatars', 's3');
|
||||
return $request->has($var) ? basename($request->file($var)->store($path)) : false;
|
||||
}
|
||||
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
// exit;
|
||||
$filepath = 'public/' . $filepath;
|
||||
return $file->store($filepath);
|
||||
}
|
||||
public static function store($file, $path)
|
||||
{
|
||||
return Storage::putFile($path, $file);
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
return Storage::delete($file);
|
||||
}
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
return Storage::putFile($filepath, $file, 'public');
|
||||
// $filepath = 'public/' . $filepath;
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function createThumb($file, $size, $sub = false)
|
||||
{
|
||||
$thumb = self::getThumbPath($file, $sub);
|
||||
$filename = self::getPublicPath($file);
|
||||
return Image::make($filename)->orientate()->widen($size)->save($thumb);
|
||||
}
|
||||
public static function createThumb($file, $size, $sub = false)
|
||||
{
|
||||
$thumb = self::getThumbPath($file, $sub);
|
||||
$filename = self::getPublicPath($file);
|
||||
return Image::make($filename)->orientate()->widen($size)->save($thumb);
|
||||
}
|
||||
|
||||
/*
|
||||
public static function getPath($file) {
|
||||
return 'public/' . self::getFilename($file);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getPublicPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getFilename($file));
|
||||
}
|
||||
/*
|
||||
public static function getPath($file) {
|
||||
return 'public/' . self::getFilename($file);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getPublicPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getFilename($file));
|
||||
}
|
||||
|
||||
public static function getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . self::getFilename($file));
|
||||
}
|
||||
public static function getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . self::getFilename($file));
|
||||
}
|
||||
|
||||
public static function getSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getFilename($file);
|
||||
}
|
||||
public static function getSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getFilename($file);
|
||||
}
|
||||
|
||||
public static function getThumbPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getThumbFilename($file));
|
||||
}
|
||||
public static function getThumbPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getThumbFilename($file));
|
||||
}
|
||||
|
||||
public static function getThumbSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getThumbFilename($file);
|
||||
}
|
||||
public static function getThumbSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getThumbFilename($file);
|
||||
}
|
||||
|
||||
public static function getFilename($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . self::getName($file);
|
||||
}
|
||||
public static function getFilename($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
public static function getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' .$file->filetype;
|
||||
}
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' . strtolower($file->filetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* [fix problem path with Storage on Windows]
|
||||
* @param [type] $path [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function fix($path)
|
||||
{
|
||||
if (self::isWindows()) {
|
||||
return str_replace('/', '\\', $path);
|
||||
} else {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
public static function move($source, $dest)
|
||||
{
|
||||
if (Storage::exists($dest)) {
|
||||
self::delete($dest);
|
||||
}
|
||||
return Storage::move($source, $dest); // transfère et renomme le fichier du dossier temporaire au dossier du client
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
// Storage::delete($file);
|
||||
// return unlink($file);
|
||||
return Storage::delete($file);
|
||||
}
|
||||
|
||||
public static function deleteFile($path)
|
||||
{
|
||||
if (Storage::exists($path)) {
|
||||
return Storage::delete($path);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteRecursive($path)
|
||||
{
|
||||
rmdir_recursive($targetDir);
|
||||
}
|
||||
|
||||
public function make_dir($path, $permissions = 0777)
|
||||
{
|
||||
return is_dir($path) || mkdir($path, $permissions, true);
|
||||
}
|
||||
|
||||
public static function isWindows()
|
||||
{
|
||||
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
||||
}
|
||||
}
|
||||
|
||||
63
app/Repositories/Core/User/Basket.php
Normal file
63
app/Repositories/Core/User/Basket.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
class Basket
|
||||
{
|
||||
|
||||
public static function first($key)
|
||||
{
|
||||
$data = self::get($key);
|
||||
return array_shift($data);
|
||||
}
|
||||
|
||||
public static function last($key)
|
||||
{
|
||||
$data = self::get($key);
|
||||
return $data ? array_pop($data) : false;
|
||||
}
|
||||
|
||||
public static function set($key, $data)
|
||||
{
|
||||
return session([$key => $data]);
|
||||
}
|
||||
|
||||
public static function get($key)
|
||||
{
|
||||
return session($key);
|
||||
}
|
||||
|
||||
public static function add($key, $value)
|
||||
{
|
||||
$data = self::isExist($key) ? self::get($key) : [];
|
||||
if (array_search($value, $data) === false) {
|
||||
array_push($data, $value);
|
||||
self::set($key, $data);
|
||||
}
|
||||
return count($data);
|
||||
}
|
||||
|
||||
public static function remove($key, $value)
|
||||
{
|
||||
$data = self::get($key);
|
||||
if (($index = array_search($value, $data)) !== false) {
|
||||
unset($data[$index]);
|
||||
}
|
||||
return self::set($key, $data);
|
||||
}
|
||||
|
||||
public static function isExist($key)
|
||||
{
|
||||
return session()->has($key);
|
||||
}
|
||||
|
||||
public static function reset($key)
|
||||
{
|
||||
return session()->forget($key);
|
||||
}
|
||||
|
||||
public static function resetAll()
|
||||
{
|
||||
return session()->flush();
|
||||
}
|
||||
}
|
||||
66
app/Repositories/Core/User/Notifications/NewUser.php
Normal file
66
app/Repositories/Core/User/Notifications/NewUser.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class NewUser extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$currentUser = \Auth::user();
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
|
||||
->line(__('notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->action(
|
||||
__('notifications.newuser.button'),
|
||||
route('users.firstlogin', $notifiable->remember_token)
|
||||
)
|
||||
->salutation(__('notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->line(__('notifications.newuser.outro'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Repositories/Core/User/Notifications/ResetPassword.php
Normal file
31
app/Repositories/Core/User/Notifications/ResetPassword.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
{
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
/*
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.resetpassword.subject'))
|
||||
->line(__('notifications.resetpassword.intro'))
|
||||
->action(
|
||||
__('notifications.resetpassword.button'),
|
||||
route('password.reset', $this->token)
|
||||
)
|
||||
->line(__('notifications.resetpassword.outro'));
|
||||
}
|
||||
*/
|
||||
}
|
||||
19
app/Repositories/Core/User/PasswordResets.php
Normal file
19
app/Repositories/Core/User/PasswordResets.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use App\Models\Core\Auth\PasswordReset;
|
||||
|
||||
class PasswordResets
|
||||
{
|
||||
|
||||
public static function getTokenByEmail($email)
|
||||
{
|
||||
return PasswordReset::byEmail($email)->first();
|
||||
}
|
||||
|
||||
public static function getEmailByToken($token)
|
||||
{
|
||||
return PasswordReset::byToken($token)->first();
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Media;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Models\Shop\Article;
|
||||
@@ -15,12 +13,6 @@ use App\Models\Shop\Article;
|
||||
class Articles
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Article::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Article::orderBy('name','asc')->get();
|
||||
@@ -28,11 +20,11 @@ class Articles
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Article::with('product')->findOrFail($id);
|
||||
$data = $article->toArray();
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
$data['prices'] = self::getPricesByArticle($article);
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$data['article'] = $article->toArray();
|
||||
$data['article']['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['article']['tags'] = self::getTagsByArticle($article);
|
||||
$data['article']['prices'] = self::getPricesByArticle($article);
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
@@ -53,7 +45,6 @@ class Articles
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
// TODO add category
|
||||
return Article::with(['prices','product','image'])->get();
|
||||
}
|
||||
|
||||
@@ -109,7 +100,7 @@ class Articles
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = Article::find($id);
|
||||
$article = self::get($id);
|
||||
$ret = $article->update($data);
|
||||
return $article;
|
||||
}
|
||||
@@ -133,12 +124,7 @@ class Articles
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->syncTags($tags, true);
|
||||
} else return false;
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
@@ -148,55 +134,27 @@ class Articles
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($article, $file);
|
||||
}
|
||||
}
|
||||
return Media::storeImages($article, $files);
|
||||
}
|
||||
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return $article->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
return Media::storeImage($article, $file);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
if ($article)
|
||||
{
|
||||
$article->getMedia();
|
||||
foreach ($article->media as $key => $media) {
|
||||
$article->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $article->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
|
||||
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;
|
||||
return Media::getThumbSrc($image);
|
||||
}
|
||||
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
$article = self::get($id);
|
||||
$article->getMedia();
|
||||
$ret = $article->media[$index]->delete();
|
||||
return "1";
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user