Add new version in repository
This commit is contained in:
@@ -7,61 +7,61 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Models\Botanic\Family;
|
||||
use App\Exports\Botanic\FamiliesExport;
|
||||
|
||||
class Families
|
||||
{
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Family::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Family::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
public static function getOptions()
|
||||
{
|
||||
return Family::get()->SortBy('name')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Family::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Family::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Family::orderBy('name','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Family::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Family::findOrFail($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Family::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Family::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 update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Family::destroy($id);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
{
|
||||
return Excel::download(new FamiliesExport, 'families.xlsx');
|
||||
}
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Family::destroy($id);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
{
|
||||
return Excel::download(new FamiliesExport, 'families.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,60 +7,59 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Models\Botanic\Genre;
|
||||
use App\Exports\Botanic\GenresExport;
|
||||
|
||||
class Genres
|
||||
{
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Genre::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Genre::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
public static function getOptions()
|
||||
{
|
||||
return Genre::get()->SortBy('name')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Genre::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Genre::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Genre::orderBy('name','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Genre::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Genre::find($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Genre::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Genre::create($data);
|
||||
}
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Genre::destroy($id);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Genre::destroy($id);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
{
|
||||
return Excel::download(new GenresExport, 'genres.xlsx');
|
||||
}
|
||||
public static function exportExcel()
|
||||
{
|
||||
return Excel::download(new GenresExport, 'genres.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,13 @@ use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
use App\Models\Botanic\Specie;
|
||||
use App\Exports\Botanic\SpeciesExport;
|
||||
|
||||
class Species
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Specie::orderBy('name');
|
||||
@@ -23,23 +22,33 @@ class Species
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Specie::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
return Specie::get()->SortBy('name')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Specie::orderBy('name','asc')->get();
|
||||
return Specie::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getDescription($id)
|
||||
{
|
||||
return self::get($id)->description;
|
||||
}
|
||||
|
||||
public static function getTags($id)
|
||||
{
|
||||
return self::get($id)->tags->toArray();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Specie::find($id);
|
||||
return Specie::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
@@ -50,7 +59,7 @@ class Species
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$id = $id ? $id : $data['id'];
|
||||
$model = self::get($id);
|
||||
$ret = $model->update($data);
|
||||
return $model;
|
||||
|
||||
@@ -13,106 +13,114 @@ use App\Exports\Botanic\VarietiesExport;
|
||||
|
||||
class Varieties
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Variety::orderBy('name')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Variety::orderBy('name')->get()->pluck('name','id')->toArray();
|
||||
}
|
||||
public static function getOptionsWithSpecie()
|
||||
{
|
||||
$varieties = Variety::with('specie')->get();
|
||||
$data = [];
|
||||
foreach ($varieties as $variety) {
|
||||
$data[$variety->id] = (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name;
|
||||
}
|
||||
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getOptionsWithSpecie()
|
||||
{
|
||||
$varieties = Variety::with('specie')->get();
|
||||
$data = [];
|
||||
foreach ($varieties as $variety) {
|
||||
$data[$variety->id] = (isset($variety->specie->name) ? $variety->specie->name . ' ' : '') . $variety->name;
|
||||
}
|
||||
asort($data, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
return $data;
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Variety::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Variety::orderBy('name','asc')->get();
|
||||
}
|
||||
public static function getDescription($id)
|
||||
{
|
||||
return self::get($id)->description;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variety::findOrFail($id);
|
||||
}
|
||||
public static function getTags($id)
|
||||
{
|
||||
return self::get($id)->tags;
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$data = $variety->toArray();
|
||||
$data['tags'] = self::getTagsByVariety($variety);
|
||||
return $data;
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Variety::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getTagsByVariety($variety)
|
||||
{
|
||||
return Tag::getTagsByModel($variety);
|
||||
}
|
||||
public static function getFull($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$data = $variety->toArray();
|
||||
$data['tags'] = self::getTagsByVariety($variety);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getTagsByVariety($variety)
|
||||
{
|
||||
return Tag::getTagsByModel($variety);
|
||||
}
|
||||
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
unset($data['images']);
|
||||
unset($data['tags']);
|
||||
$variety = self::store($data);
|
||||
self::storeImages($variety, $images);
|
||||
self::storeTags($variety, $tags);
|
||||
return $variety;
|
||||
}
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
unset($data['images']);
|
||||
unset($data['tags']);
|
||||
$variety = self::store($data);
|
||||
self::storeImages($variety, $images);
|
||||
self::storeTags($variety, $tags);
|
||||
return $variety;
|
||||
}
|
||||
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
return isset($data['id']) ? self::update($data) : self::create($data);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
return isset($data['id']) ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Variety::create($data);
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Variety::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$variety = self::get($id);
|
||||
$ret = $variety->update($data);
|
||||
return $variety;
|
||||
}
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$variety = self::get($id);
|
||||
$ret = $variety->update($data);
|
||||
return $variety;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Variety::destroy($id);
|
||||
}
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Variety::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeTags($variety, $tags)
|
||||
{
|
||||
return Tag::storeTags($variety, $tags);
|
||||
}
|
||||
public static function storeTags($variety, $tags)
|
||||
{
|
||||
return Tag::storeTags($variety, $tags);
|
||||
}
|
||||
|
||||
public static function storeImages($variety, $files)
|
||||
{
|
||||
return Media::storeImages($variety, $files);
|
||||
}
|
||||
public static function storeImages($variety, $files)
|
||||
{
|
||||
return Media::storeImages($variety, $files);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
public static function getImages($id)
|
||||
{
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
{
|
||||
return Excel::download(new VarietiesExport, 'varieties.xlsx');
|
||||
}
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
|
||||
public static function exportExcel()
|
||||
{
|
||||
return Excel::download(new VarietiesExport, 'varieties.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,67 +2,23 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Session;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Repositories\Core\Cache;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
|
||||
class Config
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
$data = SuiteParameter::init();
|
||||
$data += Client::init();
|
||||
$data += Language::init();
|
||||
return $data;
|
||||
$data['user'] = self::getUser();
|
||||
return ['init' => $data];
|
||||
}
|
||||
|
||||
public static function initHeader($options = false, $appOptions = false, $clientOptions = false, $adminOptions = false)
|
||||
public static function getUser()
|
||||
{
|
||||
|
||||
$partner_path = Partners::getPublicPath();
|
||||
|
||||
// $css_client = Clients::getPublicPath('css/client.css');
|
||||
$css_client = $partner_path . '/css/client.css';
|
||||
|
||||
if (!$clientOptions) {
|
||||
$clientOptions = ['css' => [$css_client]];
|
||||
}
|
||||
|
||||
$layout = new Layout();
|
||||
$data = $layout->init($options, $appOptions, $clientOptions, $adminOptions);
|
||||
|
||||
if (Users::getUser()) {
|
||||
$data['user'] = Users::getInfo();
|
||||
$data['user']['lang'] = Session::get('locale');
|
||||
$data = Users::getInfo();
|
||||
} else {
|
||||
Session::put('locale', 'fr');
|
||||
$data = false;
|
||||
}
|
||||
|
||||
if (Clients::isClient()) {
|
||||
$data['isClient'] = true;
|
||||
$data['client'] = Clients::getInfo();
|
||||
$data['apps'] = Clients::getApplications();
|
||||
} else {
|
||||
$data['isClient'] = false;
|
||||
$data['client']['publicPath'] = $partner_path;
|
||||
$data['apps'] = Applications::getVisibles();
|
||||
}
|
||||
$data['client']['partner']['publicPath'] = $partner_path;
|
||||
|
||||
// $layout->publish('tenant_path', $data['client']['publicPath']);
|
||||
$data['global']['tenant_path'] = $data['client']['publicPath'];
|
||||
$data['global']['roles'] = Users::getRoles();
|
||||
$data['global']['permissions'] = Users::getPermissions();
|
||||
$data['app'] = Applications::getCurrent();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getCacheVersions()
|
||||
{
|
||||
$data = Cache::getFilesVersion('assets/apps/ContractDrive/js', 'js');
|
||||
// $data += Cache::getFilesVersion('assets/apps/ContractDrive/css','css');
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
91
app/Repositories/Core/App/ApplicationClients.php
Normal file
91
app/Repositories/Core/App/ApplicationClients.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\App;
|
||||
|
||||
use App\Models\Core\App\ApplicationClient;
|
||||
use App\Repositories\Clients;
|
||||
|
||||
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();
|
||||
|
||||
if (is_array($applications_existing)) {
|
||||
$applications_new = array_diff($applications_list, $applications_existing);
|
||||
$applications_to_delete = array_diff($applications_existing, $applications_list);
|
||||
} else {
|
||||
$applications_new = $applications_list;
|
||||
$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;
|
||||
|
||||
$data['nb'] = self::countByClient($client_id);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function countByClient($id)
|
||||
{
|
||||
return ApplicationClient::byClient($id)->count();
|
||||
}
|
||||
|
||||
public static function associateApplications($client_id, $applications)
|
||||
{
|
||||
$client_name = Clients::getName($client_id);
|
||||
foreach ($applications as $key => $application_id) {
|
||||
$application = Applications::get($application_id);
|
||||
if ($application) {
|
||||
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 ]);
|
||||
}
|
||||
|
||||
public static function dissociateApplications($client_id, $applications)
|
||||
{
|
||||
$client_name = \App\Repositories\Clients::getName($client_id);
|
||||
foreach ($applications as $key => $application_id) {
|
||||
self::dissociateApplication($client_id, $application_id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function dissociateApplication($client_id, $application_id)
|
||||
{
|
||||
return ApplicationClient::byClient($client_id)->byApplication($application_id)->delete();
|
||||
}
|
||||
|
||||
public static function getByClient($id)
|
||||
{
|
||||
return ApplicationClient::byClient($id)->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getByApplication($id)
|
||||
{
|
||||
return ApplicationClient::byApplication($id)->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getClientsByApplication($id)
|
||||
{
|
||||
return ApplicationClient::byApplication($id)->get()->pluck('client_id')->toArray();
|
||||
}
|
||||
|
||||
public static function getApplicationsByClient($id)
|
||||
{
|
||||
return ApplicationClient::byClient($id)->get()->pluck('application_id')->toArray();
|
||||
}
|
||||
|
||||
public static function isActiveByName($name)
|
||||
{
|
||||
return (!Clients::isClient()) ? true : ApplicationClient::bySlug($name)->byClient(Clients::getId())->first()->active ?? false;
|
||||
}
|
||||
}
|
||||
56
app/Repositories/Core/App/ApplicationModules.php
Normal file
56
app/Repositories/Core/App/ApplicationModules.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\App;
|
||||
|
||||
use App\Models\Core\App\ApplicationModule;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class ApplicationModules
|
||||
{
|
||||
public static function select_all()
|
||||
{
|
||||
return ApplicationModule::all()->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return ApplicationModule::pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return self::get($id)->toArray();
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ApplicationModule::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ApplicationModule::destroy($id);
|
||||
}
|
||||
|
||||
public static function getName($id)
|
||||
{
|
||||
return self::get($id)->name;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ApplicationModule::findOrFail($id);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
namespace App\Repositories\Core\App;
|
||||
|
||||
use App\Models\Core\App\ApplicationPage;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class ApplicationPages
|
||||
{
|
||||
public static function getBySlug($application_id, $slug)
|
||||
|
||||
@@ -4,17 +4,57 @@ namespace App\Repositories\Core\App;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
use App\Models\Application;
|
||||
|
||||
use App\Repositories\ApplicationPages;
|
||||
use App\Models\Core\App\Application;
|
||||
use App\Repositories\Core\App\ApplicationPages;
|
||||
use App\Repositories\Languages;
|
||||
|
||||
class Applications
|
||||
{
|
||||
public static function select_all()
|
||||
{
|
||||
return Application::all()->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Application::pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
return self::get($id)->toArray();
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Application::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Application::destroy($id);
|
||||
}
|
||||
|
||||
public static function getName($id)
|
||||
{
|
||||
return self::get($id)->name;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Application::findOrFail($id)->toArray();
|
||||
return Application::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getCurrent()
|
||||
|
||||
@@ -37,16 +37,24 @@ class NewUser extends Notification
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
|
||||
->line(__('notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->line(
|
||||
__(
|
||||
'notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]
|
||||
)
|
||||
)
|
||||
->action(
|
||||
__('notifications.newuser.button'),
|
||||
route('users.firstlogin', $notifiable->remember_token)
|
||||
)
|
||||
->salutation(__('notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->salutation(
|
||||
__(
|
||||
'notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]
|
||||
)
|
||||
)
|
||||
->line(__('notifications.newuser.outro'));
|
||||
}
|
||||
|
||||
|
||||
20
app/Repositories/Core/Auth/PasswordSecurities.php
Normal file
20
app/Repositories/Core/Auth/PasswordSecurities.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Core\Auth\PasswordSecurity;
|
||||
|
||||
class PasswordSecurities
|
||||
{
|
||||
public static function create($user_id, $delay = 90)
|
||||
{
|
||||
return PasswordSecurity::create(
|
||||
[
|
||||
'user_id' => $user_id,
|
||||
'password_expiry_days' => $delay,
|
||||
'password_updated_at' => Carbon::now(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
36
app/Repositories/Core/Auth/Passwords.php
Normal file
36
app/Repositories/Core/Auth/Passwords.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
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()
|
||||
{
|
||||
$validator = new \Password\Validator(new \Password\StringHelper);
|
||||
$validator->setMinLength(5);
|
||||
$validator->setMinLowerCaseLetters(2);
|
||||
$validator->setMinUpperCaseLetters(1);
|
||||
$validator->setMinNumbers(1);
|
||||
$validator->setMinSymbols(3);
|
||||
|
||||
if ($validator->isValid($password)) {
|
||||
printf('password %s is valid' . PHP_EOL, $password);
|
||||
} else {
|
||||
printf('password %s is invalid' . PHP_EOL, $password);
|
||||
var_dump($validator->getErrors());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -48,7 +47,7 @@ class Permissions
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Permission::find($id);
|
||||
return Permission::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
@@ -70,12 +69,13 @@ class Permissions
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Permission::create($data);
|
||||
$permission = Permission::create($data);
|
||||
return $permission;
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Permission::find($data['id'])->update($data);
|
||||
return self::get($data['id'])->update($data);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
|
||||
@@ -13,7 +13,7 @@ class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
/*
|
||||
/*
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
@@ -27,5 +27,5 @@ class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
)
|
||||
->line(__('notifications.resetpassword.outro'));
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -14,23 +14,23 @@ class Roles
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function store($input)
|
||||
public static function getListByRights()
|
||||
{
|
||||
if (isset($input['id']) && $input['id']) {
|
||||
return self::update($input);
|
||||
} else {
|
||||
return self::insert($input);
|
||||
}
|
||||
$data = (!Auth::user()->hasRole('admin')) ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
|
||||
return $data->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
// ajoute une forme juridique
|
||||
public static function insert($input)
|
||||
public static function store($input)
|
||||
{
|
||||
$permissions = array_keys($input['permissions']);
|
||||
$name = $input['name'];
|
||||
$translated = $input['translated'];
|
||||
self::setTranslation($name, $translated);
|
||||
$role = Role::create(['name' => $name, 'display_name' => $name, 'translated' => $translated, 'description' => '', 'active' => true]);
|
||||
return (isset($input['id']) && $input['id']) ? self::update($input) : self::create($input);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$permissions = array_keys($data['permissions']);
|
||||
unset($data['permissions']);
|
||||
$data['active'] = true;
|
||||
$role = Role::create($data);
|
||||
$role->attachPermissions($permissions);
|
||||
return $role;
|
||||
}
|
||||
@@ -40,11 +40,8 @@ class Roles
|
||||
{
|
||||
$id = ($id) ? $id : $input['id'];
|
||||
$permissions = array_keys($input['permissions']);
|
||||
$name = $input['name'];
|
||||
$translated = $input['translated'];
|
||||
self::setTranslation($name, $translated);
|
||||
$role = Role::find($id);
|
||||
$role->update(['name' => $name, 'translated' => $translated]);
|
||||
$role = self::get($id);
|
||||
$role->update(['name' => $input['name']]);
|
||||
$role->syncPermissions($permissions);
|
||||
return $role;
|
||||
}
|
||||
@@ -52,8 +49,6 @@ class Roles
|
||||
// supprime une forme juridique
|
||||
public static function delete($id)
|
||||
{
|
||||
$old = self::select_by_id($id);
|
||||
self::deleteTranslation($old->translated);
|
||||
return Role::destroy($id);
|
||||
}
|
||||
|
||||
@@ -69,21 +64,10 @@ class Roles
|
||||
return Role::count();
|
||||
}
|
||||
|
||||
// récupère toutes les infos sur les formes juridiques
|
||||
public static function select_all()
|
||||
{
|
||||
return Role::all()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Role::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getWithPermissions($id)
|
||||
{
|
||||
$role = Role::find($id)->toArray();
|
||||
$role['permissions'] = Role::find($id)->permissions->pluck('id')->toArray();
|
||||
$role = self::get($id)->toArray();
|
||||
$role['permissions'] = self::get($id)->permissions->pluck('id')->toArray();
|
||||
return $role;
|
||||
}
|
||||
|
||||
@@ -99,7 +83,7 @@ class Roles
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Role::find($id);
|
||||
return Role::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
@@ -126,22 +110,6 @@ class Roles
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Role::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function setTranslation($name, $translated)
|
||||
{
|
||||
$lang = Translate::getLang();
|
||||
$appli = 1; // ContractDrive
|
||||
$client = 1; // Client
|
||||
Translations::setTranslation($name, $translated, $lang, $appli, $client);
|
||||
}
|
||||
|
||||
public static function deleteTranslation($translated)
|
||||
{
|
||||
$lang = Translate::getLang();
|
||||
$appli = 1; // ContractDrive
|
||||
$client = 1; // Client
|
||||
Translations::deleteTranslation($translated, $lang, $appli, $client);
|
||||
return Role::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
namespace App\Repositories\Auth;
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\Datatables\Datatables;
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Core\Auth\Team;
|
||||
use App\Models\Core\Auth\TeamUser;
|
||||
|
||||
use App\Repositories\Core\User\Users;
|
||||
use App\Repositories\Users;
|
||||
|
||||
class Teams
|
||||
{
|
||||
@@ -38,7 +39,32 @@ class Teams
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Team::get()->pluck('name', 'id');
|
||||
return Team::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getInfo($id)
|
||||
{
|
||||
return Team::find($id);
|
||||
}
|
||||
|
||||
public static function select_all()
|
||||
{
|
||||
return self::getAll()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Team::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Team::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Team::where('name', $name)->first();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
@@ -66,15 +92,31 @@ class Teams
|
||||
}
|
||||
}
|
||||
|
||||
// ajoute une équipe/service/direction
|
||||
public static function store($data)
|
||||
{
|
||||
if (isset($data['id']) && $data['id']) {
|
||||
return self::update($data);
|
||||
}
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Team::create($data);
|
||||
}
|
||||
|
||||
// met à jour les informations d'une équipe/service/direction
|
||||
public static function update($data)
|
||||
{
|
||||
return Team::find($data['id'])->update($data);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Team::count();
|
||||
}
|
||||
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return Team::find($id)->update(['active' => $active]);
|
||||
}
|
||||
}
|
||||
|
||||
158
app/Repositories/Core/Auth/UserClients.php
Normal file
158
app/Repositories/Core/Auth/UserClients.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Hyn\Tenancy\Environment;
|
||||
use Hyn\Tenancy\Database\Connection;
|
||||
use App\Models\Admin\Website;
|
||||
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
|
||||
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Models\Core\Auth\User;
|
||||
|
||||
use App\Repositories\Clients;
|
||||
|
||||
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();
|
||||
|
||||
if (is_array($clients_existing)) {
|
||||
$clients_new = array_diff($clients_list, $clients_existing);
|
||||
$clients_to_delete = array_diff($clients_existing, $clients_list);
|
||||
} else {
|
||||
$clients_new = $clients_list;
|
||||
$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 = $old_translated_name['name'];
|
||||
// $history_element_id = $documentation_category_id;
|
||||
// Histories::insert(190, $history_element_id, $history_element);
|
||||
|
||||
$data['nb'] = self::countByUser($user_id);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function countByUser($id)
|
||||
{
|
||||
return UserClient::byUser($id)->count();
|
||||
}
|
||||
|
||||
public static function associateClients($user_id, $clients)
|
||||
{
|
||||
$history = "";
|
||||
foreach ($clients as $key => $client_id) {
|
||||
$client = Clients::select_by_id($client_id);
|
||||
if ($client) {
|
||||
self::associate_client($user_id, $client_id);
|
||||
$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]);
|
||||
}
|
||||
|
||||
public static function changePasswordsByUser($user_id, $password)
|
||||
{
|
||||
try {
|
||||
$username = User::find($user_id)->username;
|
||||
$connection = app(Connection::class);
|
||||
$clients = self::getClientsByUser($user_id);
|
||||
foreach ($clients as $client_id) {
|
||||
Clients::switchClient($client_id);
|
||||
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $username)->first();
|
||||
if ($client_user) {
|
||||
$client_user->update(['password' => $password]);
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
// Partners::switchPartner();
|
||||
}
|
||||
|
||||
public static function copyUser($user_id, $client_id)
|
||||
{
|
||||
$connection = app(Connection::class);
|
||||
$user = User::on($connection->systemName())->find($user_id);
|
||||
$password = $user->password;
|
||||
Clients::switchClient($client_id);
|
||||
$client_user = User::on($connection->tenantName())->withTrashed()->where('username', $user->username)->first();
|
||||
if (!$client_user) {
|
||||
$user = $user->toArray();
|
||||
$user['password'] = $password;
|
||||
unset($user['id']);
|
||||
unset($user['created_at']);
|
||||
$client_user = User::on($connection->tenantName())->create($user);
|
||||
$client_user->attachRole('superadministrator');
|
||||
} else {
|
||||
if ($client_user->trashed()) {
|
||||
$client_user->restore();
|
||||
}
|
||||
$client_user->attachRole('superadministrator');
|
||||
}
|
||||
// TODO Copy avatar
|
||||
//
|
||||
// dump($client_user->toArray());
|
||||
// exit;
|
||||
// $client_user = User::on($connection->tenantName())->firstOrCreate(['username' => $user->username], $user->toArray());
|
||||
Partners::switchPartner();
|
||||
}
|
||||
|
||||
public static function dissociateClients($user_id, $clients)
|
||||
{
|
||||
$history = "";
|
||||
foreach ($clients as $key => $client_id) {
|
||||
self::dissociate_client($user_id, $client_id);
|
||||
$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();
|
||||
}
|
||||
|
||||
public static function deleteUser($user_id, $client_id)
|
||||
{
|
||||
$connection = app(Connection::class);
|
||||
$user = User::on($connection->systemName())->find($user_id);
|
||||
Clients::switchClient($client_id);
|
||||
$user = User::on($connection->tenantName())->where('username', $user->username)->get();
|
||||
$user->detachRole('superadministrator');
|
||||
$user->delete();
|
||||
Partners::switchPartner();
|
||||
}
|
||||
|
||||
public static function delete_associate_clients($id)
|
||||
{
|
||||
return UserClient::byUser($id)->delete();
|
||||
}
|
||||
|
||||
public static function select_clients_by_id($id)
|
||||
{
|
||||
return UserClient::byUser($id)->get()->pluck('client_id')->toArray();
|
||||
}
|
||||
|
||||
public static function getClientsByUser($id)
|
||||
{
|
||||
return UserClient::byUser($id)->get()->pluck('client_id');
|
||||
}
|
||||
|
||||
public static function getUsersByClient($id)
|
||||
{
|
||||
return UserClient::byClient($id)->get()->pluck('user_id');
|
||||
}
|
||||
}
|
||||
26
app/Repositories/Core/Auth/UserStatusTeams.php
Normal file
26
app/Repositories/Core/Auth/UserStatusTeams.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserStatusTeam;
|
||||
|
||||
class UserStatusTeams
|
||||
{
|
||||
|
||||
// supprime l'association entre les équipes et le statut utilisateur donné
|
||||
public function delete_teams($id)
|
||||
{
|
||||
return UserStatusTeam::byUserStatus($id)->delete();
|
||||
}
|
||||
|
||||
// associe une équipe avec un statut utilisateur
|
||||
public function insert_team($user_status_id, $team_id)
|
||||
{
|
||||
return UserStatusTeam::create(['team_id' => $team_id, 'user_status_id' => $user_status_id]);
|
||||
}
|
||||
|
||||
// récupère les équipes d'un statut utilisateur donné
|
||||
public function select_teams_by_id($id)
|
||||
{
|
||||
return UserStatusTeam::select('team_id')->byUserStatus($id)->get();
|
||||
}
|
||||
}
|
||||
100
app/Repositories/Core/Auth/UserStatuses.php
Normal file
100
app/Repositories/Core/Auth/UserStatuses.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserStatus;
|
||||
|
||||
class UserStatuses
|
||||
{
|
||||
// compte le nombre de statut utilisateur
|
||||
public static function count()
|
||||
{
|
||||
return UserStatus::count();
|
||||
}
|
||||
|
||||
// supprime un statut utilisateur
|
||||
public static function delete($id)
|
||||
{
|
||||
return UserStatus::destroy($id);
|
||||
}
|
||||
|
||||
// ajoute un statut utilisateur
|
||||
public static function insert($name, $translated, $negociator)
|
||||
{
|
||||
return UserStatus::create(['name' => $name, 'translated' => $translated, 'negociator' => $negociator]);
|
||||
}
|
||||
|
||||
// reset le négociateur parmi les statuts
|
||||
public static function reset_negociator_status()
|
||||
{
|
||||
return UserStatus::update(['negociator' => null]);
|
||||
}
|
||||
|
||||
// récupère toutes les infos sur les statuts utilisateur
|
||||
public static function select_all()
|
||||
{
|
||||
return UserStatus::all()->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos pour un statut utilisateur donné
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return UserStatus::find($id)->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos pour un statut utilisateur donné
|
||||
public static function select_by_name($name)
|
||||
{
|
||||
return UserStatus::byName($name)->first()->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos du statut considéré comme négociant d'un contrat
|
||||
public static function select_by_negociator()
|
||||
{
|
||||
$status = UserStatus::byNegociator()->first();
|
||||
return $status ? $status->toArray() : null;
|
||||
}
|
||||
|
||||
// met à jour le statut actif/inactif d'un statut utilisateur
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return UserStatus::find($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
// met à jour les informations d'un statut utilisateur
|
||||
public static function update($id, $name, $translated, $negociator)
|
||||
{
|
||||
return UserStatus::find($id)->update(['id' => $id, 'name' => $name, 'translated' => $translated, 'negociator' => $negociator]);
|
||||
}
|
||||
|
||||
// met à jour les informations d'un statut utilisateur
|
||||
public static function update_negociator($id, $negociator)
|
||||
{
|
||||
return UserStatus::find($id)->update(['negociator' => $negociator]);
|
||||
}
|
||||
|
||||
public static function getAllUserStatuses($input)
|
||||
{
|
||||
$data = [];
|
||||
$statuses = self::select_all();
|
||||
foreach ($statuses as $status) {
|
||||
if ($status['active'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
$item = array();
|
||||
$item['id'] = $status['id'];
|
||||
$item['name'] = \App\Repositories\Translate::translateClient($status['translated']);
|
||||
array_push($data, $item);
|
||||
}
|
||||
$data = \App\Repositories\Functions::array_orderby($data, 'name', SORT_ASC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return UserStatus::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getNegociatorsOptions()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,17 @@ namespace App\Repositories\Core\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Hyn\Tenancy\Database\Connection;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
use App\Models\Core\Auth\User;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
use App\Repositories\Clients;
|
||||
use App\Repositories\Partners;
|
||||
|
||||
class Users
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
@@ -20,54 +26,79 @@ class Users
|
||||
}
|
||||
|
||||
public static function getInfo($id = false)
|
||||
{
|
||||
return self::getWithDetail($id);
|
||||
}
|
||||
|
||||
public static function getWithDetail($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return User::where('id', $id)->with(['user_detail'])->first();
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
$user = self::get($id);
|
||||
$data = $user->toArray();
|
||||
$data['name'] = $user->name;
|
||||
$data['avatar'] = self::getAvatar($id);
|
||||
$data['last_login'] = $user->previousLoginAt();
|
||||
// $data['roles'] = self::getRoles();
|
||||
// $data['permissions'] = self::getPermissions();
|
||||
$data['roles'] = $user->roles->pluck('id')->toArray();
|
||||
$data['permissions'] = $user->allPermissions()->pluck('id')->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getEmailsByRole($role) {
|
||||
return User::select('id','email')->whereRoleIs($role)->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getIdsByRole($role) {
|
||||
return User::select('id')->whereRoleIs($role)->get()->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getListByRole($role)
|
||||
public static function store($data)
|
||||
{
|
||||
return self::selectOptions()->orderBy('nom', 'asc')->whereRoleIs($role)->get();
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
|
||||
if (!empty($data['password'])) {
|
||||
$data['password'] = Hash::make($data['password']);
|
||||
} else {
|
||||
if ($id) {
|
||||
unset($data['password']);
|
||||
} else {
|
||||
$data['password'] = Hash::make(Str::random(8));
|
||||
}
|
||||
}
|
||||
$data['remember_token'] = Str::random(32);
|
||||
$data['active'] = true;
|
||||
|
||||
$user = $id ? self::update($data, $id) : self::create($data);
|
||||
|
||||
if (isset($data['roles'])) {
|
||||
$user->roles()->sync(array_keys($data['roles']));
|
||||
}
|
||||
// $user->sendNewUserNotification($data['remember_token'], Auth::user());
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
public static function create($data)
|
||||
{
|
||||
return self::selectOptions()->get();
|
||||
$data['password'] = $data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8));
|
||||
return User::create($data);
|
||||
}
|
||||
|
||||
public static function selectOptions()
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
return User::select('id', DB::raw("concat(last_name,' ',first_name) as nom"));
|
||||
}
|
||||
|
||||
public static function hasRole($role)
|
||||
{
|
||||
$user = self::get();
|
||||
return $user ? $user->hasRole($role) : false;
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
return self::getUser()->id;
|
||||
$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::find($id);
|
||||
return User::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
$user = self::getUser();
|
||||
return $user ? $user->id : false;
|
||||
}
|
||||
|
||||
public static function getName()
|
||||
{
|
||||
$user = self::getUser();
|
||||
return $user->first_name . ' ' . $user->last_name;
|
||||
}
|
||||
|
||||
public static function getUser()
|
||||
@@ -80,12 +111,71 @@ class Users
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return User::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
$t = RoleUser::byUser($id)->delete();
|
||||
$ret = RoleUser::byUser($id)->delete();
|
||||
return User::destroy($id);
|
||||
}
|
||||
|
||||
public static function getListByRole($role)
|
||||
{
|
||||
return self::selectOptions()->orderBy('name', 'asc')->whereRoleIs($role)->get();
|
||||
}
|
||||
|
||||
public static function hasRole($role, $user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
return $user ? $user->hasRole($role) : false;
|
||||
}
|
||||
|
||||
public static function hasPermission($permission, $user = false)
|
||||
{
|
||||
if (self::isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
public static function checkPermission($permissions, $permission)
|
||||
{
|
||||
if (!strpos($permission, '*')) {
|
||||
return in_array($permission, $permissions);
|
||||
}
|
||||
$permission = str_replace('*', '', $permission);
|
||||
foreach ($permissions as $item) {
|
||||
if (stripos($item, $permission) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getRoles($user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
return $user ? $user->roles->pluck('name')->toArray() : false;
|
||||
}
|
||||
|
||||
public static function getRolesToEdit()
|
||||
{
|
||||
return Roles::getListByRights();
|
||||
}
|
||||
|
||||
public static function getPermissions($user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
return $user ? $user->allPermissions()->pluck('name')->toArray() : false;
|
||||
}
|
||||
|
||||
public static function getByTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->get();
|
||||
@@ -101,36 +191,86 @@ class Users
|
||||
return User::byTeam($id)->byUniqueTeam()->delete();
|
||||
}
|
||||
|
||||
// récupère les champs de la table
|
||||
public static function get_field_table()
|
||||
public static function getAvatar($user_id)
|
||||
{
|
||||
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
|
||||
$avatar = self::get($user_id)->avatar;
|
||||
if (!$avatar) {
|
||||
return '/assets/img/no-avatar.png';
|
||||
}
|
||||
$path = Clients::isClient() ? Clients::getPublicPath('/images/avatars/') : Partners::getPublicPath('/images/avatars/');
|
||||
return $path . $avatar;
|
||||
}
|
||||
|
||||
// ajoute un utilisateur
|
||||
public static function insert($data)
|
||||
public static function selectOptions()
|
||||
{
|
||||
return User::create($data);
|
||||
return User::select('id', DB::raw("concat(last_name,' ',first_name) as name"));
|
||||
}
|
||||
|
||||
// récupère tous les utilisateurs
|
||||
public static function select_all()
|
||||
public static function count()
|
||||
{
|
||||
return User::all()->toArray();
|
||||
return User::count();
|
||||
}
|
||||
|
||||
// récupère tous les utilisateurs pour un statut donné
|
||||
public static function select_all_by_status_id($status_id)
|
||||
{
|
||||
return User::byStatus($status_id);
|
||||
}
|
||||
|
||||
// récupère toutes les informations d'un utilisateur pour un id donné
|
||||
public static function select_by_id($user_id)
|
||||
{
|
||||
return User::with('status')->find($user_id)->toArray();
|
||||
}
|
||||
|
||||
// récupère toutes les informations d'un utilisateur pour un nom donné
|
||||
public static function select_by_name($name)
|
||||
{
|
||||
return User::byName($name)->first()->toArray();
|
||||
}
|
||||
|
||||
// récupère les utilisateurs actifs d'un statut, d'une équipe et d'une entité donnés
|
||||
public static function select_by_status_and_team_and_entity($status_id, $team_id, $third_party_id)
|
||||
{
|
||||
return User::active()->byStatus($status_id)->byTeam($team_id)->byThirdParty($third_party_id)->get()->toArray();
|
||||
}
|
||||
|
||||
// récupère toutes les informations nécessaires d'un utilisateur pour un id donné
|
||||
public static function select_datas_by_id($user_id)
|
||||
{
|
||||
return User::with('status')->find($user_id)->toArray();
|
||||
}
|
||||
|
||||
// met à jour le statut actif/inactif d'un utilisateur
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return self::get($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
public static function uploadAvatar($request)
|
||||
{
|
||||
$targetDir = 'uploads';
|
||||
$file = $request->file('avatar_file');
|
||||
$data = \App\Repositories\Core\Upload::getData($file);
|
||||
$file_uploaded = \App\Repositories\Core\Upload::store($file, $targetDir);
|
||||
$tab = pathinfo($file_uploaded);
|
||||
$response['name'] = $tab['basename'];
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
// met à jour les informations d'un utilisateur
|
||||
public static function update(Request $request)
|
||||
// met à jour l'avatar d'un utilisateur
|
||||
public static function update_avatar($id, $avatar)
|
||||
{
|
||||
return User::find($data['id'])->update($data);
|
||||
return User::find($id)->update(['avatar' => $avatar]);
|
||||
}
|
||||
|
||||
// met à jour le mot de passe d'un utilisateur
|
||||
public static function update_password($id, $password)
|
||||
{
|
||||
$user = User::find($id);
|
||||
$user->password = Hash::make($password);
|
||||
return $user->save();
|
||||
$password = Hash::make($password);
|
||||
UserClients::changePasswordsByUser($id, $password);
|
||||
$connection = app(Connection::class);
|
||||
return User::on($connection->systemName())->find($id)->update(['password' => $password]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,13 +194,15 @@ class DataTable
|
||||
if (is_array($hasfilters)) {
|
||||
foreach ($hasfilters as $hasfilter) {
|
||||
if (!empty($hasfilter['search'])) {
|
||||
$elements = $elements->whereHas($hasfilter['controller'], function ($query) use ($hasfilter) {
|
||||
if ($hasfilter['like']) {
|
||||
$query->where($hasfilter['field'], 'like', '%' . $hasfilter['search'] . '%');
|
||||
} else {
|
||||
$query->where($hasfilter['field'], '=', $hasfilter['search']);
|
||||
$elements = $elements->whereHas(
|
||||
$hasfilter['controller'], function ($query) use ($hasfilter) {
|
||||
if ($hasfilter['like']) {
|
||||
$query->where($hasfilter['field'], 'like', '%' . $hasfilter['search'] . '%');
|
||||
} else {
|
||||
$query->where($hasfilter['field'], '=', $hasfilter['search']);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,9 +219,11 @@ class DataTable
|
||||
'field' => $tab[1],
|
||||
'search' => $search,
|
||||
];
|
||||
$elements = $elements->whereHas($searchField['controller'], function ($query) use ($searchField) {
|
||||
$query->where($searchField['field'], 'like', '%' . $searchField['search'] . '%');
|
||||
});
|
||||
$elements = $elements->whereHas(
|
||||
$searchField['controller'], function ($query) use ($searchField) {
|
||||
$query->where($searchField['field'], 'like', '%' . $searchField['search'] . '%');
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$elements = $elements->where($searchcol, 'like', "%$search%");
|
||||
}
|
||||
|
||||
@@ -13,18 +13,18 @@ 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;
|
||||
|
||||
77
app/Repositories/Core/DateCalculation.php
Normal file
77
app/Repositories/Core/DateCalculation.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
use App\Repositories\Languages;
|
||||
|
||||
class DateCalculation
|
||||
{
|
||||
public static function isPast($date, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->lessThan(Carbon::now());
|
||||
}
|
||||
|
||||
public static function isFuture($date, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->greaterThan(Carbon::now());
|
||||
}
|
||||
|
||||
public static function isAfter($date1, $date2)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date1)->greaterThan(Carbon::createFromFormat(self::getFormat($format), $date2));
|
||||
}
|
||||
|
||||
public static function isBefore($date1, $date2)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date1)->lessThan(Carbon::createFromFormat(self::getFormat($format), $date2));
|
||||
}
|
||||
|
||||
public static function addYear($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->addYears($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function subYear($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->subYears($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function addMonth($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->addMonths($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function subMonth($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->subMonths($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function addWeek($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->addWeeks($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function subWeek($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->subWeeks($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function addDay($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->addDays($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function subDay($date, $nb = 1, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->subDays($nb)->format(self::getFormat($format));
|
||||
}
|
||||
|
||||
public static function getFormat($format = false)
|
||||
{
|
||||
return $format ? $format : DateTime::getLocaleFormatDate();
|
||||
}
|
||||
}
|
||||
@@ -31,16 +31,16 @@ 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;
|
||||
}
|
||||
|
||||
@@ -12,162 +12,160 @@ use function League\Period\interval_after;
|
||||
|
||||
class DateRange
|
||||
{
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
||||
{
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
||||
$labels = DateRange::getMonthNames($periods);
|
||||
foreach ($labels as $label) {
|
||||
$data[$label] = $periods;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonthWithLabels($nb, $with_actual = true)
|
||||
{
|
||||
$periods = DateRange::PeriodsToCarbon(DateRange::getPeriodsLastMonth($nb, $with_actual));
|
||||
$labels = DateRange::getMonthNames($periods);
|
||||
foreach ($labels as $label) {
|
||||
$data[$label] = $periods;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
public static function getAllMonthNames()
|
||||
{
|
||||
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
||||
}
|
||||
|
||||
public static function getAllMonthNames()
|
||||
{
|
||||
return self::getMonthNames(self::PeriodsToCarbon(self::getPeriodsLastMonth(12)));
|
||||
}
|
||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb-1);
|
||||
$t = self::getPeriodsbyMonth($begin, $end);
|
||||
return self::getPeriodsbyMonth($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastMonth($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfMonth() : self::lastMonth();
|
||||
$begin = ($nb == 1) ? $end->copy()->startOfMonth() : $end->copy()->startOfMonth()->subMonth($nb-1);
|
||||
$t = self::getPeriodsbyMonth($begin, $end);
|
||||
return self::getPeriodsbyMonth($begin, $end);
|
||||
}
|
||||
public static function getMonthNamesByPeriods($periods)
|
||||
{
|
||||
$months = [];
|
||||
foreach ($periods as $period) {
|
||||
$date = self::DatePointToCarbon($period->getStartDate());
|
||||
$months[] = DateTime::getMonthName($date);
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
|
||||
public static function getMonthNamesByPeriods($periods)
|
||||
{
|
||||
$months = [];
|
||||
foreach ($periods as $period) {
|
||||
$date = self::DatePointToCarbon($period->getStartDate());
|
||||
$months[] = DateTime::getMonthName($date);
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
public static function getMonthNames($periods)
|
||||
{
|
||||
$months = [];
|
||||
foreach ($periods as $period) {
|
||||
$months[] = DateTime::getMonthName($period['start']);
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
|
||||
public static function getMonthNames($periods)
|
||||
{
|
||||
$months = [];
|
||||
foreach ($periods as $period) {
|
||||
$months[] = DateTime::getMonthName($period['start']);
|
||||
}
|
||||
return $months;
|
||||
}
|
||||
public static function getPeriodsLastWeek($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
return static::getPeriodsbyWeek($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastWeek($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfWeek() : self::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
return static::getPeriodsbyWeek($begin, $end);
|
||||
}
|
||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
return static::getPeriodsbyDay($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastDay($nb = 1, $with_actual = true)
|
||||
{
|
||||
$end = $with_actual ? Carbon::now()->endOfDay() : static::lastDay();
|
||||
$begin = $end->copy()->subDay($nb);
|
||||
return static::getPeriodsbyDay($begin, $end);
|
||||
}
|
||||
public static function byDay()
|
||||
{
|
||||
return [Carbon::now()->startOfDay(), Carbon::now()->endOfDay()];
|
||||
}
|
||||
|
||||
public static function byDay()
|
||||
{
|
||||
return [Carbon::now()->startOfDay(), Carbon::now()->endOfDay()];
|
||||
}
|
||||
public static function byWeek()
|
||||
{
|
||||
return [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()];
|
||||
}
|
||||
|
||||
public static function byWeek()
|
||||
{
|
||||
return [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()];
|
||||
}
|
||||
public static function byMonth()
|
||||
{
|
||||
return [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()];
|
||||
}
|
||||
|
||||
public static function byMonth()
|
||||
{
|
||||
return [Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth()];
|
||||
}
|
||||
public static function byQuarter()
|
||||
{
|
||||
return [Carbon::now()->startOfQuarter(), Carbon::now()->endOfQuarter()];
|
||||
}
|
||||
|
||||
public static function byQuarter()
|
||||
{
|
||||
return [Carbon::now()->startOfQuarter(), Carbon::now()->endOfQuarter()];
|
||||
}
|
||||
public static function bySemester()
|
||||
{
|
||||
$quarter = Carbon::now()->quarter;
|
||||
switch ($quarter) {
|
||||
case 1:
|
||||
case 2:
|
||||
$date = Carbon::now()->startOfYear();
|
||||
break;
|
||||
case 3:
|
||||
$date = Carbon::now()->startOfQuarter();
|
||||
break;
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
}
|
||||
return [$date, $date->addMonth(6)];
|
||||
}
|
||||
|
||||
public static function bySemester()
|
||||
{
|
||||
$quarter = Carbon::now()->quarter;
|
||||
switch ($quarter) {
|
||||
case 1:
|
||||
case 2:
|
||||
$date = Carbon::now()->startOfYear();
|
||||
break;
|
||||
case 3:
|
||||
$date = Carbon::now()->startOfQuarter();
|
||||
break;
|
||||
case 4:
|
||||
$date = Carbon::now()->subMonth(3)->startOfQuarter();
|
||||
break;
|
||||
}
|
||||
return [$date, $date->addMonth(6)];
|
||||
}
|
||||
public static function byYear()
|
||||
{
|
||||
return [Carbon::now()->startOfYear(), Carbon::now()->endOfYear()];
|
||||
}
|
||||
|
||||
public static function byYear()
|
||||
{
|
||||
return [Carbon::now()->startOfYear(), Carbon::now()->endOfYear()];
|
||||
}
|
||||
public static function lastMonth()
|
||||
{
|
||||
return Carbon::now()->subMonth()->startOfMonth();
|
||||
}
|
||||
|
||||
public static function lastMonth()
|
||||
{
|
||||
return Carbon::now()->subMonth()->startOfMonth();
|
||||
}
|
||||
public static function lastWeek()
|
||||
{
|
||||
return Carbon::now()->subWeek()->startOfWeek();
|
||||
}
|
||||
|
||||
public static function lastWeek()
|
||||
{
|
||||
return Carbon::now()->subWeek()->startOfWeek();
|
||||
}
|
||||
public static function lastDay()
|
||||
{
|
||||
return Carbon::now()->subDay()->startOfDay();
|
||||
}
|
||||
|
||||
public static function lastDay()
|
||||
{
|
||||
return Carbon::now()->subDay()->startOfDay();
|
||||
}
|
||||
public static function getPeriodsbyMonth($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval MONTH");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyMonth($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval MONTH");
|
||||
}
|
||||
public static function getPeriodsbyWeek($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval WEEK");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyWeek($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval WEEK");
|
||||
}
|
||||
public static function getPeriodsbyDay($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval DAY");
|
||||
}
|
||||
|
||||
public static function getPeriodsbyDay($begin, $end, $interval = 1)
|
||||
{
|
||||
return self::getPeriods($begin, $end, "$interval DAY");
|
||||
}
|
||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
||||
{
|
||||
$period = new Period($begin, $end);
|
||||
foreach ($period->getDatePeriod($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
}
|
||||
return $daterange;
|
||||
}
|
||||
|
||||
public static function getPeriods($begin, $end, $duration, $interval = 1)
|
||||
{
|
||||
$period = new Period($begin, $end);
|
||||
foreach ($period->getDatePeriod($duration) as $day) {
|
||||
$daterange[] = interval_after($day, $duration);
|
||||
}
|
||||
return $daterange;
|
||||
}
|
||||
public static function PeriodsToCarbon($periods)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($periods as $period) {
|
||||
$data[] = self::PeriodToCarbon($period);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function PeriodsToCarbon($periods)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($periods as $period) {
|
||||
$data[] = self::PeriodToCarbon($period);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function PeriodToCarbon($period)
|
||||
{
|
||||
return ['start' => self::DatePointToCarbon($period->getStartDate()), 'end' => self::DatePointToCarbon($period->getEndDate())];
|
||||
}
|
||||
|
||||
public static function DatePointToCarbon($date)
|
||||
{
|
||||
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
public static function PeriodToCarbon($period)
|
||||
{
|
||||
return ['start' => self::DatePointToCarbon($period->getStartDate()), 'end' => self::DatePointToCarbon($period->getEndDate())];
|
||||
}
|
||||
|
||||
public static function DatePointToCarbon($date)
|
||||
{
|
||||
return Carbon::createFromFormat('Y-m-d H:i:s', $date->format('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,138 +10,138 @@ use App\Repositories\Languages;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
public static function getMonthName($date, $short = true)
|
||||
{
|
||||
return $short ? self::getUltraShortMonthName($date) : $date->monthName;
|
||||
}
|
||||
public static function getMonthName($date, $short = true)
|
||||
{
|
||||
return $short ? self::getUltraShortMonthName($date) : $date->monthName;
|
||||
}
|
||||
|
||||
public static function getShortMonthName($date)
|
||||
{
|
||||
return $date->shortMonthName;
|
||||
}
|
||||
public static function getShortMonthName($date)
|
||||
{
|
||||
return $date->shortMonthName;
|
||||
}
|
||||
|
||||
public static function getUltraShortMonthName($date)
|
||||
{
|
||||
return strtoupper(Str::ascii(mb_substr($date->shortMonthName,0,3)));
|
||||
}
|
||||
public static function getUltraShortMonthName($date)
|
||||
{
|
||||
return strtoupper(Str::ascii(mb_substr($date->shortMonthName, 0, 3)));
|
||||
}
|
||||
|
||||
public static function getDayName($date, $short = true)
|
||||
{
|
||||
return $short ? $date->shortDayName : $date->dayName;
|
||||
}
|
||||
public static function getDayName($date, $short = true)
|
||||
{
|
||||
return $short ? $date->shortDayName : $date->dayName;
|
||||
}
|
||||
|
||||
public static function DatetoLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
public static function DatetoLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function DatetimeToLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
public static function DatetimeToLocale($date = null)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function getDateTime()
|
||||
{
|
||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
||||
}
|
||||
public static function getDateTime()
|
||||
{
|
||||
return self::DatetimeToLocale(date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public static function getDate()
|
||||
{
|
||||
return self::DateToLocale(date('Y-m-d'));
|
||||
}
|
||||
public static function getDate()
|
||||
{
|
||||
return self::DateToLocale(date('Y-m-d'));
|
||||
}
|
||||
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
|
||||
public static function convert($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
public static function convert($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDate();
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
{
|
||||
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
public static function toFr($date)
|
||||
{
|
||||
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
|
||||
public static function toFrTime($date)
|
||||
{
|
||||
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
||||
}
|
||||
public static function toFrTime($date)
|
||||
{
|
||||
return !empty($date) ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function getYearFromDate($date)
|
||||
{
|
||||
// return date_format(DateTime::convert($signature_date), 'Y');
|
||||
$date = DateTime::convert($date);
|
||||
$date = date_create($date);
|
||||
return date_format($date, 'Y');
|
||||
}
|
||||
public static function getYearFromDate($date)
|
||||
{
|
||||
// return date_format(DateTime::convert($signature_date), 'Y');
|
||||
$date = DateTime::convert($date);
|
||||
$date = date_create($date);
|
||||
return date_format($date, 'Y');
|
||||
}
|
||||
|
||||
|
||||
public static function getLocaleFormatDate()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
public static function getLocaleFormatDate()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function getLocaleFormatDatetime()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y H:i:s';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d H:i:s';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
public static function getLocaleFormatDatetime()
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y H:i:s';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d H:i:s';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function getLocaleDateFull($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('LLLL');
|
||||
}
|
||||
public static function getLocaleDateFull($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('LLLL');
|
||||
}
|
||||
|
||||
public static function getLocaleDateFullShort($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('lll');
|
||||
}
|
||||
public static function getLocaleDateFullShort($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('lll');
|
||||
}
|
||||
|
||||
public static function getLocaleHour($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('');
|
||||
}
|
||||
public static function getLocaleHour($date)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('');
|
||||
}
|
||||
|
||||
public static function relativeTime()
|
||||
{
|
||||
}
|
||||
public static function relativeTime()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,7 @@ class Debug
|
||||
|
||||
/**
|
||||
* dump un message uniquement si debug est true
|
||||
*
|
||||
* @param string $msg [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
@@ -108,6 +109,7 @@ class Debug
|
||||
|
||||
/**
|
||||
* force la sortie d'un dump, sans passer par la debugbar ou test si debug est true
|
||||
*
|
||||
* @param string $msg [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
@@ -118,6 +120,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
|
||||
* @return [type] [description]
|
||||
|
||||
73
app/Repositories/Core/File.php
Normal file
73
app/Repositories/Core/File.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use SoftCreatR\MimeDetector\MimeDetector;
|
||||
use SoftCreatR\MimeDetector\MimeDetectorException;
|
||||
|
||||
class File
|
||||
{
|
||||
public static function checkDirOrCreate($dir)
|
||||
{
|
||||
return self::checkDir($dir) ? true : self::createDir($dir);
|
||||
}
|
||||
|
||||
public static function checkDir($dir)
|
||||
{
|
||||
// File::isDirectory($path)
|
||||
return is_dir($dir);
|
||||
}
|
||||
|
||||
public static function checkFile($file)
|
||||
{
|
||||
return file_exists($file);
|
||||
}
|
||||
|
||||
public static function createDir($dir)
|
||||
{
|
||||
Storage::makeDirectory($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteDir($dir)
|
||||
{
|
||||
Storage::deleteDirectory($dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function createFile($file, $content)
|
||||
{
|
||||
Storage::put($file, $content);
|
||||
}
|
||||
|
||||
public static function getFile($file)
|
||||
{
|
||||
return Storage::get($file);
|
||||
}
|
||||
|
||||
public static function getFilesize($file)
|
||||
{
|
||||
return Storage::size($file);
|
||||
}
|
||||
|
||||
public static function getUrlFile($file)
|
||||
{
|
||||
return Storage::url($file);
|
||||
}
|
||||
|
||||
public static function download($file, $name = false, $headers = false)
|
||||
{
|
||||
return Storage::download($file, $name, $headers);
|
||||
}
|
||||
|
||||
public static function getFileType($file)
|
||||
{
|
||||
try {
|
||||
return (new MimeDetector())->setFile($file)->getFileType();
|
||||
} catch (MimeDetectorException $e) {
|
||||
die('An error occured while trying to load the given file.');
|
||||
}
|
||||
}
|
||||
}
|
||||
77
app/Repositories/Core/HelperDate.php
Normal file
77
app/Repositories/Core/HelperDate.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class HelperDate
|
||||
{
|
||||
public static $is_debug = true;
|
||||
|
||||
public static function toLocaleFormat($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';
|
||||
}
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public static function fromLocale($d)
|
||||
{
|
||||
return self::frenchDate($d);
|
||||
}
|
||||
|
||||
public static function toLocale($d)
|
||||
{
|
||||
return self::toFrenchDate($d);
|
||||
}
|
||||
|
||||
public static function frenchDate($d)
|
||||
{
|
||||
if (!$d) {
|
||||
return null;
|
||||
}
|
||||
return Carbon::createFromFormat('d/m/Y', $d)->format('Y-m-d');
|
||||
}
|
||||
|
||||
public static function frenchDates($data, $fields)
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
if (isset($data[$field]) && $data[$field]) {
|
||||
$data[$field] = static::frenchDate($data[$field]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function toFrenchDate($d)
|
||||
{
|
||||
if ($d && $d != '0000-00-00') {
|
||||
return Carbon::createFromFormat('Y-m-d', $d)->format('d/m/Y');
|
||||
}
|
||||
return $d;
|
||||
}
|
||||
|
||||
public static function toFrenchDates($data, $fields)
|
||||
{
|
||||
foreach ($fields as $field) {
|
||||
if (isset($data[$field]) && $data[$field]) {
|
||||
$data[$field] = static::toFrenchDate($data[$field]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -7,20 +7,19 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Mailer
|
||||
{
|
||||
|
||||
public static function getTemplates()
|
||||
{
|
||||
// $mailables = MailEclipse::getMailables();
|
||||
// DB::rollBack();
|
||||
// dump($mailables);
|
||||
/*
|
||||
$mailables = (null !== $mailables) ? $mailables->sortBy('name') : collect([]);
|
||||
foreach ($mailables as $mailable)
|
||||
{
|
||||
$templates[] = $mailable['name'];
|
||||
}
|
||||
/*
|
||||
$mailables = (null !== $mailables) ? $mailables->sortBy('name') : collect([]);
|
||||
foreach ($mailables as $mailable)
|
||||
{
|
||||
$templates[] = $mailable['name'];
|
||||
}
|
||||
|
||||
*/
|
||||
*/
|
||||
$templates = ['EventInscription','EventSaveTheDate','MatinalesBadge','MatinalesThanks','MatinalesReplays'];
|
||||
return $templates;
|
||||
}
|
||||
|
||||
@@ -4,53 +4,52 @@ namespace App\Repositories\Core;
|
||||
|
||||
class Media
|
||||
{
|
||||
public static function getImages($model)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
}
|
||||
|
||||
public static function getImages($model) {
|
||||
if ($model) {
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function storeImage($model, $file)
|
||||
{
|
||||
return $model->addMedia($file)->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function storeImage($model, $file)
|
||||
{
|
||||
return $model->addMedia($file)->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return "1";
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$images = json_decode($image['responsive_images'], true);
|
||||
$urls = $images['medialibrary_original']['urls'];
|
||||
|
||||
$img = $urls[count($urls)-1];
|
||||
$src = "storage/$id/responsive-images/$img";
|
||||
return $src;
|
||||
}
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return "1";
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$images = json_decode($image['responsive_images'], true);
|
||||
/*
|
||||
$urls = $images['medialibrary_original']['urls'];
|
||||
|
||||
$img = $urls[count($urls)-1];
|
||||
$src = "storage/$id/responsive-images/$img";
|
||||
*/
|
||||
return $src ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ class Builder extends LavaryMenuBuilder
|
||||
if ($currentUser && $currentUser->ability($ability, $permission)) {
|
||||
$this->items->push($item);
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->items->push($item);
|
||||
}
|
||||
@@ -64,8 +63,8 @@ class Builder extends LavaryMenuBuilder
|
||||
/**
|
||||
* Add an item to a existing menu item as a submenu item.
|
||||
*
|
||||
* @param $id Id of the menu item to attach to
|
||||
* @param $title Title of the sub item
|
||||
* @param $id Id of the menu item to attach to
|
||||
* @param $title Title of the sub item
|
||||
* @param string $options
|
||||
*
|
||||
* @return Lavary\Menu\Item
|
||||
|
||||
@@ -12,15 +12,19 @@ class Logs
|
||||
->id('logs')
|
||||
->order(1100);
|
||||
|
||||
$menu->addTo('logs', __('boilerplate::logs.menu.stats'), [
|
||||
$menu->addTo(
|
||||
'logs', __('boilerplate::logs.menu.stats'), [
|
||||
'route' => 'boilerplate.logs.dashboard',
|
||||
'permission' => 'logs', ])
|
||||
'permission' => 'logs', ]
|
||||
)
|
||||
->order(1110)
|
||||
->activeIfRoute('boilerplate.logs.dashboard');
|
||||
|
||||
$menu->addTo('logs', __('boilerplate::logs.menu.reports'), [
|
||||
$menu->addTo(
|
||||
'logs', __('boilerplate::logs.menu.reports'), [
|
||||
'route' => 'boilerplate.logs.list',
|
||||
'permission' => 'logs', ])
|
||||
'permission' => 'logs', ]
|
||||
)
|
||||
->order(1120)
|
||||
->activeIfRoute(['boilerplate.logs.list', 'boilerplate.logs.show', 'boilerplate.logs.filter']);
|
||||
}
|
||||
|
||||
@@ -12,19 +12,25 @@ class Users
|
||||
->id('access')
|
||||
->order(1000);
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.list.title'), [
|
||||
$menu->addTo(
|
||||
'access', __('boilerplate::users.list.title'), [
|
||||
'route' => 'boilerplate.users.index',
|
||||
'permission' => 'users_crud', ])
|
||||
'permission' => 'users_crud', ]
|
||||
)
|
||||
->activeIfRoute(['boilerplate.users.index', 'boilerplate.users.edit']);
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.create.title'), [
|
||||
$menu->addTo(
|
||||
'access', __('boilerplate::users.create.title'), [
|
||||
'route' => 'boilerplate.users.create',
|
||||
'permission' => 'users_crud', ])
|
||||
'permission' => 'users_crud', ]
|
||||
)
|
||||
->activeIfRoute('boilerplate.users.create');
|
||||
|
||||
$menu->addTo('access', __('boilerplate::layout.role_management'), [
|
||||
$menu->addTo(
|
||||
'access', __('boilerplate::layout.role_management'), [
|
||||
'route' => 'boilerplate.roles.index',
|
||||
'permission' => 'roles_crud', ])
|
||||
'permission' => 'roles_crud', ]
|
||||
)
|
||||
->activeIfRoute('boilerplate.roles.*');
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.profile.title'), ['route' => 'boilerplate.user.profile'])
|
||||
|
||||
@@ -6,32 +6,17 @@ class Stat
|
||||
{
|
||||
public static $is_debug = false;
|
||||
public static $force_output = true;
|
||||
private static $_instance;
|
||||
|
||||
private function __construct()
|
||||
public static function getNewByPeriod($model, $start, $end)
|
||||
{
|
||||
return $model->whereBetween('created_at', [$start, $end])->count();
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
public static function getTotalAtDate($model, $end)
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
return $model->where('created_at', '<', $end)->count();
|
||||
}
|
||||
|
||||
public static function push($range, $var)
|
||||
{
|
||||
$tab = (is_array($var)) ? $var : array();
|
||||
foreach ($range as $item) {
|
||||
$begin = date_timestamp_get($item['begin']);
|
||||
$end = date_timestamp_get($item['end']);
|
||||
$tab[] = ['begin' => $begin, 'end' => $end, 'count' => $item['count']];
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
fonctions de rendus
|
||||
*/
|
||||
@@ -148,16 +133,16 @@ class Stat
|
||||
$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);
|
||||
}
|
||||
|
||||
98
app/Repositories/Core/Storage.php
Normal file
98
app/Repositories/Core/Storage.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
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)
|
||||
{
|
||||
return self::checkDir($dir) ? true : self::createDir($dir);
|
||||
}
|
||||
|
||||
public static function checkDir($dir)
|
||||
{
|
||||
return Storage2::disk('local')->has($dir);
|
||||
}
|
||||
|
||||
public static function checkFile($file)
|
||||
{
|
||||
return Storage2::exists($file);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static function secureDeleteFile($file)
|
||||
{
|
||||
$process = new Process(['srm', $file]);
|
||||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new ProcessFailedException($process);
|
||||
}
|
||||
}
|
||||
|
||||
public static function createFile($file, $content)
|
||||
{
|
||||
Storage2::put($file, $content);
|
||||
}
|
||||
|
||||
public static function getFile($file)
|
||||
{
|
||||
return Storage2::get($file);
|
||||
}
|
||||
|
||||
public static function getFilesize($file)
|
||||
{
|
||||
return Storage2::size($file);
|
||||
}
|
||||
|
||||
public static function getUrlFile($file)
|
||||
{
|
||||
return Storage2::url($file);
|
||||
}
|
||||
|
||||
public static function download($file, $name = false, $headers = false)
|
||||
{
|
||||
return Storage2::download($file, $name, $headers);
|
||||
}
|
||||
|
||||
public static function getPublicPath($file = false)
|
||||
{
|
||||
return public_path($file);
|
||||
}
|
||||
|
||||
public static function getFileType($file)
|
||||
{
|
||||
$file = self::getStoragePath() . $file;
|
||||
return File::getFileType($file);
|
||||
}
|
||||
|
||||
public static function getStoragePath($file = false)
|
||||
{
|
||||
return storage_path($file);
|
||||
}
|
||||
}
|
||||
@@ -4,22 +4,23 @@ namespace App\Repositories\Core;
|
||||
|
||||
class Tag
|
||||
{
|
||||
public static function getTagsByModel($model)
|
||||
{
|
||||
$tags = $model->tags;
|
||||
return $tags ? $tags->pluck('id')->toArray() : null;
|
||||
}
|
||||
|
||||
public static function getTagsByModel($model)
|
||||
{
|
||||
$tags = $model->tags;
|
||||
return $tags ? $tags->pluck('id')->toArray() : null;
|
||||
}
|
||||
|
||||
public static function storeTags($model, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $model->syncTags($tags, true);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
|
||||
public static function storeTags($model, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
return $model->syncTags($tags, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,157 +8,156 @@ use Intervention\Image\Facades\Image as Image;
|
||||
|
||||
class Upload
|
||||
{
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->getClientOriginalExtension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
$data['mime'] = $file->getMimeType();
|
||||
return $data;
|
||||
}
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->getClientOriginalExtension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
$data['mime'] = $file->getMimeType();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = pathinfo($uuid, PATHINFO_FILENAME);
|
||||
// $uuid = str_replace('.' . strtolower($data->filetype), '', $uuid);
|
||||
// $uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = pathinfo($uuid, PATHINFO_FILENAME);
|
||||
// $uuid = str_replace('.' . strtolower($data->filetype), '', $uuid);
|
||||
// $uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
public static function storeByVar($var, $path, $public = false)
|
||||
{
|
||||
// check if filename exists
|
||||
// store
|
||||
// Storage::disk('local')->put('file.txt', 'Contents');
|
||||
// $path = Storage::putFile('avatars', $request->file('avatar'));
|
||||
// $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3');
|
||||
// $path = $request->file('avatar')->storePublicly('avatars', 's3');
|
||||
return $request->has($var) ? basename($request->file($var)->store($path)) : false;
|
||||
}
|
||||
public static function storeByVar($var, $path, $public = false)
|
||||
{
|
||||
// check if filename exists
|
||||
// store
|
||||
// Storage::disk('local')->put('file.txt', 'Contents');
|
||||
// $path = Storage::putFile('avatars', $request->file('avatar'));
|
||||
// $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3');
|
||||
// $path = $request->file('avatar')->storePublicly('avatars', 's3');
|
||||
return $request->has($var) ? basename($request->file($var)->store($path)) : false;
|
||||
}
|
||||
|
||||
public static function store($file, $path)
|
||||
{
|
||||
return Storage::putFile($path, $file);
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
public static function store($file, $path)
|
||||
{
|
||||
return Storage::putFile($path, $file);
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
return Storage::putFile($filepath, $file, 'public');
|
||||
// $filepath = 'public/' . $filepath;
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
return Storage::putFile($filepath, $file, 'public');
|
||||
// $filepath = 'public/' . $filepath;
|
||||
// return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function createThumb($file, $size, $sub = false)
|
||||
{
|
||||
$thumb = self::getThumbPath($file, $sub);
|
||||
$filename = self::getPublicPath($file);
|
||||
return Image::make($filename)->orientate()->widen($size)->save($thumb);
|
||||
}
|
||||
public static function createThumb($file, $size, $sub = false)
|
||||
{
|
||||
$thumb = self::getThumbPath($file, $sub);
|
||||
$filename = self::getPublicPath($file);
|
||||
return Image::make($filename)->orientate()->widen($size)->save($thumb);
|
||||
}
|
||||
|
||||
/*
|
||||
public static function getPath($file) {
|
||||
return 'public/' . self::getFilename($file);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getPublicPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getFilename($file));
|
||||
}
|
||||
/*
|
||||
public static function getPath($file) {
|
||||
return 'public/' . self::getFilename($file);
|
||||
}
|
||||
*/
|
||||
|
||||
public static function getPublicPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getFilename($file));
|
||||
}
|
||||
|
||||
public static function getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . self::getFilename($file));
|
||||
}
|
||||
public static function getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . self::getFilename($file));
|
||||
}
|
||||
|
||||
public static function getSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getFilename($file);
|
||||
}
|
||||
public static function getSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getFilename($file);
|
||||
}
|
||||
|
||||
public static function getThumbPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getThumbFilename($file));
|
||||
}
|
||||
public static function getThumbPath($file)
|
||||
{
|
||||
return storage_path('app/public/' . self::getThumbFilename($file));
|
||||
}
|
||||
|
||||
public static function getThumbSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getThumbFilename($file);
|
||||
}
|
||||
public static function getThumbSrc($file)
|
||||
{
|
||||
return '/storage/' . self::getThumbFilename($file);
|
||||
}
|
||||
|
||||
public static function getFilename($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . self::getName($file);
|
||||
}
|
||||
public static function getFilename($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
public static function getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' . strtolower($file->filetype);
|
||||
}
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' . strtolower($file->filetype);
|
||||
}
|
||||
|
||||
/**
|
||||
* [fix problem path with Storage on Windows]
|
||||
* @param [type] $path [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function fix($path)
|
||||
{
|
||||
if (self::isWindows()) {
|
||||
return str_replace('/', '\\', $path);
|
||||
} else {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* [fix problem path with Storage on Windows]
|
||||
*
|
||||
* @param [type] $path [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function fix($path)
|
||||
{
|
||||
if (!self::isWindows()) {
|
||||
return $path;
|
||||
}
|
||||
return str_replace('/', '\\', $path);
|
||||
}
|
||||
|
||||
public static function move($source, $dest)
|
||||
{
|
||||
if (Storage::exists($dest)) {
|
||||
self::delete($dest);
|
||||
}
|
||||
return Storage::move($source, $dest); // transfère et renomme le fichier du dossier temporaire au dossier du client
|
||||
}
|
||||
public static function move($source, $dest)
|
||||
{
|
||||
if (Storage::exists($dest)) {
|
||||
self::delete($dest);
|
||||
}
|
||||
return Storage::move($source, $dest); // transfère et renomme le fichier du dossier temporaire au dossier du client
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
// Storage::delete($file);
|
||||
// return unlink($file);
|
||||
return Storage::delete($file);
|
||||
}
|
||||
public static function delete($file)
|
||||
{
|
||||
// Storage::delete($file);
|
||||
// return unlink($file);
|
||||
return Storage::delete($file);
|
||||
}
|
||||
|
||||
public static function deleteFile($path)
|
||||
{
|
||||
if (Storage::exists($path)) {
|
||||
return Storage::delete($path);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function deleteFile($path)
|
||||
{
|
||||
if (!Storage::exists($path)) {
|
||||
return false;
|
||||
}
|
||||
return Storage::delete($path);
|
||||
}
|
||||
|
||||
public static function deleteRecursive($path)
|
||||
{
|
||||
rmdir_recursive($targetDir);
|
||||
}
|
||||
public static function deleteRecursive($path)
|
||||
{
|
||||
rmdir_recursive($targetDir);
|
||||
}
|
||||
|
||||
public function make_dir($path, $permissions = 0777)
|
||||
{
|
||||
return is_dir($path) || mkdir($path, $permissions, true);
|
||||
}
|
||||
|
||||
public static function isWindows()
|
||||
{
|
||||
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
||||
}
|
||||
public function make_dir($path, $permissions = 0777)
|
||||
{
|
||||
return is_dir($path) || mkdir($path, $permissions, true);
|
||||
}
|
||||
|
||||
public static function isWindows()
|
||||
{
|
||||
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,60 +4,59 @@ namespace App\Repositories\Core\User;
|
||||
|
||||
class Basket
|
||||
{
|
||||
public static function first($key)
|
||||
{
|
||||
$data = self::get($key);
|
||||
return array_shift($data);
|
||||
}
|
||||
|
||||
public static function first($key)
|
||||
{
|
||||
$data = self::get($key);
|
||||
return array_shift($data);
|
||||
}
|
||||
public static function last($key)
|
||||
{
|
||||
$data = self::get($key);
|
||||
return $data ? array_pop($data) : false;
|
||||
}
|
||||
|
||||
public static function last($key)
|
||||
{
|
||||
$data = self::get($key);
|
||||
return $data ? array_pop($data) : false;
|
||||
}
|
||||
public static function set($key, $data)
|
||||
{
|
||||
return session([$key => $data]);
|
||||
}
|
||||
|
||||
public static function set($key, $data)
|
||||
{
|
||||
return session([$key => $data]);
|
||||
}
|
||||
public static function get($key)
|
||||
{
|
||||
return session($key);
|
||||
}
|
||||
|
||||
public static function get($key)
|
||||
{
|
||||
return session($key);
|
||||
}
|
||||
public static function add($key, $value)
|
||||
{
|
||||
$data = self::isExist($key) ? self::get($key) : [];
|
||||
if (array_search($value, $data) === false) {
|
||||
array_push($data, $value);
|
||||
self::set($key, $data);
|
||||
}
|
||||
return count($data);
|
||||
}
|
||||
|
||||
public static function add($key, $value)
|
||||
{
|
||||
$data = self::isExist($key) ? self::get($key) : [];
|
||||
if (array_search($value, $data) === false) {
|
||||
array_push($data, $value);
|
||||
self::set($key, $data);
|
||||
}
|
||||
return count($data);
|
||||
}
|
||||
public static function remove($key, $value)
|
||||
{
|
||||
$data = self::get($key);
|
||||
if (($index = array_search($value, $data)) !== false) {
|
||||
unset($data[$index]);
|
||||
}
|
||||
return self::set($key, $data);
|
||||
}
|
||||
|
||||
public static function remove($key, $value)
|
||||
{
|
||||
$data = self::get($key);
|
||||
if (($index = array_search($value, $data)) !== false) {
|
||||
unset($data[$index]);
|
||||
}
|
||||
return self::set($key, $data);
|
||||
}
|
||||
public static function isExist($key)
|
||||
{
|
||||
return session()->has($key);
|
||||
}
|
||||
|
||||
public static function isExist($key)
|
||||
{
|
||||
return session()->has($key);
|
||||
}
|
||||
public static function reset($key)
|
||||
{
|
||||
return session()->forget($key);
|
||||
}
|
||||
|
||||
public static function reset($key)
|
||||
{
|
||||
return session()->forget($key);
|
||||
}
|
||||
|
||||
public static function resetAll()
|
||||
{
|
||||
return session()->flush();
|
||||
}
|
||||
public static function resetAll()
|
||||
{
|
||||
return session()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,16 +37,24 @@ class NewUser extends Notification
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
|
||||
->line(__('notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->line(
|
||||
__(
|
||||
'notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]
|
||||
)
|
||||
)
|
||||
->action(
|
||||
__('notifications.newuser.button'),
|
||||
route('users.firstlogin', $notifiable->remember_token)
|
||||
)
|
||||
->salutation(__('notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->salutation(
|
||||
__(
|
||||
'notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]
|
||||
)
|
||||
)
|
||||
->line(__('notifications.newuser.outro'));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
/*
|
||||
/*
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
@@ -27,5 +27,5 @@ class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
)
|
||||
->line(__('notifications.resetpassword.outro'));
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use App\Models\Core\Auth\PasswordReset;
|
||||
|
||||
class PasswordResets
|
||||
{
|
||||
|
||||
public static function getTokenByEmail($email)
|
||||
{
|
||||
return PasswordReset::byEmail($email)->first();
|
||||
|
||||
18
app/Repositories/Core/User/ShopCart.php
Normal file
18
app/Repositories/Core/User/ShopCart.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
|
||||
class ShopCart
|
||||
{
|
||||
public static function add($data)
|
||||
{
|
||||
return self::get()->add($data);
|
||||
}
|
||||
|
||||
public static function get()
|
||||
{
|
||||
return \Cart::session(Users::getId());
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ use App\Models\Shop\ArticleComponent;
|
||||
|
||||
class ArticleComponents
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticleComponent::orderBy('name');
|
||||
@@ -21,7 +20,7 @@ class ArticleComponents
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticleComponent::orderBy('name','asc')->get();
|
||||
return ArticleComponent::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
@@ -32,7 +31,7 @@ class ArticleComponents
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
@@ -50,5 +49,4 @@ class ArticleComponents
|
||||
{
|
||||
return ArticleComponent::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,44 +2,35 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
use App\Models\Shop\ArticleNature;
|
||||
|
||||
use App\Models\Shop\ArticleFamily;
|
||||
|
||||
class ArticleFamilies
|
||||
class ArticleNatures
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticleFamily::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return ArticleFamily::get()->pluck('name','id')->toArray();
|
||||
return ArticleNature::get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticleFamily::orderBy('name','asc')->get();
|
||||
return ArticleNature::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticleFamily::find($id);
|
||||
return ArticleNature::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticleFamily::create($data);
|
||||
return ArticleNature::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
@@ -50,7 +41,6 @@ class ArticleFamilies
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticleFamily::destroy($id);
|
||||
return ArticleNature::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,87 +12,85 @@ use App\Models\Shop\ArticlePrice;
|
||||
|
||||
class ArticlePrices
|
||||
{
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return ArticlePrice::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return ArticlePrice::byArticle($id)->get();
|
||||
}
|
||||
public static function getByArticleWithAttribute($id)
|
||||
{
|
||||
return ArticlePrice::with('article_attribute.attribute_value')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithAttribute($id)
|
||||
{
|
||||
return ArticlePrice::with('article_attribute.attribute_value')->byArticle($id)->get();
|
||||
}
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticlePrice::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticlePrice::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticlePrice::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticlePrice::orderBy('name','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticlePrice::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticlePrice::find($id);
|
||||
}
|
||||
public static function storePrices($article_id, $prices)
|
||||
{
|
||||
// dump($article_id);
|
||||
// dump($prices);
|
||||
// exit;
|
||||
if ($prices) {
|
||||
foreach ($prices as $key => $price) {
|
||||
$price['article_attribute']['article_attribute_value_id'] = $price['attribute']['attribute_value_id'];
|
||||
$prices[$key]['article_attribute_id'] = ArticleAttributes::storeAttribute($article_id, $price['article_attribute']);
|
||||
|
||||
public static function storePrices($article_id, $prices)
|
||||
{
|
||||
// dump($article_id);
|
||||
// dump($prices);
|
||||
// exit;
|
||||
if ($prices) {
|
||||
foreach ($prices as $key => $price) {
|
||||
$price['article_attribute']['article_attribute_value_id'] = $price['attribute']['attribute_value_id'];
|
||||
$prices[$key]['article_attribute_id'] = ArticleAttributes::storeAttribute($article_id, $price['article_attribute']);
|
||||
unset($prices[$key]['article_attribute']);
|
||||
unset($prices[$key]['attribute']);
|
||||
self::store($prices[$key]);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unset($prices[$key]['article_attribute']);
|
||||
unset($prices[$key]['attribute']);
|
||||
self::store($prices[$key]);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$attributes = isset($data['attributes']) ? $data['attributes'] : false;
|
||||
unset($data['attributes']);
|
||||
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
|
||||
$ret = $attributes ? self::storeAttributes($price->id, $attributes) : false;
|
||||
|
||||
return $price->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$attributes = isset($data['attributes']) ? $data['attributes'] : false;
|
||||
unset($data['attributes']);
|
||||
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
|
||||
$ret = $attributes ? self::storeAttributes($price->id, $attributes) : false;
|
||||
|
||||
return $price->id;
|
||||
}
|
||||
|
||||
public static function storeAttributes($article_price_id,$attributes)
|
||||
{
|
||||
return ArticleAttributes::storeAttribute($article_price_id, $attributes);
|
||||
}
|
||||
public static function storeAttributes($article_price_id, $attributes)
|
||||
{
|
||||
return ArticleAttributes::storeAttribute($article_price_id, $attributes);
|
||||
}
|
||||
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticlePrice::create($data);
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticlePrice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$article = ArticlePrice::find($id);
|
||||
$article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticlePrice::destroy($id);
|
||||
}
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$article = ArticlePrice::find($id);
|
||||
$article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticlePrice::destroy($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,149 +12,178 @@ use App\Models\Shop\Article;
|
||||
|
||||
class Articles
|
||||
{
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Article::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Article::orderBy('name','asc')->get();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Article::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$data['article'] = $article->toArray();
|
||||
$data['article']['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['article']['tags'] = self::getTagsByArticle($article);
|
||||
$data['article']['prices'] = self::getPricesByArticle($article);
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$data['article'] = $article->toArray();
|
||||
$data['article']['inherited'] = self::getInherited($id);
|
||||
// dump($data);
|
||||
// exit;
|
||||
$data['article']['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['article']['tags'] = self::getTagsByArticle($article);
|
||||
// $data['article']['prices'] = self::getPricesByArticle($article);
|
||||
self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getMeta(&$data = [])
|
||||
{
|
||||
$data['products'] = ( ($data['article']['product_type'] ?? false) == 'App\Models\Botanic\Variety') ? Varieties::getOptionsWithSpecie() : Species::getOptions();
|
||||
$data['categories_options'] = Categories::getOptions();
|
||||
$data['price_generics'] = PriceGenericCategories::getOptionsWithChildrens();
|
||||
$data['families_options'] = ArticleFamilies::getOptions();
|
||||
$data['taxes_options'] = Taxes::getOptions();
|
||||
$data['packages'] = ($data['article']['article_family_id'] ?? false) ? Packages::getSelectByFamily($data['article']['article_family_id']) : [];
|
||||
$data['unities'] = ($data['packages']['id'] ?? false) ? Unities::getSelectByPackage($data['packages']['id']) : [];
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models_options'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
return $data;
|
||||
}
|
||||
public static function getInherited($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$product_type = $article->product_type;
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data[] = ['name' => 'Espèces', 'description' => Species::getDescription($article->product->specie_id), 'tags' => Species::getTags($article->product->specie_id)];
|
||||
$data[] = ['name' => 'Variétés', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$data[] = ['name' => 'Espèces', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$data[] = ['name' => 'Marchandise', 'description' => $article->product->description, 'tags' => $article->product->tags->toArray()];
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::with(['prices','product','image'])->get();
|
||||
}
|
||||
public static function getMeta(&$data = [])
|
||||
{
|
||||
$data['products'] = (($data['article']['product_type'] ?? false) == 'App\Models\Botanic\Variety') ? Varieties::getOptionsWithSpecie() : Species::getOptions();
|
||||
$data['categories_options'] = Categories::getOptions();
|
||||
$data['natures_options'] = ArticleNatures::getOptions();
|
||||
$data['packages'] = ($data['article']['article_family_id'] ?? false) ? Packages::getSelectByFamily($data['article']['article_family_id']) : [];
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models_options'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->with(['prices','product','image'])->get();
|
||||
}
|
||||
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
public static function getCategoriesByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return Prices::getByArticle($article->id);
|
||||
}
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Article::find($id);
|
||||
}
|
||||
public static function getPricesByArticle($article)
|
||||
{
|
||||
return Prices::getByArticle($article->id);
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$categories = isset($data['categories']) ? $data['categories'] : false;
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
unset($data['images']);
|
||||
unset($data['categories']);
|
||||
unset($data['tags']);
|
||||
unset($data['prices']);
|
||||
$article = self::store($data);
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
self::storePrices($article, $prices);
|
||||
return $article->id;
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Article::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$categories = isset($data['categories']) ? $data['categories'] : false;
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
unset($data['images']);
|
||||
unset($data['categories']);
|
||||
unset($data['tags']);
|
||||
unset($data['prices']);
|
||||
$article = self::store($data);
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
self::storePrices($article, $prices);
|
||||
return $article->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Article::create($data);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = self::get($id);
|
||||
$ret = $article->update($data);
|
||||
return $article;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Article::create($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Article::destroy($id);
|
||||
}
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = self::get($id);
|
||||
$ret = $article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if ($categories) {
|
||||
$categories = collect($categories)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->syncCategories($categories, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Article::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if ($categories) {
|
||||
$categories = collect($categories)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
return $article->syncCategories($categories, true);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
{
|
||||
return ArticlePrices::storePrices($article->id, $prices);
|
||||
}
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
return Media::storeImages($article, $files);
|
||||
}
|
||||
public static function storePrices($article, $prices)
|
||||
{
|
||||
return ArticlePrices::storePrices($article->id, $prices);
|
||||
}
|
||||
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return Media::storeImage($article, $file);
|
||||
}
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
return Media::storeImages($article, $files);
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return Media::storeImage($article, $file);
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
return Media::getThumbSrc($image);
|
||||
}
|
||||
public static function getImages($id)
|
||||
{
|
||||
return Media::getImages(self::get($id));
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
return Media::getThumbSrc($image);
|
||||
}
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
return Media::deleteImage(self::get($id), $index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ use App\Models\Shop\Category;
|
||||
|
||||
class Categories
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Category::orderBy('name');
|
||||
@@ -17,7 +16,7 @@ class Categories
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Category::orderBy('name','asc')->get();
|
||||
return Category::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
@@ -32,15 +31,15 @@ class Categories
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Category::get()->pluck('name','category_id')->toArray();
|
||||
return Category::get()->pluck('name', 'category_id')->toArray();
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
// $tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
// $tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
unset($data['images']);
|
||||
// unset($data['tags']);
|
||||
// unset($data['tags']);
|
||||
$category = self::store($data);
|
||||
self::storeImages($category, $images);
|
||||
// self::storeTags($category, $tags);
|
||||
@@ -50,23 +49,27 @@ class Categories
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function storeTags($category, $tags)
|
||||
{
|
||||
if ($tags) {
|
||||
$tags = collect($tags)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
$tags = collect($tags)->transform(
|
||||
function ($item, $key) {
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
return $category->syncTags($tags, true);
|
||||
} else return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImages($category, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($category, $file);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +120,7 @@ class Categories
|
||||
$id = $id ? $id : $data['id'];
|
||||
$category = Category::find($id);
|
||||
$ret = $category->update($data);
|
||||
CategoryTrees::update($data, $category->category_id);
|
||||
CategoryTrees::update($data, $category->category_id);
|
||||
return $category;
|
||||
}
|
||||
|
||||
@@ -132,5 +135,4 @@ class Categories
|
||||
{
|
||||
return app('rinvex.categories.category')->find(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,15 +8,14 @@ class CategoryTrees
|
||||
{
|
||||
public static function getTree()
|
||||
{
|
||||
$categories = app('rinvex.categories.category')->orderBy('_lft','asc')->get()->toTree()->toArray();
|
||||
$categories = app('rinvex.categories.category')->orderBy('_lft', 'asc')->get()->toTree()->toArray();
|
||||
return self::getChildren($categories[0]['children']);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getChildren($data)
|
||||
{
|
||||
$tree = [];
|
||||
foreach ($data as $item)
|
||||
{
|
||||
foreach ($data as $item) {
|
||||
$leaf = [];
|
||||
$leaf['name'] = $item['name'];
|
||||
$leaf['id'] = $item['id'];
|
||||
@@ -35,14 +34,14 @@ class CategoryTrees
|
||||
$category_target = self::getNode($target_id);
|
||||
|
||||
switch ($type) {
|
||||
case 'after':
|
||||
dump("$node_id After $target_id");
|
||||
$category->afterNode($category_target);
|
||||
break;
|
||||
case 'inside':
|
||||
dump("$node_id inside $target_id");
|
||||
$category_target->appendNode($category);
|
||||
break;
|
||||
case 'after':
|
||||
dump("$node_id After $target_id");
|
||||
$category->afterNode($category_target);
|
||||
break;
|
||||
case 'inside':
|
||||
dump("$node_id inside $target_id");
|
||||
$category_target->appendNode($category);
|
||||
break;
|
||||
}
|
||||
$category->save();
|
||||
return "1";
|
||||
@@ -77,5 +76,4 @@ class CategoryTrees
|
||||
{
|
||||
return app('rinvex.categories.category')->find($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,48 +6,46 @@ use App\Models\Shop\Customer;
|
||||
|
||||
class Customers
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Customer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Customer::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Customer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Customer::byPackage($package_id)->orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Customer::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Customer::orderBy('value','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Customer::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Customer::find($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Customer::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Customer::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return Customer::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Customer::destroy($id);
|
||||
}
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return Customer::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Customer::destroy($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,48 +6,46 @@ use App\Models\Shop\Invoice;
|
||||
|
||||
class Invoices
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Invoice::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Invoice::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Invoice::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Invoice::byPackage($package_id)->orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Invoice::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Invoice::orderBy('value','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Invoice::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Invoice::find($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Invoice::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Invoice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Invoice::destroy($id);
|
||||
}
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Invoice::destroy($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,48 +6,48 @@ use App\Models\Shop\Order;
|
||||
|
||||
class Orders
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Order::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Order::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Order::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Order::byPackage($package_id)->orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Order::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Order::orderBy('value','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Order::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Order::findOrFail($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Order::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Order::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return self::get($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Order::destroy($id);
|
||||
}
|
||||
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 Order::destroy($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,62 +2,54 @@
|
||||
|
||||
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\Package;
|
||||
|
||||
class Packages
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
public static function getOptions()
|
||||
{
|
||||
return Package::orderBy('value', 'asc')->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Package::orderBy('value','asc')->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Package::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getSelectByFamily($family_id)
|
||||
{
|
||||
return Package::orderBy('value','asc')->byArticleFamily($family_id)->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getName($id)
|
||||
{
|
||||
return self::get($id)->value;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Package::orderBy('value','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Package::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Package::find($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Package::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Package::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 update($data)
|
||||
{
|
||||
return Package::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Package::destroy($id);
|
||||
}
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Package::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\PriceGenericCategory;
|
||||
|
||||
class PriceGenericCategories
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = PriceGenericCategory::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceGenericCategory::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceGenericCategory::find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return PriceGenericCategory::get()->pluck('name','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsWithChildrens()
|
||||
{
|
||||
$prices = PriceGenericCategory::with('price_generics')->get();
|
||||
$data = [];
|
||||
foreach ($prices as $key => $price)
|
||||
{
|
||||
$data[$key]['label'] = $price->name;
|
||||
foreach($price->price_generics as $generic)
|
||||
{
|
||||
$data[$key]['options'][$generic->id] = $generic->name;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$category = $id ? self::update($data) : self::create($data);
|
||||
return $category->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceGenericCategory::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$category = PriceGenericCategory::find($id);
|
||||
$category->update($data);
|
||||
return $category;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return PriceGenericCategory::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\PriceGenericValue;
|
||||
|
||||
class PriceGenericValues
|
||||
{
|
||||
|
||||
public static function getByPriceGeneric($id)
|
||||
{
|
||||
return PriceGenericValue::byPriceGeneric($id)->get();
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = PriceGenericValue::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceGenericValue::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceGenericValue::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($generic_id, $values)
|
||||
{
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$value['price_generic_id'] = $generic_id;
|
||||
self::store($value);
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
return $price->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceGenericValue::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$article = PriceGenericValue::find($id);
|
||||
$article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return PriceGenericValue::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
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\PriceGeneric;
|
||||
|
||||
class PriceGenerics
|
||||
{
|
||||
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return PriceGeneric::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithValues($id)
|
||||
{
|
||||
return PriceGeneric::with('values')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = PriceGeneric::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
$model = PriceGeneric::with('category')->get()->toArray();
|
||||
dump($model);
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceGeneric::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceGeneric::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return PriceGeneric::with(['category','prices'])->find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$prices = isset($data['prices']) ? $data['prices'] : false;
|
||||
unset($data['prices']);
|
||||
$generic = $id ? self::update($data) : self::create($data);
|
||||
PriceGenericValues::storePrices($generic->id, $prices);
|
||||
return $generic->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceGeneric::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$generic = PriceGeneric::find($id);
|
||||
$generic->update($data);
|
||||
return $generic;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return PriceGeneric::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
67
app/Repositories/Shop/PriceListValues.php
Normal file
67
app/Repositories/Shop/PriceListValues.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\PriceListValue;
|
||||
|
||||
class PriceListValues
|
||||
{
|
||||
public static function getByPriceListValue($id)
|
||||
{
|
||||
return PriceListValue::byPriceListValue($id)->get();
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = PriceListValue::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceListValue::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceListValue::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($generic_id, $values)
|
||||
{
|
||||
foreach ($values as $value) {
|
||||
$value['price_generic_id'] = $generic_id;
|
||||
self::store($value);
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
return $price->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceListValue::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 PriceListValue::destroy($id);
|
||||
}
|
||||
}
|
||||
70
app/Repositories/Shop/PriceLists.php
Normal file
70
app/Repositories/Shop/PriceLists.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
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 getByArticle($id)
|
||||
{
|
||||
return PriceList::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithValues($id)
|
||||
{
|
||||
return PriceList::with('values')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return PriceList::with('prices')->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return PriceList::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return PriceList::find($id);
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return PriceList::with(['price_list_values'])->find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = $data['id'] ?? false;
|
||||
$price_list_values = $data['price_list_values'] ?? false;
|
||||
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;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return PriceList::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 PriceList::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -13,50 +13,51 @@ use App\Models\Shop\Price;
|
||||
|
||||
class Prices
|
||||
{
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
$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 getByArticle($id)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Price::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Price::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Price::orderBy('name','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Price::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Price::find($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Price::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Price::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Price::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Price::destroy($id);
|
||||
}
|
||||
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 Price::destroy($id);
|
||||
}
|
||||
}
|
||||
|
||||
48
app/Repositories/Shop/SaleChannels.php
Normal file
48
app/Repositories/Shop/SaleChannels.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\SaleChannel;
|
||||
|
||||
class SaleChannels
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return SaleChannel::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return SaleChannel::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return SaleChannel::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return SaleChannel::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 SaleChannel::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ use App\Models\Shop\TagGroup;
|
||||
|
||||
class TagGroups
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = TagGroup::query();
|
||||
@@ -17,8 +16,8 @@ class TagGroups
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return TagGroup::get()->SortBy('name')->pluck('name','id')->toArray();
|
||||
}
|
||||
return TagGroup::get()->SortBy('name')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTreeTags()
|
||||
{
|
||||
@@ -39,7 +38,7 @@ class TagGroups
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return TagGroup::orderBy('name','asc')->get();
|
||||
return TagGroup::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
@@ -50,7 +49,7 @@ class TagGroups
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
@@ -68,5 +67,4 @@ class TagGroups
|
||||
{
|
||||
return TagGroup::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use App\Models\Shop\Tag;
|
||||
|
||||
class Tags
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Tag::orderBy('name');
|
||||
@@ -21,12 +20,12 @@ class Tags
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tag::get()->pluck('name','id')->toArray();
|
||||
}
|
||||
return Tag::get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Tag::orderBy('order','asc')->get();
|
||||
return Tag::orderBy('order', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
@@ -37,7 +36,7 @@ class Tags
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
|
||||
48
app/Repositories/Shop/TariffUnities.php
Normal file
48
app/Repositories/Shop/TariffUnities.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\TariffUnity;
|
||||
|
||||
class TariffUnities
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return TariffUnity::orderBy('id', 'asc')->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return TariffUnity::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return TariffUnity::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return TariffUnity::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 TariffUnity::destroy($id);
|
||||
}
|
||||
}
|
||||
63
app/Repositories/Shop/Tariffs.php
Normal file
63
app/Repositories/Shop/Tariffs.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Tariff;
|
||||
|
||||
class Tariffs
|
||||
{
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Tariff::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tariff::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getStatuses()
|
||||
{
|
||||
return ['Actif','Suspendu','Invisible','Obsolete'];
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Tariff::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Tariff::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Tariff::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 Tariff::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ use App\Models\Shop\Tax;
|
||||
|
||||
class Taxes
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
return Datatables::of($model)->make(true);
|
||||
@@ -20,12 +19,12 @@ class Taxes
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tax::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
return Tax::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Tax::orderBy('value','asc')->get();
|
||||
return Tax::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
@@ -36,7 +35,7 @@ class Taxes
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
@@ -45,14 +44,16 @@ class Taxes
|
||||
return Tax::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
return Tax::find($id)->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Tax::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,48 +6,53 @@ use App\Models\Shop\Unity;
|
||||
|
||||
class Unities
|
||||
{
|
||||
public static function getOptions()
|
||||
{
|
||||
return Unity::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Unity::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Unity::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Unity::byPackage($package_id)->orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Unity::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Unity::orderBy('value','asc')->get();
|
||||
}
|
||||
public static function getName($id)
|
||||
{
|
||||
return self::get($id)->value;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Unity::find($id);
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Unity::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Unity::create($data);
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Unity::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
return Unity::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Unity::destroy($id);
|
||||
}
|
||||
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 Unity::destroy($id);
|
||||
}
|
||||
}
|
||||
|
||||
85
app/Repositories/Shop/Variations.php
Normal file
85
app/Repositories/Shop/Variations.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Variation;
|
||||
|
||||
class Variations
|
||||
{
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Variation::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
$variations = Variation::with(['package','unity'])->get();
|
||||
foreach ($variations as $variation) {
|
||||
$data[$variation->id] = self::getName($variation);
|
||||
}
|
||||
natsort($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getNameByID($id)
|
||||
{
|
||||
return self::getName(sef::getFull($id));
|
||||
}
|
||||
|
||||
public static function getName($variation)
|
||||
{
|
||||
return $variation->package->value . ' ' . $variation->quantity . ' ' . $variation->unity->value;
|
||||
}
|
||||
|
||||
public static function buildName($data)
|
||||
{
|
||||
return Packages::getName($data['package_id']) . ' ' . $data['quantity'] . ' ' . Unities::getName($data['unity_id']);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Variation::orderBy('value', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return Variation::with(['package','unity'])->findOrFail($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Variation::findOrFail($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['name'] = self::buildName($data);
|
||||
return Variation::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$variation = self::get($id);
|
||||
$data['name'] = self::buildName($data);
|
||||
$variation->update($data);
|
||||
return $variation;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Variation::destroy($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user