CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Making some changes to Joomla's userType attribute
Pages: [1]

Author Topic: Making some changes to Joomla's userType attribute  (Read 3425 times)

slaterino

  • Guest
Making some changes to Joomla's userType attribute
August 07, 2009, 02:10:48 pm
Hi,
I was wondering if anyone could help me. I am trying to do a quick fix on a script so am doing a modification around the userType value. Basically, I have 2 registration screens. Both registration processes need to assign the user to a different User Management Group, in my case Business and User. As the registration screens both have a different 'Itemid' I was thinking one easy way to do it was to get Joomla to look for a certain 'Itemid.' If that condition was met it would assign them as a 'Business', otherwise it would use the default set in Joomla, which in my case is 'User.' Hence, I have come up with this code:
Code: [Select]
$Itemid = mysql_real_escape_string($_GET['Itemid']);
if ($Itemid == '13')
{$userType = 'Business';}
else
{$userType = $userParams->get('new_usertype');}

This code works in practice, i.e. if I create a test module, but when I have tried including it in the CMSUser.php (under // get the default usertype) file it always assigns the User as the default, which is 'User.' It seems to be ignoring the $_GET command. Does anyone know a way around this? Or a better method?

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Making some changes to Joomla's userType attribute
August 07, 2009, 04:03:19 pm
seems like it should work.
throw some echo statements inside the IF clause to see what's happening.

support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

slaterino

  • Guest
Re: Making some changes to Joomla's userType attribute
August 10, 2009, 07:25:03 pm
Hi,
I have been trying for the last few days to get this thing working with no luck so far, though I do think I am getting closer to sorting it. What I have ended up doing in the CMSUser.php file is something like this:

Code: [Select]
$Itemid = mysql_real_escape_string($_GET['Itemid']);

if ($Itemid == '13')
{
echo "Business";

class CRM_Core_BAO_CMSUser
{
static function createJoomlaUser( &$params, $mail )
{
$userType = 'Business';
}
}
}
else
{
echo "User";

class CRM_Core_BAO_CMSUser
{
static function createJoomlaUser( &$params, $mail )
{
$userType = 'User';
}
}
}

Okay, so I've just included the sections I have changed here. Everyway I tried to run the function it was always defaulting to the User Access Level I had specified in Joomla admin. So I thought I would duplicate the class function and use an IF/ELSE clause to see what would happen. With the code above it echoes Business and User on the correct pages. However, it always defaults to whatever is entered in the second of the classes when the page is completed. No matter what this value is the registration will default to it. Why is this? Is it something to do with static functions? Is it not possible to use a class twice in a statement. I am still learning how this whole area works so please let me know what I am doing wrong and if you have any advice on how I can fix it.

Thanks
Russ

rogerco

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 5
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 01:43:01 am
Hi,
There seem to be three files called CMSuser.php - I take it you are looking in the one in CRM/Core/BAO and are playing with the function createJoomlaUser() around line 493?

The lines
Code: [Select]
   
     $userParams = &JComponentHelper::getParams('com_users');
        // get the default usertype
     $userType = $userParams->get('new_usertype');

are a call to a core Joomla function to return the default Joomla New User Type as set in your backend "Joomla-Site-System-New User Registration Type" opption. The only possible choices are Registered, Author, Editor or Publisher. There is no Joomla user type 'Business' so of course it is setting the default.

Not sure exactly what you are trying to achieve here - are your Business users going to be registered as Author or Editor types automatically so that they have some additional rights on the rest of the content (creating articles, using menu's and modules flagged as 'Special'), or are you wanting to assign them to a different group of contacts within the CiviCRM database.

If the former then I think you should be able to just use your original
Code: [Select]

   $Itemid = mysql_real_escape_string($_GET['Itemid']);
   if ($Itemid == '13') {
           $userType = 'Author'; //or whatever level you want to assign them
   } else {
           $userType = $userParams->get('new_usertype');
   }

If the latter then you just need to create an appropriate group or tag and set each registration form to assign new contacts to the appropriate group?

Hope this helps
RogerCO

slaterino

  • Guest
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 06:33:23 am
Roger,
You are right that it is that CMSUser.php which I am editing, however it is possible to create extra User Account Groups, so in addition to Author, Editor, etc., I have created 2 new user groups, Business and User (these are selectable as New User Registration Types). Basically, as stated in my first post, I have 2 Registration forms and I need these forms to automatically assign 2 different levels of user. I have tried using exactly the same code as you have suggested using combinations of Business/User, Author/Editor and many more but in this case it always ignores the IF clause and just runs the ELSE statement. I have tried echo'ing $Itemid in this code but nothing shows. I am assuming for some reason that it is not possible to use a GET clause in this function and that is why it is not working.

This is why I was trying to find a different way of doing this, as in the coding I listed and I know for certain that the IF statement is working correctly, as the code which I have chosen to echo definately does echo at the top of each page. However, as I explained, no matter what statement is echo'd at the top of the page (whether it says User or Business) for some reason the code which is used is always the bottom code. It will always default to whatever is written here, and by this mean I mean what I have hard-coded. In the example I listed the value that is set as the default in Joomla is ignored and its the hard-coded statement in the ELSE statement which is always run. This behaviour seems really odd to me. Why when the IF/ELSE clause seems to work correctly for printing the echo'd statements would it always just use the $userType that's listed in the ELSE statement?

It seems like someone really doesn't want me to hard-code this! All of my ideas seem to fall at the first hurdle!

rogerco

  • I post occasionally
  • **
  • Posts: 66
  • Karma: 5
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 08:23:14 am
Oh, I see - my next guess would be that in adding the new groups into jos_core_acl_aro_groups table something has gone wrong that has broken the  $acl->get_group_id( '', $userType);

This will be a problem in the Joomla modification you have made and JFactory::getACL() is perhaps not recognising the $usertype='Business' so is simply returning the default id.

Check if the left and right links on the new usertype you have created are correctly formed, and do you also have to make a change in the jos_groups table and get that linked correctly?

Might be a question better solved in the Joomla website forum?

Does it work on a vanilla Joomla site with just the standard user groups?

slaterino

  • Guest
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 08:49:37 am
The new user groups have definately been added correctly, as per instructions on the Joomla site. The thing is it's not that it's switching to the default value in Joomla, it's that it's always using the value that is listed in the ELSE statement. The $gid value is always being entered correctly in the tables, as are the usernames. For instance, with the code I posted earlier, the Usertype will always be added as 'User' no matter what the $Itemid is. But if I changed the value in the ELSE statement to 'Business' then it will add the user as a 'Business' user without any problems, it's just that it always uses the value in the ELSE statement and ignores the value in the IF statement, despite echo'ing the correct value. It's so confusing.

I will try and get some more help on a Joomla forum. I have asked before but they were slightly confused as nobody had encountered the CMSUser.php file before.

Also, I have tried the same with Author and Editor but get the same results.

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 09:21:27 am
Ok, I think this is happening because CMSUser.php isn't called until after the profile is submitted, at which point the Itemid is lost (weakness in Civi -- it doesn't carry the Itemid past the initial page). So the conditional statement reverts to the else value. I'll look at it some more and see if I can come up with a workaround.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

slaterino

  • Guest
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 03:23:58 pm
I thought that might be a possibility and I tried using $_SESSION variables to see if this would work but again had no luck. Thanks for having a look into this. It will be amazing to get this thing sorted!

Thanks,
Russ

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 03:25:24 pm
I gave it a try, but had to do some work. We just need to retrieve the variable from the preProcess and then pass it to the postProcess. not sure the best way to do that.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Making some changes to Joomla's userType attribute
August 11, 2009, 07:12:55 pm

u can do this via hooks :)

store the itemID in the buildForm hook and retrieve it in the postProcess hook

this is for all publically exposed "form" pages, right? i'll think a bit on how to make it generic and integrate it with the core code

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

slaterino

  • Guest
Re: Making some changes to Joomla's userType attribute
August 12, 2009, 03:11:22 pm
Okay, this is my first time using hooks and I've had a go at putting something together that makes sense to me but doesn't seem to be working. This is the code I have come up with:

Code: [Select]
function itemid_civicrm_buildForm( $formName, &$form )
{
CRM_Core_Error::debug( $formName );
CRM_Core_Error::debug( $form );
exit( );

    if ( $formName == 'CRM_Profile_Create_User_Registration' || $formName == 'CRM_Profile_Create_Business_Registration' )
{
$Itemid = mysql_real_escape_string($_GET['Itemid']);
$form->assign( 'Itemid', $Itemid );
}
}

function itemid_civicrm_postProcess( $formName, &$form )
{
CRM_Core_Error::debug( $formName );
CRM_Core_Error::debug( $form );
exit( );

    if ( $formName == 'CRM_Profile_Create_User_Registration' || $formName == 'CRM_Profile_Create_Business_Registration' &&
        $form->getVar( 'Itemid' ) == '13' )
{$userType = 'Business';
}
else
{$userType = $userParams->get('new_usertype');
}

I have put this code in a module which I have assigned to the page I want to use it. I have then left out the code regarding $userType from the cmsuser.php file. Is this the correct way to do it? Sorry for my complete naiveity on this matter! But I am really trying!

Russ

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Making some changes to Joomla's userType attribute
August 12, 2009, 07:04:16 pm

check the instructions on the issue here:

http://issues.civicrm.org/jira/browse/CRM-4528

also call the function: joomla_civicrm_buildForm( $formName, &$form ) etc

and store it in a file called civicrmHooks.php

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Making some changes to Joomla's userType attribute
August 12, 2009, 07:18:36 pm
Russ,
the reference to "module" in the hook instructions is drupal specific (misleading, i know -- we'll need to update).
you can save the civicrmHooks.php file within the CRM directory, or if you have a php override directory setup, within that
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Making some changes to Joomla's userType attribute

This forum was archived on 2017-11-26.