Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
Helpers
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Modulus
Helpers
Commits
42eda644
Commit
42eda644
authored
May 05, 2020
by
Sylvain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mise à jour de dynamik
parent
4488a462
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
290 additions
and
5 deletions
+290
-5
src/Helpers/Bootstrap4.php
src/Helpers/Bootstrap4.php
+148
-0
src/Helpers/Dynamik.php
src/Helpers/Dynamik.php
+94
-3
src/array.php
src/array.php
+19
-1
src/convert.php
src/convert.php
+1
-1
src/time.php
src/time.php
+28
-0
No files found.
src/Helpers/Bootstrap4.php
0 → 100644
View file @
42eda644
<?php
namespace
Goldenscarab\Modulus\Helpers
;
use
Illuminate\Support\Arr
;
class
Bootstrap4
{
/**
* Retourne le rendu html d'un bouton
* ex : <button type="button" class="btn [CLASSES]" [ATTRIBUTES]>[LABEL]</button>
*
* @param array $attrs
* [
* 'label' => 'Nom du bouton',
* 'class' => 'btn-success btn-sm',
* 'id' => 'id-du-bouton' (option)
* ]
* @return string
*/
public
static
function
renderButton
(
array
$attrs
)
:
string
{
$render
=
''
;
$template
=
'<button type="button" class="btn %s"%s>%s</button>'
;
$class
=
mixte_get
(
$attrs
,
'class'
,
'btn-default btn-sm btn-flat'
);
$label
=
mixte_get
(
$attrs
,
'label'
);
$attributes
=
Arr
::
except
(
$attrs
,
[
'class'
,
'label'
,
'permission'
]);
$render
=
vsprintf
(
$template
,
[
$class
,
self
::
renderAttributes
(
$attributes
),
$label
]);
return
$render
;
}
/**
* Retourne le rendu html d'un lien de type bouton
* ex : <a class="btn [CLASSES]" href="[LIEN]" [ATTRIBUTES]>[LABEL]</a>
*
* @param array $attrs
* [
* 'label' => 'Nom du bouton',
* 'class' => 'btn-success btn-sm',
* 'href => 'test.html',
* 'id' => 'id-du-bouton' (option)
* ]
* @return string
*/
public
static
function
renderAButton
(
array
$attrs
)
:
string
{
$render
=
''
;
$template
=
'<a class="btn %s"%s>%s</a>'
;
$class
=
mixte_get
(
$attrs
,
'class'
,
'btn-success btn-sm btn-flat text-nowrap'
);
$label
=
mixte_get
(
$attrs
,
'label'
);
$attributes
=
Arr
::
except
(
$attrs
,
[
'class'
,
'label'
,
'permission'
]);
$render
=
vsprintf
(
$template
,
[
$class
,
self
::
renderAttributes
(
$attributes
),
$label
]);
return
$render
;
}
public
static
function
renderAButtonDropDown
(
array
$attrs
)
:
string
{
$render
=
''
;
$template
=
<<<EOT
<div class="btn-group">
%s
<button type="button" class="btn btn-sm %s dropdown-toggle" data-toggle="dropdown" aria-expanded="false"%s>
%s
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
%s
</div>
</div>
EOT;
$render_button
=
self
::
renderAButton
(
data_get
(
$attrs
,
'button'
));
$dropdown
=
data_get
(
$attrs
,
'dropdown'
);
$attrs_dropdown
=
Arr
::
except
(
$dropdown
,
[
'items'
,
'class'
,
'label'
,
'permission'
]);
$class_dropdown
=
data_get
(
$dropdown
,
'class'
,
'btn-default'
);
$label_dropdown
=
data_get
(
$dropdown
,
'label'
);
$items_dropdown
=
data_get
(
$dropdown
,
'items'
,
[]);
$render
=
vsprintf
(
$template
,
[
$render_button
,
$class_dropdown
,
self
::
renderAttributes
(
$attrs_dropdown
),
$label_dropdown
,
self
::
renderDropdownItems
(
$items_dropdown
)
]);
return
$render
;
}
public
static
function
renderDropdownItems
(
array
$items
)
:
string
{
$render
=
''
;
$template
=
'<a class="dropdown-item%s"%s>%s</a>'
;
foreach
(
$items
as
$item
)
{
if
(
is_array
(
$item
)
&&
!
array_key_exists
(
'label'
,
$item
))
{
throw
new
\InvalidArgumentException
(
"Dropdown required key `label` "
.
json_encode
(
$item
)
.
' given'
);
}
if
(
is_string
(
$item
))
{
$render
.=
$item
;
continue
;
}
$attrs
=
Arr
::
except
(
$item
,
[
'label'
,
'class'
]);
$label
=
data_get
(
$item
,
'label'
,
'N/A'
);
$class
=
data_get
(
$item
,
'class'
);
$render
.=
vsprintf
(
$template
,
[
empty
(
$class
)
?
''
:
' '
.
$class
,
self
::
renderAttributes
(
$attrs
),
$label
]);
}
return
$render
;
}
private
static
function
renderAttributes
(
array
$attrs
)
:
string
{
$render
=
''
;
$template
=
' %s="%s"'
;
foreach
(
$attrs
as
$name
=>
$value
)
{
$render
.=
vsprintf
(
$template
,
[
$name
,
$value
]);
}
return
$render
;
}
}
src/Helpers/Dynamik.php
View file @
42eda644
...
...
@@ -30,14 +30,17 @@ class Dynamik
{
$val
=
$this
->
getValue
(
$data
[
'value'
]);
$operator
=
data_get
(
$data
,
'operator'
,
'=='
);
$true
=
data_get
(
$data
,
'true'
,
true
);
$comparator
=
$data
[
'comparator'
]
;
$true
=
data_get
(
$data
,
'true'
);
$comparator
=
data_get
(
$data
,
'comparator'
,
true
)
;
$false
=
data_get
(
$data
,
'false'
);
switch
(
$operator
)
{
case
'=='
:
$value
=
$val
==
$comparator
?
$true
:
$false
;
break
;
case
'==='
:
$value
=
$val
===
$comparator
?
$true
:
$false
;
break
;
case
'>'
:
$value
=
$val
>
$comparator
?
$true
:
$false
;
break
;
...
...
@@ -47,6 +50,9 @@ class Dynamik
case
'!='
:
$value
=
$val
!=
$comparator
?
$true
:
$false
;
break
;
case
'!=='
:
$value
=
$val
!==
$comparator
?
$true
:
$false
;
break
;
case
'<='
:
$value
=
$val
<=
$comparator
?
$true
:
$false
;
break
;
...
...
@@ -106,7 +112,7 @@ class Dynamik
{
$value
=
null
;
$function
=
$data
[
'function'
];
$args
=
$data
[
'args'
]
;
$args
=
data_get
(
$data
,
'args'
)
;
// Traitement sur le nom de la fonction (suppression des parenthèses)
$function
=
preg_replace
(
'/(\(.*)/'
,
''
,
$function
);
...
...
@@ -123,6 +129,37 @@ class Dynamik
return
$value
;
}
/**
* Récupération d'une valeur url depuis une route avec des arguments
* $structure =
* [
* 'route' => 'ma.route',
* 'args' => [':id', 'param' => ':name'],
* ]
*
* @param array $data
* @return String
*/
public
function
getUrlValue
(
$data
)
{
$value
=
null
;
$route
=
$this
->
getValue
(
$data
[
'route'
]);
$args
=
$data
[
'args'
];
// Préparation des arguments pour la route
if
(
!
is_array
(
$args
))
{
$args
=
[
$args
];
}
$arguments
=
[];
foreach
(
$args
as
$key
=>
$val
)
{
$arguments
[
$key
]
=
$this
->
getValue
(
$val
);
}
$value
=
route
(
$route
,
$arguments
);
return
$value
;
}
/**
* Récupération d'une valeur dynamique (en préfixant avec « : »)
* Exemple :
...
...
@@ -153,6 +190,8 @@ class Dynamik
$values
[]
=
$this
->
getFormatedValue
(
$d
);
}
else
if
(
$key
===
'callback'
)
{
$values
[]
=
$this
->
getCallbackValue
(
$d
);
}
else
if
(
$key
===
'url'
)
{
$values
[]
=
$this
->
getUrlValue
(
$d
);
}
else
{
$values
[]
=
$this
->
getValue
(
$d
);
}
...
...
@@ -177,4 +216,56 @@ class Dynamik
return
$value
;
}
/**
* Remplacement des données dynamik d'un tableau d'argument en valeur
*
* @param array $datas
* @return array
*/
public
function
dynamikize
(
array
$datas
)
:
array
{
$dynamikized
=
[];
foreach
(
$datas
as
$key
=>
$data
)
{
if
(
$this
->
isDynamik
(
$data
))
{
$value
=
$this
->
getValue
(
$data
);
}
else
{
$value
=
$data
;
}
if
(
is_array
(
$value
))
{
$dynamik
=
$this
->
dynamikize
(
$value
);
}
else
{
$dynamik
=
$value
;
}
$dynamikized
[
$key
]
=
$dynamik
;
}
return
$dynamikized
;
}
/**
* Test si une valeur est de type dynamik
*
* @param Mixte $data
* @return boolean
*/
private
function
isDynamik
(
$data
)
:
bool
{
$keys_dynamik
=
[
'condition'
,
'template'
,
'callback'
,
'url'
];
if
(
is_array
(
$data
))
{
foreach
(
$keys_dynamik
as
$key
)
{
if
(
array_key_exists
(
$key
,
$data
))
{
return
true
;
}
}
}
else
if
(
preg_match
(
'/^:.*$/'
,
$data
))
{
return
true
;
}
return
false
;
}
}
src/array.php
View file @
42eda644
...
...
@@ -13,7 +13,6 @@ if ( !function_exists('is_indexed_array')) {
}
}
if
(
!
function_exists
(
'array_keys_exists'
))
{
/**
* Test si plusieurs clefs sont présentes dans un tableau
...
...
@@ -28,3 +27,22 @@ if ( !function_exists('array_keys_exists')) {
}
}
if
(
!
function_exists
(
'array_contains'
))
{
/**
* Test si au moins un élément est présent dans un tableau
*
* @param array $keys
* @param array $arr
* @return boolean
*/
function
array_contains
(
array
$keys
,
array
$arr
)
:
bool
{
foreach
(
$keys
as
$key
)
{
if
(
in_array
(
$key
,
$arr
))
{
return
true
;
}
}
return
false
;
}
}
src/convert.php
View file @
42eda644
...
...
@@ -191,7 +191,7 @@ if ( !function_exists('string_to_float')) {
* @param String $value Valeur à virgule
* @return Float Nombre flottant
*/
function
string_to_float
(
string
$value
)
function
string_to_float
(
$value
)
{
if
(
!
is_null
(
$value
))
{
return
floatval
(
str_replace
(
','
,
'.'
,
$value
));
...
...
src/time.php
View file @
42eda644
...
...
@@ -108,3 +108,31 @@ if ( !function_exists('gte_time')) {
return
$sec1
>=
$sec2
;
}
}
if
(
!
function_exists
(
'time_to_float'
))
{
/**
* Convertir une heure de type HH:MM:SS en nombre flottant
*
* @param string $time
* @return float
*/
function
time_to_float
(
$time
)
:
float
{
$float
=
0
;
$split
=
explode
(
":"
,
$time
);
$hou
=
intval
(
@
$split
[
0
]);
$min
=
intval
(
@
$split
[
1
]);
$sec
=
intval
(
@
$split
[
2
]);
// On met tout en seconde
$seconds
=
$hou
*
60
*
60
;
$seconds
+=
$min
*
60
;
$seconds
+=
$sec
;
$float
=
$seconds
/
3600
;
return
$float
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment