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
c5457c79
Commit
c5457c79
authored
Dec 02, 2015
by
Côme Chilliet
Browse files
Fixes #4346 Fixed template apply and Select/Set attributes '0' handling
parent
fa5a14bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/class_template.inc
View file @
c5457c79
...
...
@@ -28,6 +28,8 @@ class template
protected
$tabObject
;
protected
$attributes
;
protected
$applied
=
FALSE
;
function
__construct
(
$type
,
$dn
,
$targetdn
=
NULL
)
{
$this
->
type
=
$type
;
...
...
@@ -59,6 +61,20 @@ class template
}
}
/* Used when you need to re-apply the same template with different values */
function
reset
()
{
list
(
$this
->
attrs
,
)
=
plugin
::
tpl_fetch_template
(
$this
->
dn
);
$this
->
tabObject
=
objects
::
create
(
$this
->
type
);
$tempTabObject
=
objects
::
open
(
$this
->
dn
,
$this
->
type
);
/* Used to know which tab is activated */
foreach
(
$tempTabObject
->
by_object
as
$class
=>
&
$plugin
)
{
if
(
$plugin
->
is_account
||
$plugin
->
ignore_account
)
{
$this
->
tabObject
->
by_object
[
$class
]
->
is_account
=
$plugin
->
is_account
;
}
}
$this
->
applied
=
FALSE
;
}
function
getDn
()
{
return
$this
->
dn
;
...
...
@@ -93,13 +109,9 @@ class template
function
deserialize
(
$values
)
{
$SAVED_POST
=
$_POST
;
foreach
(
$values
as
$class
=>
$class_values
)
{
$_POST
=
$class_values
;
$_POST
[
$class
.
'_posted'
]
=
TRUE
;
$this
->
tabObject
->
by_object
[
$class
]
->
save_object
();
$this
->
tabObject
->
by_object
[
$class
]
->
deserializeValues
(
$class_values
);
}
$_POST
=
$SAVED_POST
;
}
function
save_object
()
...
...
@@ -145,11 +157,15 @@ class template
return
$smarty
->
fetch
(
get_template_path
(
'simpleplugin.tpl'
));
}
/* Apply template and current values to an object and returns it for saving or edition */
/* Apply template and current values to an object and returns it for saving or edition
* Cannot be called twice! If you need to, call reset between calls */
function
apply
(
$targetdn
=
NULL
)
{
if
(
$targetdn
!==
NULL
)
{
$this
->
tabObject
=
objects
::
open
(
$targetdn
,
$this
->
type
);
}
elseif
(
$this
->
applied
)
{
trigger_error
(
'Templates can’t be applied twice without calling reset before'
);
return
;
}
foreach
(
$this
->
tabObject
->
by_object
as
$class
=>
&
$plugin
)
{
...
...
@@ -183,6 +199,8 @@ class template
$this
->
attrs
=
plugin
::
tpl_parse_attrs
(
$this
->
attrs
);
$this
->
tabObject
->
adapt_from_template
(
$this
->
attrs
,
call_user_func_array
(
'array_merge'
,
$this
->
attributes
));
$this
->
tabObject
->
getBaseObject
()
->
base
=
$this
->
getBase
();
$this
->
applied
=
TRUE
;
return
$this
->
tabObject
;
}
}
include/simpleplugin/class_attribute.inc
View file @
c5457c79
...
...
@@ -571,6 +571,17 @@ class Attribute
}
}
/*! \brief Apply value from RPC requests
*
* \param array values the values array
*/
function
deserializeValue
(
$values
)
{
if
(
isset
(
$values
[
$this
->
getLdapName
()]))
{
$this
->
setValue
(
$values
[
$this
->
getLdapName
()]);
}
}
/*! \brief Add ACL information around display
*
* \param string $display the display information to pass through ACL
...
...
@@ -1043,7 +1054,7 @@ class SelectAttribute extends Attribute
*/
function
__construct
(
$label
,
$description
,
$ldapName
,
$required
=
FALSE
,
$choices
=
array
(),
$defaultValue
=
""
,
$outputs
=
NULL
,
$acl
=
""
)
{
if
(
!
in_array
(
$defaultValue
,
$choices
)
&&
isset
(
$choices
[
0
]))
{
if
(
!
in_array
(
$defaultValue
,
$choices
,
TRUE
)
&&
isset
(
$choices
[
0
]))
{
$defaultValue
=
$choices
[
0
];
}
parent
::
__construct
(
$label
,
$description
,
$ldapName
,
$required
,
$defaultValue
,
$acl
);
...
...
@@ -1053,14 +1064,14 @@ class SelectAttribute extends Attribute
function
setChoices
(
$choices
,
$outputs
=
NULL
)
{
$this
->
outputs
=
NULL
;
if
(
!
$this
->
isRequired
()
&&
!
in_array
(
""
,
$choices
))
{
if
(
!
$this
->
isRequired
()
&&
!
in_array
(
""
,
$choices
,
TRUE
))
{
array_unshift
(
$choices
,
""
);
if
(
is_array
(
$outputs
))
{
array_unshift
(
$outputs
,
_
(
"None"
));
}
}
$this
->
choices
=
$choices
;
if
(
!
in_array
(
$this
->
defaultValue
,
$this
->
choices
)
&&
isset
(
$this
->
choices
[
0
]))
{
if
(
!
in_array
(
$this
->
defaultValue
,
$this
->
choices
,
TRUE
)
&&
isset
(
$this
->
choices
[
0
]))
{
$this
->
defaultValue
=
$this
->
choices
[
0
];
}
if
(
is_array
(
$outputs
))
{
...
...
@@ -1083,11 +1094,11 @@ class SelectAttribute extends Attribute
protected
function
setRequired
(
$bool
)
{
parent
::
setRequired
(
$bool
);
$key
=
array_search
(
""
,
$this
->
choices
);
$key
=
array_search
(
""
,
$this
->
choices
,
TRUE
);
if
(
$this
->
isRequired
()
&&
(
$key
!==
FALSE
))
{
unset
(
$this
->
choices
[
$key
]);
unset
(
$this
->
outputs
[
""
]);
}
elseif
(
!
$this
->
isRequired
()
&&
!
in_array
(
""
,
$this
->
choices
))
{
}
elseif
(
!
$this
->
isRequired
()
&&
!
in_array
(
""
,
$this
->
choices
,
TRUE
))
{
$this
->
choices
[]
=
""
;
if
(
!
isset
(
$this
->
output
[
""
]))
{
$this
->
output
[
""
]
=
_
(
"None"
);
...
...
@@ -1131,7 +1142,7 @@ class SelectAttribute extends Attribute
}
else
{
$outputs
=
$this
->
choices
;
}
$key
=
array_search
(
''
,
$outputs
);
$key
=
array_search
(
''
,
$outputs
,
TRUE
);
if
(
$key
!==
FALSE
)
{
$outputs
[
$key
]
=
' '
;
}
...
...
@@ -1993,10 +2004,10 @@ class SetAttribute extends Attribute
function
addPostValue
(
$value
)
{
if
(
empty
(
$value
)
)
{
if
(
$value
===
''
)
{
return
FALSE
;
}
if
(
$this
->
valueUnicity
&&
in_array
(
$value
,
$this
->
postValue
))
{
if
(
$this
->
valueUnicity
&&
in_array
(
$value
,
$this
->
postValue
,
TRUE
))
{
return
FALSE
;
}
$this
->
postValue
[]
=
$value
;
...
...
@@ -2445,6 +2456,17 @@ class CompositeAttribute extends Attribute
}
}
function
deserializeValue
(
$values
)
{
if
(
$this
->
visible
)
{
foreach
(
$this
->
attributes
as
&
$attribute
)
{
$attribute
->
setDisabled
(
$this
->
disabled
);
$attribute
->
deserializeValue
(
$values
);
}
unset
(
$attribute
);
}
}
function
renderFormInput
()
{
$display
=
""
;
...
...
include/simpleplugin/class_simplePlugin.inc
View file @
c5457c79
...
...
@@ -963,6 +963,15 @@ class simplePlugin extends plugin
{
return
$this
->
attributesAccess
[
$field
]
->
foreignKeyCheck
(
$value
,
$source
);
}
function
deserializeValues
(
$values
)
{
/* Walk through attributes */
foreach
(
$this
->
attributesAccess
as
$ldapName
=>
&
$attr
)
{
/* Load values */
$attr
->
deserializeValue
(
$values
);
}
unset
(
$attr
);
}
}
?>
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