minor fixes
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\City;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Cities
|
||||
{
|
||||
public static function getCitiesByName($query)
|
||||
{
|
||||
return City::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))
|
||||
->where('nom', 'LIKE', "{$query}%")
|
||||
->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getCitiesByCP($query)
|
||||
{
|
||||
return City::select('id', DB::raw("concat(nom,' (',code_postal,')') as text"))
|
||||
->where('code_postal', 'LIKE', "%{$query}%")
|
||||
->orderBy('nom', 'ASC')->take(30)->get();
|
||||
}
|
||||
|
||||
public static function getCPByCity($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
|
||||
return explode('-', $ville->code_postal);
|
||||
}
|
||||
|
||||
public static function getNomByCity($id)
|
||||
{
|
||||
$ville = self::get($id);
|
||||
|
||||
return $ville->nom;
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return City::find($id);
|
||||
}
|
||||
|
||||
public static function getCoords($adresse)
|
||||
{
|
||||
$geocode = app('geocoder')->geocode($adresse)->get();
|
||||
if (! count($geocode)) {
|
||||
return false;
|
||||
}
|
||||
$res = $geocode[0]->getCoordinates()->toArray();
|
||||
$latitude = $res[0];
|
||||
$longitude = $res[1];
|
||||
|
||||
return ['latitude' => $latitude, 'longitude' => $longitude];
|
||||
}
|
||||
|
||||
public static function getCoordsByCity($id)
|
||||
{
|
||||
$ville = City::find($id);
|
||||
|
||||
return ['latitude' => $ville->latitude, 'longitude' => $ville->longitude];
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\PasswordSecurity;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PasswordSecurities
|
||||
{
|
||||
public static function create($user_id, $delay = 90)
|
||||
{
|
||||
return PasswordSecurity::create([
|
||||
'user_id' => $user_id,
|
||||
'password_expiry_days' => $delay,
|
||||
'password_updated_at' => Carbon::now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getUserName($id)
|
||||
{
|
||||
return self::getUser($id)->username;
|
||||
}
|
||||
|
||||
public static function getUser($id)
|
||||
{
|
||||
return PasswordSecurity::with('user')->find($id)->user;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
class Passwords
|
||||
{
|
||||
public static function validator()
|
||||
{
|
||||
$validator = new \Password\Validator(new \Password\StringHelper());
|
||||
$validator->setMinLength(5);
|
||||
$validator->setMinLowerCaseLetters(2);
|
||||
$validator->setMinUpperCaseLetters(1);
|
||||
$validator->setMinNumbers(1);
|
||||
$validator->setMinSymbols(3);
|
||||
|
||||
if ($validator->isValid($password)) {
|
||||
printf('password %s is valid'.PHP_EOL, $password);
|
||||
} else {
|
||||
printf('password %s is invalid'.PHP_EOL, $password);
|
||||
var_dump($validator->getErrors());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\Permission;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Permissions
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getModules()
|
||||
{
|
||||
return Permission::select('module')->distinct('module')->get()->pluck('module');
|
||||
}
|
||||
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Permission::where('name', $name)->first();
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Permission::query();
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\Role;
|
||||
use App\Models\Core\Auth\RoleUser;
|
||||
use App\Traits\Model\Basic;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
class Roles
|
||||
{
|
||||
use Basic, LaratrustUserTrait;
|
||||
|
||||
public static function getListByRights()
|
||||
{
|
||||
$data = ! Auth::user()->hasRole('admin') ? Role::whereNotIn('name', ['admin'])->get() : Role::all();
|
||||
|
||||
return $data->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$permissions = array_keys($data['permissions']);
|
||||
unset($data['permissions']);
|
||||
$data['active'] = true;
|
||||
$role = Role::create($data);
|
||||
$role->attachPermissions($permissions);
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
public static function update($input, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $input['id'];
|
||||
$permissions = array_keys($input['permissions']);
|
||||
$role = self::get($id);
|
||||
$role->update(['name' => $input['name']]);
|
||||
$role->syncPermissions($permissions);
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
public static function toggleActive($id, $active)
|
||||
{
|
||||
return Role::find($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
public static function getWithPermissions($id)
|
||||
{
|
||||
$role = self::get($id)->toArray();
|
||||
$role['permissions'] = self::get($id)->permissions->pluck('id')->toArray();
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
public static function getByName($name)
|
||||
{
|
||||
return Role::where('name', $name)->first();
|
||||
}
|
||||
|
||||
public static function getRolesByUser($user_id = false)
|
||||
{
|
||||
$user_id = $user_id ? $user_id : Users::getId();
|
||||
|
||||
return RoleUser::byUser($user_id);
|
||||
}
|
||||
|
||||
public static function getUsersByRole($id)
|
||||
{
|
||||
return RoleUser::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getUsersIdByRole($id)
|
||||
{
|
||||
return self::getUsersByRole($id)->pluck('user_id');
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return RoleUser::query();
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\Team;
|
||||
use App\Models\Core\Auth\TeamUser;
|
||||
use App\Repositories\Users;
|
||||
use App\Traits\Model\Basic;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
class Teams
|
||||
{
|
||||
use Basic, 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 getByName($name)
|
||||
{
|
||||
return Team::where('name', $name)->first();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Team::query();
|
||||
}
|
||||
}
|
||||
@@ -9,57 +9,12 @@ use App\Traits\Model\Basic;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
|
||||
use Laratrust\Traits\LaratrustUserTrait;
|
||||
|
||||
class Users
|
||||
{
|
||||
use Basic, LaratrustUserTrait;
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
return self::hasRole('admin');
|
||||
}
|
||||
|
||||
public static function getInfo($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
if (! $id) {
|
||||
return false;
|
||||
}
|
||||
$user = self::get($id);
|
||||
$data = $user->toArray();
|
||||
$data['name'] = $user->name;
|
||||
$data['avatar'] = self::getAvatar($id);
|
||||
$data['roles'] = $user->roles->pluck('id')->toArray();
|
||||
$data['permissions'] = $user->allPermissions()->pluck('id')->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
if ($data['id'] ?? false) {
|
||||
unset($data['password']);
|
||||
}
|
||||
$user = $data['id'] ?? false ? self::update($data) : self::create($data);
|
||||
$user->roles()->sync(array_keys($data['roles'] ?? []));
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
$data['password'] = $data['password'] ?? Hash::make($data['password']);
|
||||
$data['remember_token'] = Str::random(32);
|
||||
$data['active'] = true;
|
||||
$user = User::create($data);
|
||||
PasswordSecurities::create($user->id);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function getId()
|
||||
{
|
||||
$user = self::getUser();
|
||||
@@ -94,98 +49,6 @@ class Users
|
||||
return User::orderBy('name')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
{
|
||||
$ret = RoleUser::byUser($id)->delete();
|
||||
|
||||
return User::destroy($id);
|
||||
}
|
||||
|
||||
public static function getListByRole($role)
|
||||
{
|
||||
return self::selectOptions()->orderBy('name')->whereRoleIs($role)->get();
|
||||
}
|
||||
|
||||
public static function hasRole($role, $user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
|
||||
return $user ? $user->hasRole($role) : false;
|
||||
}
|
||||
|
||||
public static function hasPermission($permission, $user = false)
|
||||
{
|
||||
if (self::isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
$user = $user ? $user : self::getUser();
|
||||
$permissions = self::getPermissions($user);
|
||||
|
||||
return $user ? self::checkPermission($permissions, $permission) : false;
|
||||
// TODO why is posing problem ???
|
||||
// return $user ? $user->hasPermission($permission) : false;
|
||||
}
|
||||
|
||||
public static function checkPermission($permissions, $permission)
|
||||
{
|
||||
if (! strpos($permission, '*')) {
|
||||
return in_array($permission, $permissions);
|
||||
}
|
||||
$permission = str_replace('*', '', $permission);
|
||||
foreach ($permissions as $item) {
|
||||
if (stripos($item, $permission) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getRoles($user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
|
||||
return $user ? $user->roles->pluck('name')->toArray() : false;
|
||||
}
|
||||
|
||||
public static function getRolesToEdit()
|
||||
{
|
||||
return Roles::getListByRights();
|
||||
}
|
||||
|
||||
public static function getPermissions($user = false)
|
||||
{
|
||||
$user = $user ? $user : self::getUser();
|
||||
|
||||
return $user ? $user->allPermissions()->pluck('name')->toArray() : false;
|
||||
}
|
||||
|
||||
public static function getByTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->get();
|
||||
}
|
||||
|
||||
public static function getByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->get();
|
||||
}
|
||||
|
||||
public static function destroyByUniqueTeam($id)
|
||||
{
|
||||
return User::byTeam($id)->byUniqueTeam()->delete();
|
||||
}
|
||||
|
||||
public static function getAvatar($user_id)
|
||||
{
|
||||
$avatar = self::get($user_id)->avatar;
|
||||
if (! $avatar) {
|
||||
return '/assets/img/no-avatar.png';
|
||||
}
|
||||
$path = '/images/avatars/';
|
||||
|
||||
return $path.$avatar;
|
||||
}
|
||||
|
||||
public static function selectOptions()
|
||||
{
|
||||
return User::select('id', DB::raw("concat(last_name,' ',first_name) as name"));
|
||||
@@ -201,24 +64,6 @@ class Users
|
||||
return self::get($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
public static function uploadAvatar($request)
|
||||
{
|
||||
$targetDir = 'uploads';
|
||||
$file = $request->file('avatar_file');
|
||||
$data = Upload::getData($file);
|
||||
$file_uploaded = Upload::store($file, $targetDir);
|
||||
$tab = pathinfo($file_uploaded);
|
||||
|
||||
return [
|
||||
'name' => $tab['basename'],
|
||||
];
|
||||
}
|
||||
|
||||
public static function updateAvatar($id, $avatar)
|
||||
{
|
||||
return User::find($id)->update(['avatar' => $avatar]);
|
||||
}
|
||||
|
||||
public static function updatePassword($id, $password)
|
||||
{
|
||||
$password = Hash::make($password);
|
||||
@@ -226,11 +71,6 @@ class Users
|
||||
return User::find($id)->update(['password' => $password]);
|
||||
}
|
||||
|
||||
public static function validate($username, $field = 'current_password')
|
||||
{
|
||||
return PasswordRules::changePassword($username, $field);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return User::query();
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Collective\Html\Eloquent\Form;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
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]]);
|
||||
}
|
||||
}
|
||||
@@ -1,172 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Export
|
||||
{
|
||||
public $xls;
|
||||
|
||||
public $sheet;
|
||||
|
||||
public $filename;
|
||||
|
||||
public $stockage;
|
||||
|
||||
public $lig;
|
||||
|
||||
public $nb;
|
||||
|
||||
public $debug;
|
||||
|
||||
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');
|
||||
$this->sheet->setCellValue($coord, $txt);
|
||||
}
|
||||
|
||||
public function writeCell($lig, $col, $txt)
|
||||
{
|
||||
$coord = $this->conv($lig, $col);
|
||||
$this->sheet->setCellValue($coord, $txt);
|
||||
}
|
||||
|
||||
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])) {
|
||||
$this->writeCell($this->lig, $col, $txt);
|
||||
$this->nb++;
|
||||
$col++;
|
||||
|
||||
continue;
|
||||
}
|
||||
$tabs = self::getReverseMultiOptions($txt);
|
||||
foreach ($tabs as $key2 => $value) {
|
||||
$txt .= $multioptions[$key][$key2].'\n';
|
||||
}
|
||||
|
||||
$this->writeCell($this->lig, $col, $txt);
|
||||
$this->nb++;
|
||||
$col++;
|
||||
}
|
||||
} 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) {
|
||||
return;
|
||||
}
|
||||
$objWriter = PHPExcel_IOFactory::createWriter($this->xls, 'Excel2007');
|
||||
if (! $this->stockage) {
|
||||
$this->header();
|
||||
$objWriter->save('php://output');
|
||||
} else {
|
||||
$objWriter->save('text.xlsx');
|
||||
}
|
||||
}
|
||||
|
||||
public function conv($lig, $col)
|
||||
{
|
||||
$c = static::convColtoTxt($col);
|
||||
|
||||
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 = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$var = substr($key, 0, -8);
|
||||
$options[$var] = $value;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
class Images
|
||||
{
|
||||
use Imageable;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailLog;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class MailLogs
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getSubject($id)
|
||||
{
|
||||
return MailParser::getSubject(self::get($id)->event);
|
||||
}
|
||||
|
||||
public static function getParsed($id)
|
||||
{
|
||||
return MailParser::getParsed(self::get($id)->event);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return MailLog::query();
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use ZBateson\MailMimeParser\Header\HeaderConsts;
|
||||
use ZBateson\MailMimeParser\MailMimeParser;
|
||||
|
||||
class MailParser
|
||||
{
|
||||
public static function getParsed($mail)
|
||||
{
|
||||
$model = self::getModel($mail);
|
||||
|
||||
return [
|
||||
'from' => self::getFromByModel($model),
|
||||
'subject' => self::getSubjectByModel($model),
|
||||
'content' => self::getHtmlByModel($model),
|
||||
'to_name' => self::getToNameByModel($model),
|
||||
'to_email' => self::getToEmailByModel($model),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSubject($mail)
|
||||
{
|
||||
return self::getSubjectByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getText($mail)
|
||||
{
|
||||
return self::getTextByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getHtml($mail)
|
||||
{
|
||||
return self::getHtmlByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getFrom($mail)
|
||||
{
|
||||
return self::getFromByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getToName($mail)
|
||||
{
|
||||
return self::getToNameByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getToEmail($mail)
|
||||
{
|
||||
return self::getToEmailByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getSubjectByModel($model)
|
||||
{
|
||||
return $model->getHeaderValue(HeaderConsts::SUBJECT);
|
||||
}
|
||||
|
||||
public static function getTextByModel($model)
|
||||
{
|
||||
return $model->getTextContent();
|
||||
}
|
||||
|
||||
public static function getFromByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::FROM)->getPersonName();
|
||||
}
|
||||
|
||||
public static function getToNameByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::TO)->getAddresses()[0]->getName();
|
||||
}
|
||||
|
||||
public static function getToEmailByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::TO)->getAddresses()[0]->getEmail();
|
||||
}
|
||||
|
||||
public static function getHtmlByModel($model)
|
||||
{
|
||||
return $model->getHtmlContent();
|
||||
}
|
||||
|
||||
public static function getModel($mail)
|
||||
{
|
||||
$mailParser = new MailMimeParser();
|
||||
|
||||
return $mailParser->parse($mail, false);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use View;
|
||||
|
||||
class Menu extends LavaryMenu
|
||||
{
|
||||
public function make($name, $callback)
|
||||
public function make($name, $callback, $arr = [])
|
||||
{
|
||||
if (! is_callable($callback)) {
|
||||
return;
|
||||
|
||||
@@ -2,41 +2,66 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Barryvdh\Debugbar\Facades\Debugbar;
|
||||
use Barryvdh\DomPDF\Facade\Pdf as DomPDF;
|
||||
use Barryvdh\Snappy\Facades\SnappyPdf;
|
||||
use GravityMedia\Ghostscript\Ghostscript;
|
||||
use Imagick;
|
||||
use Mpdf\Mpdf;
|
||||
use Spatie\PdfToText\Pdf as PDFToText;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class PDF
|
||||
{
|
||||
public function convertView($view, $data, $filename)
|
||||
{
|
||||
try {
|
||||
Browsershot::html(view($view, $data)->render())
|
||||
->noSandbox()
|
||||
->waitUntilNetworkIdle()
|
||||
->format('A4')
|
||||
->showBackground()
|
||||
->savePdf('temp.pdf');
|
||||
|
||||
$postRoute = URL::signedRoute('orderinvoices.store', ['order' => $this->order]);
|
||||
Http::attach('invoice', file_get_contents('temp.pdf'), $filename)
|
||||
->post($postRoute)
|
||||
->throw();
|
||||
} catch (\Exception $exception) {
|
||||
Log::error($exception);
|
||||
}
|
||||
}
|
||||
|
||||
public static function view($view, $data, $filename = 'file.pdf')
|
||||
{
|
||||
\Debugbar::disable();
|
||||
Debugbar::disable();
|
||||
$pdf = DomPDF::loadView($view, $data);
|
||||
|
||||
return $pdf->download($filename);
|
||||
}
|
||||
|
||||
public static function countPages($filename)
|
||||
{
|
||||
$image = new Imagick();
|
||||
$image->pingImage($filename);
|
||||
|
||||
return $image->getNumberImages();
|
||||
|
||||
/*
|
||||
$pdftext = file_get_contents($filename);
|
||||
|
||||
return preg_match_all("/\/Page\W*(\d+)/", $pdftext, $dummy);
|
||||
*/
|
||||
}
|
||||
|
||||
public function getPDFPages($document)
|
||||
{
|
||||
$cmd = '/path/to/pdfinfo'; // Linux
|
||||
$cmd = 'C:\\path\\to\\pdfinfo.exe'; // Windows
|
||||
|
||||
// Parse entire output
|
||||
// Surround with double quotes if file name has spaces
|
||||
exec("$cmd \"$document\"", $output);
|
||||
|
||||
// Iterate through lines
|
||||
$pagecount = 0;
|
||||
foreach ($output as $op) {
|
||||
// Extract the number
|
||||
if (preg_match("/Pages:\s*(\d+)/i", $op, $matches) === 1) {
|
||||
$pagecount = intval($matches[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $pagecount;
|
||||
}
|
||||
|
||||
public static function getText($filename)
|
||||
{
|
||||
return PDFToText::getText($filename);
|
||||
}
|
||||
|
||||
public static function convertHTML($html)
|
||||
{
|
||||
$mpdf = new Mpdf();
|
||||
@@ -45,11 +70,11 @@ class PDF
|
||||
return $mpdf->Output();
|
||||
}
|
||||
|
||||
public static function convertURL($url)
|
||||
public static function convertURL($url, $filename = 'sample.pdf')
|
||||
{
|
||||
$pdf = SnappyPdf::loadFile($url);
|
||||
|
||||
return $pdf->download('invoice.pdf');
|
||||
return $pdf->download($filename);
|
||||
}
|
||||
|
||||
public static function convertIfNeeded($filename)
|
||||
@@ -62,13 +87,14 @@ class PDF
|
||||
public static function getVersion($filename)
|
||||
{
|
||||
$pdf = fopen($filename, 'r');
|
||||
if ($pdf) {
|
||||
$line_first = fgets($pdf);
|
||||
fclose($pdf);
|
||||
} else {
|
||||
if (! $pdf) {
|
||||
echo 'error opening the file.';
|
||||
|
||||
return false;
|
||||
}
|
||||
preg_match_all('!\d+!', $line_first, $matches);
|
||||
$lineFirst = fgets($pdf);
|
||||
fclose($pdf);
|
||||
preg_match_all('!\d+!', $lineFirst, $matches);
|
||||
$version = implode('.', $matches[0]);
|
||||
|
||||
return (float) $version;
|
||||
@@ -76,35 +102,31 @@ class PDF
|
||||
|
||||
public static function downgrade($filename)
|
||||
{
|
||||
$new_filename = $filename.'-temp';
|
||||
$newFilename = $filename.'-temp';
|
||||
$ghostscript = new Ghostscript([
|
||||
'quiet' => false,
|
||||
]);
|
||||
|
||||
$device = $ghostscript->createPdfDevice($new_filename);
|
||||
$device = $ghostscript->createPdfDevice($newFilename);
|
||||
$device->setCompatibilityLevel(1.4);
|
||||
|
||||
// dump($device);
|
||||
$process = $device->createProcess($filename);
|
||||
// dump($process);
|
||||
// echo '$ ' . $process->getCommandLine() . PHP_EOL;
|
||||
// exit;
|
||||
|
||||
$process->run(function ($type, $buffer) {
|
||||
if ($type === Process::ERR) {
|
||||
throw new \RuntimeException($buffer);
|
||||
}
|
||||
// print $buffer;
|
||||
});
|
||||
|
||||
unlink($filename);
|
||||
rename($new_filename, $filename);
|
||||
rename($newFilename, $filename);
|
||||
}
|
||||
|
||||
public static function downgrade2($filename)
|
||||
{
|
||||
$new_filename = $filename.'-temp';
|
||||
shell_exec('gs -dBATCH -dCompatibilityLevel=1.4 -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="'.$new_filename.'" "'.$filename.'"');
|
||||
$newFilename = $filename.'-temp';
|
||||
$options = '-dBATCH -dCompatibilityLevel=1.4 -dNOPAUSE -q -sDEVICE=pdfwrite';
|
||||
shell_exec("gs {$options} -sOutputFile=\"{$newFilename}\" \"{$filename}\"");
|
||||
unlink($filename);
|
||||
rename($new_filename, $filename);
|
||||
rename($newFilename, $filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Stat
|
||||
{
|
||||
public static $is_debug = false;
|
||||
|
||||
public static $force_output = true;
|
||||
|
||||
public static function getNewByPeriod($model, $start, $end)
|
||||
{
|
||||
return $model->whereBetween('created_at', [$start, $end])->count();
|
||||
}
|
||||
|
||||
public static function getTotalAtDate($model, $end)
|
||||
{
|
||||
return $model->where('created_at', '<', $end)->count();
|
||||
}
|
||||
|
||||
public static function renderStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
self::renderStatsJson(self::getStatsbyMultiVar($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsbyVar($var)
|
||||
{
|
||||
self::renderStatsJson(self::getStatsbyVar($var));
|
||||
}
|
||||
|
||||
public static function renderStatsbyOptions($var, $var_option = '')
|
||||
{
|
||||
self::renderStatsJson(self::getStatsbyOptions($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsJson($data)
|
||||
{
|
||||
return json_encode($data, JSON_NUMERIC_CHECK);
|
||||
}
|
||||
|
||||
public static function getStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
if ($var_option) {
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getOption($var_option);
|
||||
|
||||
return self::getStatsbyMultiOptions($var, $options);
|
||||
}
|
||||
|
||||
public static function getCountByPeriod($var, $begin, $end)
|
||||
{
|
||||
return self::getModel()
|
||||
->whereBetween($var, $begin, $end)
|
||||
->count();
|
||||
}
|
||||
|
||||
public static function getCountbyVar($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
|
||||
return self::getModel()
|
||||
->select($db::raw("count(id) as y, {$var} as name"))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function getStatsbyOptions($var, $var_option = '')
|
||||
{
|
||||
if ($var_option ?? false) {
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
$nb = self::getCountbyOption($var);
|
||||
$data = [];
|
||||
foreach ($options as $key => $value) {
|
||||
$y = (int) $nb[$key];
|
||||
$data[] = ['y' => $y, 'name' => $value];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getCountbyOption($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = self::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)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($options as $key => $value) {
|
||||
$nb = self::getCountbyBin($var, $key);
|
||||
$data[] = ['y' => $nb, 'name' => $value];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getCountbyBin($var, $value)
|
||||
{
|
||||
$bit = pow(2, $value);
|
||||
|
||||
return self::getModel()->where($var, '&', $bit)->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 self::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();
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,10 @@ class Trees
|
||||
return $tree;
|
||||
}
|
||||
|
||||
public static function moveTree($node_id, $target_id, $type)
|
||||
public static function moveTree($node_id, $target_id, $type, $model)
|
||||
{
|
||||
$item = self::getNode($node_id);
|
||||
$item_target = self::getNode($target_id);
|
||||
$item = self::getNode($node_id, $model);
|
||||
$item_target = self::getNode($target_id, $model);
|
||||
|
||||
switch ($type) {
|
||||
case 'after':
|
||||
@@ -49,7 +49,7 @@ class Trees
|
||||
|
||||
public static function create($data, $model)
|
||||
{
|
||||
$parent = $data['parent_id'] ?? false ? self::getNode($data['parent_id']) : self::getRoot();
|
||||
$parent = $data['parent_id'] ?? false ? self::getNode($data['parent_id'], $model) : self::getRoot($model);
|
||||
$tree = $model->create(['name' => $data['name']]);
|
||||
$tree->appendToNode($parent)->save();
|
||||
|
||||
@@ -69,9 +69,9 @@ class Trees
|
||||
// return Category::destroy($id);
|
||||
}
|
||||
|
||||
public static function getRoot()
|
||||
public static function getRoot($model)
|
||||
{
|
||||
return self::getNode(1);
|
||||
return self::getNode(1, $model);
|
||||
}
|
||||
|
||||
public static function getNode($id, $model)
|
||||
|
||||
@@ -10,24 +10,19 @@ class BasketStores
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public function has($key)
|
||||
public static function has($key)
|
||||
{
|
||||
return Basket::find($key);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
public static function get($key)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return new CartCollection(Basket::find($key)->cart_data);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return self::has($key) ? new CartCollection(Basket::find($key)->cart_data) : [];
|
||||
}
|
||||
|
||||
public function put($key, $value)
|
||||
public static function put($key, $value)
|
||||
{
|
||||
if ($row = Basket::find($key)) {
|
||||
// update
|
||||
$row->cart_data = $value;
|
||||
$row->save();
|
||||
} else {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\InvoicePayment;
|
||||
use Bnb\PayboxGateway\Requests\Paybox\AuthorizationWithCapture;
|
||||
use Bnb\PayboxGateway\Requests\PayboxDirect\Capture;
|
||||
use Bnb\PayboxGateway\Responses\Exceptions\InvalidSignature;
|
||||
@@ -35,9 +36,9 @@ class Paybox
|
||||
}
|
||||
}
|
||||
|
||||
public static function getPreviousAuthorizedRequest()
|
||||
public static function getPreviousAuthorizedRequest($request)
|
||||
{
|
||||
$payment = Payment::where('number', $request->input('order_number'))->firstOrFail();
|
||||
$payment = InvoicePayment::where('number', $request->input('order_number'))->firstOrFail();
|
||||
$captureRequest = App::make(Capture::class);
|
||||
$response = $captureRequest->setAmount($payment->amount)
|
||||
->setPayboxCallNumber($payment->call_number)
|
||||
|
||||
@@ -15,7 +15,6 @@ class PriceListValues
|
||||
return [
|
||||
'unities' => Unities::getOptions(),
|
||||
'taxes_options' => Taxes::getOptions(),
|
||||
'categories' => PriceListValueCategories::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class Tariffs
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Tariff::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$data = Tariff::byAutocomplete($str)->orderBy('name')->limit(30)->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
|
||||
@@ -11,7 +11,7 @@ class Taxes
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Tax::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
return Tax::orderBy('value', 'asc')->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -11,12 +11,12 @@ class Unities
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Unity::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
return Unity::orderBy('value', 'asc')->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Unity::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
|
||||
return Unity::byPackage($package_id)->orderBy('value', 'asc')->pluck('value', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -20,7 +20,7 @@ class Variations
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Variation::where('name', 'LIKE', "%{$str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$data = Variation::where('name', 'LIKE', "%{$str}%")->orderBy('name')->limit(30)->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Repositories\Core\Auth\Users as parentUsers;
|
||||
use App\Repositories\Shop\SaleChannels;
|
||||
|
||||
class Users extends parentUsers
|
||||
{
|
||||
public static function getInfo($id = false)
|
||||
{
|
||||
$data = parent::getInfo($id);
|
||||
$sale_channel_default = SaleChannels::getDefault();
|
||||
$data['sale_channel'] = $sale_channel_default ? $sale_channel_default->toArray() : false;
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user