Keyword

User groups permissions

More
6 years 3 weeks ago #168832 by Leo
User groups permissions was created by Leo
Good morning, I would need to configure the frontend editing (parameters k2) for the different user groups. For example, I wanted to allow images to be uploaded only to a particular user group. Do you have any suggestions?
Thank you

Please Log in or Create an account to join the conversation.

More
6 years 3 weeks ago #168843 by JoomlaWorks
Replied by JoomlaWorks on topic User groups permissions
This is really an edge case.

While it's possible to have different user groups posting content to different categories in the frontend, you can only disable features by overriding the "itemform.php" template override in K2. In this case, you'd need to bring in the PHP code that is included in that file and then use some logic to hide or show the form fields you don't want or want to display to your user groups. It's dead simple to retrieve the K2 user group for example. So it's a matter of copying the PHP override, adding some "ifs" around the fields you want to control and that's it.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
6 years 3 weeks ago #168924 by Leo
Replied by Leo on topic User groups permissions
ok thanks.
I understand where to edit the file but how can I recover the id or the name of the k2 user group?

Please Log in or Create an account to join the conversation.

More
6 years 3 weeks ago #168927 by JoomlaWorks
Replied by JoomlaWorks on topic User groups permissions
First off, make sure your users belong to some K2 User Group.

The quick way to get the K2 group ID is to make a tiny query based on the active user's identity:
<?php

// Get current user's K2 Group
$user = JFactory::getUser();
$db = JFactory::getDbo();
$query = "SELECT * FROM #__k2_users WHERE userID=".(int)$user->id;
$db->setQuery($query, 0, 1);
$k2User = $db->loadObject();
$userK2Group = $k2User->group;

$userK2Group will return the K2 user group for the active user.

Add this at the top of your itemform.php override so you can control the flow afterwards.

P.S. The plan for the next major update of K2 is to also ditch the use of such queries and instead offer a nice API to make everyone's life easier :)

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum