add shipping rules

This commit is contained in:
Ludovic CANDELLIER
2023-07-16 14:45:42 +02:00
parent 72a7b270f9
commit 0879b0abf0
459 changed files with 6219 additions and 5416 deletions

View File

@@ -2,21 +2,17 @@
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\Models\Botanic\Family;
use App\Exports\Botanic\FamiliesExport;
use App\Models\Botanic\Family;
use Maatwebsite\Excel\Facades\Excel;
use Yajra\DataTables\DataTables;
class Families
{
public static function getDatatable()
{
$model = Family::orderBy('name');
return Datatables::of($model)->make(true);
}
@@ -39,6 +35,7 @@ class Families
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -52,6 +49,7 @@ class Families
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,14 +2,12 @@
namespace App\Repositories\Botanic;
use Maatwebsite\Excel\Facades\Excel;
use App\Models\Botanic\Genre;
use App\Exports\Botanic\GenresExport;
use App\Models\Botanic\Genre;
use Maatwebsite\Excel\Facades\Excel;
class Genres
{
public static function getOptions()
{
return Genre::get()->SortBy('name')->pluck('name', 'id')->toArray();
@@ -28,6 +26,7 @@ class Genres
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -41,6 +40,7 @@ class Genres
$id = $id ? $id : $data['id'];
$model = self::get($id);
$model->update($data);
return $model;
}

View File

@@ -2,14 +2,11 @@
namespace App\Repositories\Botanic;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Facades\Excel;
use App\Repositories\Core\Tag;
use App\Models\Botanic\Specie;
use App\Exports\Botanic\SpeciesExport;
use App\Models\Botanic\Specie;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
use Maatwebsite\Excel\Facades\Excel;
class Species
{
@@ -33,6 +30,7 @@ class Species
public static function getTags($id)
{
$model = self::get($id) ?? false;
return $model ? $model->tags->toArray() : false;
}
@@ -41,6 +39,7 @@ class Species
$specie = self::get($id);
$data = $specie->toArray();
$data['tags'] = self::getTagsBySpecie($specie);
return $data;
}
@@ -49,7 +48,6 @@ class Species
return Tag::getTagsByModel($specie);
}
public static function get($id)
{
return Specie::with('tags.tag_group')->find($id);
@@ -64,6 +62,7 @@ class Species
$specie = self::store($data);
self::storeImages($specie, $images);
self::storeTags($specie, $tags);
return $specie;
}
@@ -82,6 +81,7 @@ class Species
$id = $id ? $id : $data['id'];
$model = self::get($id);
$ret = $model->update($data);
return $model;
}

View File

@@ -2,14 +2,11 @@
namespace App\Repositories\Botanic;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Facades\Excel;
use App\Repositories\Core\Tag;
use App\Models\Botanic\Variety;
use App\Exports\Botanic\VarietiesExport;
use App\Models\Botanic\Variety;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
use Maatwebsite\Excel\Facades\Excel;
class Varieties
{
@@ -25,9 +22,10 @@ class Varieties
$varieties = Variety::with('specie')->get();
$data = [];
foreach ($varieties as $variety) {
$data[$variety->id] = (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name;
$data[$variety->id] = (isset($variety->specie->name) ? $variety->specie->name.' ' : '').$variety->name;
}
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
return $data;
}
@@ -56,6 +54,7 @@ class Varieties
$variety = self::get($id);
$data = $variety->toArray();
$data['tags'] = self::getTagsByVariety($variety);
return $data;
}
@@ -73,6 +72,7 @@ class Varieties
$variety = self::store($data);
self::storeImages($variety, $images);
self::storeTags($variety, $tags);
return $variety;
}
@@ -91,6 +91,7 @@ class Varieties
$id = $id ? $id : $data['id'];
$variety = self::get($id);
$ret = $variety->update($data);
return $variety;
}

View File

@@ -2,10 +2,8 @@
namespace App\Repositories;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use App\Models\City;
use Illuminate\Support\Facades\DB;
class Cities
{
@@ -22,13 +20,15 @@ class Cities
public static function getCPByCity($id)
{
$ville = self::get($id);
$codes = explode("-", $ville->code_postal);
$codes = explode('-', $ville->code_postal);
return $codes;
}
public static function getNomByCity($id)
{
$ville = self::get($id);
return $ville->nom;
}
@@ -44,23 +44,24 @@ class Cities
// dump($adresse);
$geocode = app('geocoder')->geocode($adresse)->get();
// dump($geocode);
if (!count($geocode)) {
if (! count($geocode)) {
return false;
}
// dump($geocode);
$res = $geocode[0]->getCoordinates()->toArray();
// dump($res);
$latitude = $res[0];
$longitude = $res[1];
// dump($latitude);
// dump($longitude);
return ['latitude' => $latitude, 'longitude' => $longitude];
// dump($geocode);
$res = $geocode[0]->getCoordinates()->toArray();
// dump($res);
$latitude = $res[0];
$longitude = $res[1];
// dump($latitude);
// dump($longitude);
return ['latitude' => $latitude, 'longitude' => $longitude];
}
public static function getCoordsByCity($id)
{
$ville = City::find($id);
return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude];
}
}

View File

@@ -2,7 +2,6 @@
namespace App\Repositories;
use App\Repositories\Users;
use App\Repositories\Shop\Categories;
use App\Repositories\Shop\Homepages;

View File

@@ -10,7 +10,7 @@ class ApplicationClients
public static function associate($client_id, $applications_list)
{
$applications_existing = self::getApplicationsByClient($client_id);
$applications_list = is_array($applications_list) ? $applications_list : array();
$applications_list = is_array($applications_list) ? $applications_list : [];
if (is_array($applications_existing)) {
$applications_new = array_diff($applications_list, $applications_existing);
@@ -20,9 +20,9 @@ class ApplicationClients
$applications_to_delete = [];
}
$history_element_infos = (!empty($applications_new)) ? self::associateApplications($client_id, $applications_new) : false;
$history_element_infos2 = (!empty($applications_to_delete)) ? self::dissociateApplications($client_id, $applications_to_delete) : false;
$history_element_infos = (! empty($applications_new)) ? self::associateApplications($client_id, $applications_new) : false;
$history_element_infos2 = (! empty($applications_to_delete)) ? self::dissociateApplications($client_id, $applications_to_delete) : false;
$data['nb'] = self::countByClient($client_id);
return $data;
@@ -42,12 +42,13 @@ class ApplicationClients
self::associateApplication($client_id, $application_id);
}
}
return true;
}
public static function associateApplication($client_id, $application_id)
{
return ApplicationClient::create(['client_id' => $client_id, 'application_id' => $application_id, 'active' => true ]);
return ApplicationClient::create(['client_id' => $client_id, 'application_id' => $application_id, 'active' => true]);
}
public static function dissociateApplications($client_id, $applications)
@@ -56,6 +57,7 @@ class ApplicationClients
foreach ($applications as $key => $application_id) {
self::dissociateApplication($client_id, $application_id);
}
return true;
}
@@ -86,6 +88,6 @@ class ApplicationClients
public static function isActiveByName($name)
{
return (!Clients::isClient()) ? true : ApplicationClient::bySlug($name)->byClient(Clients::getId())->first()->active ?? false;
return (! Clients::isClient()) ? true : ApplicationClient::bySlug($name)->byClient(Clients::getId())->first()->active ?? false;
}
}

View File

@@ -24,6 +24,7 @@ class ApplicationModules
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
return $id ? self::update($data, $id) : self::create($data);
}
@@ -35,6 +36,7 @@ class ApplicationModules
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
return self::get($id)->update($data);
}
@@ -47,7 +49,7 @@ class ApplicationModules
{
return self::get($id)->name;
}
public static function get($id)
{
return ApplicationModule::findOrFail($id);

View File

@@ -1,4 +1,5 @@
<?php
namespace App\Repositories\Core\App;
use App\Models\Core\App\ApplicationPage;
@@ -8,12 +9,14 @@ class ApplicationPages
public static function getBySlug($application_id, $slug)
{
$app = ApplicationPage::active()->byApplication($application_id)->bySlug($slug)->first();
return $app ? $app->toArray() : null;
}
public static function getActiveByApplication($application_id)
{
$app = ApplicationPage::active()->byApplication($application_id)->get();
return $app ? $app->toArray() : null;
}
}

View File

@@ -2,15 +2,12 @@
namespace App\Repositories\Core\App;
use Illuminate\Support\Facades\Route;
use App\Models\Core\App\Application;
use App\Repositories\Core\App\ApplicationPages;
use App\Repositories\Languages;
use Illuminate\Support\Facades\Route;
class Applications
{
public static function getFullBySlug($slug)
{
return Application::with('clients')->active()->bySlug($slug)->first();
@@ -34,6 +31,7 @@ class Applications
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
return $id ? self::update($data, $id) : self::create($data);
}
@@ -47,6 +45,7 @@ class Applications
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
@@ -59,7 +58,7 @@ class Applications
{
return self::get($id)->name;
}
public static function get($id)
{
return Application::findOrFail($id);
@@ -83,6 +82,7 @@ class Applications
}
$data['langs'] = Languages::getActive();
$data['lang'] = Languages::getCurrent();
return $data;
}
@@ -106,11 +106,13 @@ class Applications
return Application::active()->bySlug($slug)->first();
}
public static function toggleActive($id, $active) {
public static function toggleActive($id, $active)
{
return self::update(['active' => $active], $id);
}
public static function toggleVisible($id, $visible) {
public static function toggleVisible($id, $visible)
{
return self::update(['visible' => $visible], $id);
}
}

View File

@@ -14,6 +14,7 @@ class Arrays
}
}
unset($array[$oldkey]);
return $array;
}
@@ -35,31 +36,32 @@ class Arrays
public static function alternate_chunk($array, $parts)
{
$t = 0;
$result = array();
$result = [];
$max = ceil(count($array) / $parts);
foreach (array_chunk($array, $max) as $v) {
if ($t < $parts) {
$result[] = $v;
} else {
foreach ($v as $d) {
$result[] = array($d);
$result[] = [$d];
}
}
$t += count($v);
}
return $result;
}
public static function fill_chunk($array, $parts)
{
$t = 0;
$result = array_fill(0, $parts - 1, array());
$result = array_fill(0, $parts - 1, []);
$max = ceil(count($array) / $parts);
foreach ($array as $v) {
count($result[$t]) >= $max and $t ++;
count($result[$t]) >= $max and $t++;
$result[$t][] = $v;
}
return $result;
}
}

View File

@@ -2,8 +2,8 @@
namespace App\Repositories\Core\Auth;
use Carbon\Carbon;
use App\Models\Core\Auth\PasswordSecurity;
use Carbon\Carbon;
class PasswordSecurities
{
@@ -16,12 +16,13 @@ class PasswordSecurities
]);
}
public static function getUserName($id) {
public static function getUserName($id)
{
return self::getUser($id)->username;
}
public static function getUser($id) {
public static function getUser($id)
{
return PasswordSecurity::with('user')->find($id)->user;
}
}

View File

@@ -2,19 +2,6 @@
namespace App\Repositories\Core\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
use LangleyFoxall\LaravelNISTPasswordRules\ContextSpecificWords;
use LangleyFoxall\LaravelNISTPasswordRules\DerivativesOfContextSpecificWords;
use LangleyFoxall\LaravelNISTPasswordRules\RepetitiveCharacters;
use LangleyFoxall\LaravelNISTPasswordRules\SequentialCharacters;
use App\Repositories\Users;
class Passwords
{
public static function validator()
@@ -27,9 +14,9 @@ class Passwords
$validator->setMinSymbols(3);
if ($validator->isValid($password)) {
printf('password %s is valid' . PHP_EOL, $password);
printf('password %s is valid'.PHP_EOL, $password);
} else {
printf('password %s is invalid' . PHP_EOL, $password);
printf('password %s is invalid'.PHP_EOL, $password);
var_dump($validator->getErrors());
}
}

View File

@@ -1,12 +1,9 @@
<?php
namespace App\Repositories\Core\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Laratrust\Traits\LaratrustUserTrait;
use Yajra\DataTables\DataTables;
use App\Models\Core\Auth\Permission;
use Yajra\DataTables\DataTables;
class Permissions
{
@@ -53,12 +50,14 @@ class Permissions
public static function getTable($id)
{
$datas = Permission::withCount(['users']);
return Datatables::of($datas)->make(true);
}
public static function delete($id)
{
Users::destroyByUniquePermission($id);
return Permission::destroy($id);
}
@@ -70,6 +69,7 @@ class Permissions
public static function create($data)
{
$permission = Permission::create($data);
return $permission;
}

View File

@@ -2,21 +2,20 @@
namespace App\Repositories\Core\Auth;
use Illuminate\Support\Facades\DB;
use App\Models\Core\Auth\Role;
use App\Models\Core\Auth\RoleUser;
use Illuminate\Support\Facades\Auth;
use Laratrust\Traits\LaratrustUserTrait;
use Yajra\DataTables\DataTables;
use App\Models\Core\Auth\Role;
use App\Models\Core\Auth\RoleUser;
class Roles
{
use LaratrustUserTrait;
public static function getListByRights()
{
$data = (!Auth::user()->hasRole('admin')) ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
$data = (! Auth::user()->hasRole('admin')) ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
return $data->pluck('name', 'id')->toArray();
}
@@ -32,6 +31,7 @@ class Roles
$data['active'] = true;
$role = Role::create($data);
$role->attachPermissions($permissions);
return $role;
}
@@ -43,6 +43,7 @@ class Roles
$role = self::get($id);
$role->update(['name' => $input['name']]);
$role->syncPermissions($permissions);
return $role;
}
@@ -68,6 +69,7 @@ class Roles
{
$role = self::get($id)->toArray();
$role['permissions'] = self::get($id)->permissions->pluck('id')->toArray();
return $role;
}
@@ -89,12 +91,14 @@ class Roles
public static function getTable($id)
{
$datas = Role::orderBy('name', 'asc');
return Datatables::of($datas)->make(true);
}
public static function getRolesByUser($user_id = false)
{
$user_id = $user_id ? $user_id : Users::getId();
return RoleUser::byUser($user_id);
}

View File

@@ -2,15 +2,11 @@
namespace App\Repositories\Core\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Laratrust\Traits\LaratrustUserTrait;
use Yajra\DataTables\DataTables;
use App\Models\Core\Auth\Team;
use App\Models\Core\Auth\TeamUser;
use App\Repositories\Users;
use Laratrust\Traits\LaratrustUserTrait;
use Yajra\DataTables\DataTables;
class Teams
{
@@ -19,6 +15,7 @@ class Teams
public static function getTeamsByUser($user_id = false)
{
$user_id = $user_id ? $user_id : Users::getId();
return TeamUser::byUser($user_id);
}
@@ -75,12 +72,14 @@ class Teams
public static function getTable($id)
{
$datas = Team::with(['societe'])->withCount(['users']);
return Datatables::of($datas)->make(true);
}
public static function delete($id)
{
Users::destroyByUniqueTeam($id);
return Team::destroy($id);
}
@@ -97,6 +96,7 @@ class Teams
if (isset($data['id']) && $data['id']) {
return self::update($data);
}
return self::create($data);
}

View File

@@ -2,9 +2,8 @@
namespace App\Repositories\Core\Auth;
use App\Models\Core\Auth\UserClient;
use App\Models\Core\Auth\User;
use App\Models\Core\Auth\UserClient;
use App\Repositories\Clients;
class UserClients
@@ -12,7 +11,7 @@ class UserClients
public static function associate($user_id, $clients_list)
{
$clients_existing = self::getClientsByUser($user_id)->toArray();
$clients_list = is_array($clients_list) ? $clients_list : array();
$clients_list = is_array($clients_list) ? $clients_list : [];
if (is_array($clients_existing)) {
$clients_new = array_diff($clients_list, $clients_existing);
@@ -22,9 +21,9 @@ class UserClients
$clients_to_delete = $clients_existing;
}
$history_element_infos = (!empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
$history_element_infos2 = (!empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
$history_element_infos = (! empty($clients_new)) ? self::associateClients($user_id, $clients_new) : false;
$history_element_infos2 = (! empty($clients_to_delete)) ? self::dissociateClients($user_id, $clients_to_delete) : false;
// $history_element = $old_translated_name['name'];
// $history_element_id = $documentation_category_id;
// Histories::insert(190, $history_element_id, $history_element);
@@ -41,20 +40,22 @@ class UserClients
public static function associateClients($user_id, $clients)
{
$history = "";
$history = '';
foreach ($clients as $key => $client_id) {
$client = Clients::get($client_id);
if ($client) {
self::associate_client($user_id, $client_id);
$history .= $client['name'] . "| ";
$history .= $client['name'].'| ';
}
}
return $history;
}
public static function associate_client($user_id, $client_id)
{
self::copyUser($user_id, $client_id);
return UserClient::create(['user_id' => $user_id, 'client_id' => $client_id]);
}
@@ -83,7 +84,7 @@ class UserClients
$password = $user->password;
Clients::switchClient($client_id);
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $user->username)->first();
if (!$client_user) {
if (! $client_user) {
$user = $user->toArray();
$user['password'] = $password;
unset($user['id']);
@@ -106,17 +107,19 @@ class UserClients
public static function dissociateClients($user_id, $clients)
{
$history = "";
$history = '';
foreach ($clients as $key => $client_id) {
self::dissociate_client($user_id, $client_id);
$history .= $client['name'] . "| ";
$history .= $client['name'].'| ';
}
return $history;
}
public static function dissociate_client($user_id, $client_id)
{
self::deleteUser($user_id, $client_id);
return UserClient::byUser($user_id)->byClient($client_id)->delete();
}

View File

@@ -2,18 +2,15 @@
namespace App\Repositories\Core\Auth;
use App\Models\Core\Auth\RoleUser;
use App\Models\Core\Auth\User;
use App\Repositories\Core\Upload;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laratrust\Traits\LaratrustUserTrait;
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
use App\Models\Core\Auth\User;
use App\Models\Core\Auth\RoleUser;
use App\Repositories\Core\Upload;
use Laratrust\Traits\LaratrustUserTrait;
class Users
{
@@ -27,7 +24,7 @@ class Users
public static function getInfo($id = false)
{
$id = $id ? $id : self::getId();
if (!$id) {
if (! $id) {
return false;
}
$user = self::get($id);
@@ -36,6 +33,7 @@ class Users
$data['avatar'] = self::getAvatar($id);
$data['roles'] = $user->roles->pluck('id')->toArray();
$data['permissions'] = $user->allPermissions()->pluck('id')->toArray();
return $data;
}
@@ -46,6 +44,7 @@ class Users
}
$user = ($data['id'] ?? false) ? self::update($data) : self::create($data);
$user->roles()->sync(array_keys($data['roles'] ?? []));
return $user;
}
@@ -56,6 +55,7 @@ class Users
$data['active'] = true;
$user = User::create($data);
PasswordSecurities::create($user->id);
return $user;
}
@@ -64,25 +64,29 @@ class Users
$id = $id ? $id : $data['id'];
$user = self::get($id);
$ret = $user->update($data);
return $user;
}
public static function get($id = false)
{
$id = $id ? $id : self::getId();
return User::findOrFail($id);
}
public static function getId()
{
$user = self::getUser();
return $user ? $user->id : false;
}
public static function getName($id = false)
{
$user = $id ? self::get($id) : self::getUser();
return $user->first_name . ' ' . $user->last_name;
return $user->first_name.' '.$user->last_name;
}
public static function getUsername($id = false)
@@ -108,6 +112,7 @@ class Users
public static function delete($id)
{
$ret = RoleUser::byUser($id)->delete();
return User::destroy($id);
}
@@ -119,6 +124,7 @@ class Users
public static function hasRole($role, $user = false)
{
$user = $user ? $user : self::getUser();
return $user ? $user->hasRole($role) : false;
}
@@ -129,14 +135,15 @@ class Users
}
$user = $user ? $user : self::getUser();
$permissions = self::getPermissions($user);
return $user ? self::checkPermission($permissions, $permission) : false;
// TODO why is posing problem ???
// return $user ? $user->hasPermission($permission) : false;
// return $user ? $user->hasPermission($permission) : false;
}
public static function checkPermission($permissions, $permission)
{
if (!strpos($permission, '*')) {
if (! strpos($permission, '*')) {
return in_array($permission, $permissions);
}
$permission = str_replace('*', '', $permission);
@@ -145,12 +152,14 @@ class Users
return true;
}
}
return false;
}
public static function getRoles($user = false)
{
$user = $user ? $user : self::getUser();
return $user ? $user->roles->pluck('name')->toArray() : false;
}
@@ -158,10 +167,11 @@ class Users
{
return Roles::getListByRights();
}
public static function getPermissions($user = false)
{
$user = $user ? $user : self::getUser();
return $user ? $user->allPermissions()->pluck('name')->toArray() : false;
}
@@ -183,11 +193,12 @@ class Users
public static function getAvatar($user_id)
{
$avatar = self::get($user_id)->avatar;
if (!$avatar) {
if (! $avatar) {
return '/assets/img/no-avatar.png';
}
$path = '/images/avatars/';
return $path . $avatar;
return $path.$avatar;
}
public static function selectOptions()
@@ -233,6 +244,7 @@ class Users
$file_uploaded = Upload::store($file, $targetDir);
$tab = pathinfo($file_uploaded);
$response['name'] = $tab['basename'];
return $response;
}
@@ -244,6 +256,7 @@ class Users
public static function update_password($id, $password)
{
$password = Hash::make($password);
return User::find($id)->update(['password' => $password]);
}

View File

@@ -2,29 +2,30 @@
namespace App\Repositories\Core;
use App\Repositories\Core\Arrays;
use App\Models\Shop\Category;
class Categories
{
public static function getFancyTree()
{
$categories = self::getTree(true);
$categories = Arrays::changeKeyName($categories, 'title', 'name');
$categories = Arrays::changeKeyName($categories, 'key', 'id');
return $categories;
}
public static function getTreeVisibles($withFolder = false)
{
$categories = self::getCategoryTreeVisibles()->toArray();
return $categories ? self::getChildren($categories[0]['children'], $withFolder) : [];
}
public static function getTree($withFolder = false)
{
$categories = self::getCategoryTree()->toArray();
return self::getChildren($categories[0]['children'], $withFolder);
}
@@ -58,6 +59,7 @@ class Categories
}
// $tree = collect($tree)->sortBy('name')->toArray();
$tree = collect($tree)->toArray();
return $tree;
}
@@ -77,15 +79,16 @@ class Categories
break;
}
$category->save();
return "1";
}
return '1';
}
public static function create($data)
{
$parent = ($data['parent_id'] ?? false) ? self::getNode($data['parent_id']) : self::getRoot();
$category = self::getModel()->create(['name' => $data['name']]);
$category->appendToNode($parent)->save();
return $category;
}
@@ -94,6 +97,7 @@ class Categories
$id = $id ? $id : $data['id'];
$item = self::getNode($id);
$item->update($data);
return $item;
}

View File

@@ -2,15 +2,12 @@
namespace App\Repositories\Core;
use BeyondCode\Comments\Comment;
use App\Datatables\Admin\Core\CommentsDataTable;
use App\Models\Core\Comment as rawComment;
use App\Repositories\Core\Auth\Users;
use App\Datatables\Admin\Core\CommentsDataTable;
class Comments
{
public static function get($id)
{
return rawComment::find($id);
@@ -19,12 +16,14 @@ class Comments
public static function getDatatable()
{
$model = new CommentsDataTable();
return $model->html();
}
public static function getCommentsByModel($model, $model_id)
{
$class = self::getClass($model);
return self::getCommentsByClass($class, $model_id);
}
@@ -40,14 +39,14 @@ class Comments
public static function getClass($model)
{
return 'App\Models\\' . str_replace('.', '\\', $model);
return 'App\Models\\'.str_replace('.', '\\', $model);
}
public static function getByModel($model)
{
return $model ? $model->comments->sortByDesc('updated_at')->toArray() : false;
}
public static function storeComments($model, $comments)
{
foreach (($comments ?? []) as $comment) {
@@ -66,6 +65,7 @@ class Comments
unset($data['_token']);
$data['commentable_type'] = Comments::getClass($data['commentable_type']);
$data['commentable_id'] = (int) $data['commentable_id'];
return $id ? self::update($data, $id) : self::create($data);
}
@@ -74,6 +74,7 @@ class Comments
unset($data['id']);
$data['is_approved'] = true;
$data['user_id'] = Users::getId();
return rawComment::create($data);
}
@@ -82,6 +83,7 @@ class Comments
$id = $id ? $id : $data['id'];
$model = self::get($id);
$model->update($data);
return $model;
}

View File

@@ -2,8 +2,8 @@
namespace App\Repositories\Core;
use Illuminate\Support\Facades\Schema;
use Collective\Html\Eloquent\Form;
use Illuminate\Support\Facades\Schema;
class Database
{
@@ -13,20 +13,21 @@ class Database
$data = self::getTableFields($model);
foreach ($data as $item) {
switch ($item['type']) {
case 'integer':
$form .= Form::number($item['name']);
break;
case 'string':
$form .= Form::number($item['name']);
break;
case 'date':
$form .= Form::date($item['name']);
break;
case 'boolean':
$form .= Form::checkbox($item['name']);
break;
case 'integer':
$form .= Form::number($item['name']);
break;
case 'string':
$form .= Form::number($item['name']);
break;
case 'date':
$form .= Form::date($item['name']);
break;
case 'boolean':
$form .= Form::checkbox($item['name']);
break;
}
}
return $form;
}
@@ -40,6 +41,7 @@ class Database
$type = Schema::getColumnType($table->getTable(), $column);
array_push($data, ['name' => $column, 'type' => $type]);
}
return $data;
}

View File

@@ -2,9 +2,7 @@
namespace App\Repositories\Core;
use Illuminate\Support\Str;
use Carbon\Carbon;
use Jenssegers\Date\Date;
class DateCalculation
{

View File

@@ -2,8 +2,7 @@
namespace App\Repositories\Core;
use \Carbon\Carbon;
use \League\Period\Period;
use Carbon\Carbon;
class DateHelper
{
@@ -31,17 +30,18 @@ class DateHelper
{
$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;
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;
}

View File

@@ -3,16 +3,11 @@
namespace App\Repositories\Core;
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;
use League\Period\Period;
class DateRange
{
public static function today()
{
return self::previousDay(0);
@@ -72,6 +67,7 @@ class DateRange
foreach ($labels as $label) {
$data[$label] = $periods;
}
return $data;
}
@@ -85,6 +81,7 @@ class DateRange
$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);
}
@@ -95,6 +92,7 @@ class DateRange
$date = self::DatePointToCarbon($period->getStartDate());
$months[] = DateTime::getMonthName($date);
}
return $months;
}
@@ -104,6 +102,7 @@ class DateRange
foreach ($periods as $period) {
$months[] = DateTime::getMonthName($period['start']);
}
return $months;
}
@@ -111,6 +110,7 @@ class DateRange
{
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
$begin = $end->copy()->subWeek($nb);
return self::getPeriodsbyWeek($begin, $end);
}
@@ -118,6 +118,7 @@ class DateRange
{
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
$begin = $end->copy()->subDay($nb);
return self::getPeriodsbyDay($begin, $end);
}
@@ -156,6 +157,7 @@ class DateRange
$date = Carbon::now()->subMonth(3)->startOfQuarter();
break;
}
return [$date, $date->addMonth(6)];
}
@@ -200,6 +202,7 @@ class DateRange
foreach ($period->getDatePeriod($duration) as $day) {
$daterange[] = interval_after($day, $duration);
}
return $daterange;
}
@@ -209,6 +212,7 @@ class DateRange
foreach ($periods as $period) {
$data[] = self::PeriodToCarbon($period);
}
return $data;
}

View File

@@ -11,6 +11,7 @@ trait DateStats
{
$start = Carbon::now()->startOfMonth($prev);
$end = Carbon::now()->endOfMonth($prev);
return self::countByPeriod($start, $end);
}
@@ -23,12 +24,14 @@ trait DateStats
{
$start = Carbon::now()->startOfMonth($prev);
$end = Carbon::now()->endOfMonth($prev);
return self::avgByPeriod($start, $end, $field);
}
public static function avgByPeriod($start, $end, $field)
{
$c = self::countByPeriod($start, $end);
return $c ? round(self::sumByPeriod($start, $end, $field) / $c, 2) : 0;
}
@@ -36,6 +39,7 @@ trait DateStats
{
$start = Carbon::now()->startOfMonth($prev);
$end = Carbon::now()->endOfMonth($prev);
return self::sumByPeriod($start, $end, $field);
}

View File

@@ -2,12 +2,10 @@
namespace App\Repositories\Core;
use Illuminate\Support\Str;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Jenssegers\Date\Date;
use App\Repositories\Languages;
class DateTime
{
public static function getMonthName($date, $short = true)
@@ -33,22 +31,24 @@ class DateTime
public static function DatetoLocale($date = null)
{
$format = self::getLocaleFormatDate();
if (!is_null($date) && !empty($date)) {
if (! is_null($date) && ! empty($date)) {
$date = Carbon::parse($date)->format($format);
} elseif ($date == 'now') {
$date = today()->format($format);
}
return $date;
}
public static function DatetimeToLocale($date = null)
{
$format = self::getLocaleFormatDatetime();
if (!is_null($date) && !empty($date)) {
if (! is_null($date) && ! empty($date)) {
$date = Carbon::parse($date)->format($format);
} elseif ($date == 'now') {
$date = now()->format($format);
}
return $date;
}
@@ -70,7 +70,8 @@ class DateTime
public static function convert($date)
{
$format = self::getLocaleFormatDate();
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
return ! empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
}
public static function convertTime($date)
@@ -79,17 +80,18 @@ class DateTime
if (strlen($date) == 16) {
$date .= ':00';
}
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
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;
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;
return ! empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
}
public static function getYearFromDate($date)
@@ -97,10 +99,10 @@ class DateTime
// 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();
@@ -112,6 +114,7 @@ class DateTime
default:
$format = 'Y-m-d';
}
return $format;
}
@@ -126,6 +129,7 @@ class DateTime
default:
$format = 'Y-m-d H:i:s';
}
return $format;
}
@@ -157,6 +161,7 @@ class DateTime
public static function getISOFormat($format, $date = false)
{
$date = $date ? $date : now();
return Carbon::parse($date)->isoFormat($format);
}

View File

@@ -2,15 +2,16 @@
namespace App\Repositories\Core;
use \League\CLImate\CLImate;
use \Timer;
use League\CLImate\CLImate;
use Timer;
class Debug
{
// $is_debug binaire 0 ou 1 debug, 0 ou 1 force output
public static $_instance;
public static $app;
public static $debugbar;
private function __construct()
@@ -28,9 +29,9 @@ class Debug
return class_exists('Clockwork\Support\Laravel\ClockworkServiceProvider') ? true : false;
}
public static function start($var = '', $params = array(), $txt = '')
public static function start($var = '', $params = [], $txt = '')
{
if (!static::isDebug()) {
if (! static::isDebug()) {
return false;
}
$var = (empty($var)) ? static::getMethod() : $var;
@@ -42,7 +43,7 @@ class Debug
*/
// TODO Fixer la longueur des params string passés
if (is_null($params)) {
$params = array();
$params = [];
}
Timer::start($var, $params);
@@ -58,7 +59,7 @@ class Debug
public static function stop($var = '')
{
if (!static::isDebug()) {
if (! static::isDebug()) {
return false;
}
$var = (empty($var)) ? static::getMethod() : $var;
@@ -97,7 +98,7 @@ class Debug
/**
* dump un message uniquement si debug est true
*
* @param string $msg [description]
* @param string $msg [description]
* @return [type] [description]
*/
public static function message($msg, $cat = '')
@@ -110,7 +111,7 @@ class Debug
/**
* force la sortie d'un dump, sans passer par la debugbar ou test si debug est true
*
* @param string $msg [description]
* @param string $msg [description]
* @return [type] [description]
*/
public static function fdump($msg, $cat = '')
@@ -122,7 +123,7 @@ class Debug
* dump un message suivant le handler de sortie prévu (log, debugbar, cli, ...)
*
* @param [type] $msg [description]
* @param boolean $force si true, force la sortie en output direct
* @param bool $force si true, force la sortie en output direct
* @return [type] [description]
*/
public static function dump($msg, $cat = '', $force = false)
@@ -133,18 +134,19 @@ class Debug
dump($msg);
}
if (!self::isDebug()){
return;}
if (static::isCLI()) {
self::dumpCli($msg, $cat);
}
if (static::isDebugbar()) {
self::dumpDebugbar($msg, $cat);
}
if (static::isClockwork()) {
self::dumpClockwork($msg, $cat);
}
if (! self::isDebug()) {
return;
}
if (static::isCLI()) {
self::dumpCli($msg, $cat);
}
if (static::isDebugbar()) {
self::dumpDebugbar($msg, $cat);
}
if (static::isClockwork()) {
self::dumpClockwork($msg, $cat);
}
}
public static function dumpDebugbar($msg, $cat = '', $force = false)
@@ -199,10 +201,11 @@ class Debug
$is_debug = false;
}
} else {
dump("la isDebug::165");
dump('la isDebug::165');
dump($caller);
$is_debug = true;
}
return $is_debug;
}
@@ -212,8 +215,8 @@ class Debug
$backtrace = debug_backtrace();
$backtrace = array_reverse($backtrace);
foreach ($backtrace as $item) {
$caller = isset($item['class']) ? $item['class'] . $item['type'] . $item['function'] : $item['function'];
$place = isset($item['file']) ? $item['file'] . ' at ' . $item['line'] : '';
$caller = isset($item['class']) ? $item['class'].$item['type'].$item['function'] : $item['function'];
$place = isset($item['file']) ? $item['file'].' at '.$item['line'] : '';
$txt .= "$caller | $place \n";
}
static::dump($txt, '', $force);
@@ -222,12 +225,12 @@ class Debug
public static function getLocation()
{
return static::getMethod() . ' at ' . static::getFile() . ' line ' . static::getLine();
return static::getMethod().' at '.static::getFile().' line '.static::getLine();
}
public static function getMethod()
{
return (static::getClass() . static::getType() . static::getFunction());
return static::getClass().static::getType().static::getFunction();
}
public static function getClass()
@@ -269,6 +272,7 @@ class Debug
while ($backtrace[$k]['class'] == 'App\Repositories\Core\Debug') {
$k++;
}
return (object) $backtrace[$k];
}
@@ -280,6 +284,7 @@ class Debug
while ($backtrace[$k]['class'] == 'App\Repositories\Core\Debug') {
$k++;
}
return (object) $backtrace[$k - 1];
}
@@ -288,14 +293,15 @@ class Debug
$backtrace = debug_backtrace();
$object = isset($backtrace[0]['object']) ? $backtrace[0]['object'] : null;
$k = 1;
while (isset($backtrace[$k]) && (!isset($backtrace[$k]['object']) || $object === $backtrace[$k]['object'])) {
while (isset($backtrace[$k]) && (! isset($backtrace[$k]['object']) || $object === $backtrace[$k]['object'])) {
$k++;
}
return isset($backtrace[$k]['object']) ? $backtrace[$k]['object'] : null;
}
public static function isCLI()
{
return (PHP_SAPI == 'cli');
return PHP_SAPI == 'cli';
}
}

View File

@@ -5,11 +5,17 @@ namespace App\Repositories\Core;
class Export
{
public $xls;
public $sheet;
public $filename;
public $stockage;
public $lig;
public $nb;
public $debug;
public function __construct()
@@ -75,16 +81,18 @@ class Export
if (isset($options[$key])) {
$txt = $options[$key][$txt];
}
if (!isset($multioptions[$key])){
$this->writeCell($this->lig, $col, $txt);
$this->nb++;
$col++;
continue;}
$tabs = self::getReverseMultiOptions($txt);
foreach ($tabs as $key2 => $value) {
$txt .= $multioptions[$key][$key2] . '\n';
}
if (! isset($multioptions[$key])) {
$this->writeCell($this->lig, $col, $txt);
$this->nb++;
$col++;
continue;
}
$tabs = self::getReverseMultiOptions($txt);
foreach ($tabs as $key2 => $value) {
$txt .= $multioptions[$key][$key2].'\n';
}
$this->writeCell($this->lig, $col, $txt);
$this->nb++;
$col++;
@@ -104,41 +112,43 @@ class Export
{
// Redirect output to a clients web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $this->filename . '"');
header('Content-Disposition: attachment;filename="'.$this->filename.'"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
// header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0
}
public function close()
{
if ($this->debug){
return;}
// Debug::message($this->xls);
$objWriter = PHPExcel_IOFactory::createWriter($this->xls, 'Excel2007');
// Debug::message($objWriter);
// exit;
if (!$this->stockage) {
$this->header();
$objWriter->save('php://output');
} else {
// $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$objWriter->save('text.xlsx');
}
if ($this->debug) {
return;
}
// Debug::message($this->xls);
$objWriter = PHPExcel_IOFactory::createWriter($this->xls, 'Excel2007');
// Debug::message($objWriter);
// exit;
if (! $this->stockage) {
$this->header();
$objWriter->save('php://output');
} else {
// $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$objWriter->save('text.xlsx');
}
}
public function conv($lig, $col)
{
$c = static::convColtoTxt($col);
$lig = $this->lig;
return ("$c$lig");
return "$c$lig";
}
public function convColtoTxt($col)
@@ -151,22 +161,25 @@ class Export
$c = '';
}
$c .= chr(65 + $col1);
return ($c);
return $c;
}
public function getOption($var)
{
$data = $this->init();
return ($data[$var . '_options']);
return $data[$var.'_options'];
}
public function getOptions($data)
{
$options = array();
$options = [];
foreach ($data as $key => $value) {
$var = substr($key, 0, -8);
$options[$var] = $value;
}
return $options;
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Repositories\Core;
use Illuminate\Support\Facades\Storage;
use SoftCreatR\MimeDetector\MimeDetector;
use SoftCreatR\MimeDetector\MimeDetectorException;
@@ -32,6 +31,7 @@ class File
public static function deleteDir($dir)
{
Storage::deleteDirectory($dir);
return true;
}
@@ -65,7 +65,7 @@ class File
try {
return (new MimeDetector())->setFile($file)->getFileType();
} catch (MimeDetectorException $e) {
die('An error occured while trying to load the given file.');
exit('An error occured while trying to load the given file.');
}
}
}

View File

@@ -6,25 +6,26 @@ class Geolocation
{
public static function getCoords($address, $zipcode, $city)
{
if (!(!empty($address) && !empty($zipcode) && !empty($city))){
return;}
$address = $address . ' , ' . $city . ' ' . $zipcode . ' , ' . 'France';
$geocode = app('geocoder')->geocode($address)->get();
if (!count($geocode)) {
return false;
}
$res = $geocode[0]->getCoordinates()->toArray();
// dump($res);
$longitude = $res[0];
$latitude = $res[1];
// dump($latitude);
// dump($longitude);
// exit;
return ['latitude' => $latitude, 'longitude' => $longitude];
if (! (! empty($address) && ! empty($zipcode) && ! empty($city))) {
return;
}
$address = $address.' , '.$city.' '.$zipcode.' , '.'France';
$geocode = app('geocoder')->geocode($address)->get();
if (! count($geocode)) {
return false;
}
$res = $geocode[0]->getCoordinates()->toArray();
// dump($res);
$longitude = $res[0];
$latitude = $res[1];
// dump($latitude);
// dump($longitude);
// exit;
return ['latitude' => $latitude, 'longitude' => $longitude];
}
public static function autocomplete($query)
{

View File

@@ -10,22 +10,22 @@ class HelperDate
public static function toLocaleFormat($date)
{
if (!(!is_null($date) && !empty($date))) {
if (! (! is_null($date) && ! empty($date))) {
return $date;
}
$locale = session('locale');
switch ($locale) {
case 'fr':
$format = 'd/m/Y';
break;
case 'en':
$format = 'Y-m-d';
break;
default:
$format = 'Y-m-d';
case 'fr':
$format = 'd/m/Y';
break;
case 'en':
$format = 'Y-m-d';
break;
default:
$format = 'Y-m-d';
}
$date = Carbon::parse($date)->format($format);
return $date;
}
@@ -41,9 +41,10 @@ class HelperDate
public static function frenchDate($d)
{
if (!$d) {
if (! $d) {
return null;
}
return Carbon::createFromFormat('d/m/Y', $d)->format('Y-m-d');
}
@@ -54,6 +55,7 @@ class HelperDate
$data[$field] = static::frenchDate($data[$field]);
}
}
return $data;
}
@@ -62,6 +64,7 @@ class HelperDate
if ($d && $d != '0000-00-00') {
return Carbon::createFromFormat('Y-m-d', $d)->format('d/m/Y');
}
return $d;
}
@@ -72,6 +75,7 @@ class HelperDate
$data[$field] = static::toFrenchDate($data[$field]);
}
}
return $data;
}
}

View File

@@ -6,5 +6,5 @@ use App\Traits\Repository\Imageable;
class Images
{
use Imageable;
use Imageable;
}

View File

@@ -4,22 +4,23 @@ namespace App\Repositories\Core;
class Medias
{
public static function getImage($model, $conversion = 'normal', $collection = 'images')
{
$img = $model->getMedia($collection)->first();
return $img ? $img->getUrl($conversion) : false;
}
public static function getImages($model)
{
if (!$model) {
if (! $model) {
return false;
}
$model->getMedia();
foreach ($model->media as $key => $media) {
$model->media[$key]['url'] = $media->getUrl();
}
return $model->media;
}
@@ -42,6 +43,7 @@ class Medias
public static function deleteImages($model, $collection = 'images')
{
$ret = $model->clearMediaCollection($collection);
return true;
}
@@ -49,38 +51,41 @@ class Medias
{
$model->getMedia();
$ret = $model->media[$index]->delete();
return true;
}
public static function buildURL($image, $conversion = '')
{
return self::getPath($image) . self::getConversion($image, $conversion);
return self::getPath($image).self::getConversion($image, $conversion);
}
public static function getPath($image)
{
$model = basename(str_replace('\\', '/', $image->model_type));
return '/storage/' . $model . '/' . $image->collection_name . '/' . $image->id;
return '/storage/'.$model.'/'.$image->collection_name.'/'.$image->id;
}
public static function getConversion($image, $conversion = '')
{
// return $conversion ? '/conversions/' . $image->name . '-' . $conversion . self::getExtension($image->file_name) : $image->file_name;
return $conversion ? '/conversions/' . $image->name . '-' . $conversion . '.jpg' : $image->file_name;
return $conversion ? '/conversions/'.$image->name.'-'.$conversion.'.jpg' : $image->file_name;
}
public static function getExtension($filename)
{
return '.' . pathinfo($filename, PATHINFO_EXTENSION);
return '.'.pathinfo($filename, PATHINFO_EXTENSION);
}
public static function getImageSrc($image)
{
if (!$image) {
if (! $image) {
return null;
}
$id = $image['id'];
$filename = self::getFilename($image);
return "/storage/$id/$filename";
}
@@ -101,13 +106,14 @@ class Medias
public static function getSrcByType($image, $type)
{
return $image ? '/storage/' . $image['id'] . '/conversions/' . self::getFilename($image, $type) : false;
return $image ? '/storage/'.$image['id'].'/conversions/'.self::getFilename($image, $type) : false;
}
public static function getFilename($image, $type = false)
{
$image['name'] = self::convertName($image['name']);
return $image['name'] . ($type ? '-' . $type : '') . self::getExtension($image['file_name']);
return $image['name'].($type ? '-'.$type : '').self::getExtension($image['file_name']);
}
public static function convertName($name)

View File

@@ -6,8 +6,6 @@ use Auth;
use Illuminate\Support\Collection;
use Lavary\Menu\Builder as LavaryMenuBuilder;
use App\Repositories\Users;
/**
* Class Builder.
*
@@ -20,9 +18,8 @@ class Builder extends LavaryMenuBuilder
/**
* Adds an item to the menu.
*
* @param string $title
* @param string $options
*
* @param string $title
* @param string $options
* @return \Lavary\Menu\Item|Item
*/
public function add($title, $options = '')
@@ -65,8 +62,7 @@ class Builder extends LavaryMenuBuilder
*
* @param $id Id of the menu item to attach to
* @param $title Title of the sub item
* @param string $options
*
* @param string $options
* @return Lavary\Menu\Item
*/
public function addTo($id, $title, $options = '')
@@ -74,7 +70,7 @@ class Builder extends LavaryMenuBuilder
$parent = $this->whereId($id)->first();
if (isset($parent)) {
if (!isset($this->root[$parent->id])) {
if (! isset($this->root[$parent->id])) {
$parent->attr(['url' => '#', 'class' => 'treeview']);
// $str = '<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>';
// $parent->append($str);

View File

@@ -9,7 +9,6 @@ class Item extends LavaryMenuItem
/**
* Set the item icon using font-awesome.
*
* @param $icon
*
* @return self
*/
@@ -23,7 +22,6 @@ class Item extends LavaryMenuItem
/**
* Set the item order.
*
* @param $order
*
* @return self
*/
@@ -37,29 +35,29 @@ class Item extends LavaryMenuItem
/**
* Make the item active.
*
* @param string|array $routes
*
* @param string|array $routes
* @return self
*/
public function activeIfRoute($routes = null)
{
if (!empty($routes)) {
if (! empty($routes)) {
if (is_string($routes)) {
$routes = [$routes];
}
foreach ($routes as $pattern) {
$arr = [$pattern];
if (!if_route_pattern($arr)){
continue;}
$this->activate();
if (strstr($this->title, 'circle-o')) {
$this->title = str_replace('fa-circle-o', 'fa-dot-circle-o', $this->title);
}
// dump($this);
return $this;
if (! if_route_pattern($arr)) {
continue;
}
$this->activate();
if (strstr($this->title, 'circle-o')) {
$this->title = str_replace('fa-circle-o', 'fa-dot-circle-o', $this->title);
}
// dump($this);
return $this;
}
return $this;
}

View File

@@ -14,16 +14,16 @@ class Logs
$menu->addTo(
'logs', __('boilerplate::logs.menu.stats'), [
'route' => 'boilerplate.logs.dashboard',
'permission' => 'logs', ]
'route' => 'boilerplate.logs.dashboard',
'permission' => 'logs', ]
)
->order(1110)
->activeIfRoute('boilerplate.logs.dashboard');
$menu->addTo(
'logs', __('boilerplate::logs.menu.reports'), [
'route' => 'boilerplate.logs.list',
'permission' => 'logs', ]
'route' => 'boilerplate.logs.list',
'permission' => 'logs', ]
)
->order(1120)
->activeIfRoute(['boilerplate.logs.list', 'boilerplate.logs.show', 'boilerplate.logs.filter']);

View File

@@ -9,21 +9,22 @@ class Menu extends LavaryMenu
{
public function make($name, $callback)
{
if (!is_callable($callback)){
return;}
if (!array_key_exists($name, $this->menu)) {
$this->menu[$name] = new Builder($name, $this->loadConf($name));
}
// Registering the items
call_user_func($callback, $this->menu[$name]);
// Storing each menu instance in the collection
$this->collection->put($name, $this->menu[$name]);
// Make the instance available in all views
View::share($name, $this->menu[$name]);
return $this->menu[$name];
if (! is_callable($callback)) {
return;
}
if (! array_key_exists($name, $this->menu)) {
$this->menu[$name] = new Builder($name, $this->loadConf($name));
}
// Registering the items
call_user_func($callback, $this->menu[$name]);
// Storing each menu instance in the collection
$this->collection->put($name, $this->menu[$name]);
// Make the instance available in all views
View::share($name, $this->menu[$name]);
return $this->menu[$name];
}
}

View File

@@ -14,22 +14,22 @@ class Users
$menu->addTo(
'access', __('boilerplate::users.list.title'), [
'route' => 'boilerplate.users.index',
'permission' => 'users_crud', ]
'route' => 'boilerplate.users.index',
'permission' => 'users_crud', ]
)
->activeIfRoute(['boilerplate.users.index', 'boilerplate.users.edit']);
$menu->addTo(
'access', __('boilerplate::users.create.title'), [
'route' => 'boilerplate.users.create',
'permission' => 'users_crud', ]
'route' => 'boilerplate.users.create',
'permission' => 'users_crud', ]
)
->activeIfRoute('boilerplate.users.create');
$menu->addTo(
'access', __('boilerplate::layout.role_management'), [
'route' => 'boilerplate.roles.index',
'permission' => 'roles_crud', ]
'route' => 'boilerplate.roles.index',
'permission' => 'roles_crud', ]
)
->activeIfRoute('boilerplate.roles.*');

View File

@@ -16,6 +16,7 @@ class Number
$formatter->setLanguageManager($languageManager);
$price = $formatter->format($value, '0,0');
return $price;
}
}

View File

@@ -3,9 +3,9 @@
namespace App\Repositories\Core;
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
use Barryvdh\Snappy\Facades\SnappyPdf;
use GravityMedia\Ghostscript\Ghostscript;
use Mpdf\Mpdf;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Symfony\Component\Process\Process;
class PDF
@@ -18,15 +18,13 @@ class PDF
->waitUntilNetworkIdle()
->format('A4')
->showBackground()
->savePdf("temp.pdf");
->savePdf('temp.pdf');
$postRoute = URL::signedRoute('orderinvoices.store', ['order' => $this->order]);
Http::attach('invoice', file_get_contents('temp.pdf'), $filename)
->post($postRoute)
->throw();
}
catch (\Exception $exception )
{
} catch (\Exception $exception) {
Log::error($exception);
}
}
@@ -35,6 +33,7 @@ class PDF
{
\Debugbar::disable();
$pdf = DomPDF::loadView($view, $data);
return $pdf->download($filename);
}
@@ -42,12 +41,14 @@ class PDF
{
$mpdf = new Mpdf();
$mpdf->WriteHTML($html);
return $mpdf->Output();
}
public static function convertURL($url)
{
$pdf = SnappyPdf::loadFile($url);
return $pdf->download('invoice.pdf');
}

View File

@@ -7,6 +7,7 @@ use Carbon\Carbon;
class Stat
{
public static $is_debug = false;
public static $force_output = true;
public static function getNewByPeriod($model, $start, $end)
@@ -45,6 +46,7 @@ class Stat
$var_option = $var;
}
$options = self::getOption($var_option);
return self::getStatsbyMultiOptions($var, $options);
}
@@ -53,6 +55,7 @@ class Stat
$count = self::getModel()
->whereBetween($var, $begin, $end)
->count();
return $count;
}
@@ -64,10 +67,9 @@ class Stat
->groupBy($var)
->get();
// var_Debug::message($data);
return ($data);
return $data;
}
public static function getStatsbyOptions($var, $var_option = '')
{
if (empty($var_option)) {
@@ -81,7 +83,7 @@ class Stat
$data[] = ['y' => $y, 'name' => $value];
}
// var_Debug::message($data);
return ($data);
return $data;
}
public static function getCountbyOption($var)
@@ -98,7 +100,8 @@ class Stat
$data[$key] = (int) $data[$key]->nb;
}
}
return ($data);
return $data;
}
public static function getStatsbyMultiOptions($var, $options)
@@ -107,7 +110,8 @@ class Stat
$nb = self::getCountbyBin($var, $key);
$data[] = ['y' => $nb, 'name' => $value];
}
return ($data);
return $data;
}
public static function getCountbyBin($var, $value)
@@ -116,27 +120,28 @@ class Stat
$count = self::getModel()
->where($var, '&', $bit)
->count();
return $count;
}
public static function getStatsbyPeriod($begin = '', $end = '', $period = 'days')
{
$end = Carbon::now();
$begin = Carbon::now()->subMonth(1);
switch ($period) {
case 'days':
$periods = DateRange::getPeriodsbyDay($begin, $end);
break;
case 'months':
$periods = DateRange::getPeriodsbyMonth($begin, $end);
break;
case 'weeks':
$periods = DateRange::getPeriodsbyWeek($begin, $end);
break;
default:
case 'days':
$periods = DateRange::getPeriodsbyDay($begin, $end);
break;
case 'months':
$periods = DateRange::getPeriodsbyMonth($begin, $end);
break;
case 'weeks':
$periods = DateRange::getPeriodsbyWeek($begin, $end);
break;
default:
}
return ($periods);
return $periods;
}
public static function serializeValues($tab)
@@ -154,7 +159,7 @@ class Stat
$tab = $collection->pluck($var)->toArray();
}
return implode(",", $tab);
return implode(',', $tab);
}
public static function avgByVar($tab, $var)

View File

@@ -3,13 +3,9 @@
namespace App\Repositories\Core;
use Illuminate\Support\Facades\Storage as Storage2;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use SoftCreatR\MimeDetector\MimeDetector;
use SoftCreatR\MimeDetector\MimeDetectorException;
class Storage
{
public static function checkDirOrCreate($dir)
@@ -30,18 +26,21 @@ class Storage
public static function createDir($dir)
{
Storage2::makeDirectory($dir);
return true;
}
public static function deleteDir($dir)
{
Storage2::deleteDirectory($dir);
return true;
}
public static function deleteFile($file)
{
Storage2::delete($file);
return true;
}
@@ -49,8 +48,8 @@ class Storage
{
$process = new Process(['srm', $file]);
$process->run();
if (!$process->isSuccessful()) {
if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
}
@@ -87,7 +86,8 @@ class Storage
public static function getFileType($file)
{
$file = self::getStoragePath() . $file;
$file = self::getStoragePath().$file;
return File::getFileType($file);
}

View File

@@ -7,6 +7,7 @@ class Tag
public static function getTagsByModel($model)
{
$tags = $model->tags;
return $tags ? $tags->pluck('id')->toArray() : null;
}
@@ -17,6 +18,7 @@ class Tag
return (int) $item;
}
)->toArray() : false;
return $tags ? $model->syncTags($tags, true) : false;
}
}

View File

@@ -7,6 +7,7 @@ class Trees
public static function getTree($model)
{
$tree = $model->orderBy('_lft', 'asc')->get()->toTree()->toArray();
return self::getChildren($tree[0]['children']);
}
@@ -23,6 +24,7 @@ class Trees
}
$tree[] = $leaf;
}
return $tree;
}
@@ -32,25 +34,26 @@ class Trees
$item_target = self::getNode($target_id);
switch ($type) {
case 'after':
// dump("$node_id After $target_id");
$item->afterNode($item_target);
break;
case 'inside':
// dump("$node_id inside $target_id");
$item_target->appendNode($item);
break;
case 'after':
// dump("$node_id After $target_id");
$item->afterNode($item_target);
break;
case 'inside':
// dump("$node_id inside $target_id");
$item_target->appendNode($item);
break;
}
$item->save();
return "1";
}
return '1';
}
public static function create($data, $model)
{
$parent = (isset($data['parent_id']) && $data['parent_id']) ? self::getNode($data['parent_id']) : self::getRoot();
$tree = $model->create(['name' => $data['name']]);
$tree->appendToNode($parent)->save();
return $tree;
}
@@ -58,6 +61,7 @@ class Trees
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
return $item->update(['name' => $data['name']]);
}

View File

@@ -2,7 +2,6 @@
namespace App\Repositories\Core;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image as Image;
@@ -14,6 +13,7 @@ class Upload
$data['filetype'] = $file->getClientOriginalExtension();
$data['filesize'] = $file->getSize();
$data['mime'] = $file->getMimeType();
return $data;
}
@@ -23,6 +23,7 @@ class Upload
$pos = strrpos($file, '/');
$uuid = substr($file, $pos + 1);
$uuid = pathinfo($uuid, PATHINFO_FILENAME);
return $uuid;
}
@@ -35,6 +36,7 @@ class Upload
// $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3');
// $path = $request->file('avatar')->storePublicly('avatars', 's3');
$request = Request();
return $request->has($var) ? basename($request->file($var)->store($path)) : false;
}
@@ -55,6 +57,7 @@ class Upload
{
$thumb = self::getThumbPath($file, $sub);
$filename = self::getPublicPath($file);
return Image::make($filename)->orientate()->widen($size)->save($thumb);
}
@@ -63,49 +66,52 @@ class Upload
return 'public/' . self::getFilename($file);
}
*/
public static function getPublicPath($file)
{
return storage_path('app/public/' . self::getFilename($file));
return storage_path('app/public/'.self::getFilename($file));
}
public static function getPrivatePath($file)
{
return storage_path('app/' . self::getFilename($file));
return storage_path('app/'.self::getFilename($file));
}
public static function getSrc($file)
{
return '/storage/' . self::getFilename($file);
return '/storage/'.self::getFilename($file);
}
public static function getThumbPath($file)
{
return storage_path('app/public/' . self::getThumbFilename($file));
return storage_path('app/public/'.self::getThumbFilename($file));
}
public static function getThumbSrc($file)
{
return '/storage/' . self::getThumbFilename($file);
return '/storage/'.self::getThumbFilename($file);
}
public static function getFilename($file)
{
$file = (is_array($file)) ? (object) $file : $file;
return $file->filepath . '/' . self::getName($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);
return $file->filepath.'/'.$sub.self::getName($file);
}
public static function getName($file)
{
$file = (is_array($file)) ? (object) $file : $file;
return $file->uuid . '.' . strtolower($file->filetype);
return $file->uuid.'.'.strtolower($file->filetype);
}
/**
@@ -116,9 +122,10 @@ class Upload
*/
public static function fix($path)
{
if (!self::isWindows()) {
if (! self::isWindows()) {
return $path;
}
return str_replace('/', '\\', $path);
}
@@ -127,6 +134,7 @@ class Upload
if (Storage::exists($dest)) {
self::delete($dest);
}
return Storage::move($source, $dest);
}
@@ -144,9 +152,9 @@ class Upload
{
return is_dir($path) || mkdir($path, $permissions, true);
}
public static function isWindows()
{
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
}

View File

@@ -7,12 +7,14 @@ 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;
}
@@ -33,6 +35,7 @@ class Basket
array_push($data, $value);
self::set($key, $data);
}
return count($data);
}
@@ -42,6 +45,7 @@ class Basket
if (($index = array_search($value, $data)) !== false) {
unset($data[$index]);
}
return self::set($key, $data);
}

View File

@@ -13,8 +13,7 @@ class NewUser extends Notification
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @param mixed $notifiable
* @return string[]
*/
public function via($notifiable)
@@ -25,8 +24,7 @@ class NewUser extends Notification
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
@@ -40,7 +38,7 @@ class NewUser extends Notification
->line(
__(
'notifications.newuser.intro', [
'name' => $currentUser->first_name.' '.$currentUser->last_name,
'name' => $currentUser->first_name.' '.$currentUser->last_name,
]
)
)
@@ -51,7 +49,7 @@ class NewUser extends Notification
->salutation(
__(
'notifications.salutation', [
'name' => $currentUser->first_name.' '.$currentUser->last_name,
'name' => $currentUser->first_name.' '.$currentUser->last_name,
]
)
)
@@ -61,8 +59,7 @@ class NewUser extends Notification
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)

View File

@@ -9,8 +9,7 @@ class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
/*

View File

@@ -2,9 +2,7 @@
namespace App\Repositories\Core\User;
use App\Repositories\Core\Auth\Users;
use Illuminate\Support\Facades\Auth;
use \Cart;
use Cart;
class ShopCart
{
@@ -20,6 +18,7 @@ class ShopCart
} else {
self::get()->add($item);
}
return [
'count' => self::count(),
'quantity' => self::getTotalQuantity(),
@@ -45,6 +44,7 @@ class ShopCart
public static function clear()
{
Cart::clear();
return self::get()->clear();
}

View File

@@ -2,10 +2,8 @@
namespace App\Repositories\Core\User;
use Darryldecode\Cart\CartCollection;
use App\Models\Core\CartStorage;
use App\Repositories\Core\Auth\Users;
use Darryldecode\Cart\CartCollection;
class ShopCartStorage
{
@@ -16,11 +14,12 @@ class ShopCartStorage
public function get($key)
{
if (!$this->has($key)) {
if (! $this->has($key)) {
return [];
}
return new CartCollection(CartStorage::find($key)->cart_data);
return new CartCollection(CartStorage::find($key)->cart_data);
}
public function put($key, $value)
@@ -31,7 +30,7 @@ class ShopCartStorage
} else {
CartStorage::create([
'id' => $key,
'cart_data' => $value
'cart_data' => $value,
]);
}
}

View File

@@ -2,10 +2,10 @@
namespace App\Repositories\Shop;
use App\Models\Shop\ArticleNature;
use App\Models\Shop\Article;
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;
class ArticleNatures
@@ -18,6 +18,7 @@ class ArticleNatures
public static function getProductType($id)
{
$type = self::get($id)->product_type ?? false;
return $type ? self::getProductTypes()[$type] : false;
}
@@ -40,6 +41,7 @@ class ArticleNatures
case Merchandise::class:
return 2;
}
return false;
}
@@ -61,6 +63,7 @@ class ArticleNatures
public static function getOptionsByProductTypeModel($model)
{
$type = self::getProductTypeByModel($model);
return self::getOptionsByProductType($type);
}
@@ -87,6 +90,7 @@ class ArticleNatures
public static function getNamesByIds($ids)
{
$names = ArticleNature::byIds($ids)->pluck('name')->toArray();
return array_map('strtolower', $names);
}
@@ -98,6 +102,7 @@ class ArticleNatures
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -111,6 +116,7 @@ class ArticleNatures
$id = $id ? $id : $data['id'];
$item = self::get($id);
$ret = $item->update($data);
return $item;
}

View File

@@ -2,17 +2,14 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Repositories\Core\Tag;
use App\Repositories\Core\Medias;
use App\Repositories\Core\Comments;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Models\Shop\Article;
use App\Models\Shop\Merchandise;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Repositories\Core\Comments;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
use Illuminate\Support\Str;
class Articles
{
@@ -25,6 +22,7 @@ class Articles
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -40,6 +38,7 @@ class Articles
'prices' => $offer->tariff->price_lists->first()->price_list_values->toArray(),
];
}
return $data ?? false;
}
@@ -56,6 +55,7 @@ class Articles
$data[strtolower($sibling->article_nature->name)] = $sibling->description;
}
}
return $data ?? false;
}
@@ -82,9 +82,10 @@ class Articles
{
$articles = Article::with(['article_nature'])->get();
foreach ($articles as $article) {
$data[$article->id] = ($article->article_nature->name ?? null) . ' - ' . $article->name;
$data[$article->id] = ($article->article_nature->name ?? null).' - '.$article->name;
}
asort($data, SORT_NATURAL);
return $data;
}
@@ -97,6 +98,7 @@ class Articles
{
$data = self::getArticle($id);
$data['offers'] = self::getOffersGroupedByNature($id, $sale_channel_id);
return $data;
}
@@ -113,6 +115,7 @@ class Articles
$data['categories'] = self::getCategoriesNameByArticle($article);
$data['tags'] = self::getFullTagsSlugByArticle($article);
$data['comments'] = Comments::getByModel($article);
return $data;
}
@@ -150,6 +153,7 @@ class Articles
($data['plus'] ?? null);
*/
$data['description'] = $article->description;
return $data;
}
@@ -166,6 +170,7 @@ class Articles
]),
];
}
return $data ?? [];
}
@@ -174,10 +179,10 @@ class Articles
$articles = self::getArticlesWithOffers($options);
foreach ($articles as $article) {
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
if (!count($price_lists)) {
if (! count($price_lists)) {
continue;
}
if (!is_array($data[$article->name] ?? false)) {
if (! is_array($data[$article->name] ?? false)) {
$data[$article->name] = self::getDataForSale($article);
}
$prices = $price_lists[0]['price_list_values'][0];
@@ -187,6 +192,7 @@ class Articles
if ($data ?? false) {
ksort($data);
}
return $data ?? false;
}
@@ -236,6 +242,7 @@ class Articles
'offers.tariff.price_lists.price_list_values',
'offers.variation.package',
])->get();
return $data;
}
@@ -249,6 +256,7 @@ class Articles
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('article_nature_id')->unique();
return array_values($data->toArray());
}
@@ -260,6 +268,7 @@ class Articles
$type = ArticleNatures::getProductTypeNameByClass($class);
$data[$type] = true;
}
return array_keys($data);
}
@@ -268,6 +277,7 @@ class Articles
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
$model = self::getModelByOptions($options);
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('product_type')->unique();
return $data->toArray();
}
@@ -294,6 +304,7 @@ class Articles
$model = $model->merchandise();
break;
}
return $model;
}
@@ -301,6 +312,7 @@ class Articles
{
$data['article'] = self::getArticleEdit($id);
self::getMeta($data);
return $data;
}
@@ -312,12 +324,14 @@ class Articles
$data['categories'] = self::getCategoriesByArticle($article);
$data['tags'] = self::getTagsByArticle($article);
$data['comments'] = Comments::getByModel($article);
return $data;
}
public static function getInherited($id)
{
$article = Article::with('product.tags.tag_group')->findOrFail($id);
return self::getInheritedByProduct($article->product_id, $article->product_type);
}
@@ -350,10 +364,11 @@ class Articles
$data[] = [
'name' => 'Marchandise',
'description' => $product->description,
'tags' => $product->tags->toArray()
'tags' => $product->tags->toArray(),
];
break;
}
return $data ?? false;
}
@@ -370,6 +385,7 @@ class Articles
$data['images'] = Merchandises::getImages($product_id);
break;
}
return $data ?? false;
}
@@ -398,6 +414,7 @@ class Articles
'App\Models\Botanic\Variety' => 'Variétés',
'App\Models\Shop\Merchandise' => 'Marchandise',
];
return $data;
}
@@ -414,6 +431,7 @@ class Articles
public static function getProductTypeByCategory($category_id)
{
$models = self::getProductTypesModelsByCategory($category_id);
return (($models[0] ?? false) == Merchandise::class) ? 'merchandise' : 'botanic';
}
@@ -470,10 +488,11 @@ class Articles
$data += $article->tags->toArray();
foreach ($data as $tag) {
if (!isset($tags[$tag['group']][$tag['name']])) {
if (! isset($tags[$tag['group']][$tag['name']])) {
$tags[$tag['group']][] = $tag['name'];
}
}
return $tags ?? null;
}
@@ -490,12 +509,14 @@ class Articles
public static function getFullImagesByArticleId($id)
{
$article = self::get($id);
return $article ? self::getFullImagesByArticle($article) : false;
}
public static function countFullImagesByArticleId($id)
{
$article = self::get($id);
return $article ? self::countFullImagesByArticle($article) : 0;
}
@@ -523,6 +544,7 @@ class Articles
$images = count($merchandise->images ?? []) ? $merchandise->images : $images;
break;
}
return $images;
}
@@ -548,6 +570,7 @@ class Articles
$image = $article->product->image ?? false;
break;
}
return $image;
}
@@ -555,26 +578,28 @@ class Articles
{
$images = $data['images'] ?? false;
unset($data['images']);
$categories = $data['categories'] ?? false;
unset($data['categories']);
$tags = $data['tags'] ?? false;
unset($data['tags']);
$prices = $data['prices'] ?? false;
unset($data['prices']);
$article = self::store($data);
self::storeImages($article, $images);
self::storeCategories($article, $categories);
self::storeTags($article, $tags);
return $article->id;
}
public static function store($data)
{
$data['visible'] = $data['visible'] ?? false;
return ($data['id'] ?? false) ? self::update($data) : self::create($data);
}
@@ -588,6 +613,7 @@ class Articles
$id = $id ? $id : $data['id'];
$article = self::get($id);
$ret = $article->update($data);
return $article;
}
@@ -598,7 +624,7 @@ class Articles
public static function storeCategories($article, $categories)
{
if (!$categories) {
if (! $categories) {
return false;
}
$categories = collect($categories)->transform(
@@ -606,6 +632,7 @@ class Articles
return (int) $item;
}
)->toArray();
return $article->syncCategories($categories, true);
}
@@ -632,6 +659,7 @@ class Articles
public static function getHash($id)
{
$name = self::get($id)->name ?? false;
return $name ? hash('crc32c', Str::slug($name)) : false;
}
}

View File

@@ -9,10 +9,11 @@ class Baskets
{
public static function addBasket($offer_id, $quantity = 1, $update = false)
{
if (ShopCart::has($offer_id) && !$quantity) {
if (ShopCart::has($offer_id) && ! $quantity) {
$ret = ShopCart::remove($offer_id);
}
$data = $quantity ? self::getBasketData($offer_id, $quantity) : false;
return $data ? ShopCart::add($data, $update) : false;
}
@@ -28,7 +29,7 @@ class Baskets
$prices = Offers::getPrice($item->id, $item->quantity, $sale_channel_id);
$detail[] = [
'offer_id' => (int) $item->id,
'name' => $offer->article->name . ' (' . $offer->variation->name . ')',
'name' => $offer->article->name.' ('.$offer->variation->name.')',
'quantity' => (int) $item->quantity,
'price' => (float) $prices->price,
'tax' => $prices->price_taxed - $prices->price,
@@ -48,6 +49,7 @@ class Baskets
'shipping' => $shipping,
'total_shipped' => $total_taxed + $shipping,
];
return $data ?? false;
}
@@ -68,7 +70,7 @@ class Baskets
'article.image',
'price_lists.price_list_values',
])->withPriceListsBySaleChannel($sale_channel_id)
->whereIn('id', ShopCart::keys())->get();
->whereIn('id', ShopCart::keys())->get();
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();
$article_nature = strtolower($offer->article->article_nature->name);
@@ -82,12 +84,14 @@ class Baskets
'latin' => $offer->article->product->specie->latin ?? false,
];
}
return $data ?? false;
}
public static function getBasketData($id, $quantity = 1)
{
$offer = Offers::get($id, ['article', 'variation']);
return [
'id' => $id,
'name' => self::getArticleName($offer),

View File

@@ -3,8 +3,8 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Category;
use App\Repositories\Core\Tag;
use App\Repositories\Core\Categories as CategoryTrees;
use App\Repositories\Core\Tag;
class Categories
{
@@ -13,6 +13,7 @@ class Categories
$category = Articles::get($id)->categories()->first();
$ancestors = self::getAncestorsByCategory($category->id);
$ancestors[] = $category->toArray();
return $ancestors;
}
@@ -21,6 +22,7 @@ class Categories
$category = self::get($id);
$ancestors = $category->getAncestors()->toArray();
unset($ancestors[0]);
return $ancestors;
}
@@ -46,6 +48,7 @@ class Categories
$data['name'] = $category->name;
$data['description'] = $category->description;
$data['tags'] = self::getTagsByCategory($category);
return $data;
}
@@ -81,16 +84,18 @@ class Categories
$tags = $data['tags'] ?? false;
unset($data['tags']);
$category = self::store($data);
self::storeImages($category, $images);
self::storeTags($category, $tags);
return $category;
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
return $id ? self::update($data, $id) : self::create($data);
}
@@ -116,13 +121,14 @@ class Categories
public static function getImages($id)
{
$category = self::get($id);
if (!$category) {
if (! $category) {
return false;
}
$category->getMedia();
foreach ($category->media as $key => $media) {
$category->media[$key]['url'] = $media->getUrl();
}
return $category->media;
}
@@ -131,7 +137,8 @@ class Categories
$category = self::get($id);
$category->getMedia();
$ret = $category->media[$index]->delete();
return "1";
return '1';
}
public static function moveTree($node_id, $target_id, $type)
@@ -149,6 +156,7 @@ class Categories
$id = $id ? (int) $id : $data['id'];
$category = self::get($id);
$ret = $category->update($data);
return $category;
}

View File

@@ -23,7 +23,7 @@ class CustomerAddresses
public static function add($user_id, $data)
{
$name = $data['company'] ? $data['company'] : $data['first_name'] . ' ' . $data['last_name'];
$name = $data['company'] ? $data['company'] : $data['first_name'].' '.$data['last_name'];
if ($data['use_for_delivery'] ?? false) {
return self::store([
'customer_id' => $user_id,
@@ -49,6 +49,7 @@ class CustomerAddresses
{
$id = $data['id'] ?? false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -62,6 +63,7 @@ class CustomerAddresses
$id = $id ? $id : $data['id'];
$delivery = self::get($id);
$delivery->update($data);
return $delivery;
}

View File

@@ -6,7 +6,7 @@ use Spatie\Stats\BaseStats;
class CustomerStats extends BaseStats
{
public function getName() : string
public function getName(): string
{
return 'customers';
}

View File

@@ -3,14 +3,12 @@
namespace App\Repositories\Shop;
use App\Datatables\Shop\CustomerOrdersDataTable;
use App\Models\Shop\Customer;
use App\Repositories\Core\File;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laravolt\Avatar\Avatar;
use App\Repositories\Core\File;
use App\Models\Shop\Customer;
class Customers
{
public static function count()
@@ -32,6 +30,7 @@ class Customers
'deliveries' => Deliveries::getAll('sale_channel')->toArray(),
'orders' => $orders_datatable->html(),
];
return $data;
}
@@ -39,16 +38,17 @@ class Customers
{
$customer = $id ? self::get($id) : self::getAuth();
$file = self::makeAvatarFilename($customer);
if (!File::checkFile($file)) {
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;
$name = $customer->first_name.' '.$customer->last_name;
$avatar = new Avatar();
$ret = $avatar->create($name)
->setBackground('#F2B90F')
@@ -58,6 +58,7 @@ class Customers
->setDimension(36)
->setFontSize(16)
->save($filename);
return $ret;
}
@@ -65,19 +66,21 @@ class Customers
{
$path = storage_path(self::getStorage());
if (File::checkDirOrCreate($path)) {
$filename = $path . self::getAvatarFilename($customer);
$filename = $path.self::getAvatarFilename($customer);
}
return $filename ?? false;
}
public static function getAvatarFilename($customer)
{
return 'user-' . $customer->uuid . '.png';
return 'user-'.$customer->uuid.'.png';
}
public static function getAddresses($id = false)
{
$customer = self::getWithAddresses($id);
return $customer ? $customer->addresses : false;
}
@@ -89,7 +92,8 @@ class Customers
public static function getName($id = false)
{
$user = $id ? self::get($id) : self::getAuth();
return $user ? $user->first_name . ' ' . $user->last_name : '';
return $user ? $user->first_name.' '.$user->last_name : '';
}
public static function getAuth()
@@ -110,6 +114,7 @@ class Customers
public static function get($id = false, $relations = false)
{
$id = $id ? $id : self::getId();
return $id ? ($relations ? Customer::with($relations)->findOrFail($id) : Customer::findOrFail($id)) : false;
}
@@ -118,6 +123,7 @@ class Customers
$customer = self::get($id, 'addresses');
$data = $customer->toArray();
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
return $data;
}
@@ -130,6 +136,7 @@ class Customers
$customer = self::store($data);
self::storeDeliveries($customer, $deliveries);
self::storeAddresses($customer, $addresses);
return $customer->id;
}
@@ -140,7 +147,7 @@ class Customers
public static function storeDeliveries($customer, $deliveries)
{
if (!$deliveries) {
if (! $deliveries) {
return false;
}
$deliveries = collect($deliveries)->transform(
@@ -148,6 +155,7 @@ class Customers
return (int) $item;
}
)->toArray();
return $customer->deliveries()->sync($deliveries);
}
@@ -176,6 +184,7 @@ class Customers
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
return $user;
}
@@ -184,6 +193,7 @@ class Customers
$id = $id ? $id : $data['id'];
$customer = self::get($id);
$customer->update($data);
return $customer;
}
@@ -195,13 +205,15 @@ class Customers
public static function getStorage($filename = false)
{
$path = '/app/public/Customers/';
return $filename ? $path . $filename : $path;
return $filename ? $path.$filename : $path;
}
public static function getPublic($filename = false)
{
$path = '/storage/Customers/';
return $filename ? $path . $filename : $path;
return $filename ? $path.$filename : $path;
}
public static function guard()

View File

@@ -2,11 +2,8 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Homepage;
class Dashboards
{
public static function getStats($start, $end)
{
return [

View File

@@ -14,6 +14,7 @@ class Deliveries
public static function getAll($relations = false)
{
$model = $relations ? Delivery::with($relations) : Delivery::query();
return $model->orderBy('name', 'asc')->get();
}
@@ -31,6 +32,7 @@ class Deliveries
{
$id = $data['id'] ?? false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -44,6 +46,7 @@ class Deliveries
$id = $id ? $id : $data['id'];
$delivery = self::get($id);
$delivery->update($data);
return $delivery;
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\DeliveryPackage;
class DeliveryPackages
{
public static function getOptions()
{
return DeliveryPackage::pluck('name', 'id');
}
public static function get($id)
{
return DeliveryPackage::find($id);
}
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return DeliveryPackage::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return DeliveryPackage::destroy($id);
}
}

View File

@@ -6,13 +6,49 @@ use App\Models\Shop\DeliveryTypeCalculation;
class DeliveryTypeCalculations
{
public static function getByDeliveryType($type_id)
public static function getByDeliveryType($typeId)
{
return DeliveryTypeCalculation::byDeliveryTpe($type_id)->get();
return DeliveryTypeCalculation::byDeliveryTpe($typeId)->get();
}
public static function getPrice($type_id, $weight)
public static function getPrice($typeId, $weight)
{
return DeliveryTypeCalculation::byDeliveryType($type_id)->byWeight($weight)->get();
return DeliveryTypeCalculation::byDeliveryType($typeId)->byWeight($weight)->get();
}
public static function getOptions()
{
return DeliveryTypeCalculation::pluck('name', 'id');
}
public static function get($id)
{
return DeliveryTypeCalculation::find($id);
}
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return DeliveryTypeCalculation::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return DeliveryTypeCalculation::destroy($id);
}
}

View File

@@ -10,4 +10,35 @@ class DeliveryTypes
{
return DeliveryType::pluck('name', 'id');
}
public static function get($id)
{
return DeliveryType::find($id);
}
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
return DeliveryType::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return DeliveryType::destroy($id);
}
}

View File

@@ -6,10 +6,10 @@ use App\Models\Shop\Homepage;
class Homepages
{
public static function getLast()
{
$model = Homepage::latest('id')->first();
return $model ? $model->text : '';
}
@@ -36,6 +36,7 @@ class Homepages
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -49,6 +50,7 @@ class Homepages
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,13 +2,10 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\InvoicePayment;
class InvoicePayments
{
public static function get($id, $relations = false)
{
return $relations ? InvoicePayment::with($relations)->findOrFail($id) : InvoicePayment::findOrFail($id);
@@ -29,6 +26,7 @@ class InvoicePayments
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -6,7 +6,7 @@ use Spatie\Stats\BaseStats;
class InvoiceStats extends BaseStats
{
public function getName() : string
public function getName(): string
{
return 'invoices';
}

View File

@@ -2,9 +2,9 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use Carbon\Carbon;
use App\Models\Shop\Invoice;
use Carbon\Carbon;
use Illuminate\Support\Str;
class Invoices
{
@@ -19,6 +19,7 @@ class Invoices
'order' => $order->toArray(),
'customer' => $customer->toArray(),
];
return view('Shop.Invoices.mail', $data)->render();
}
@@ -30,6 +31,7 @@ class Invoices
public static function saveInvoice($order_id, $data)
{
$data['order_id'] = $order_id;
return self::store($data);
}
@@ -46,6 +48,7 @@ class Invoices
public static function countByMonth()
{
$start = Carbon::now()->beginOfMonth();
return Invoice::where('created_at', '>', $start);
}
@@ -59,6 +62,7 @@ class Invoices
InvoiceStats::increase($data['total_taxed']);
$data['uuid'] = Str::uuid()->toString();
$data['ref'] = self::getNewRef();
return Invoice::create($data);
}
@@ -67,6 +71,7 @@ class Invoices
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
@@ -74,13 +79,15 @@ class Invoices
{
$invoice = self::get($id);
InvoiceStats::decrease($invoice->total_priced);
return Invoice::destroy($id);
}
public static function getNewRef()
{
$ref = date('ym') . '00000';
$ref = date('ym').'00000';
$last_ref = Invoice::orderBy('id', 'desc')->first();
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
}

View File

@@ -2,8 +2,8 @@
namespace App\Repositories\Shop;
use App\Repositories\Core\Tag;
use App\Models\Shop\Merchandise;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
class Merchandises
@@ -17,6 +17,7 @@ class Merchandises
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -37,7 +38,7 @@ class Merchandises
public static function getStatuses()
{
return ['Actif','Suspendu','Invisible','Obsolete'];
return ['Actif', 'Suspendu', 'Invisible', 'Obsolete'];
}
public static function getAll()
@@ -53,6 +54,7 @@ class Merchandises
public static function getFull($id)
{
$data = self::get($id)->toArray();
return $data;
}
@@ -65,6 +67,7 @@ class Merchandises
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item;
}
@@ -77,6 +80,7 @@ class Merchandises
$merchandise = self::store($data);
self::storeImages($merchandise, $images);
self::storeTags($merchandise, $tags);
return $merchandise;
}
@@ -95,6 +99,7 @@ class Merchandises
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -3,7 +3,6 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Offer;
use App\Repositories\Core\User\ShopCart;
class Offers
{
@@ -29,6 +28,7 @@ class Offers
])->find($id);
$images = Articles::getFullImagesByArticle($offer->article);
$offer->article->image = Articles::getPreviewSrc($images[0] ?? false);
return $offer;
}
@@ -36,6 +36,7 @@ class Offers
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($sale_channel_id, $quantity)->find($id);
return $offer->price_lists->first()->price_list_values->first();
}
@@ -57,6 +58,7 @@ class Offers
public static function getOffersBySaleChannelRaw($sale_channel_id = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
return Offer::active()->byStockAvailable()
->with([
'article_nature',
@@ -77,9 +79,10 @@ class Offers
public static function getThumbSrc(Offer $offer)
{
$image = $offer->article ? Articles::getFullImageByArticle($offer->article) : false;
return $image ? Articles::getThumbSrc($image) : false;
}
public static function getLast()
{
return Offer::with(['article.image'])->active()->orderByDesc('updated_at')->get();
@@ -92,6 +95,7 @@ class Offers
$offers1 = self::getByCategory($category_id)->toArray();
$offers2 = self::getByTags($tags)->toArray();
$data = array_merge($offers1, $offers2);
return $data;
}
@@ -130,6 +134,7 @@ class Offers
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -12,6 +12,7 @@ class OrderDetails
$item['order_id'] = $order_id;
$detail = self::store($item);
}
return true;
}
@@ -35,6 +36,7 @@ class OrderDetails
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -6,7 +6,7 @@ use Spatie\Stats\BaseStats;
class OrderStats extends BaseStats
{
public function getName() : string
public function getName(): string
{
return 'orders';
}

View File

@@ -2,15 +2,14 @@
namespace App\Repositories\Shop;
use Carbon\Carbon;
use App\Mail\Acheminement;
use App\Mail\ConfirmationCommande;
use App\Mail\Preparation;
use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Carbon\Carbon;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
class Orders
{
@@ -35,6 +34,7 @@ class Orders
unset($data['detail']);
unset($data['payment_type']);
unset($data['sale_channel_id']);
return ($order && $detail) ? Invoices::saveInvoice($order->id, $data) : false;
}
@@ -47,6 +47,7 @@ class Orders
{
$order = self::get($order_id, ['customer', 'address']);
$mail = new ConfirmationCommande($order);
return Mail::to($order->customer->email)->send($mail);
}
@@ -54,6 +55,7 @@ class Orders
{
$order = self::get($order_id, ['customer', 'address']);
$mail = new Preparation($order);
return Mail::to($order->customer->email)->send($mail);
}
@@ -61,6 +63,7 @@ class Orders
{
$order = self::get($order_id, ['customer', 'address']);
$mail = new Acheminement($order);
return Mail::to($order->customer->email)->send($mail);
}
@@ -73,6 +76,7 @@ class Orders
{
$start = Carbon::now()->subHours(24);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
}
@@ -80,12 +84,14 @@ class Orders
{
$start = Carbon::now()->subHours(48);
$end = Carbon::now();
return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
}
public static function countInPreparationMore48H()
{
$start = Carbon::now()->subHours(48);
return Order::preparation()->where('updated_at', '>', $start)->count();
}
@@ -120,6 +126,7 @@ class Orders
OrderStats::increase();
$data['uuid'] = Str::uuid()->toString();
$data['ref'] = self::getNewRef();
return Order::create($data);
}
@@ -128,6 +135,7 @@ class Orders
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
@@ -150,6 +158,7 @@ class Orders
public static function getStatusByName($name)
{
$data = array_flip(self::statuses());
return $data[$name] ?? '';
}
@@ -170,8 +179,9 @@ class Orders
public static function getNewRef()
{
$ref = date('ym') . '00000';
$ref = date('ym').'00000';
$last_ref = Order::orderBy('id', 'desc')->first();
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
}

View File

@@ -6,7 +6,6 @@ use App\Models\Shop\Package;
class Packages
{
public static function getOptions()
{
return Package::orderBy('value', 'asc')->pluck('value', 'id')->toArray();
@@ -31,6 +30,7 @@ class Packages
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -44,6 +44,7 @@ class Packages
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -3,14 +3,12 @@
namespace App\Repositories\Shop;
use App;
use Devpark\PayboxGateway\Requests\AuthorizationWithCapture;
use Devpark\PayboxGateway\Responses\Verify;
use Devpark\PayboxGateway\Requests\Capture;
use Devpark\PayboxGateway\Responses\Verify;
class Paybox
{
public static function makeAuthorizationRequest($amount, $customer_email = 'test@example.com')
{
$authorizationRequest = App::make(AuthorizationWithCapture::class);
@@ -26,11 +24,10 @@ class Paybox
try {
$success = $payboxVerify->isSuccess($invoice->total_shipped);
if ($success) {
// process order here after making sure it was real payment
// process order here after making sure it was real payment
}
echo "OK";
}
catch (InvalidSignature $e) {
echo 'OK';
} catch (InvalidSignature $e) {
Log::alert('Invalid payment signature detected');
}
}
@@ -44,10 +41,9 @@ class Paybox
->setPayboxTransactionNumber($payment->transaction_number)
->setDayRequestNumber(2)
->send();
if ($response->isSuccess()) {
// process order here
// process order here
}
}
}

View File

@@ -2,20 +2,16 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use App\Models\Shop\PriceListValue;
use App\Models\Shop\PriceList;
use App\Models\Shop\Offer;
use App\Models\Shop\PriceListValue;
class PriceListValues
{
public static function getPriceByOffer($offer_id, $quantity = 1, $sale_channel_id = false)
{
$prices = self::getPricesByOffer($offer_id, $sale_channel_id);
$price = $prices ? $prices->where('quantity', '<=', $quantity)->sortByDesc('quantity')->first() : false;
return $price ? $price->price_taxed : false;
}
@@ -26,6 +22,7 @@ class PriceListValues
$sale_channel_id ? $query->bySaleChannel($sale_channel_id) : $query;
},
])->find($offer_id)->price_lists->first();
return $price_list ? $price_list->price_list_values : false;
}
@@ -58,6 +55,7 @@ class PriceListValues
{
$id = isset($data['id']) ? $data['id'] : false;
$price = $id ? self::update($data) : self::create($data);
return $price;
}
@@ -71,6 +69,7 @@ class PriceListValues
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,15 +2,10 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use App\Models\Shop\PriceList;
class PriceLists
{
public static function getByOfferAndSaleChannel($offer_id, $sale_channel_id)
{
return PriceList::bySaleChannel($sale_channel_id)->byOffer($offer_id)->get();
@@ -28,7 +23,7 @@ class PriceLists
public static function getStatuses()
{
return ['Actif','Suspendu','Invisible','Obsolete'];
return ['Actif', 'Suspendu', 'Invisible', 'Obsolete'];
}
public static function getByTariff($id)
@@ -53,6 +48,7 @@ class PriceLists
if ($n <= 3) {
$price_list['price_list_values'] += array_fill($n, 3 - $n, '');
}
return $price_list;
}
@@ -78,6 +74,7 @@ class PriceLists
unset($data['price_list_values']);
$price_list = $id ? self::update($data) : self::create($data);
PriceListValues::storePrices($price_list->id, $price_list_values);
return $price_list;
}
@@ -91,6 +88,7 @@ class PriceLists
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,14 +2,8 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Yajra\DataTables\DataTables;
use App\Models\Shop\Article;
use App\Models\Shop\Price;
use Yajra\DataTables\DataTables;
class Prices
{
@@ -17,12 +11,14 @@ class Prices
{
$data['prices'] = Price::byArticle($id)->notGeneric()->get()->toArray();
$data['generics'] = Price::byArticle($id)->generic()->with(['generic.prices', 'generic.category'])->get()->toArray();
return $data;
}
public static function getDatatable()
{
$model = Price::orderBy('name');
return Datatables::of($model)->make(true);
}
@@ -40,6 +36,7 @@ class Prices
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -53,6 +50,7 @@ class Prices
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,8 +2,8 @@
namespace App\Repositories\Shop;
use App\Repositories\Core\Tag;
use App\Models\Shop\Producer;
use App\Repositories\Core\Tag;
use App\Traits\Repository\Imageable;
class Producers
@@ -17,6 +17,7 @@ class Producers
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -50,6 +51,7 @@ class Producers
$producer = self::get($id);
$data = $producer->toArray();
$data['tags'] = self::getTagsByProducer($producer);
return $data;
}
@@ -67,6 +69,7 @@ class Producers
$producer = self::store($data);
self::storeImages($producer, $images);
self::storeTags($producer, $tags);
return $producer;
}
@@ -85,6 +88,7 @@ class Producers
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -9,6 +9,7 @@ class SaleChannels
public static function getDefaultID()
{
$default = self::getDefault();
return $default ? self::getDefault()->id : false;
}
@@ -41,6 +42,7 @@ class SaleChannels
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -54,6 +56,7 @@ class SaleChannels
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,8 +2,6 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Article;
class Searches
{
public static function getResults($options)

View File

@@ -2,14 +2,12 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\TagGroup;
use App\Models\Shop\Tag;
use App\Models\Shop\TagGroup;
use Illuminate\Support\Str;
class TagGroups
{
public static function getOptions()
{
return TagGroup::get()->SortBy('name')->pluck('name', 'id')->toArray();
@@ -21,7 +19,7 @@ class TagGroups
$tag_groups = TagGroup::pluck('name', 'id')->toArray();
foreach ($tags as $tag) {
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
if (!$tag['articles_count']) {
if (! $tag['articles_count']) {
continue;
}
$data[$tag['tag_group_id']]['tags'][] = [
@@ -30,6 +28,7 @@ class TagGroups
'count' => $tag['articles_count'],
];
}
return $data;
}
@@ -40,13 +39,14 @@ class TagGroups
foreach ($items as $group) {
$group_tags = [];
foreach ($group->tags as $tag) {
$group_tags[$tag->id] = $group->name . ' - ' . $tag->name;
$group_tags[$tag->id] = $group->name.' - '.$tag->name;
}
$tags[] = [
'label' => $group->name,
'options' => $group_tags,
'label' => $group->name,
'options' => $group_tags,
];
}
return $tags;
}
@@ -73,12 +73,14 @@ class TagGroups
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
$data['slug'] = Str::slug($data['name']);
return TagGroup::create($data);
}
@@ -91,6 +93,7 @@ class TagGroups
}
$model->update($data);
Tags::updateGroup($id, $data['name']);
return $model;
}

View File

@@ -2,15 +2,14 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\Tag;
use Illuminate\Support\Str;
class Tags
{
public static function getTagHtml($tag)
{
return '<span class="btn btn-xs btn-secondary pb-2 mr-2 mb-2">' . self::getFullnameByTag($tag) . '</span>';
return '<span class="btn btn-xs btn-secondary pb-2 mr-2 mb-2">'.self::getFullnameByTag($tag).'</span>';
}
public static function getOptions()
@@ -32,8 +31,9 @@ class Tags
{
$tags = Tag::with('tag_group')->get()->toArray();
foreach ($tags as $tag) {
$data[$tag['id']] = $tag['tag_group']['name'] . '-' . $tag['name'];
$data[$tag['id']] = $tag['tag_group']['name'].'-'.$tag['name'];
}
return $data;
}
@@ -45,12 +45,13 @@ class Tags
public static function getFullname($id)
{
$tag = Tag::with('tag_group')->find($id);
return $tag ? self::getFullnameByTag($tag) : false;
}
public static function getFullnameByTag($tag)
{
return $tag->tag_group->name . '-' . $tag->name;
return $tag->tag_group->name.'-'.$tag->name;
}
public static function get($id)
@@ -61,6 +62,7 @@ class Tags
public static function store($data)
{
$item = ($data['id'] ?? false) ? self::update($data) : self::create($data);
return $item->id;
}
@@ -70,10 +72,10 @@ class Tags
$data['group'] = TagGroups::getName($data['tag_group_id']);
$data['sort_order'] = self::getNewOrder($data['tag_group_id']);
$tag = Tag::create($data);
return $tag;
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
@@ -81,6 +83,7 @@ class Tags
$data['slug'] = self::buildSlug($data);
$data['group'] = TagGroups::getName($data['tag_group_id']);
$tag->update($data);
return $tag;
}
@@ -102,6 +105,7 @@ class Tags
public static function getNewOrder($tag_group_id)
{
$tag = Tag::byGroup($tag_group_id)->orderBy('sort_order', 'desc')->first();
return $tag ? (int) $tag->sort_order + 1 : 1;
}
}

View File

@@ -25,6 +25,7 @@ class TariffUnities
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -38,6 +39,7 @@ class TariffUnities
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -13,6 +13,7 @@ class Tariffs
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -55,6 +56,7 @@ class Tariffs
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -68,6 +70,7 @@ class Tariffs
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,17 +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\Models\Shop\Tax;
class Taxes
{
public static function getOptions()
{
return Tax::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
@@ -32,6 +25,7 @@ class Taxes
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
@@ -45,6 +39,7 @@ class Taxes
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,8 +2,6 @@
namespace App\Repositories\Shop\Traits;
use App\Repositories\Shop\Customers;
use App\Repositories\Core\DateTime;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;

View File

@@ -35,6 +35,7 @@ class Unities
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
@@ -48,6 +49,7 @@ class Unities
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}

View File

@@ -2,9 +2,8 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Str;
use App\Models\Shop\Variation;
use Illuminate\Support\Str;
class Variations
{
@@ -15,6 +14,7 @@ class Variations
foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name];
}
return $export;
}
@@ -25,6 +25,7 @@ class Variations
$data[$variation->id] = self::getName($variation);
}
natsort($data);
return $data;
}
@@ -35,12 +36,12 @@ class Variations
public static function getName($variation)
{
return $variation->package->value . ' ' . $variation->quantity . ' ' . ($variation->unity->value ?? null) . ' ' . Str::limit(strip_tags($variation->description), 15, ' (...)');
return $variation->package->value.' '.$variation->quantity.' '.($variation->unity->value ?? null).' '.Str::limit(strip_tags($variation->description), 15, ' (...)');
}
public static function buildName($data)
{
return Packages::getName($data['package_id']) . ' ' . $data['quantity'] . ' ' . Unities::getName($data['unity_id']);
return Packages::getName($data['package_id']).' '.$data['quantity'].' '.Unities::getName($data['unity_id']);
}
public static function getAll()
@@ -62,12 +63,14 @@ class Variations
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data) : self::create($data);
return $item->id;
}
public static function create($data)
{
$data['name'] = self::buildName($data);
return Variation::create($data);
}
@@ -77,6 +80,7 @@ class Variations
$variation = self::get($id);
$data['name'] = self::buildName($data);
$variation->update($data);
return $variation;
}

View File

@@ -12,6 +12,7 @@ class Users extends parentUsers
$data = parent::getInfo($id);
$sale_channel_default = SaleChannels::getDefault();
$data['sale_channel'] = $sale_channel_default ? $sale_channel_default->toArray() : false;
return $data;
}
}