drop down restrictions

I would say use a database join element instead which would point to a database table which contains columns for the label, the value and the view access.

You could then write either an sql where statement to filter the options based on teh current users access level or use the eval sub options textarea to filter the returned options.

Im not at my pc to be able to give you more precise help though I think the eval method would be the simplest
 
Does the eval options method allow us to remove an option? I thought it just allowed us to modify the text?

Just checked that code, and we just do:

PHP:
			foreach ($this->_optionVals[$sql] as &$opt)
			{
				eval($eval);
			}

... so we might need to tweak that code so we add a key to the foreach that loops around the options? So the eval'ed code could unset the $key?

Or to make it easier for the users, maybe just add some code so if the eval() returns false, we remove the option?

-- hugh
 
I would say use a database join element instead which would point to a database table which contains columns for the label, the value and the view access.

You could then write either an sql where statement to filter the options based on teh current users access level
Did you try this one? (I think the rest is a discussion between Rob and Hugh)
 
... or use the eval sub options textarea to filter the returned options.

Im not at my pc to be able to give you more precise help though I think the eval method would be the simplest

Is there a tutorial on using these options?
 
You'll have to change your element to a dbjoin for both ways.

Your php code would go into the "eval options" (it's not the code Hugh is showing, this is fabrik source code), see the tooltip. But as Hugh says I assume it's only for changing the options text not for restricting the displayed ones.
 
Seems that either Hugh added the code to remove options or it was already there.
So here' how I've done this:

I create a Fabrik list called 'dbjoin_use_view_test', that we will use to contain the database joins data, and add the following element:

label - a string in the format '{view level id}:{actual label}

(Note the list will automatically create id, and date_time elements)

So say for example you want an option in your database join to show up for public users (and your view levels are set to the Joomla default). You would enter a label of:

Code:
1:this is my label visible to one and all
for registered users
Code:
2: ohh you registered with us - neat
for special users
Code:
3: oh get you aren't you special
You can see where I get the 1,2,3 from from this page administrator/index.php?option=com_users&view=levels, in the ID column.


Then in your initial list when you want to show your dropdown element create a database join element, give it a label and a name, assign it to a group, and add these options specific

table: dbjoin_use_view_test
value: id
label: label

eval options:

PHP:
$bits = explode(':', $opt->text);
$accessLevel = $bits[0];
$opt->text = $bits[1];
$user = JFactory::getUser();
$levels = $user->getAuthorisedViewLevels();
if (!in_array($accessLevel, $levels)) {
  return false;
}
I'll walk through these lines of code:

The eval PHP code loops over each option of the select list created by the database join element. So this code is run on each option, which is referenced as the variable $opt, it has two properties, value and label.
PHP:
$bits = explode(':', $opt->text);
This explodes the label into an array, (the access level, and the actual label we want to use)
PHP:
$accessLevel = $bits[0];
Assign the access level to $accessLevel

PHP:
$opt->text = $bits[1];
Set the option label to the actual label we want to use, e.g. "this is my label visible to one and all" and not "this is my label visible to one and all"

PHP:
$user = JFactory::getUser();
$levels = $user->getAuthorisedViewLevels();
this gets the current logged in user
and then gets which authorised view levels he can see. This is an array

PHP:
if (!in_array($accessLevel, $levels)) {
  return false;
}
Finally we check if the option should be seen by the current user, if not then we return false. Doing so tells the database join element to remove the option from the select list it will render

-Rob
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top