[WIP] Setup of skeleton
This commit is contained in:
23
app/Repositories/ApplicationPages.php
Normal file
23
app/Repositories/ApplicationPages.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\ApplicationPage;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
class ApplicationPages
|
||||
{
|
||||
public static function getBySlug($application_id, $slug)
|
||||
{
|
||||
$app = ApplicationPage::active()->byApplication($application_id)->bySlug($slug)->first();
|
||||
return $app ? $app->toArray() : null;
|
||||
}
|
||||
|
||||
// récupère toutes les pages actives pour une application
|
||||
public static function getActiveByApplication($application_id)
|
||||
{
|
||||
$app = ApplicationPage::active()->byApplication($application_id)->get();
|
||||
return $app ? $app->toArray() : null;
|
||||
}
|
||||
}
|
||||
60
app/Repositories/Applications.php
Normal file
60
app/Repositories/Applications.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
use App\Models\Application;
|
||||
|
||||
use App\Repositories\ApplicationPages;
|
||||
use App\Repositories\Languages;
|
||||
|
||||
class Applications
|
||||
{
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Application::findOrFail($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getCurrent()
|
||||
{
|
||||
$route = explode('.', Route::currentRouteName());
|
||||
$app = isset($route[0]) ? $route[0] : null;
|
||||
$page = isset($route[1]) ? $route[1] : null;
|
||||
$action = isset($route[2]) ? $route[2] : null;
|
||||
|
||||
if (self::getBySlug($app)) {
|
||||
$data['current'] = self::getBySlug($app)->toArray();
|
||||
$application_id = $data['current']['id'];
|
||||
$data['page'] = ApplicationPages::getBySlug($application_id, $page);
|
||||
$data['pages'] = ApplicationPages::getActiveByApplication($application_id);
|
||||
$data['action'] = $action;
|
||||
} else {
|
||||
$data['current']['slug'] = $app;
|
||||
}
|
||||
$data['langs'] = Languages::getActive();
|
||||
$data['lang'] = Languages::getCurrent();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getActives()
|
||||
{
|
||||
return Application::active()->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getActivesWithModules()
|
||||
{
|
||||
return Application::with('modules')->active()->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getVisibles()
|
||||
{
|
||||
return Application::visible()->get()->toArray();
|
||||
}
|
||||
|
||||
public static function getBySlug($slug)
|
||||
{
|
||||
return Application::active()->bySlug($slug)->first();
|
||||
}
|
||||
}
|
||||
66
app/Repositories/Cities.php
Normal file
66
app/Repositories/Cities.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ville;
|
||||
|
||||
class Villes
|
||||
{
|
||||
public static function getVillesByName($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('nom', 'LIKE', "$query%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getVillesByCP($query)
|
||||
{
|
||||
return Ville::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))->where('code_postal', 'LIKE', "%q$guery%")->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getCPByVille($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
$codes = explode("-", $ville->code_postal);
|
||||
return $codes;
|
||||
}
|
||||
|
||||
public static function getNomByVille($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
return $ville->nom;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Ville::find($id);
|
||||
}
|
||||
|
||||
public static function getCoords($adresse)
|
||||
{
|
||||
// dd(app('geocoder')->geocode('Los Angeles, CA')->get());
|
||||
// dd(app('geocoder')->geocode('5 boulevard du Port, Amiens, France')->get());
|
||||
// dump($adresse);
|
||||
$geocode = app('geocoder')->geocode($adresse)->get();
|
||||
// dump($geocode);
|
||||
if (count($geocode)) {
|
||||
// dump($geocode);
|
||||
$res = $geocode[0]->getCoordinates()->toArray();
|
||||
// dump($res);
|
||||
$latitude = $res[0];
|
||||
$longitude = $res[1];
|
||||
// dump($latitude);
|
||||
// dump($longitude);
|
||||
return ['latitude' => $latitude, 'longitude' => $longitude];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCoordsByVille($id)
|
||||
{
|
||||
$ville = Ville::find($id);
|
||||
return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude];
|
||||
}
|
||||
}
|
||||
68
app/Repositories/Config.php
Normal file
68
app/Repositories/Config.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Session;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Repositories\Core\Cache;
|
||||
|
||||
class Config
|
||||
{
|
||||
public static function init()
|
||||
{
|
||||
$data = SuiteParameter::init();
|
||||
$data += Client::init();
|
||||
$data += Language::init();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function initHeader($options = false, $appOptions = false, $clientOptions = false, $adminOptions = false)
|
||||
{
|
||||
|
||||
$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');
|
||||
} else {
|
||||
Session::put('locale', 'fr');
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
48
app/Repositories/Core/Cache.php
Normal file
48
app/Repositories/Core/Cache.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use TheSeer\DirectoryScanner\DirectoryScanner;
|
||||
|
||||
class Cache
|
||||
{
|
||||
public static function getAutoVersion($file)
|
||||
{
|
||||
$filePath = public_path() . $file;
|
||||
|
||||
if (!file_exists($filePath)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$version = filemtime($filePath);
|
||||
|
||||
return '?v=' . $version;
|
||||
}
|
||||
|
||||
public static function getFilesVersion($folder, $type)
|
||||
{
|
||||
$folder = str_replace('.', '/', $folder);
|
||||
// dump($folder);
|
||||
// dump($type);
|
||||
// exit;
|
||||
$scanner = new DirectoryScanner;
|
||||
$scanner->addInclude('*.'.$type);
|
||||
// $scanner->addExclude('*filter*');
|
||||
// $scanner->addExclude('./src/*');
|
||||
$path = public_path() . '/' . $folder;
|
||||
|
||||
$data = [];
|
||||
foreach ($scanner($path) as $i) {
|
||||
// dump($i);
|
||||
$sub = $i->getPath();
|
||||
$sub = str_replace($path, '', $sub);
|
||||
$sub = str_replace('\\', '/', $sub);
|
||||
// dump($sub);
|
||||
$filename = '/' . $folder . $sub . '/' . $i->getFilename();
|
||||
// dump($filename);
|
||||
$mtime = $i->getMTime();
|
||||
$data[$filename] = $mtime;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
341
app/Repositories/Core/DataTable.php
Normal file
341
app/Repositories/Core/DataTable.php
Normal file
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Repositories\Core\Debug;
|
||||
|
||||
class DataTable
|
||||
{
|
||||
public static $is_debug = 0;
|
||||
|
||||
public static function render($data, $options)
|
||||
{
|
||||
$items = static::get($data, $options);
|
||||
$data = $items['elements'] ? $items['elements'] : array();
|
||||
$success = true;
|
||||
$message = '';
|
||||
|
||||
$json = [
|
||||
'success' => $success,
|
||||
'data' => $data,
|
||||
'message' => $message,
|
||||
'code' => $success ? 200 : 500,
|
||||
'recordsTotal' => $items['total'],
|
||||
'recordsFiltered' => $items['totalFiltered'],
|
||||
];
|
||||
|
||||
\Debugbar::disable();
|
||||
echo json_encode($json);
|
||||
|
||||
return $json;
|
||||
exit;
|
||||
|
||||
return response()->json($json);
|
||||
}
|
||||
|
||||
public static function get($data, $options = array())
|
||||
{
|
||||
// Debug::fdump($options);
|
||||
$model = self::getModel($options);
|
||||
$select = isset($options['select']) ? $options['select'] : '';
|
||||
$elements = new $model();
|
||||
$table = $elements->getTable();
|
||||
$real_id = $table . '.id';
|
||||
|
||||
$data2 = static::getElements($data, $options);
|
||||
// Debug::fdump($data2);
|
||||
$elements = $data2['elements'];
|
||||
$length = $data2['length'];
|
||||
$skip = $data2['skip'];
|
||||
$order = $data2['order'];
|
||||
$sort = $data2['sort'];
|
||||
|
||||
// Debug::fdump($elements->get()->toArray());
|
||||
//
|
||||
// Debug::fdump($order);
|
||||
// exit;
|
||||
|
||||
if (strpos($order, '.')) {
|
||||
$tab = explode('.', $order);
|
||||
$nb_model = count($tab) - 1;
|
||||
for ($i = 0; $i < $nb_model; $i++) {
|
||||
$controller = $tab[$i];
|
||||
if (isset($options['namespace'])) {
|
||||
$namespace = $options['namespace'];
|
||||
} else {
|
||||
$namespace = 'App\Models\\';
|
||||
}
|
||||
$jointModelObj = $namespace.ucfirst(Str::camel($controller));
|
||||
// Debug::fdump($controller);
|
||||
$jointModel = new $jointModelObj();
|
||||
$jointTable = $jointModel->getTable();
|
||||
// Debug::fdump($controller);
|
||||
// Debug::fdump($jointTable);
|
||||
if ($table !== $jointTable) {
|
||||
$elements = $elements->leftJoin($jointTable, $jointTable.'.id', '=', $controller.'_id');
|
||||
}
|
||||
$table = $controller;
|
||||
}
|
||||
$order = $jointTable . '.' . $tab[$nb_model];
|
||||
}
|
||||
|
||||
/*
|
||||
if (!empty($select)) {
|
||||
$elements = $elements->select('*',"$real_id as id", $select);
|
||||
} else {
|
||||
$elements = $elements->select('*',"$real_id as id");
|
||||
}
|
||||
*/
|
||||
// Debug::fdump($order);
|
||||
$elements = $elements->orderBy($order, $sort);
|
||||
|
||||
if (!empty($options['order']) && ($options['order'] !== $order)) {
|
||||
$elements = $elements->orderBy($options['order'], $options['sort']);
|
||||
}
|
||||
// Debug::dump($elements);
|
||||
if (isset($options['trash']) && $options['trash']) {
|
||||
$elements = $elements->withTrashed()->take($length)->skip($skip)->get();
|
||||
} else {
|
||||
$elements = $elements->take($length)->skip($skip)->get();
|
||||
}
|
||||
// Debug::dump($elements);
|
||||
|
||||
$tab = [
|
||||
'elements' => $elements->toArray(),
|
||||
'total' => $data2['total'],
|
||||
'totalFiltered' => $data2['totalFiltered']
|
||||
];
|
||||
|
||||
// dump($elements->toArray());
|
||||
|
||||
return $tab;
|
||||
}
|
||||
|
||||
public static function getModel($options)
|
||||
{
|
||||
// return '\App\Models\\'.$options['app'].$options['model'];
|
||||
return $options['model'];
|
||||
}
|
||||
|
||||
|
||||
public static function getElements($data, $options)
|
||||
{
|
||||
$vars = static::QueryBuilder($data, $options);
|
||||
// Debug::fdump($vars);
|
||||
$model = self::getModel($options);
|
||||
// Debug::dump($model);
|
||||
|
||||
$elements = new $model();
|
||||
$total = $elements::count();
|
||||
|
||||
// Debug::dump($vars);
|
||||
// exit;
|
||||
|
||||
if (is_array($vars)) {
|
||||
extract($vars);
|
||||
}
|
||||
// dump($order);
|
||||
if (empty($order)) {
|
||||
$order = $options['order'];
|
||||
$sort = $options['sort'];
|
||||
}
|
||||
|
||||
$with = (isset($options['with'])) ? $options['with'] : null;
|
||||
$withCount = (isset($options['withCount'])) ? $options['withCount'] : null;
|
||||
$where = (isset($vars['where'])) ? $vars['where'] : null;
|
||||
$searchcol = (isset($vars['searchcol'])) ? $vars['searchcol'] : null;
|
||||
$filter = (isset($vars['filter'])) ? $vars['filter'] : null;
|
||||
|
||||
Debug::dump($with);
|
||||
Debug::dump($withCount);
|
||||
Debug::dump($where);
|
||||
Debug::dump($searchcol);
|
||||
Debug::dump($filter);
|
||||
|
||||
$elements = ($with) ? $elements->with($with) : $elements;
|
||||
$elements = ($withCount) ? $elements->withCount($withCount) : $elements;
|
||||
$elements = ($where) ? $elements->whereRaw($where) : $elements;
|
||||
$elements = ($filter) ? $elements->whereRaw($filter) : $elements;
|
||||
|
||||
// Debug::fdump($elements->get()->toArray());
|
||||
// Debug::message($where);
|
||||
// exit;
|
||||
|
||||
$elements = static::addSearchFilter($elements, $hasfilters);
|
||||
$elements = static::addSearch($elements, $searchcol, $search);
|
||||
|
||||
Debug::dump($hasfilters);
|
||||
// dump($search);
|
||||
//
|
||||
|
||||
$totalFiltered = $elements->count();
|
||||
|
||||
// Debug::breakpoint($elements);
|
||||
// exit;
|
||||
|
||||
$data2 = [
|
||||
'elements' => $elements,
|
||||
'total' => $total,
|
||||
'totalFiltered' => $totalFiltered,
|
||||
'length' => $length,
|
||||
'skip' => $skip,
|
||||
'order' => $order,
|
||||
'sort' => $sort,
|
||||
];
|
||||
|
||||
// var_dump($data2['elements']->get()->toArray());
|
||||
return $data2;
|
||||
}
|
||||
|
||||
public static function addSearchFilter($elements, $hasfilters)
|
||||
{
|
||||
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']);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return $elements;
|
||||
}
|
||||
|
||||
public static function addSearch($elements, $searchcol, $search)
|
||||
{
|
||||
if (!empty($search)) {
|
||||
if (strpos($searchcol, '.')) {
|
||||
$tab = explode('.', $searchcol);
|
||||
$searchField = [
|
||||
'controller' => $tab[0],
|
||||
'field' => $tab[1],
|
||||
'search' => $search,
|
||||
];
|
||||
$elements = $elements->whereHas($searchField['controller'], function ($query) use ($searchField) {
|
||||
$query->where($searchField['field'], 'like', '%' . $searchField['search'] . '%');
|
||||
});
|
||||
} else {
|
||||
$elements = $elements->where($searchcol, 'like', "%$search%");
|
||||
}
|
||||
}
|
||||
return $elements;
|
||||
}
|
||||
|
||||
|
||||
public static function QueryBuilder($data, $options = array())
|
||||
{
|
||||
$model = self::getModel($options);
|
||||
$elements = new $model();
|
||||
$table = $elements->getTable();
|
||||
$filter = '';
|
||||
$hasfilters = array();
|
||||
// Debug::fdump($data);
|
||||
// Debug::message($data);
|
||||
// Debug::dump($options);
|
||||
// Debug::dump($data);
|
||||
|
||||
if (is_array($options) && is_array($options['likefields'])) {
|
||||
$likefields = $options['likefields'];
|
||||
}
|
||||
$length = isset($data['length']) ? (int) $data['length'] : 10;
|
||||
$skip = isset($data['start']) ? (int) $data['start'] : 0;
|
||||
if (isset($data['search'])) {
|
||||
$search = ($data['search']['value'] !== '') ? $data['search']['value'] : '';
|
||||
} else {
|
||||
$search = null;
|
||||
}
|
||||
|
||||
// Debug::fdump($data);
|
||||
if (isset($data['order'])) {
|
||||
if ($data['order'][0]['dir']) { //on est sur qu'un tri est en cours, pb de la colonne 0
|
||||
$sort = ($data['order'][0]['dir']);
|
||||
$order = self::getSortcol($data);
|
||||
}
|
||||
} else {
|
||||
$order = null;
|
||||
$sort = null;
|
||||
}
|
||||
|
||||
// Debug::dump($order);
|
||||
|
||||
if (isset($data['columns']) && is_array($data['columns'])) {
|
||||
foreach ($data['columns'] as $item) {
|
||||
$filter_search = $item['search']['value'];
|
||||
$filter_col = ($item['name']) ? $item['name'] : $item['data'];
|
||||
|
||||
// Debug::dump($filter_col);
|
||||
// Debug::dump($filter_search);
|
||||
// Debug::dump(is_null($filter_search));
|
||||
|
||||
if (!is_null($filter_search)) {
|
||||
// Debug::dump($item);
|
||||
// Debug::dump($filter_search);
|
||||
// Debug::dump($filter_col);
|
||||
|
||||
if (strpos($filter_col, '.')) {
|
||||
$tab = explode('.', $filter_col);
|
||||
if (is_array($likefields) && in_array($filter_col, $likefields)) {
|
||||
$like = true;
|
||||
} else {
|
||||
$like = false;
|
||||
}
|
||||
|
||||
$hasfilters[] = [
|
||||
'controller' => $tab[0],
|
||||
'field' => $tab[1],
|
||||
'search' => $filter_search,
|
||||
'like' => $like,
|
||||
];
|
||||
} else {
|
||||
// $filter_col = $table . '.' .$item['data'];
|
||||
$filter .= (!empty($filter)) ? ' and ' : '';
|
||||
if (is_array($likefields) && in_array($filter_col, $likefields)) {
|
||||
$filter .= "($table.$filter_col LIKE '%$filter_search%')";
|
||||
} else {
|
||||
$filter .= "($table.$filter_col = '$filter_search')";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['where'])) {
|
||||
$where = $data['where'];
|
||||
} else {
|
||||
$where = null;
|
||||
}
|
||||
|
||||
$options = [
|
||||
'length' => $length,
|
||||
'skip' => $skip,
|
||||
'search' => $search,
|
||||
'order' => $order,
|
||||
'sort' => $sort,
|
||||
'filter' => $filter,
|
||||
'hasfilters' => $hasfilters,
|
||||
'where' => $where,
|
||||
];
|
||||
|
||||
Debug::dump($options);
|
||||
return $options;
|
||||
}
|
||||
|
||||
public static function getSortcol($data)
|
||||
{
|
||||
$sortcol = $data['order'][0]['column'];
|
||||
if (!is_null($sortcol) && ($sortcol !== 0)) {
|
||||
if (!empty($data['columns'][$sortcol]['name'])) {
|
||||
$order = $data['columns'][$sortcol]['name'];
|
||||
} else {
|
||||
$order = $data['columns'][$sortcol]['data'];
|
||||
}
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
50
app/Repositories/Core/Database.php
Normal file
50
app/Repositories/Core/Database.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Collective\Html\Eloquent\FormAccessible;
|
||||
|
||||
class Database
|
||||
{
|
||||
public static function getForm($model)
|
||||
{
|
||||
$form = '';
|
||||
$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;
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
public static function getTableFields($model)
|
||||
{
|
||||
$table = new $model();
|
||||
$data = [];
|
||||
// get the column names for the table
|
||||
$columns = Schema::getColumnListing($table->getTable());
|
||||
foreach ($columns as &$column) {
|
||||
$type = Schema::getColumnType($table->getTable(), $column);
|
||||
array_push($data, ['name' => $column, 'type' => $type]);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getPopulate($model, $route, $id)
|
||||
{
|
||||
echo Form::model($model, ['route' => [$route.'.update', $id]]);
|
||||
}
|
||||
}
|
||||
52
app/Repositories/Core/DateHelper.php
Normal file
52
app/Repositories/Core/DateHelper.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use \Carbon\Carbon;
|
||||
use \League\Period\Period;
|
||||
|
||||
class DateHelper
|
||||
{
|
||||
public static function byDay()
|
||||
{
|
||||
return Carbon::now()->startOfDay();
|
||||
}
|
||||
|
||||
public static function byWeek()
|
||||
{
|
||||
return Carbon::now()->startOfWeek();
|
||||
}
|
||||
|
||||
public static function byMonth()
|
||||
{
|
||||
return Carbon::now()->startOfMonth();
|
||||
}
|
||||
|
||||
public static function byQuarter()
|
||||
{
|
||||
return Carbon::now()->startOfQuarter();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static function byYear()
|
||||
{
|
||||
return Carbon::now()->startOfYear();
|
||||
}
|
||||
}
|
||||
114
app/Repositories/Core/DateRange.php
Normal file
114
app/Repositories/Core/DateRange.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use \Carbon\Carbon;
|
||||
use \League\Period\Period;
|
||||
|
||||
class DateRange
|
||||
{
|
||||
public static function getPeriodsLastMonth($nb)
|
||||
{
|
||||
$end = static::lastMonth();
|
||||
$begin = $end->copy()->subMonth($nb);
|
||||
return static::getPeriodsbyMonth($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastWeek($nb)
|
||||
{
|
||||
$end = static::lastWeek();
|
||||
$begin = $end->copy()->subWeek($nb);
|
||||
return static::getPeriodsbyWeek($begin, $end);
|
||||
}
|
||||
|
||||
public static function getPeriodsLastDay($nb)
|
||||
{
|
||||
$end = 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 byWeek()
|
||||
{
|
||||
return [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()];
|
||||
}
|
||||
|
||||
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 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 lastMonth()
|
||||
{
|
||||
$start = Carbon::parse('first day of last month');
|
||||
$start->addMonth()->startOfDay();
|
||||
return $start;
|
||||
}
|
||||
|
||||
public static function lastWeek()
|
||||
{
|
||||
return Carbon::parse('last monday');
|
||||
}
|
||||
|
||||
public static function lastDay()
|
||||
{
|
||||
return Carbon::parse('yesterday');
|
||||
}
|
||||
|
||||
public static function getPeriodsbyMonth($begin, $end)
|
||||
{
|
||||
return (static::getPeriods($begin, $end, 'MONTH'));
|
||||
}
|
||||
|
||||
public static function getPeriodsbyWeek($begin, $end)
|
||||
{
|
||||
return (static::getPeriods($begin, $end, 'WEEK'));
|
||||
}
|
||||
|
||||
public static function getPeriodsbyDay($begin, $end)
|
||||
{
|
||||
return (static::getPeriods($begin, $end, 'DAY'));
|
||||
}
|
||||
|
||||
public static function getPeriods($begin, $end, $interval)
|
||||
{
|
||||
$period = new Period($begin, new \DateTime($end));
|
||||
foreach ($period->getDatePeriod("1 $interval") as $day) {
|
||||
$daterange[] = Period::createFromDuration($day->format('Y-m-d H:i:s'), "1 $interval");
|
||||
}
|
||||
return ($daterange);
|
||||
}
|
||||
}
|
||||
59
app/Repositories/Core/DateTime.php
Normal file
59
app/Repositories/Core/DateTime.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
public static function getLang()
|
||||
{
|
||||
return session('locale') ? session('locale') : 'fr';
|
||||
}
|
||||
|
||||
public static function convert($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y', $date)->isoFormat('Y-MM-DD') : null;
|
||||
}
|
||||
|
||||
public static function convertTime($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y H:i', $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function toFr($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
|
||||
public static function toFrTime($date)
|
||||
{
|
||||
return $date ? Carbon::parse($date)->isoFormat('DD/MM/Y HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function FromDatetimeFr($date)
|
||||
{
|
||||
return $date ? Carbon::createFromFormat('d/m/Y H:i:s', $date) : null;
|
||||
}
|
||||
|
||||
public static function DatetimeToStamp($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
public static function DatetimeToDate($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('DD/MM/Y') : null;
|
||||
}
|
||||
|
||||
public static function DatetimeToTime($date)
|
||||
{
|
||||
return $date ? self::FromDatetimeFr($date)->isoFormat('HH:mm') : null;
|
||||
}
|
||||
|
||||
public static function isPast($date)
|
||||
{
|
||||
return self::FromDatetimeFr($date)->isPast();
|
||||
}
|
||||
}
|
||||
297
app/Repositories/Core/Debug.php
Normal file
297
app/Repositories/Core/Debug.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use \League\CLImate\CLImate;
|
||||
use \Timer;
|
||||
|
||||
class Debug
|
||||
{
|
||||
|
||||
// $is_debug binaire 0 ou 1 debug, 0 ou 1 force output
|
||||
public static $_instance;
|
||||
public static $app;
|
||||
public static $debugbar;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
// $this->debugbar = DebugBar::getInstance()->debugbar;
|
||||
}
|
||||
|
||||
public static function isDebugbar()
|
||||
{
|
||||
return class_exists('Barryvdh\Debugbar\ServiceProvider') ? true : false;
|
||||
}
|
||||
|
||||
public static function isClockwork()
|
||||
{
|
||||
return class_exists('Clockwork\Support\Laravel\ClockworkServiceProvider') ? true : false;
|
||||
}
|
||||
|
||||
public static function start($var = '', $params = array(), $txt = '')
|
||||
{
|
||||
if (!static::isDebug()) {
|
||||
return false;
|
||||
}
|
||||
$var = (empty($var)) ? static::getMethod() : $var;
|
||||
$params = (empty($params)) ? static::getArgs() : $params;
|
||||
/*
|
||||
foreach ($params as $key => $value) {
|
||||
$params[$key] = substr($value,30);
|
||||
}
|
||||
*/
|
||||
// TODO Fixer la longueur des params string passés
|
||||
if (is_null($params)) {
|
||||
$params = array();
|
||||
}
|
||||
|
||||
Timer::start($var, $params);
|
||||
|
||||
if (static::isDebugbar()) {
|
||||
\Debugbar::startMeasure($var, $txt);
|
||||
}
|
||||
|
||||
if (static::isClockwork()) {
|
||||
// clock()->startEvent($var, $txt);
|
||||
}
|
||||
}
|
||||
|
||||
public static function stop($var = '')
|
||||
{
|
||||
if (!static::isDebug()) {
|
||||
return false;
|
||||
}
|
||||
$var = (empty($var)) ? static::getMethod() : $var;
|
||||
Timer::stop();
|
||||
|
||||
if (static::isDebugbar()) {
|
||||
\Debugbar::stopMeasure($var);
|
||||
}
|
||||
|
||||
if (static::isClockwork()) {
|
||||
// clock()->endEvent($var);
|
||||
}
|
||||
}
|
||||
|
||||
public static function render($force = false)
|
||||
{
|
||||
static::dump((string) Timer::result(), '', $force);
|
||||
}
|
||||
|
||||
public static function memory($force = false)
|
||||
{
|
||||
static::dump(memory_get_usage(), '', $force);
|
||||
}
|
||||
|
||||
public static function breakpoint($msg = '', $cat = '', $force = true)
|
||||
{
|
||||
static::dump($msg, $cat, $force);
|
||||
static::header('paramètres');
|
||||
static::dump(static::getArgs(), '', $force);
|
||||
static::footer('paramètres');
|
||||
static::render($force);
|
||||
static::backtrace($force);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* dump un message uniquement si debug est true
|
||||
* @param string $msg [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function message($msg, $cat = '')
|
||||
{
|
||||
if (static::isDebug()) {
|
||||
static::dump($msg, $cat);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* force la sortie d'un dump, sans passer par la debugbar ou test si debug est true
|
||||
* @param string $msg [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function fdump($msg, $cat = '')
|
||||
{
|
||||
static::dump($msg, $cat, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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]
|
||||
*/
|
||||
public static function dump($msg, $cat = '', $force = false)
|
||||
{
|
||||
$cat = $cat ? $cat : self::getClass();
|
||||
if ($force || self::isForcedOutput()) {
|
||||
dump(self::getLocation());
|
||||
dump($msg);
|
||||
}
|
||||
|
||||
if (self::isDebug()) {
|
||||
if (static::isCLI()) {
|
||||
self::dumpCli($msg, $cat);
|
||||
}
|
||||
if (static::isDebugbar()) {
|
||||
self::dumpDebugbar($msg, $cat);
|
||||
}
|
||||
if (static::isClockwork()) {
|
||||
self::dumpClockwork($msg, $cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function dumpDebugbar($msg, $cat = '', $force = false)
|
||||
{
|
||||
\Debugbar::addMessage(self::getLocation(), $cat);
|
||||
\Debugbar::addMessage($msg, $cat);
|
||||
}
|
||||
|
||||
public static function dumpClockwork($msg, $cat = '')
|
||||
{
|
||||
clock($msg);
|
||||
}
|
||||
|
||||
public static function dumpCli($msg, $cat = '')
|
||||
{
|
||||
$climate = new CLImate;
|
||||
// $climate->yellow()->bold()->out($message);
|
||||
// $climate->white()->bold()->out($output);
|
||||
// $climate->out($msg);
|
||||
// dump(self::getLocation());
|
||||
// dump($msg);
|
||||
}
|
||||
|
||||
public static function header($titre = '')
|
||||
{
|
||||
static::dump("*********** $titre ************");
|
||||
}
|
||||
|
||||
public static function footer($titre = '')
|
||||
{
|
||||
static::dump("*********** Fin $titre ************");
|
||||
}
|
||||
|
||||
public static function isDebug()
|
||||
{
|
||||
return self::getIsDebug() && 1;
|
||||
}
|
||||
|
||||
public static function isForcedOutput()
|
||||
{
|
||||
return self::getIsDebug() > 1;
|
||||
}
|
||||
|
||||
public static function getIsDebug()
|
||||
{
|
||||
$caller = (array) static::getCaller();
|
||||
// dump($caller);
|
||||
if ($caller['class']) {
|
||||
if (isset($caller['class']::$is_debug)) {
|
||||
$is_debug = $caller['class']::$is_debug;
|
||||
} else {
|
||||
$is_debug = false;
|
||||
}
|
||||
} else {
|
||||
dump("la isDebug::165");
|
||||
dump($caller);
|
||||
$is_debug = true;
|
||||
}
|
||||
return $is_debug;
|
||||
}
|
||||
|
||||
public static function backtrace($force = false)
|
||||
{
|
||||
$txt = '';
|
||||
$backtrace = debug_backtrace();
|
||||
$backtrace = array_reverse($backtrace);
|
||||
foreach ($backtrace as $item) {
|
||||
$caller = isset($item['class']) ? $item['class'] . $item['type'] . $item['function'] : $item['function'];
|
||||
$place = isset($item['file']) ? $item['file'] . ' at ' . $item['line'] : '';
|
||||
$txt .= "$caller | $place \n";
|
||||
}
|
||||
static::dump($txt, '', $force);
|
||||
// dump($backtrace);
|
||||
}
|
||||
|
||||
public static function getLocation()
|
||||
{
|
||||
return static::getMethod() . ' at ' . static::getFile() . ' line ' . static::getLine();
|
||||
}
|
||||
|
||||
public static function getMethod()
|
||||
{
|
||||
return (static::getClass() . static::getType() . static::getFunction());
|
||||
}
|
||||
|
||||
public static function getClass()
|
||||
{
|
||||
return static::getCaller()->class;
|
||||
}
|
||||
|
||||
public static function getFunction()
|
||||
{
|
||||
return static::getCaller()->function;
|
||||
}
|
||||
|
||||
public static function getType()
|
||||
{
|
||||
return static::getCaller()->type;
|
||||
}
|
||||
|
||||
public static function getArgs()
|
||||
{
|
||||
// dump(static::getCaller()->args);
|
||||
return static::getCaller()->args;
|
||||
}
|
||||
|
||||
public static function getLine()
|
||||
{
|
||||
return static::getParent()->line;
|
||||
}
|
||||
|
||||
public static function getFile()
|
||||
{
|
||||
return static::getParent()->file;
|
||||
}
|
||||
|
||||
public static function getCaller()
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
// dump($backtrace);
|
||||
$k = 1;
|
||||
while ($backtrace[$k]['class'] == 'App\Repositories\Core\Debug') {
|
||||
$k++;
|
||||
}
|
||||
return (object) $backtrace[$k];
|
||||
}
|
||||
|
||||
public static function getParent()
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
// dump($backtrace);
|
||||
$k = 1;
|
||||
while ($backtrace[$k]['class'] == 'App\Repositories\Core\Debug') {
|
||||
$k++;
|
||||
}
|
||||
return (object) $backtrace[$k - 1];
|
||||
}
|
||||
|
||||
public static function getRoot()
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
$object = isset($backtrace[0]['object']) ? $backtrace[0]['object'] : null;
|
||||
$k = 1;
|
||||
while (isset($backtrace[$k]) && (!isset($backtrace[$k]['object']) || $object === $backtrace[$k]['object'])) {
|
||||
$k++;
|
||||
}
|
||||
return isset($backtrace[$k]['object']) ? $backtrace[$k]['object'] : null;
|
||||
}
|
||||
|
||||
public static function isCLI()
|
||||
{
|
||||
return (PHP_SAPI == 'cli');
|
||||
}
|
||||
}
|
||||
159
app/Repositories/Core/Export.php
Normal file
159
app/Repositories/Core/Export.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Export
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '1G');
|
||||
$this->xls = new PHPExcel();
|
||||
}
|
||||
|
||||
public function create($filename, $stockage = false)
|
||||
{
|
||||
$this->sheet = $this->xls->setActiveSheetIndex(0);
|
||||
$this->filename = $filename;
|
||||
$this->stockage = $stockage;
|
||||
$this->lig = 1;
|
||||
}
|
||||
|
||||
public function setColumnsTitle($data)
|
||||
{
|
||||
$col = 0;
|
||||
foreach ($data as $value) {
|
||||
$this->writeTitle($this->lig, $col, $value);
|
||||
$col++;
|
||||
}
|
||||
$this->lig++;
|
||||
}
|
||||
|
||||
public function writeTitle($lig, $col, $txt)
|
||||
{
|
||||
$coord = $this->conv($lig, $col);
|
||||
$style = $this->sheet->getStyle($coord);
|
||||
$styleFont = $style->getFont();
|
||||
$styleFont->setBold(true);
|
||||
$styleFont->setSize(12);
|
||||
$styleFont->setName('Arial');
|
||||
// $styleFont->getColor()->setARGB(PHPExcel_Style_Color::COLOR_GREEN);
|
||||
$this->sheet->setCellValue($coord, $txt);
|
||||
if ($this->debug) {
|
||||
echo "Col $col Ligne $lig : $coord Text $txt<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
public function writeCell($lig, $col, $txt)
|
||||
{
|
||||
$coord = $this->conv($lig, $col);
|
||||
$this->sheet->setCellValue($coord, $txt);
|
||||
if ($this->debug) {
|
||||
echo "Col $col Ligne $lig : $coord Text $txt<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
public function exportRow($data, $config = null)
|
||||
{
|
||||
if ($config) {
|
||||
$vars = $config['vars'];
|
||||
$options = $config['options'];
|
||||
$multioptions = $config['multioptions'];
|
||||
}
|
||||
$col = 0;
|
||||
if (is_array($vars)) {
|
||||
foreach ($vars as $key) {
|
||||
$txt = $data[$key];
|
||||
if (isset($options[$key])) {
|
||||
$txt = $options[$key][$txt];
|
||||
}
|
||||
if (isset($multioptions[$key])) {
|
||||
$tabs = BaseController::getReverseMultiOptions($txt);
|
||||
foreach ($tabs as $key2 => $value) {
|
||||
$txt .= $multioptions[$key][$key2] . '\n';
|
||||
}
|
||||
}
|
||||
$this->writeCell($this->lig, $col, $txt);
|
||||
$this->nb++;
|
||||
$col++;
|
||||
}
|
||||
} else {
|
||||
foreach ($data as $value) {
|
||||
$txt = $value;
|
||||
$this->writeCell($this->lig, $col, $txt);
|
||||
$this->nb++;
|
||||
$col++;
|
||||
}
|
||||
}
|
||||
$this->lig++;
|
||||
}
|
||||
|
||||
public function header()
|
||||
{
|
||||
// Redirect output to a client’s web browser (Excel5)
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment;filename="' . $this->filename . '"');
|
||||
header('Cache-Control: max-age=0');
|
||||
// If you're serving to IE 9, then the following may be needed
|
||||
// header('Cache-Control: max-age=1');
|
||||
|
||||
// If you're serving to IE over SSL, then the following may be needed
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
|
||||
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||
header('Pragma: public'); // HTTP/1.0
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
if (!$this->debug) {
|
||||
// Debug::message($this->xls);
|
||||
$objWriter = PHPExcel_IOFactory::createWriter($this->xls, 'Excel2007');
|
||||
// Debug::message($objWriter);
|
||||
// exit;
|
||||
if (!$this->stockage) {
|
||||
$this->header();
|
||||
$objWriter->save('php://output');
|
||||
} else {
|
||||
// $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
|
||||
$objWriter->save('text.xlsx');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function conv($lig, $col)
|
||||
{
|
||||
$c = static::convColtoTxt($col);
|
||||
$lig = $this->lig;
|
||||
return ("$c$lig");
|
||||
}
|
||||
|
||||
public function convColtoTxt($col)
|
||||
{
|
||||
$col1 = $col % 26;
|
||||
$col2 = (int) floor($col / 26);
|
||||
if ($col2) {
|
||||
$c = chr(64 + $col2);
|
||||
} else {
|
||||
$c = '';
|
||||
}
|
||||
$c .= chr(65 + $col1);
|
||||
return ($c);
|
||||
}
|
||||
|
||||
public function getOption($var)
|
||||
{
|
||||
$data = $this->init();
|
||||
return ($data[$var . '_options']);
|
||||
}
|
||||
|
||||
public function getOptions($data)
|
||||
{
|
||||
$options = array();
|
||||
foreach ($data as $key => $value) {
|
||||
$var = substr($key, 0, -8);
|
||||
$options[$var] = $value;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
32
app/Repositories/Core/Geolocation.php
Normal file
32
app/Repositories/Core/Geolocation.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Geolocation
|
||||
{
|
||||
public static function getCoords($address, $zipcode, $city)
|
||||
{
|
||||
if (!empty($address) && !empty($zipcode) && !empty($city)) {
|
||||
$address = $address . ' , ' . $city . ' ' . $zipcode . ' , ' . 'France';
|
||||
|
||||
$geocode = app('geocoder')->geocode($address)->get();
|
||||
|
||||
if (count($geocode)) {
|
||||
$res = $geocode[0]->getCoordinates()->toArray();
|
||||
// dump($res);
|
||||
$longitude = $res[0];
|
||||
$latitude = $res[1];
|
||||
// dump($latitude);
|
||||
// dump($longitude);
|
||||
// exit;
|
||||
return ['latitude' => $latitude, 'longitude' => $longitude];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function autocomplete($query)
|
||||
{
|
||||
}
|
||||
}
|
||||
94
app/Repositories/Core/Menu/Builder.php
Normal file
94
app/Repositories/Core/Menu/Builder.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Support\Collection;
|
||||
use Lavary\Menu\Builder as LavaryMenuBuilder;
|
||||
|
||||
use App\Repositories\Users;
|
||||
|
||||
/**
|
||||
* Class Builder.
|
||||
*
|
||||
* @property Collection $items;
|
||||
*/
|
||||
class Builder extends LavaryMenuBuilder
|
||||
{
|
||||
private $root = [];
|
||||
|
||||
/**
|
||||
* Adds an item to the menu.
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $options
|
||||
*
|
||||
* @return \Lavary\Menu\Item|Item
|
||||
*/
|
||||
public function add($title, $options = '')
|
||||
{
|
||||
$title = sprintf('<span>%s</span>', $title);
|
||||
|
||||
$id = isset($options['id']) ? $options['id'] : $this->id();
|
||||
|
||||
$item = new Item($this, $id, $title, $options);
|
||||
|
||||
if (isset($options['icon'])) {
|
||||
$item->icon($options['icon']);
|
||||
}
|
||||
|
||||
if (isset($options['role']) || isset($options['permission'])) {
|
||||
$ability = ['admin'];
|
||||
if (isset($options['role'])) {
|
||||
$ability = $ability + explode(',', $options['role']);
|
||||
}
|
||||
|
||||
$permission = null;
|
||||
if (isset($options['permission'])) {
|
||||
$permission = explode(',', $options['permission']);
|
||||
}
|
||||
|
||||
$currentUser = Auth::user();
|
||||
|
||||
if ($currentUser && $currentUser->ability($ability, $permission)) {
|
||||
$this->items->push($item);
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->items->push($item);
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 string $options
|
||||
*
|
||||
* @return Lavary\Menu\Item
|
||||
*/
|
||||
public function addTo($id, $title, $options = '')
|
||||
{
|
||||
$parent = $this->whereId($id)->first();
|
||||
|
||||
if (isset($parent)) {
|
||||
if (!isset($this->root[$parent->id])) {
|
||||
$parent->attr(['url' => '#', 'class' => 'treeview']);
|
||||
// $str = '<span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>';
|
||||
// $parent->append($str);
|
||||
$this->root[$parent->id] = true;
|
||||
}
|
||||
|
||||
$item = $parent->add($title, $options);
|
||||
} else {
|
||||
$item = $this->add($title, $options);
|
||||
}
|
||||
|
||||
$item->icon('circle-o');
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
77
app/Repositories/Core/Menu/Item.php
Normal file
77
app/Repositories/Core/Menu/Item.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use Lavary\Menu\Item as LavaryMenuItem;
|
||||
|
||||
class Item extends LavaryMenuItem
|
||||
{
|
||||
/**
|
||||
* Set the item icon using font-awesome.
|
||||
*
|
||||
* @param $icon
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function icon($icon)
|
||||
{
|
||||
$this->prepend(sprintf('<i class="%s"></i>', $icon));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item order.
|
||||
*
|
||||
* @param $order
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function order($order)
|
||||
{
|
||||
$this->data('order', $order);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the item active.
|
||||
*
|
||||
* @param string|array $routes
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function activeIfRoute($routes = null)
|
||||
{
|
||||
if (!empty($routes)) {
|
||||
if (is_string($routes)) {
|
||||
$routes = [$routes];
|
||||
}
|
||||
|
||||
foreach ($routes as $pattern) {
|
||||
$arr = [$pattern];
|
||||
if (if_route_pattern($arr)) {
|
||||
$this->activate();
|
||||
|
||||
if (strstr($this->title, 'circle-o')) {
|
||||
$this->title = str_replace('fa-circle-o', 'fa-dot-circle-o', $this->title);
|
||||
}
|
||||
// dump($this);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$activeClass = $this->builder->conf('active_class');
|
||||
$this->attributes['class'] = Builder::formatGroupClass(['class' => $activeClass], $this->attributes);
|
||||
$this->isActive = true;
|
||||
|
||||
if (strstr($this->title, 'circle-o')) {
|
||||
$this->title = str_replace('fa-circle-o', 'fa-dot-circle-o', $this->title);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
27
app/Repositories/Core/Menu/Logs.php
Normal file
27
app/Repositories/Core/Menu/Logs.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Sebastienheyd\Boilerplate\Menu;
|
||||
|
||||
use Sebastienheyd\Boilerplate\Menu\Builder as Builder;
|
||||
|
||||
class Logs
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add(__('boilerplate::logs.menu.category'), ['permission' => 'logs', 'icon' => 'list'])
|
||||
->id('logs')
|
||||
->order(1100);
|
||||
|
||||
$menu->addTo('logs', __('boilerplate::logs.menu.stats'), [
|
||||
'route' => 'boilerplate.logs.dashboard',
|
||||
'permission' => 'logs', ])
|
||||
->order(1110)
|
||||
->activeIfRoute('boilerplate.logs.dashboard');
|
||||
|
||||
$menu->addTo('logs', __('boilerplate::logs.menu.reports'), [
|
||||
'route' => 'boilerplate.logs.list',
|
||||
'permission' => 'logs', ])
|
||||
->order(1120)
|
||||
->activeIfRoute(['boilerplate.logs.list', 'boilerplate.logs.show', 'boilerplate.logs.filter']);
|
||||
}
|
||||
}
|
||||
29
app/Repositories/Core/Menu/Menu.php
Normal file
29
app/Repositories/Core/Menu/Menu.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use Lavary\Menu\Menu as LavaryMenu;
|
||||
use View;
|
||||
|
||||
class Menu extends LavaryMenu
|
||||
{
|
||||
public function make($name, $callback)
|
||||
{
|
||||
if (is_callable($callback)) {
|
||||
if (!array_key_exists($name, $this->menu)) {
|
||||
$this->menu[$name] = new Builder($name, $this->loadConf($name));
|
||||
}
|
||||
|
||||
// Registering the items
|
||||
call_user_func($callback, $this->menu[$name]);
|
||||
|
||||
// Storing each menu instance in the collection
|
||||
$this->collection->put($name, $this->menu[$name]);
|
||||
|
||||
// Make the instance available in all views
|
||||
View::share($name, $this->menu[$name]);
|
||||
|
||||
return $this->menu[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
33
app/Repositories/Core/Menu/Users.php
Normal file
33
app/Repositories/Core/Menu/Users.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Menu;
|
||||
|
||||
use App\Repositories\Core\Menu\Builder as Builder;
|
||||
|
||||
class Users
|
||||
{
|
||||
public function make(Builder $menu)
|
||||
{
|
||||
$menu->add(__('boilerplate::layout.access'), ['icon' => 'users'])
|
||||
->id('access')
|
||||
->order(1000);
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.list.title'), [
|
||||
'route' => 'boilerplate.users.index',
|
||||
'permission' => 'users_crud', ])
|
||||
->activeIfRoute(['boilerplate.users.index', 'boilerplate.users.edit']);
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.create.title'), [
|
||||
'route' => 'boilerplate.users.create',
|
||||
'permission' => 'users_crud', ])
|
||||
->activeIfRoute('boilerplate.users.create');
|
||||
|
||||
$menu->addTo('access', __('boilerplate::layout.role_management'), [
|
||||
'route' => 'boilerplate.roles.index',
|
||||
'permission' => 'roles_crud', ])
|
||||
->activeIfRoute('boilerplate.roles.*');
|
||||
|
||||
$menu->addTo('access', __('boilerplate::users.profile.title'), ['route' => 'boilerplate.user.profile'])
|
||||
->activeIfRoute('boilerplate.user.profile');
|
||||
}
|
||||
}
|
||||
21
app/Repositories/Core/Number.php
Normal file
21
app/Repositories/Core/Number.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Stillat\Numeral\Languages\LanguageManager;
|
||||
use Stillat\Numeral\Numeral;
|
||||
|
||||
class Number
|
||||
{
|
||||
public static function price($value)
|
||||
{
|
||||
$formatter = new Numeral;
|
||||
$languageManager = new LanguageManager;
|
||||
$languageManager->setCulture('fr-FR');
|
||||
|
||||
$formatter->setLanguageManager($languageManager);
|
||||
|
||||
$price = $formatter->format($value, '0,0');
|
||||
return $price;
|
||||
}
|
||||
}
|
||||
187
app/Repositories/Core/Stat.php
Normal file
187
app/Repositories/Core/Stat.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Stat
|
||||
{
|
||||
public static $is_debug = false;
|
||||
public static $force_output = true;
|
||||
private static $_instance;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
public static function renderStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyMultiVar($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsbyVar($var)
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyVar($var));
|
||||
}
|
||||
|
||||
public static function renderStatsbyOptions($var, $var_option = '')
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyOptions($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsJson($data)
|
||||
{
|
||||
Response::headers()->set('Content-Type', 'application/json');
|
||||
Response::setBody(json_encode($data, JSON_NUMERIC_CHECK));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fonctions internes
|
||||
*/
|
||||
|
||||
public static function getStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
if (empty($var_option)) {
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
return self::getInstance()->getStatsbyMultiOptions($var, $options);
|
||||
}
|
||||
|
||||
public static function getCountByPeriod($var, $begin, $end)
|
||||
{
|
||||
$count = static::getModel()
|
||||
->whereBetween($var, $begin, $end)
|
||||
->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
public static function getCountbyVar($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = static::getModel()
|
||||
->select($db::raw("count(id) as y, $var as name"))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
// var_Debug::message($data);
|
||||
return ($data);
|
||||
}
|
||||
|
||||
|
||||
public static function getStatsbyOptions($var, $var_option = '')
|
||||
{
|
||||
if (empty($var_option)) {
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
$nb = static::getCountbyOption($var);
|
||||
// var_Debug::message($nb);
|
||||
foreach ($options as $key => $value) {
|
||||
$y = (int) $nb[$key];
|
||||
$data[] = ['y' => $y, 'name' => $value];
|
||||
}
|
||||
// var_Debug::message($data);
|
||||
return ($data);
|
||||
}
|
||||
|
||||
public static function getCountbyOption($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = static::getModel()
|
||||
->select($db::raw('count(id) as nb'))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($data[$key])) {
|
||||
$data[$key] = (int) $data[$key]['nb'];
|
||||
} else {
|
||||
$data[$key] = (int) $data[$key]->nb;
|
||||
}
|
||||
}
|
||||
return ($data);
|
||||
}
|
||||
|
||||
public static function getStatsbyMultiOptions($var, $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
$nb = static::getCountbyBin($var, $key);
|
||||
$data[] = ['y' => $nb, 'name' => $value];
|
||||
}
|
||||
return ($data);
|
||||
}
|
||||
|
||||
public static function getCountbyBin($var, $value)
|
||||
{
|
||||
$bit = pow(2, $value);
|
||||
$count = static::getModel()
|
||||
->where($var, '&', $bit)
|
||||
->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
public static function getStatsbyPeriod($begin = '', $end = '', $period = 'days')
|
||||
{
|
||||
$end = Carbon::now();
|
||||
$begin = Carbon::now()->subMonth(1);
|
||||
switch ($period) {
|
||||
case 'days':
|
||||
$periods = DateRange::getPeriodsbyDay($begin, $end);
|
||||
break;
|
||||
case 'months':
|
||||
$periods = DateRange::getPeriodsbyMonth($begin, $end);
|
||||
break;
|
||||
case 'weeks':
|
||||
$periods = DateRange::getPeriodsbyWeek($begin, $end);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return ($periods);
|
||||
}
|
||||
|
||||
public static function serializeValues($tab)
|
||||
{
|
||||
return static::serializeByVar($tab, 'count');
|
||||
}
|
||||
|
||||
public static function serializeByVar($tab, $var, $n = 0)
|
||||
{
|
||||
$collection = collect($tab);
|
||||
|
||||
if ($n) {
|
||||
$tab = $collection->pluck($var)->slice(-$n)->toArray();
|
||||
} else {
|
||||
$tab = $collection->pluck($var)->toArray();
|
||||
}
|
||||
|
||||
return implode(",", $tab);
|
||||
}
|
||||
|
||||
public static function avgByVar($tab, $var)
|
||||
{
|
||||
return collect($tab)->pluck($var)->avg();
|
||||
}
|
||||
}
|
||||
101
app/Repositories/Core/Upload.php
Normal file
101
app/Repositories/Core/Upload.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Facades\Image as Image;
|
||||
|
||||
class Upload
|
||||
{
|
||||
public static function getData($file)
|
||||
{
|
||||
$data['filename'] = $file->getClientOriginalName();
|
||||
$data['filetype'] = $file->extension();
|
||||
$data['filesize'] = $file->getSize();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getUuid($file, $data)
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
public static function store($file, $filepath)
|
||||
{
|
||||
return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function storePublic($file, $filepath)
|
||||
{
|
||||
// exit;
|
||||
$filepath = 'public/' . $filepath;
|
||||
return $file->store($filepath);
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
return Storage::delete($file);
|
||||
}
|
||||
|
||||
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 getPrivatePath($file)
|
||||
{
|
||||
return storage_path('app/' . 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 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 getThumbFilename($file, $sub = false)
|
||||
{
|
||||
$sub = $sub ? $sub : 'thumbs/';
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->filepath . '/' . $sub . self::getName($file);
|
||||
}
|
||||
|
||||
public static function getName($file)
|
||||
{
|
||||
$file = (is_array($file)) ? (object) $file : $file;
|
||||
return $file->uuid . '.' .$file->filetype;
|
||||
}
|
||||
}
|
||||
66
app/Repositories/Core/User/NewUser.php
Normal file
66
app/Repositories/Core/User/NewUser.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class NewUser extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$currentUser = \Auth::user();
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
|
||||
->line(__('notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->action(
|
||||
__('notifications.newuser.button'),
|
||||
route('users.firstlogin', $notifiable->remember_token)
|
||||
)
|
||||
->salutation(__('notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]))
|
||||
->line(__('notifications.newuser.outro'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Repositories/Core/User/ResetPassword.php
Normal file
31
app/Repositories/Core/User/ResetPassword.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
{
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
/*
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.resetpassword.subject'))
|
||||
->line(__('notifications.resetpassword.intro'))
|
||||
->action(
|
||||
__('notifications.resetpassword.button'),
|
||||
route('password.reset', $this->token)
|
||||
)
|
||||
->line(__('notifications.resetpassword.outro'));
|
||||
}
|
||||
*/
|
||||
}
|
||||
217
app/Repositories/Shop/Products.php
Normal file
217
app/Repositories/Shop/Products.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Product;
|
||||
|
||||
class Products
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = Product::with(['sections'])->orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function select_all()
|
||||
{
|
||||
return Product::select('id','name','active')->orderBy('name','asc')->get()->toArray();
|
||||
}
|
||||
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return Product::find($id)->toArray();
|
||||
}
|
||||
|
||||
public static function getId($Product = false)
|
||||
{
|
||||
$Product = self::get($Product);
|
||||
return $Product ? $Product->id : false;
|
||||
}
|
||||
|
||||
public static function get($Product = false)
|
||||
{
|
||||
$website = self::getWebsite($Product);
|
||||
return $website ? Product::byWebsite($website->id)->first() : false;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
if (!$id) {
|
||||
$Product_id = self::create($data);
|
||||
} else {
|
||||
$Product_id = self::update($data);
|
||||
}
|
||||
|
||||
ApplicationProducts::associate($Product_id, $data['applications']);
|
||||
|
||||
return $Product_id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$slug = Str::slug($data['slug'],'-');
|
||||
$url = $slug . '.' . Partners::getDomain();
|
||||
$website = Websites::create($url);
|
||||
$item = [];
|
||||
$item['website_id'] = $website->id;
|
||||
$item['name'] = $data['name'];
|
||||
$item['slug'] = $slug;
|
||||
$item['repository'] = $slug;
|
||||
$item['session_name'] = $slug . '_sess';
|
||||
$item['logo_image'] = 'logo.png';
|
||||
$item['background_image'] = 'login-background.jpg';
|
||||
$item['custom_css'] = 'Product.css';
|
||||
$item['active'] = true;
|
||||
$Product = Product::create($item);
|
||||
|
||||
$DB_system = Partners::getDBName();
|
||||
$sql = "GRANT SELECT ON `$DB_system`.* TO '" . $website->uuid . "'@localhost";
|
||||
DB::connection('system')->statement($sql);
|
||||
// GRANT SELECT ON `legstack`.* TO '828656d3463e45c0a33e9cc8b5c2f265'@'127.0.0.1';
|
||||
return $Product->id;
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
$Product = Product::find($id);
|
||||
|
||||
}
|
||||
|
||||
public static function getPublicPath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getLocalPath() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getPrivatePath renvoie le chemin complet du repertoire du tenant ]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getPrivatePath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getPrivateDir($repository, $Product);
|
||||
}
|
||||
|
||||
public static function getPrivateDir($repository = false, $Product = false)
|
||||
{
|
||||
return self::getLocalDir() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getRelativePath renvoie le chemin relatif au storage ]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getRelativePath($repository = false, $Product = false)
|
||||
{
|
||||
return self::getTenancyRoot() . self::getPath($repository, $Product);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getPath renvoie le chemin relatif à la tenancy root]
|
||||
* @param boolean $repository [description]
|
||||
* @param boolean $Product [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getPath($repository = false, $Product = false)
|
||||
{
|
||||
$path = '/'. self::getSlug($Product);
|
||||
$path .= $repository ? $repository : '';
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* [getStorage revoie le storage du tenant (local, S3, ...)]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getStorage()
|
||||
{
|
||||
return Storage::disk('tenant');
|
||||
}
|
||||
|
||||
public static function getDirectory()
|
||||
{
|
||||
return app(\Hyn\Tenancy\Website\Directory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* [getLocalDir renvoie le chemin complet vers la tenancy sur le disque]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getLocalDir()
|
||||
{
|
||||
return storage_path('app' . self::getTenancyRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* [getLocalPath revnoie le chemin public vers la tenancy publique]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getLocalPath()
|
||||
{
|
||||
return '/storage' . self::getTenancyRoot();
|
||||
}
|
||||
|
||||
public static function getSlug($Product = false)
|
||||
{
|
||||
if ($Product) {
|
||||
return $Product;
|
||||
}
|
||||
|
||||
$website = self::getWebsite();
|
||||
if ($website) {
|
||||
return($website->uuid);
|
||||
}
|
||||
|
||||
/*
|
||||
// regarde si le Product existe et qu'il possède au moins une licence valide pour une des applications
|
||||
$host = array_key_exists('HTTP_HOST', $_SERVER) ? $_SERVER['HTTP_HOST'] : 'legtech.legtech';
|
||||
$url_hostname = explode(".", $host); // décompose l'url de base
|
||||
$slug = $url_hostname[0];
|
||||
if ($slug == 'legstack') {
|
||||
$slug = 'legtech';
|
||||
}
|
||||
return $slug;
|
||||
*/
|
||||
}
|
||||
|
||||
// récupère les informations de connexion à la base du Product
|
||||
public static function getDatabaseEnvironment($Product_id)
|
||||
{
|
||||
return Product::byId($Product_id)->first()->toArray();
|
||||
}
|
||||
|
||||
public static function isProduct()
|
||||
{
|
||||
$website = self::getWebsite();
|
||||
$is_Product = $website ? true : false;
|
||||
return $is_Product;
|
||||
}
|
||||
|
||||
public static function getWebsite()
|
||||
{
|
||||
return \Hyn\Tenancy\Facades\TenancyFacade::website();
|
||||
}
|
||||
|
||||
public static function getWebsiteByProduct($id)
|
||||
{
|
||||
$Product = Product::find($id);
|
||||
return Website::find($Product->website_id);
|
||||
}
|
||||
|
||||
}
|
||||
80
app/Repositories/Teams.php
Normal file
80
app/Repositories/Teams.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
use Yajra\Datatables\Datatables;
|
||||
|
||||
use App\Team;
|
||||
use App\Models\TeamUser;
|
||||
|
||||
use App\Repositories\Users;
|
||||
|
||||
class Teams
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function getTeamsByUser($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : Users::getId();
|
||||
return TeamUser::byUser($user_id);
|
||||
}
|
||||
|
||||
public static function getUsersByTeam($id)
|
||||
{
|
||||
return TeamUser::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getUsersIdByTeam($id)
|
||||
{
|
||||
return self::getUsersByTeam($id)->pluck('user_id');
|
||||
}
|
||||
|
||||
public static function getUsersByTeam2($id)
|
||||
{
|
||||
return Team::find($id)->users();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Team::get()->pluck('name', 'id');
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Team::find($id);
|
||||
}
|
||||
|
||||
public static function getTable($id)
|
||||
{
|
||||
$datas = Team::with(['societe'])->withCount(['users']);
|
||||
return Datatables::of($datas)->make(true);
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
Users::destroyByUniqueTeam($id);
|
||||
return Team::destroy($id);
|
||||
}
|
||||
|
||||
public static function destroyBySociete($id)
|
||||
{
|
||||
$teams = Team::bySociete($id)->get();
|
||||
foreach ($teams as $team) {
|
||||
self::delete($team->id);
|
||||
}
|
||||
}
|
||||
|
||||
// ajoute une équipe/service/direction
|
||||
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);
|
||||
}
|
||||
}
|
||||
177
app/Repositories/Users.php
Normal file
177
app/Repositories/Users.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
use App\User;
|
||||
use App\Models\RoleUser;
|
||||
use App\Models\Societe;
|
||||
use App\Models\Hestimmo\Partenaire;
|
||||
|
||||
class Users
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
return (self::hasRole('admin')) ? true : false;
|
||||
}
|
||||
|
||||
public static function isPartenaire()
|
||||
{
|
||||
return (self::hasRole('partenaire')) ? self::getPartenaireId() : false;
|
||||
}
|
||||
|
||||
public static function isPromoteur()
|
||||
{
|
||||
return (self::hasRole('promoteur')) ? self::getPromoteurId() : false;
|
||||
}
|
||||
|
||||
public static function isCommercial()
|
||||
{
|
||||
return (self::hasRole('commercial')) ? true : false;
|
||||
}
|
||||
|
||||
public static function getPartenaireId($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
$partenaire = Partenaire::byUser($user_id)->first();
|
||||
return $partenaire ? $partenaire->id : null;
|
||||
}
|
||||
|
||||
public static function getPartenaire($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
return Societe::partenaireByUser($user_id)->first();
|
||||
}
|
||||
|
||||
public static function getPromoteurId($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
return Promoteur::byUser($user_id)->first()->id;
|
||||
}
|
||||
|
||||
public static function getPromoteur($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : self::getId();
|
||||
return Societe::promoteurByUser($user_id)->first();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return self::selectOptions()->orderBy('nom', 'asc')->whereRoleIs($role)->get();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return self::selectOptions()->get();
|
||||
}
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
public static function get($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
return User::find($id);
|
||||
}
|
||||
|
||||
public static function getUser()
|
||||
{
|
||||
return Auth::user();
|
||||
}
|
||||
|
||||
public static function isConnected()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
$t = RoleUser::byUser($id)->delete();
|
||||
return User::destroy($id);
|
||||
}
|
||||
|
||||
public static function getByTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->get();
|
||||
}
|
||||
|
||||
public static function destroyByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->delete();
|
||||
}
|
||||
|
||||
// récupère les champs de la table
|
||||
public static function get_field_table()
|
||||
{
|
||||
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
|
||||
}
|
||||
|
||||
// ajoute un utilisateur
|
||||
public static function insert($data)
|
||||
{
|
||||
return User::create($data);
|
||||
}
|
||||
|
||||
// récupère tous les utilisateurs
|
||||
public static function select_all()
|
||||
{
|
||||
return User::all()->toArray();
|
||||
}
|
||||
|
||||
|
||||
// met à jour les informations d'un utilisateur
|
||||
public static function update(Request $request)
|
||||
{
|
||||
return User::find($data['id'])->update($data);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user