Advanced Form Template Rules
Estimated reading: 2 minutes
In Deepser you can define the rules for loading Form Templates via PHP script.
It is useful to be able to define conditions “manually” by scripts when they are too complex or particular to be expressed by query-builder.
To define a rule by scripting, go to the configuration menu of the Form Template, move to the tab (on top) Edit Rules and click the icon </> above the query-builder (as shown in the picture).
In this area you will find the code automatically generated by query-builder that you can integrate or replace with custom PHP code.
EXAMPLE: TEMPLATE FOR IT SECOND LEVEL MEMBERS
In the following example we want to make a template visible only to users who are members of a specific group: IT Second Level.
To do this you need to enter the following PHP code in the Rules scripting area.
//retrieve the current user
$currentUser = Deep::helper('deep_admin')->getCurrentUser();
//IT Second Level group id = 5
//check if the user is in IT Second Level group
if($currentUser->isInGroup(5)){
//original condition generated by the query-bulder
if( $this->getModel()->getData('type_id')==1 &&
( $this->getModel()->getData('category1')==5 ||
$this->getModel()->getData('category1')==17 ||
$this->getModel()->getData('category1')==2 )){
//if both conditions are verified the template form is loaded
return true;
}
}
else{
//else return false and evaluate the rules of the next template
return false;
}