Want users 2 join ACL group through front end profile plugin

ultramanjones
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Aug 24, 2011 1:10 pm

Want users 2 join ACL group through front end profile plugin

Postby ultramanjones » Fri Mar 16, 2012 4:35 pm

I have created a group called "subscriber" and I want the users to be able to choose to join this group simply by clicking a radio button when registering or changing their profile options. Then I will send an email to all users in this group concerning updates and etc. from the company. I would prefer not to have to manually add them all to this group based on requests in email or what have you. I really want this to be automatic.

Since the User Manager in 2.5 has the option to do a Mass Mail simply by selecting which groups to send to, I think this is a logical solution, if only I can figure out how to assign this group through some sort of php script directly associated with the profile plugin. Any ideas, of course, are totally welcome.

Thanks to using code from this: http://docs.joomla.org/Creating_a_profile_plugin I've got the radio buttons made, now I just need to make them do something!

Any ideas peoples!?

=======
UPDATE
=======

Ok, this is going to be embarrassing, but seeing as I don't know PHP, I think I've gotten pretty close to cobbling together some code for this, but it still doesn't work. I'm probably making some terrible simple syntax error and just don't know it. Anyway, I have come up with this code to add to the profile.php file that "comes with" Joomla.

Here's what I did.
I added these imports to the top of profile.php

Code: Select all

jimport( 'joomla.user.helper' );

jimport( 'joomla.user.user');

jimport( 'joomla.utilities.arrayhelper' );


And then inside of the onUserAfterSave function I added... (my addition is after the comments)

Code: Select all

function onUserAfterSave($data, $isNew, $result, $error)
   {
      $userId   = JArrayHelper::getValue($data, 'id', 0, 'int');
      //
      //BEGIN CUSTOM CODE
      //
      //put this inside the onUserAfterSave function in profile.php
      // This code will check if the user clicked the radio button for email
      // updates by checking the 'subscribe' boolean in the data
      // then assign the user to that group (group 9) if true   
      $groupID = 9; //9 is the value for the subscriber group in the ACL
      $subscribeFlag = JArrayHelper::getValue($data, 'subscribe', 0, 'boolean');
      //DEBUG code that forces if statement to come up true
      //$subscribeFlag = 1;
      echo $subscribeFlag;
      if (!($subscribeFlag == 0))
      {
         try
         {
         JUserHelper::addUserToGroup($userId, $groupID);
         }
         catch (JException $e)
         {
            $this->_subject->setError($e->getMessage());
            return false;
         }
      }
      
      //END CUSTOM CODE
      //

--------------------------------
If I un-comment the line:

Code: Select all

//$subscribeFlag = 1;


then when I use the front end register form to create a new user they are automatically added to the "subscriber" group (and the registered group) every time, which I can see in the back end, by going to the user manager.

So my problem appears to be in retrieving the value from the radio button.
The line above:

Code: Select all

$subscribeFlag = JArrayHelper::getValue($data, 'subscribe', 0, 'boolean');

Isn't getting it done.

Hopefully this is a simple PHP fundamental thing that I will figure out soon...
Thanks in advance
Cheers!

ultramanjones

ultramanjones
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Aug 24, 2011 1:10 pm

Re: Want users 2 join ACL group through front end profile pl

Postby ultramanjones » Mon Mar 19, 2012 10:31 pm

Finally got it working!

Here is the version of the code that works.

Code: Select all

function onUserAfterSave($data, $isNew, $result, $error)
   {
      $userId   = JArrayHelper::getValue($data, 'id', 0, 'int');
      //
      //BEGIN CUSTOM CODE
      //
      //put this inside the onUserAfterSave function in profile.php
      // This code will check if the user clicked the radio button for email
      // updates by checking the 'subscribe' field in the data array
      // then assign the user to that group (group 9) if true   
      $groupID = 9; //9 is the value for the subscriber group in the ACL
      $subscribeFlag = ($data['profile']['subscribe']);
      if (!($subscribeFlag == 0))
      {
         try
         {
         JUserHelper::addUserToGroup($userId, $groupID);
         }
         catch (JException $e)
         {
            $this->_subject->setError($e->getMessage());
            return false;
         }
      }
      
      //END CUSTOM CODE
      //

---------------------------------------

Mind you, you will need to create the radio button with the name "subscribe" by editing the .xml and .ini files.
Here are the files I had to edit (with FileZilla) to make this work:

Code: Select all

/yoo_quantum/plugins/user/profile/profile.xml
/yoo_quantum/plugins/user/profile/profiles/profile.xml
/yoo_quantum/plugins/user/profile/profile.php
/yoo_quantum/administrator/language/en-GB/en-GB.plg_user_profile.ini


I'm going to post a link here with the full solution, once I get a chance to throw it up on my blog.
UPDATE: Here's that link http://ultraopengl.[URL banned].com/2012/03/joomla-25-add-field-to-register-form.html.
I hope this helps someone!

Cheers!

ultramanjones


Return to “Access Control List (ACL) in Joomla! 2.5”

Who is online

Users browsing this forum: No registered users and 3 guests