This commit is contained in:
ludo
2025-02-15 12:12:42 +01:00
parent d1cc62c9b1
commit 592402a6c1
53 changed files with 1098 additions and 404 deletions

View File

@@ -2,22 +2,20 @@
namespace App\Repositories\Core\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rules\Password;
class Passwords
{
public static function validator()
public static function validator($request)
{
$validator = new \Password\Validator(new \Password\StringHelper());
$validator->setMinLength(5);
$validator->setMinLowerCaseLetters(2);
$validator->setMinUpperCaseLetters(1);
$validator->setMinNumbers(1);
$validator->setMinSymbols(3);
return Validator::make($request->all(), [
'password' => ['required', 'confirmed', self::rules()],
]);
}
if ($validator->isValid($password)) {
printf('password %s is valid'.PHP_EOL, $password);
} else {
printf('password %s is invalid'.PHP_EOL, $password);
var_dump($validator->getErrors());
}
public static function rules()
{
return Password::min(10)->mixedCase()->numbers()->symbols()->uncompromised();
}
}

View File

@@ -41,8 +41,6 @@ class Teams
public static function delete($id)
{
Users::destroyByUniqueTeam($id);
return Team::destroy($id);
}

View File

@@ -3,28 +3,22 @@
namespace App\Repositories\Core;
use App\Datatables\Admin\Core\CommentsDataTable;
use App\Models\Core\Comment as rawComment;
use App\Models\Core\Comment;
use App\Repositories\Core\Auth\Users;
use App\Traits\Model\Basic;
class Comments
{
public static function get($id)
{
return rawComment::find($id);
}
use Basic;
public static function getDatatable()
{
$model = new CommentsDataTable();
return $model->html();
return (new CommentsDataTable())->html();
}
public static function getCommentsByModel($model, $model_id)
{
$class = self::getClass($model);
return self::getCommentsByClass($class, $model_id);
return self::getCommentsByClass(self::getClass($model), $model_id);
}
public static function getCommentsByClass($class, $id)
@@ -32,14 +26,14 @@ class Comments
return self::getByModel(self::getModel($class, $id));
}
public static function getModel($class, $id)
public static function getItem($class, $id)
{
return $class::find($id);
}
public static function getClass($model)
{
return 'App\Models\\'.str_replace('.', '\\', $model);
return 'App\Models\\' . str_replace('.', '\\', $model);
}
public static function getByModel($model)
@@ -75,25 +69,11 @@ class Comments
$data['is_approved'] = true;
$data['user_id'] = Users::getId();
return rawComment::create($data);
return Comment::create($data);
}
public static function update($data, $id = false)
public static function getModel()
{
$id = $id ? $id : $data['id'];
$model = self::get($id);
$model->update($data);
return $model;
}
public static function deleteComments($model)
{
return true;
}
public static function deleteComment($model, $index)
{
return true;
return Comment::query();
}
}

View File

@@ -4,23 +4,22 @@ namespace App\Repositories\Shop;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Traits\Model\Basic;
use App\Traits\Repository\Imageable;
class ArticleImages
{
use Basic, Imageable;
use Imageable;
public static function getFullImagesByArticleId($id)
{
$article = self::get($id);
$article = Articles::get($id);
return $article ? self::getFullImagesByArticle($article) : false;
}
public static function countFullImagesByArticleId($id)
{
$article = self::get($id);
$article = Articles::get($id);
return $article ? self::countFullImagesByArticle($article) : 0;
}

View File

@@ -9,67 +9,6 @@ class CustomerAddresses
{
use Basic;
public static function add($userId, $data)
{
self::addDeliveryAddress($userId, $data);
self::addInvoiceAddress($userId, $data);
}
public static function addDeliveryAddress($userId, $data)
{
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
$delivery = $data['use_for_delivery'] ?? false;
$data = [
'customer_id' => $userId,
'type' => 2,
'name' => $name,
'address' => $delivery ? $data['delivery_address'] : $data['address'],
'address2' => $delivery ? $data['delivery_address2'] : $data['address2'],
'zipcode' => $delivery ? $data['delivery_zipcode'] : $data['zipcode'],
'city' => $delivery ? $data['delivery_city'] : $data['city'],
];
return self::store($data);
}
public static function addInvoiceAddress($userId, $data)
{
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
$data = [
'customer_id' => $userId,
'type' => 1,
'name' => $name,
'address' => $data['address'],
'address2' => $data['address2'],
'zipcode' => $data['zipcode'],
'city' => $data['city'],
];
return self::store($data);
}
public static function getInvoiceAddress($customerId)
{
$addresses = CustomerAddress::byCustomer($customerId)->byInvoicing()->get();
if (count($addresses)) {
$address = $addresses->first();
}
return $address;
}
public static function getDeliveryAddress($customerId)
{
$addresses = CustomerAddress::byCustomer($customerId)->byDelivery()->get();
if (count($addresses)) {
$address = $addresses->first();
}
return $address;
}
public static function storeByCustomer($customer, $data)
{
$deliveries = $data['deliveries'] ?? false;
@@ -87,6 +26,72 @@ class CustomerAddresses
}
}
public static function createByCustomer($customerId, $data)
{
self::addDeliveryAddress($customerId, $data);
self::addInvoiceAddress($customerId, $data);
}
public static function addDeliveryAddress($customerId, $data)
{
$delivery = $data['use_for_delivery'] ?? false;
$data = array_merge($data, [
'address' => $delivery ? $data['delivery_address'] : $data['address'],
'address2' => $delivery ? $data['delivery_address2'] : $data['address2'],
'zipcode' => $delivery ? $data['delivery_zipcode'] : $data['zipcode'],
'city' => $delivery ? $data['delivery_city'] : $data['city'],
]);
return self::addAddress($customerId, $data, 2);
}
public static function addInvoiceAddress($customerId, $data)
{
return self::addAddress($customerId, $data, 1);
}
public static function addAddress($customerId, $data, $type)
{
$name = $data['company'] ? $data['company'] : $data['first_name'] . ' ' . $data['last_name'];
$data = [
'customer_id' => $customerId,
'type' => $type,
'name' => $name,
'address' => $data['address'],
'address2' => $data['address2'],
'zipcode' => $data['zipcode'],
'city' => $data['city'],
];
return self::store($data);
}
public static function getInvoiceAddress($customerId)
{
$addresses = CustomerAddress::byCustomer($customerId)->byInvoicing()->get();
return count($addresses) ? $addresses->first() : self::getByCustomer($customerId);
}
public static function getDeliveryAddress($customerId)
{
$addresses = CustomerAddress::byCustomer($customerId)->byDelivery()->get();
return count($addresses) ? $addresses->first() : self::getByCustomer($customerId);
}
public static function getByCustomer($customerId = false)
{
$customer = Customers::get($customerId);
return $customer ? $customer->only(['address', 'adress2', 'zipcode', 'city']) : false;
}
public static function getIconByType($type)
{
return ((int) $type === 1) ? '<i class="fa fa-fw fa-truck"></i>' : '<i class="fa fa-fw fa-file-invoice"></i>';
}
public static function toggleActive($id, $active)
{
return self::update(['active' => $active], $id);

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Repositories\Shop;
use App\Repositories\Core\File;
use Laravolt\Avatar\Avatar;
class CustomerAvatars
{
public static function getImg($id = false)
{
$avatar = self::getAvatar($id);
$name = Customers::getName($id);
return "<img src='{$avatar}' class='img-fluid' title='{$name}'>";
}
public static function getAvatar($id = false)
{
$customer = $id ? Customers::get($id) : Customers::getAuth();
$file = self::makeAvatarFilename($customer);
if (!File::checkFile($file)) {
self::createAvatar($customer);
}
return self::getPublic(self::getAvatarFilename($customer));
}
public static function createAvatar($customer)
{
$filename = self::makeAvatarFilename($customer);
$name = $customer->first_name . ' ' . $customer->last_name;
$avatar = new Avatar();
return $avatar->create($name)
->setBackground('#F2B90F')
->setForeground('#335012')
->setBorder(1, '#28a745')
->setFontFamily('Roboto Condensed')
->setDimension(36)
->setFontSize(16)
->save($filename);
}
public static function makeAvatarFilename($customer)
{
$path = storage_path(self::getStorage());
if (File::checkDirOrCreate($path)) {
$filename = $path . self::getAvatarFilename($customer);
}
return $filename ?? false;
}
public static function getAvatarFilename($customer)
{
return 'user-' . $customer->uuid . '.png';
}
public static function getStorage($filename = false)
{
$path = '/app/public/Customers/';
return $filename ? $path . $filename : $path;
}
public static function getPublic($filename = false)
{
$path = '/storage/Customers/';
return $filename ? $path . $filename : $path;
}
}

View File

@@ -9,6 +9,13 @@ class CustomerSaleChannels
{
use Basic;
public static function createByCustomer($customerId)
{
$customer = Customers::get($customerId);
return $customer->sale_channels()->sync(SaleChannels::getDefault());
}
public static function destroyByCustomerAndSaleChannel($customerId, $saleChannelId)
{
return CustomerSaleChannel::byCustomer($customerId)->bySaleChannel($saleChannelId)->delete();

View File

@@ -5,11 +5,9 @@ namespace App\Repositories\Shop;
use App\Datatables\Shop\CustomerInvoicesDataTable;
use App\Datatables\Shop\CustomerOrdersDataTable;
use App\Models\Shop\Customer;
use App\Repositories\Core\File;
use App\Traits\Model\Basic;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laravolt\Avatar\Avatar;
class Customers
{
@@ -32,20 +30,24 @@ class Customers
public static function getSaleChannels($customerId = false)
{
$customer = $customerId ? self::get($customerId) : self::getAuth();
$saleChannels = $customer ? $customer->sale_channels : false;
return $customer ? $customer->sale_channels : SaleChannels::getDefault();
return $saleChannels ? $saleChannels : SaleChannels::getDefault();
}
public static function getSaleChannel()
public static function getSaleChannel($customerId = false)
{
return SaleChannels::getDefault();
$saleChannels = self::getSaleChannels($customerId);
return $saleChannels->first();
}
public static function getDeliveries()
{
$customer = self::getAuth();
$deliveries = $customer ? $customer->deliveries : false;
return $customer ? $customer->deliveries : Deliveries::getDefault();
return $deliveries ? $deliveries : [Deliveries::getDefault()];
}
public static function getOptions()
@@ -63,48 +65,6 @@ class Customers
] : abort('403');
}
public static function getAvatar($id = false)
{
$customer = $id ? self::get($id) : self::getAuth();
$file = self::makeAvatarFilename($customer);
if (!File::checkFile($file)) {
self::createAvatar($customer);
}
return self::getPublic(self::getAvatarFilename($customer));
}
public static function createAvatar($customer)
{
$filename = self::makeAvatarFilename($customer);
$name = $customer->first_name . ' ' . $customer->last_name;
$avatar = new Avatar();
return $avatar->create($name)
->setBackground('#F2B90F')
->setForeground('#335012')
->setBorder(1, '#28a745')
->setFontFamily('Roboto Condensed')
->setDimension(36)
->setFontSize(16)
->save($filename);
}
public static function makeAvatarFilename($customer)
{
$path = storage_path(self::getStorage());
if (File::checkDirOrCreate($path)) {
$filename = $path . self::getAvatarFilename($customer);
}
return $filename ?? false;
}
public static function getAvatarFilename($customer)
{
return 'user-' . $customer->uuid . '.png';
}
public static function getAddresses($id = false)
{
$customer = self::getWithAddresses($id);
@@ -126,26 +86,6 @@ class Customers
return $user ? $user->name : '';
}
public static function getAuth()
{
return self::guard()->user();
}
public static function getId()
{
return self::guard()->id();
}
public static function isNotConnected()
{
return !self::isConnected();
}
public static function isConnected()
{
return self::guard()->check();
}
public static function edit($id)
{
if (!$id) {
@@ -178,14 +118,9 @@ class Customers
return $customer->id;
}
public static function storeDeliveries($customer, $deliveries)
public static function storeDeliveries($customerId, $deliveries)
{
if (!$deliveries) {
return false;
}
$deliveries = collect($deliveries)->transform(function ($item) {
return (int) $item;
})->toArray();
$customer = self::get($customerId);
return $customer->deliveries()->sync($deliveries);
}
@@ -200,18 +135,9 @@ class Customers
public static function storeSaleChannels($customerId, $saleChannels)
{
$oldSaleChannels = self::getSaleChannelIds($customerId);
$deleteSaleChannels = array_diff($oldSaleChannels, $saleChannels);
$newSaleChannels = array_diff($saleChannels, $oldSaleChannels);
$customer = self::get($customerId);
$data = ['customer_id' => $customerId];
foreach ($newSaleChannels as $saleChannelId) {
$data['sale_channel_id'] = $saleChannelId;
CustomerSaleChannels::store($data);
}
foreach ($deleteSaleChannels as $saleChannelId) {
CustomerSaleChannels::destroyByCustomerAndSaleChannel($customerId, $saleChannelId);
}
return $customer->sale_channels()->sync($saleChannels);
}
public static function create($data)
@@ -223,18 +149,24 @@ class Customers
return Customer::create($data);
}
public static function getStorage($filename = false)
public static function getAuth()
{
$path = '/app/public/Customers/';
return $filename ? $path . $filename : $path;
return self::guard()->user();
}
public static function getPublic($filename = false)
public static function getId()
{
$path = '/storage/Customers/';
return self::guard()->id();
}
return $filename ? $path . $filename : $path;
public static function isNotConnected()
{
return !self::isConnected();
}
public static function isConnected()
{
return self::guard()->check();
}
public static function guard()

View File

@@ -19,7 +19,7 @@ class Deliveries
public static function getByCustomer($customerId = false)
{
$customer = $customerId ? Customers::get($customerId) : Customers::getAuth();
$saleChannels = $customer ? $customer->sale_channels->pluck('id')->toArray() : false;
$saleChannels = $customer ? $customer->sale_channels->pluck('id')->toArray() : [SaleChannels::getDefaultID()];
return $saleChannels ? self::getBySaleChannels($saleChannels) : false;
}