Synchro back-office, fix on tariffs
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserStatusTeam;
|
||||
|
||||
class UserStatusTeams
|
||||
{
|
||||
|
||||
// supprime l'association entre les équipes et le statut utilisateur donné
|
||||
public function delete_teams($id)
|
||||
{
|
||||
return UserStatusTeam::byUserStatus($id)->delete();
|
||||
}
|
||||
|
||||
// associe une équipe avec un statut utilisateur
|
||||
public function insert_team($user_status_id, $team_id)
|
||||
{
|
||||
return UserStatusTeam::create(['team_id' => $team_id, 'user_status_id' => $user_status_id]);
|
||||
}
|
||||
|
||||
// récupère les équipes d'un statut utilisateur donné
|
||||
public function select_teams_by_id($id)
|
||||
{
|
||||
return UserStatusTeam::select('team_id')->byUserStatus($id)->get();
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
<?php
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use App\Models\Core\Auth\UserStatus;
|
||||
|
||||
class UserStatuses
|
||||
{
|
||||
// compte le nombre de statut utilisateur
|
||||
public static function count()
|
||||
{
|
||||
return UserStatus::count();
|
||||
}
|
||||
|
||||
// supprime un statut utilisateur
|
||||
public static function delete($id)
|
||||
{
|
||||
return UserStatus::destroy($id);
|
||||
}
|
||||
|
||||
// ajoute un statut utilisateur
|
||||
public static function insert($name, $translated, $negociator)
|
||||
{
|
||||
return UserStatus::create(['name' => $name, 'translated' => $translated, 'negociator' => $negociator]);
|
||||
}
|
||||
|
||||
// reset le négociateur parmi les statuts
|
||||
public static function reset_negociator_status()
|
||||
{
|
||||
return UserStatus::update(['negociator' => null]);
|
||||
}
|
||||
|
||||
// récupère toutes les infos sur les statuts utilisateur
|
||||
public static function select_all()
|
||||
{
|
||||
return UserStatus::all()->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos pour un statut utilisateur donné
|
||||
public static function select_by_id($id)
|
||||
{
|
||||
return UserStatus::find($id)->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos pour un statut utilisateur donné
|
||||
public static function select_by_name($name)
|
||||
{
|
||||
return UserStatus::byName($name)->first()->toArray();
|
||||
}
|
||||
|
||||
// récupère les infos du statut considéré comme négociant d'un contrat
|
||||
public static function select_by_negociator()
|
||||
{
|
||||
$status = UserStatus::byNegociator()->first();
|
||||
return $status ? $status->toArray() : null;
|
||||
}
|
||||
|
||||
// met à jour le statut actif/inactif d'un statut utilisateur
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return UserStatus::find($id)->update(['active' => $active]);
|
||||
}
|
||||
|
||||
// met à jour les informations d'un statut utilisateur
|
||||
public static function update($id, $name, $translated, $negociator)
|
||||
{
|
||||
return UserStatus::find($id)->update(['id' => $id, 'name' => $name, 'translated' => $translated, 'negociator' => $negociator]);
|
||||
}
|
||||
|
||||
// met à jour les informations d'un statut utilisateur
|
||||
public static function update_negociator($id, $negociator)
|
||||
{
|
||||
return UserStatus::find($id)->update(['negociator' => $negociator]);
|
||||
}
|
||||
|
||||
public static function getAllUserStatuses($input)
|
||||
{
|
||||
$data = [];
|
||||
$statuses = self::select_all();
|
||||
foreach ($statuses as $status) {
|
||||
if ($status['active'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
$item = array();
|
||||
$item['id'] = $status['id'];
|
||||
$item['name'] = \App\Repositories\Translate::translateClient($status['translated']);
|
||||
array_push($data, $item);
|
||||
}
|
||||
$data = \App\Repositories\Functions::array_orderby($data, 'name', SORT_ASC);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return UserStatus::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getNegociatorsOptions()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class DateTime
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
$date = today()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ class DateTime
|
||||
if (!is_null($date) && !empty($date)) {
|
||||
$date = Carbon::parse($date)->format($format);
|
||||
} elseif ($date == 'now') {
|
||||
$date = Carbon::now()->format($format);
|
||||
$date = now()->format($format);
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
@@ -76,6 +76,9 @@ class DateTime
|
||||
public static function convertTime($date)
|
||||
{
|
||||
$format = self::getLocaleFormatDatetime();
|
||||
if (strlen($date) == 16) {
|
||||
$date .= ':00';
|
||||
}
|
||||
return !empty($date) ? Carbon::createFromFormat($format, $date)->isoFormat('Y-MM-DD HH:mm:ss') : null;
|
||||
}
|
||||
|
||||
@@ -102,12 +105,12 @@ class DateTime
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
@@ -116,29 +119,45 @@ class DateTime
|
||||
{
|
||||
$locale = self::getLang();
|
||||
switch ($locale) {
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y H:i:s';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d H:i:s';
|
||||
case 'fr':
|
||||
case 'en':
|
||||
$format = 'd/m/Y H:i:s';
|
||||
break;
|
||||
default:
|
||||
$format = 'Y-m-d H:i:s';
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
public static function getLocaleDateFull($date)
|
||||
public static function getLocaleDateFull($date = false)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('LLLL');
|
||||
return self::getISOFormat('LL', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleDateFullShort($date)
|
||||
public static function getLocaleDateTimeFull($date = false)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('lll');
|
||||
return self::getISOFormat('LLL', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleHour($date)
|
||||
public static function getLocaleDateFullShort($date = false)
|
||||
{
|
||||
return Carbon::parse($date)->isoFormat('');
|
||||
return self::getISOFormat('ll', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleDateTimeFullShort($date = false)
|
||||
{
|
||||
return self::getISOFormat('lll', $date);
|
||||
}
|
||||
|
||||
public static function getLocaleTime($date = false)
|
||||
{
|
||||
return self::getISOFormat('LT', $date);
|
||||
}
|
||||
|
||||
public static function getISOFormat($format, $date = false)
|
||||
{
|
||||
$date = $date ? $date : now();
|
||||
return Carbon::parse($date)->isoFormat($format);
|
||||
}
|
||||
|
||||
public static function relativeTime()
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Media
|
||||
{
|
||||
public static function getImages($model)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
}
|
||||
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($model, $file)
|
||||
{
|
||||
return $model->addMedia($file)->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return "1";
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$images = json_decode($image['responsive_images'], true);
|
||||
/*
|
||||
$urls = $images['medialibrary_original']['urls'];
|
||||
|
||||
$img = $urls[count($urls)-1];
|
||||
$src = "storage/$id/responsive-images/$img";
|
||||
*/
|
||||
return $src ?? null;
|
||||
}
|
||||
}
|
||||
99
app/Repositories/Core/Medias.php
Normal file
99
app/Repositories/Core/Medias.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
class Medias
|
||||
{
|
||||
|
||||
public static function getImage($model, $conversion = 'normal', $collection = 'images')
|
||||
{
|
||||
$img = $model->getMedia($collection)->first();
|
||||
return $img ? $img->getUrl($conversion) : false;
|
||||
}
|
||||
|
||||
public static function getImages($model)
|
||||
{
|
||||
if (!$model) {
|
||||
return false;
|
||||
}
|
||||
$model->getMedia();
|
||||
foreach ($model->media as $key => $media) {
|
||||
$model->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $model->media;
|
||||
}
|
||||
|
||||
public static function storeImages($model, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($model, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($model, $file, $collection = 'images')
|
||||
{
|
||||
return $model->addMedia($file)->sanitizingFileName(function ($fileName) {
|
||||
return str_replace(['#', '/', '\\', ' '], '-', $fileName);
|
||||
})->toMediaCollection($collection);
|
||||
}
|
||||
|
||||
public static function deleteImages($model, $collection = 'images')
|
||||
{
|
||||
$ret = $model->clearMediaCollection($collection);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteImage($model, $index)
|
||||
{
|
||||
$model->getMedia();
|
||||
$ret = $model->media[$index]->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function buildURL($image, $conversion = '')
|
||||
{
|
||||
return self::getPath($image) . self::getConversion($image, $conversion);
|
||||
}
|
||||
|
||||
public static function getPath($image)
|
||||
{
|
||||
$model = basename(str_replace('\\', '/', $image->model_type));
|
||||
return '/storage/' . $model . '/' . $image->collection_name . '/' . $image->id;
|
||||
}
|
||||
|
||||
public static function getConversion($image, $conversion = '')
|
||||
{
|
||||
// return $conversion ? '/conversions/' . $image->name . '-' . $conversion . self::getExtension($image->file_name) : $image->file_name;
|
||||
return $conversion ? '/conversions/' . $image->name . '-' . $conversion . '.jpg' : $image->file_name;
|
||||
}
|
||||
|
||||
public static function getExtension($filename)
|
||||
{
|
||||
return '.' . pathinfo($filename, PATHINFO_EXTENSION);
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$filename = $image['name'] . '-thumb' . self::getExtension($image['file_name']);
|
||||
|
||||
return "/storage/$id/conversions/$filename";
|
||||
}
|
||||
|
||||
public static function getPreviewSrc($image)
|
||||
{
|
||||
if (!$image) {
|
||||
return null;
|
||||
}
|
||||
$id = $image['id'];
|
||||
$filename = $image['name'] . '-preview' . self::getExtension($image['file_name']);
|
||||
|
||||
return "/storage/$id/conversions/$filename";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user