1. DATAFull
  2. Features Request
  3. Wednesday, March 18 2020, 07:48 PM
I would like to know if it is possible to create a field to change the User permission group in K2.

Thanks in advance for your help.
admin Accepted Answer
Admin
Hi,
Easy Profile does not do this natively but it is possible by creating a simple Plugin, you can follow these steps:
- Download our skeleton plugin (you can find it at http://docs.easy-profile.com/index.php/article/triggers)
- Install it from Joomla Installer
- Enable it from Extensions->Plugins
- Open file /plugins/jsn/skeleton/skeleton.php
- Remove sample functions: "triggerFieldAvatarUpdate" and "triggerProfileUpdate"
- Add a function like this:
public function triggerProfileUpdate($user,&$data,$changed,$isNew)
{
if(isset($data['HERE_THE_ALIAS_OF_YOUR_FIELD']) && !empty($data['HERE_THE_ALIAS_OF_YOUR_FIELD'])){
$value = $data['HERE_THE_ALIAS_OF_YOUR_FIELD'];
if($value == 'opt1') {
/* HERE THE CODE TO ADD USER TO K2 GROUP, FOR EXAMPLE WITH A SQL QUERY */
}
else{
/* HERE THE CODE TO REMOVE USER FROM K2 GROUP, FOR EXAMPLE WITH A SQL QUERY */
}
}
}


IMPORTANT NOTE: This code is not tested and not supported, this is only for example purpose.
  1. more than a month ago
  2. Features Request
  3. # 1
DATAFull Accepted Answer
Pro
Thanks for the answer, but it was a little vague, after configuring the code, what is the procedure to create a select with this function? I didn't see any way to customize the selects, is there any specific field to use this skeleton?
  1. more than a month ago
  2. Features Request
  3. # 2
admin Accepted Answer
Admin
Hi,
before use this code you have to create the field, for example a field of type select with alias like "k2_group" and following options
normal|Normal
author|Author
each option need to have following syntax "value|text"

So after create the field you can customize the code with something like
public function triggerProfileUpdate($user,&$data,$changed,$isNew)
{
if(isset($data['k2_group']) && !empty($data['k2_group'])){
$value = $data['k2_group'];
if($value == 'author') {
/* HERE THE CODE TO ADD USER TO K2 GROUP, FOR EXAMPLE WITH A SQL QUERY */
}
else{
/* HERE THE CODE TO REMOVE USER FROM K2 GROUP, FOR EXAMPLE WITH A SQL QUERY */
}
}
}
  1. more than a month ago
  2. Features Request
  3. # 3
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.