Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fusiondirectory
fusiondirectory
Commits
8c730365
Commit
8c730365
authored
Oct 06, 2014
by
Côme Bernigaud
Committed by
Benoit Mortier
Oct 06, 2014
Browse files
Added TimeAttribute and ByteSizeAttribute to avoid some math to the user
parent
c971e2b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/simpleplugin/class_helpersAttribute.inc
View file @
8c730365
...
...
@@ -211,4 +211,80 @@ class CommaListAttribute extends CompositeAttribute
}
}
class
UnitIntAttribute
extends
CompositeAttribute
{
/* $units should contains 1 in its keys as a fallback unit */
function
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$units
,
$min
=
FALSE
,
$max
=
FALSE
,
$defaultValue
=
""
,
$acl
=
""
)
{
parent
::
__construct
(
$description
,
$ldapName
,
array
(
new
IntAttribute
(
''
,
''
,
$ldapName
.
'_int'
,
$required
,
$min
,
$max
,
$defaultValue
),
new
SelectAttribute
(
''
,
''
,
$ldapName
.
'_select'
,
TRUE
,
array_keys
(
$units
),
''
,
array_values
(
$units
)),
),
''
,
''
,
$acl
,
$label
);
$this
->
setLinearRendering
(
TRUE
);
}
function
readValues
(
$value
)
{
if
(
$value
===
''
)
{
return
array
(
''
,
0
);
}
$choices
=
$this
->
attributes
[
1
]
->
getChoices
();
sort
(
$choices
);
/* Find the approriate unit */
for
(
$i
=
(
count
(
$choices
)
-
1
);
(
$value
%
$choices
[
$i
]
!=
0
)
&&
(
$i
>
0
);
$i
--
);
print_r
(
array
(
$value
/
$choices
[
$i
],
$i
));
return
array
(
$value
/
$choices
[
$i
],
$choices
[
$i
]);
}
function
writeValues
(
$values
)
{
if
(
$values
[
0
]
===
''
)
{
return
''
;
}
return
$values
[
0
]
*
$values
[
1
];
}
function
displayValue
(
$value
)
{
$values
=
$this
->
readValues
(
$value
);
return
$values
[
0
]
.
$this
->
attributes
[
1
]
->
displayValue
(
$values
[
1
]);
}
}
class
BytesSizeAttribute
extends
UnitIntAttribute
{
function
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$min
=
FALSE
,
$max
=
FALSE
,
$defaultValue
=
""
,
$acl
=
""
)
{
$units
=
array
(
1
=>
_
(
'B'
),
pow
(
1024
,
1
)
=>
_
(
'KiB'
),
pow
(
1024
,
2
)
=>
_
(
'MiB'
),
pow
(
1024
,
3
)
=>
_
(
'GiB'
),
pow
(
1024
,
4
)
=>
_
(
'TiB'
),
);
parent
::
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$units
,
$min
,
$max
,
$defaultValue
,
$acl
);
}
}
class
TimeAttribute
extends
UnitIntAttribute
{
function
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$min
=
FALSE
,
$max
=
FALSE
,
$defaultValue
=
""
,
$acl
=
""
)
{
$units
=
array
(
1
=>
_
(
'seconds'
),
60
=>
_
(
'minutes'
),
3600
=>
_
(
'hours'
),
86400
=>
_
(
'days'
),
);
parent
::
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$units
,
$min
,
$max
,
$defaultValue
,
$acl
);
}
}
?>
Write
Preview
Supports
Markdown
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