I meant to use FlexiAccess Groups for controlling the output. That is what you said you want, people to see different things depending on what they are.
First create the groups in FlexiAccess with appropriate name and assign users to the groups.
Be careful with the FlexiAccess Group names to be lower case, we will use them below
I have not tested this code but it should work.
Put this in your template file e.g.
mytemplate/category_items.php
used by the category view to display the table of items.
Code:
// 1. Get the Flexi Groups of the user
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$user_grpIDs = explode(',', trim($user->gmid));
if ($user_grpIDs[0]=='') $user_grpIDs = array();
// 2. Get the Flexi Groups IDs when given their name
$grpnamearr = array('teacherss','students','parents');
$grpnamelist = "'" . implode("','", $grpnamearr) . "'";
$query = "SELECT name,id FROM #__flexiaccess_groups WHERE name IN (".$grpnamelist.")";
$db->setQuery($query);
$arr = $db->loadResultArray();
foreach ($arr as $grpinfo) {
$grpIDbyname[$grpinfo['name']] = $grpinfo['id'];
}
// 3. Find out what group (or groups) the user belongs to
foreach ($grpnamearr as $grpname) {
$grpID = $grpIDbyname[ $grpinfo[$grpname] ];
$isA[$grpname] = in_array( $grpID, $user_grpIDs);
}
Then replace the lines that produce table header:
Code:
<?php foreach ($columns as $name => $label) : ?>
<th id="field_<?php echo $name; ?>" scope="col"><?php echo $label; ?></th>
<?php endforeach; ?>
with:
Code:
<?php foreach ($columns as $name => $label) : ?>
<?php
$output_field = false;
if ($field->name=='sel_field_forcat_a' || $field->name=='sel_field_forcat_b' || ...) {
if ($isA['teachers'] || $isA['students'] ...) $output_field = true;
}
if ($field->name=='sel_field_forcat_g' || $field->name=='sel_field_forcat_k' || ...) {
if ($isA['parents'] || $isA['teachers'] ...) $output_field = true;
}
?>
<?php if ($output_field) : ?>
<th id="field_<?php echo $name; ?>" scope="col"><?php echo $label; ?></th>
<?php endif; ?>
<?php endforeach; ?>
and the lines that produce the rows:
Code:
<!-- BOF fields -->
<?php foreach ($columns as $name => $label) : ?>
<td><?php echo isset($item->positions['table']->{$name}->display) ? $item->positions['table']->{$name}->display : ''; ?></td>
<?php endforeach; ?>
<!-- EOF fields -->
with:
Code:
<!-- BOF fields -->
<?php foreach ($columns as $name => $label) : ?>
<?php
$output_field = false;
if ($field->name=='sel_field_forcat_a' || $field->name=='sel_field_forcat_b' || ...) {
if ($isA['teachers'] || $isA['students'] ...) $output_field = true;
}
if ($field->name=='sel_field_forcat_g' || $field->name=='sel_field_forcat_k' || ...) {
if ($isA['parents'] || $isA['teachers'] ...) $output_field = true;
}
?>
<?php if ($output_field) : ?>
<td><?php echo isset($item->positions['table']->{$name}->display) ? $item->positions['table']->{$name}->display : ''; ?></td>
<?php endif; ?>
<?php endforeach; ?>
<!-- EOF fields -->
For other view e.g. item view, you use the same first part of this code,
but for the second part of this code you need to go the appropriate template position 'mypos' e.g. find the statement:
Code:
<?php foreach ($this->item->positions['mypos'] as $field) : ?>
and place the code inside ...
Regards