[WIP] Add thumb on offers, refactor categories, try to fix counter on relations polymorphic with eage loader, bad pattern !
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use TheSeer\DirectoryScanner\DirectoryScanner;
|
||||
|
||||
class Cache
|
||||
{
|
||||
public static function getAutoVersion($file)
|
||||
{
|
||||
$filePath = public_path() . $file;
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$version = filemtime($filePath);
|
||||
|
||||
return '?v=' . $version;
|
||||
}
|
||||
|
||||
public static function getFilesVersion($folder, $type)
|
||||
{
|
||||
$folder = str_replace('.', '/', $folder);
|
||||
// dump($folder);
|
||||
// dump($type);
|
||||
// exit;
|
||||
$scanner = new DirectoryScanner;
|
||||
$scanner->addInclude('*.'.$type);
|
||||
// $scanner->addExclude('*filter*');
|
||||
// $scanner->addExclude('./src/*');
|
||||
$path = public_path() . '/' . $folder;
|
||||
|
||||
$data = [];
|
||||
foreach ($scanner($path) as $i) {
|
||||
// dump($i);
|
||||
$sub = $i->getPath();
|
||||
$sub = str_replace($path, '', $sub);
|
||||
$sub = str_replace('\\', '/', $sub);
|
||||
// dump($sub);
|
||||
$filename = '/' . $folder . $sub . '/' . $i->getFilename();
|
||||
// dump($filename);
|
||||
$mtime = $i->getMTime();
|
||||
$data[$filename] = $mtime;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use App\Repositories\Core\Arrays;
|
||||
|
||||
class CategoryTrees
|
||||
class Categories
|
||||
{
|
||||
public static function getTree($withFolder = false)
|
||||
{
|
||||
@@ -74,9 +74,9 @@ class CategoryTrees
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['category_id'];
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::getNode($id);
|
||||
$item->update(['name' => $data['name']]);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Category;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Repositories\Core\Categories as CategoryTrees;
|
||||
|
||||
class Categories
|
||||
{
|
||||
@@ -19,8 +20,10 @@ class Categories
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$category = Category::with('CategoryTree')->find($id);
|
||||
$category = self::get($id);
|
||||
$data = $category->toArray();
|
||||
$data['name'] = $category->name;
|
||||
$data['description'] = $category->description;
|
||||
$data['tags'] = self::getTagsByCategory($category);
|
||||
return $data;
|
||||
}
|
||||
@@ -35,11 +38,6 @@ class Categories
|
||||
return $category->tags->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Category::byCategory($category_id)->first();
|
||||
}
|
||||
|
||||
public static function getTree()
|
||||
{
|
||||
return CategoryTrees::getTree();
|
||||
@@ -47,7 +45,7 @@ class Categories
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Category::orderBy('name', 'asc')->pluck('name', 'category_id')->toArray();
|
||||
return Category::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
|
||||
@@ -26,6 +26,14 @@ class Customers
|
||||
return Customer::find($id);
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$customer = Customer::with(['addresses'])->find($id);
|
||||
$data = $customer->toArray();
|
||||
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$deliveries = $data['deliveries'];
|
||||
|
||||
@@ -6,17 +6,42 @@ use App\Models\Shop\Offer;
|
||||
|
||||
class Offers
|
||||
{
|
||||
|
||||
public static function getThumbSrcById($id)
|
||||
{
|
||||
return self::getThumbSrc(self::get($id));
|
||||
}
|
||||
|
||||
public static function getThumbSrc(Offer $offer)
|
||||
{
|
||||
return Articles::getThumbSrc($offer->article->image);
|
||||
}
|
||||
|
||||
public static function getLast()
|
||||
{
|
||||
return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
|
||||
}
|
||||
|
||||
|
||||
public static function getByCategoryWithTags($category_id)
|
||||
{
|
||||
$category = Categories::get($category_id);
|
||||
$tags = Categories::getTagsByCategory($category);
|
||||
$offers1 = self::getByCategory($category_id)->toArray();
|
||||
$offers2 = self::getByTags($tags)->toArray();
|
||||
$data = array_merge($offers1, $offers2);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Offer::with(['article.image'])->byCategory($category_id)->get();
|
||||
}
|
||||
|
||||
public static function getByTags($tags)
|
||||
{
|
||||
return Offer::with(['article.tags'])->byTags($tags)->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Offer::orderBy('value', 'asc')->get();
|
||||
|
||||
@@ -15,6 +15,16 @@ class Tags
|
||||
return Tag::get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getWithCountOffers()
|
||||
{
|
||||
return Tag::withCount(['offers'])->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getWithCountArticles()
|
||||
{
|
||||
return Tag::withCount(['articles'])->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsFullName()
|
||||
{
|
||||
$tags = Tag::with('group')->get();
|
||||
|
||||
Reference in New Issue
Block a user