Buy Now
Sign in

E-mail to selected user from a specific usergroup

SPABO , October 23 2014
Answered
Featured
S
SPABO

Next to sending an email to a selected user user the dynamic-data-dropdown, I wish to see only the users which are in a specific usergroup

The usergroup is called "Docenten" and I can se this in the table jos2_usergroups , with the id nbr. 10

Any ideas how to get this data pulled in the form?

GreyHead

Hi SPABO,

There's a Joomla! method JAccess::getUsersByGroup('group_id'); that will return an array of all the user-id's from that group. You'd then need to loop through that list to get names and emails for them. There's an example in this StackOverFlow answer.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

S
SPABO

But where and how and what to implement this in a dynamic drop down, where I can select a specific user?
(Note : In the V4 version)

GreyHead

HI SPABO,

Use a Custom Code action in the form ON Load event to get an array of users in the format:

				$form->data['users']
=> [0][id] => '111',
[name] => 'name_a',
=> [1][id] => '222',
[name] => 'name_b',
. . .

Then you can use this in the Dynamic Date option of the DropDown.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

S
SPABO

In this way you load users I think, but I want to load only users from e specific user group

GreyHead

Hi SPABO,

I told you in my previous post how to get a list of users from a specific group.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

S
SPABO

Sorry Bob, for me not clear at all. :(

S
SPABO

Sorry for "bumping", but the idea is to load dynamically users which are in a specific usergroup

Currently (with the db multi record loader) I hava ALL the users loaded.

Anybody?

GreyHead

Hi SPABO,

What code have you taken from the StackOverFlow answer?

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

S
SPABO

Bob,
Nothing at all, as I simply don't know where to put this.
I also wonder if this generates dynamically the users from a selected/specific usergroup.
Kees

GreyHead

Hi Kees,

Yes, you asked for code that got the users from a specific group - so that is what it does. I suggest that you try implementing it; you may need to get help with writing the code if that isn't your strength yet.

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

S
SPABO

Hi Bob,
This is what I "created"

				<?
jimport( 'joomla.access.access' );
   $docenten = JAccess::getUsersByGroup(2);
   jimport( 'joomla.user.user' );
   foreach($docenten as $docenten){
   $users =& JFactory::getUser($docenten);

   //check if user is NOT blocked or NOT activated yet
   if($users->block == '0' && empty($users->activation)){

//create array not object for better sorting possibilities
$docent[$Docenten] = (array) $users;
}

}

array_multisort($docent, SORT_ASC);
var_dump($docent);
   ?>


Not sur if this is okay in this way, but I have no clue how and where to implement it......

admin

Hi,

Loading users from specific user group(s) will need a Join, a quick way to do this using the GCore framework in v5 is below:

				
<?php
$list = \GCore\Admin\Models\User::getInstance()->find('list', array('fields' => array('id', 'name'), 'conditions' => array('GroupUser.group_id' => 9)));   

Where 9 is the group id, you can replace it by an array of ids!
The $list variable should have an associative array with keys = users ids and values = users names, you can use 2 different fields if you like.

But then, what would you like to do with this list of users ?

Regards,
Max

Max
If your main question got answered then please mark the answer using the button!

S
SPABO

Perhaps I was not clear on this:

I wish to achieve to select an user , but not just a user , but only an user which is from a specific user-group

The code yoy provided, can I implement this is the current form( which is using the DB read function in "On Load" and "On Submit"???

No clue what you are saying here... :?
need a Join, a quick way to do this using the GCore framework in v5 is below:

admin

Select it how ? from a dropdown ?

Then what will you do with this user selection ?

Max
If your main question got answered then please mark the answer using the button!

S
SPABO

Correct Max,
From a dropdown and sending an e-mail.

Pls find the topic I started on this, but this shows ALL the users
https://www.chronoengine.com/forums/posts/f2/t97735.html?page=3

GreyHead

HI SPABO,

I have already given you the Joomla! code to do much the same as Max's code. You seem to have got that in the first part of the code you posted but I'm afraid that the last part makes little sense to me :-(

Bob

ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much

S
SPABO

And still I have nu clue what the both are saying, neither I have a solution.

admin

Hi SPABO,

if you are using v4 then you will have to do it the way Bob has posted, and you will need a custom code action to format the results (Bob already posted this too) before you feed them to the "Dynamic data" in the dropdown settings.

However, if you are going to use v5 then things will be much easier, first, use this code instead since you will need the list under the model:

				
<?php
$list = \GCore\Admin\Models\User::getInstance()->find('all', array('fields' => array('id', 'name'), 'conditions' => array('GroupUser.group_id' => 2)));
$form->data["User"] = \GCore\Libs\Arr::getVal($list, array("[n]", "User"), array());

Then in your "Dynamic data" for the dropdown, enter "User" in the "Data path" and id for the "value" and "name" for the "text".

Now, when the form submits you need to find the selected user's email and inject it in the form data array, use this code in a custom code action before the email action:
				
<?php
$form->data["dropdown_name"] = \GCore\Admin\Models\User::getInstance()->field("email", array("id" => $form->data["dropdown_name"]));


Finally use "dropdown_name" (which is your dropdown's field name) in the "Dynamic to" of the Email action!
Regards,
Max

Max
If your main question got answered then please mark the answer using the button!

admin

I have just updated my latest post above because 1 line of code was missing!

Max
If your main question got answered then please mark the answer using the button!