Commit 2fff4f1a authored by Sylvain's avatar Sylvain

Modification noms de méthodes

parent e01f526a
......@@ -7,133 +7,133 @@ use Illuminate\Support\Str;
if ( !function_exists('carbonize')) {
/**
* Converti recursivement les dates fr en Instance Carbon dans une collection
* @param Mixed $target Données à traitées
* @param Mixed $collection Données à traitées
* @return Mixed Les données après traitement
*/
function carbonize($target)
function carbonize($collection)
{
if ($target instanceof Collection) {
$target = $target->map(function($item, $key) {
if ($collection instanceof Collection) {
$collection = $collection->map(function($item, $key) {
return carbonize($item);
});
} else if (is_object($target)) {
$datas_array = get_object_vars($target);
} else if (is_object($collection)) {
$datas_array = get_object_vars($collection);
foreach ($datas_array as $key => $value) {
$target->{$key} = carbonize($value);
$collection->{$key} = carbonize($value);
}
} else if (is_array($target)) {
foreach ($target as $key => $value) {
$target[$key] = carbonize($value);
} else if (is_array($collection)) {
foreach ($collection as $key => $value) {
$collection[$key] = carbonize($value);
}
} else {
// Detection d'une date selon le format
if (preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/", $target)) {
$target = \Carbon\Carbon::createFromFormat('d/m/Y', $target)->startOfDay();
} else if (preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2}$/", $target)) {
$target = \Carbon\Carbon::createFromFormat('d/m/y', $target)->startOfDay();
if (preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/", $collection)) {
$collection = \Carbon\Carbon::createFromFormat('d/m/Y', $collection)->startOfDay();
} else if (preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{2}$/", $collection)) {
$collection = \Carbon\Carbon::createFromFormat('d/m/y', $collection)->startOfDay();
}
}
return $target;
return $collection;
}
}
if ( !function_exists('collectize')) {
/**
* Converti les tableaux d'une collection en Instance de Collection
* @param Mixed $target Données à traitées
* @param Mixed $collection Données à traitées
* @return Mixed Les données après traitement
*/
function collectize($target)
*/
function collectize($collection)
{
if ($target instanceof Collection) {
$target = $target->map(function($item, $key) {
if ($collection instanceof Collection) {
$collection = $collection->map(function($item, $key) {
return collectize($item);
});
} else if (is_object($target)) {
$datas_array = get_object_vars($target);
} else if (is_object($collection)) {
$datas_array = get_object_vars($collection);
foreach ($datas_array as $key => $value) {
$target->{$key} = collectize($value);
$collection->{$key} = collectize($value);
}
} else if (is_array($target)) {
} else if (is_array($collection)) {
foreach ($target as $key => $value) {
$target[$key] = collectize($value);
foreach ($collection as $key => $value) {
$collection[$key] = collectize($value);
}
$target = collect($target);
}
$collection = collect($collection);
}
return $target;
return $collection;
}
}
if ( !function_exists('objectize')) {
/**
* Converti les tableaux associatif d'une collection en stdObject
* @param Mixed $target Données à traitées
* @param Mixed $collection Données à traitées
* @return Mixed Les données après traitement
*/
function objectize($target)
function objectize($collection)
{
if ($target instanceof Collection) {
$target = $target->map(function($item, $key) {
if ($collection instanceof Collection) {
$collection = $collection->map(function($item, $key) {
return objectize($item);
});
} else if (is_object($target)) {
$datas_array = get_object_vars($target);
} else if (is_object($collection)) {
$datas_array = get_object_vars($collection);
foreach ($datas_array as $key => $value) {
$target->{$key} = objectize($value);
$collection->{$key} = objectize($value);
}
} else if (is_array($target)) {
} else if (is_array($collection)) {
// Détection d'un tableau associatif
if(count($target) != 0 && array_keys($target) !== range(0, count($target) - 1)) {
if(count($collection) != 0 && array_keys($collection) !== range(0, count($collection) - 1)) {
$sub_data = new \StdClass;
foreach ($target as $key => $value) {
foreach ($collection as $key => $value) {
if (is_array($value)) {
$sub_data->{$key} = objectize($value);
} else {
$sub_data->{$key} = $value;
}
}
$target = $sub_data;
$collection = $sub_data;
} else {
foreach ($target as $key => $value) {
$target[$key] = objectize($value);
foreach ($collection as $key => $value) {
$collection[$key] = objectize($value);
}
}
}
}
return $target;
return $collection;
}
}
if ( !function_exists('csv_to_collect')) {
if ( !function_exists('csv_to_collection')) {
/**
* Retourne une collection d'object standard à partir d'une chaine de caractère de type csv
* @param string $csv Le contenu du CSV
* @param string $delimiter Le séparateur du CSV
* @return Collection La collection
*/
function csv_to_collect(string $csv, string $delimiter = ';')
function csv_to_collection(string $csv, string $delimiter = ';')
{
$datas = array();
$collect = collect();
$headers = [];
// Conversion du string en tableau brut
$lines = explode(PHP_EOL, $content);
$lines = explode(PHP_EOL, $csv);
foreach ($lines as $line => $value) {
if ($line == 0) {
$headers = explode($delimiter, $value);
......@@ -150,9 +150,9 @@ if ( !function_exists('csv_to_collect')) {
$obj_line = new stdClass;
foreach ($headers as $col => $name) {
if (isset($data[$col])) {
$col_name = str_replace('-', '_', str_slug($name));
$col_name = str_replace('-', '_', Str::slug($name));
$value = trim(trim($data[$col], '"'));
$obj_line->{$col_name} = $value;
}
......
<?php
use Illuminate\Support\HtmlString;
use Illuminate\Support\Collection;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
if ( !function_exists('calc_percent')) {
if ( !function_exists('calc_increase_percent')) {
/**
* Calcul le pourcentage d'accroissement entre 2 valeurs
* @param int|float $old_value
* @param int|float $new_value
* @return float La valeur d'accroissement
*/
function calc_percent($old_value, $new_value)
function calc_increase_percent($old_value, $new_value)
{
if ($new_value == 0) {
return 0;
......@@ -30,24 +31,6 @@ if ( !function_exists('calc_percent')) {
}
}
if ( !function_exists('data_get_multi')) {
/**
* Récupère un tableau de données depuis une cible à partir d'un tableau de clés
* @param Mixed $target La donnée source
* @param Array $keys Tableau des clés à rechercher
* @param Mixed $default Valeur par défaut
* @return Array Tableau des données récoltées
*/
function data_get_multi($target, array $keys, $default = null)
{
$datas = array();
foreach ($keys as $key) {
$datas[] = data_get($target, $key, $default);
}
return $datas;
}
}
if (! function_exists('mixte_get')) {
/**
* Récupération avancée de contenu depuis une source Mixte, en utilisant la notation «.»
......@@ -119,4 +102,22 @@ if (! function_exists('mixte_get')) {
return $target;
}
}
\ No newline at end of file
}
if ( !function_exists('mixte_get_multi')) {
/**
* Récupère un tableau de données depuis une cible à partir d'un tableau de clés
* @param Mixed $target La donnée source
* @param Array $keys Tableau des clés à rechercher
* @param Mixed $default Valeur par défaut
* @return Array Tableau des données récoltées
*/
function mixte_get_multi($target, array $keys, $default = null)
{
$datas = array();
foreach ($keys as $key) {
$datas[] = mixte_get($target, $key, $default);
}
return $datas;
}
}
......@@ -46,7 +46,7 @@ if ( !function_exists('make_thumb_image')) {
* @param integer $height Hauteur de l'image (null pour automatique)
* @param string $type Type mime de l'image
* @param integer $quality Qualité de l'image, niveau de compression
* @return void
* @return string Le chemin vers le fichier image miniature
*/
function make_thumb_image($path_image, $width = 200, $height = null, $type = 'jpg', $quality = 80)
{
......@@ -58,7 +58,7 @@ if ( !function_exists('make_thumb_image')) {
$img = Image::make($path_image);
$filename = $img->filename . '_thumb.'. $format;
$filename = $img->filename . '_thumb.'. $type;
$pathname = $img->dirname . '/' . $filename;
$img->resize($width, $height, function ($constraint) {
......
<?php
use Illuminate\Support\HtmlString;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Facades\Request;
if ( !function_exists('col_sort')) {
/**
* Affiche un icon de tri de colonne dans une vue tableau
* Affiche un icon de tri de colonne dans une vue liste
* @param String $filter_name Nom de la colonne à trier (nom en BDD)
* @return String Le HTML permettant le tri (icon + lien)
*/
......@@ -19,7 +20,7 @@ if ( !function_exists('col_sort')) {
// Si le paramètre de tri correspond à celui de l'url
if ($url_filter_name == $filter_name) {
// En fonction du sens de tri
if ($url_filter_sort == 'desc') {
......@@ -32,7 +33,7 @@ if ( !function_exists('col_sort')) {
$icon = '<span class="sort asc ml-1"><i class="fa fa-sort-amount-asc"></i></span>';
}
} else {
$url_params = ['sorting' => $filter_name, 'direction' => 'asc'];
......@@ -71,4 +72,4 @@ if ( !function_exists('pos_sort')) {
return $item_position;
}
}
\ No newline at end of file
}
......@@ -5,9 +5,9 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Str;
if ( !function_exists('sum_times')) {
if ( !function_exists('sum_times')) {
/**
* Additionne des hh:mm:ss pour en afficher un total formaté
* Additionne tableau de string au format `hh:mm:ss` pour en afficher un total formaté
* @param Array $times Tableau d'heures à additionner
* @param Integer $segments Le nombre de segments souhaités (defaut : 3)
* @return String Le resultat de la somme formaté
......@@ -18,7 +18,7 @@ if ( !function_exists('sum_times')) {
$min = 0;
$sec = 0;
$total_time = '00:00';
foreach ($times as $time) {
$split = explode(":", $time);
......@@ -41,14 +41,14 @@ if ( !function_exists('sum_times')) {
$seconds = sprintf('%02d', $seconds);
switch ($segments) {
case 1 :
case 1 :
$result = $hours;
break;
case 2 :
case 2 :
$result = $hours.":".$minutes;
break;
default :
default :
$result = $hours.":".$minutes.":".$seconds;
break;
}
......@@ -59,7 +59,7 @@ if ( !function_exists('sum_times')) {
if ( !function_exists('gte_time')) {
/**
* Comparaison d'une heure à une autre
* Compare un string de type horaire avec un autre (plus grand ou égal à)
* @param String $time1 Heure 1
* @param String $time2 Heure 2
* @return Boolean Heure 1 supérieur à heure 2
......@@ -71,7 +71,7 @@ if ( !function_exists('gte_time')) {
$sec = 0;
$sec1 = 0;
$sec2 = 0;
// Dispatch des valeurs heure 1
$split = explode(":", $time1);
......@@ -107,4 +107,4 @@ if ( !function_exists('gte_time')) {
// Comparaison
return $sec1 >= $sec2;
}
}
\ No newline at end of file
}
......@@ -5,12 +5,12 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Request;
if ( !function_exists('get_query_array')) {
if ( !function_exists('current_query_to_array')) {
/**
* Retourne un tableau avec les paramètres de l'url courante
* @return array Un tableau contenant les paramètres
*/
function get_query_array()
function current_query_to_array()
{
parse_str(Request::getQueryString(), $array);
......@@ -18,15 +18,14 @@ if ( !function_exists('get_query_array')) {
}
}
if (! function_exists('str_current_query')) {
if (! function_exists('current_query_to_string')) {
/**
* Récupère l'url courante retourne ses paramètres non vide
*
* @return string
* Retourne paramètres de l'url courante sans ses paramètres vides
* @return string La requête courante
*/
function str_current_query() : string
function current_query_to_string() : string
{
$queries = array_filter(get_query_array());
$queries = array_filter(current_query_to_array());
return http_build_query($queries);
}
}
......@@ -43,4 +42,4 @@ if (! function_exists('current_route_belongs')) {
$uri = trim($route, '/');
return Request::is($uri . '*');
}
}
\ No newline at end of file
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment