123 Posts
EclipseMedia
7 years ago
17
Topic

I need to have certain fields that makeup a Content Type only viewable to a specific usergroup. The article itself needs to be Public so I can't restrict the whole article, only certain fields in the article. 

I'm going to create a Dynamic field that pulls in Joomla Usergroups from MySQL. The restricted fields then needs to only allow viewing to the usergroup selected in the dynamic field. :)

Any ideas? Thank you

Get a VIP membership
4229 Posts
Kadministrator
7 years ago
0
Level 1

There is restriction field that can do this 

https://www.seblod.com/store/extensions/10872

123 Posts
EclipseMedia
7 years ago
0
Level 1

I installed the plugin as you suggested. The issue is,is that the fields need to be restricted based on what usergroup the admin selects when they create the seblod (content type) article. Here is the scenario

1) Joomla admin creates a new seblod article called Activities (content type)

2) The admin clicks a dropdown selection field consisting of Joomla usergroups, they select which usergroup this Article is for (example "partner" usergroup)

3) Once saved. The public can still see the article, bit only fields viewable are "title, location and description". The other fields "resources, participants and trainer" fields are only visible to users who are logged in and belong to the usergroup selected by the admin in Step 2

I hope this makes sense. Thank you Klas :)

1283 Posts
Bucklash
7 years ago
2
Level 1

Hi

How about a position override:

if (usergroup a) {}

else if (usergroup b) {}

To get fields values uss 

$cck->renderField('field_name');


$cck->getValue('field_name');


$cck->get('field_name')->value;

Bucklash

123 Posts
EclipseMedia
7 years ago
1
Level 2

Sounds promising. Are you able to give me a little more details? Where to apply the position override.

1283 Posts
Bucklash
7 years ago
0
Level 3

Hi

Quick answer, look at this: 

overriding-a-position

You create a position override which your template picks up, and renders whatever you have 'coded'.

4229 Posts
Kadministrator
7 years ago
0
Level 1

Alternative solution would be to use beforeRender code field and do a check there - if field is not supposed to show set $field->display = 0;$field->state = 0;

123 Posts
EclipseMedia
7 years ago
1
Level 1

So I just tried to do a test. But creating an overide file and just having "test" to see if it works but it doesn't This is the path

/templates/seb_one/positions/article/content/topa.php

What am I doing wrong?

85 Posts
kromoadv
7 years ago
0
Level 2

top-a.php

123 Posts
EclipseMedia
7 years ago
0
Level 1

OK Thank you, I got it working. :)

123 Posts
EclipseMedia
7 years ago
3
Level 1

Now that I can override a position. I need these 2 things

1) A dropdown select in Admin Form (edit article content type) listing all Joomla Usergroups to allow the person to select a usergroup

2) A condition in the override php file to only display if the the user belongs to the usergroup selected in Admin Form.

Thank you so much!

4229 Posts
Kadministrator
7 years ago
2
Level 2

123 Posts
EclipseMedia
7 years ago
1
Level 3

Hi Klas. I understand how to create a file to override a position. 

I need to know, what selection field do I use to display a list of Joomla Usergroups to select. 

Then I will create an override (if statement) to only show the position based on the Usergroup selected

4229 Posts
Kadministrator
7 years ago
0
Level 4

For usergroups field you can use Joomla Library -> usergroup (you need to create new field instance, existing one has user object for storage which most likely won't work for you)

123 Posts
EclipseMedia
7 years ago
3
Level 1

Hi Klas,

I have a code that restricts the fields by 2 specific usergroups.

<?php
$user =& JFactory::getUser();
$uid = $user->id;

jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($uid, false);
if(in_array(8, $groups) or in_array(10, $groups)):?>

Which does successfully restricts the content to usergroup IDs 8 and 10.

But I need the 10 to be replaced by a CCK text field called usergroup_id 

I tried this but it doesn't work. I think I am missing something simple.

<?php
$user =& JFactory::getUser();
$uid = $user->id;

jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser($uid, false);
if(in_array(8, $groups) or in_array(echo $cck->getValue('usergroup_id');, $groups)):?>

4229 Posts
Kadministrator
7 years ago
2
Level 2

echo prints information, but you dont't want that - use

or in_array($cck->getValue('usergroup_id'), $groups)
123 Posts
EclipseMedia
7 years ago
1
Level 3

Hi Klas.

I would like to have 3 arrays but I get an php error.

if(in_array(8, $groups) or in_array($cck->getValue('usergroup_id') or in_array($cck->getValue('usergroup_id2'), $groups)):?>

Can you see why I would have an error. I just want to have 3 instead of 2 arrays

4229 Posts
Kadministrator
7 years ago
0
Level 4

in_array($cck->getValue('usergroup_id') is not complete , $groups) is missing

Get a Book for SEBLOD