[WIP] Setup of skeleton

This commit is contained in:
Ludovic CANDELLIER
2020-03-25 00:08:27 +01:00
parent baf8e13c25
commit 36267139a1
377 changed files with 18248 additions and 26 deletions

View 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;
}
}

View 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;
}
}

View 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]]);
}
}

View 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();
}
}

View 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);
}
}

View 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();
}
}

View 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');
}
}

View 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 clients 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;
}
}

View 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)
{
}
}

View 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;
}
}

View 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;
}
}

View 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']);
}
}

View 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];
}
}
}

View 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');
}
}

View 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;
}
}

View 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();
}
}

View 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;
}
}

View 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 [
//
];
}
}

View 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'));
}
*/
}