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) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Using different profiles based on the user role
Pages: [1]

Author Topic: Using different profiles based on the user role  (Read 1216 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Using different profiles based on the user role
June 29, 2010, 02:54:35 am
Hi,

Would want to have different registration forms based on the role of the user when creating a drupal contact.

Is there a way to say profile X is on the user registration only if the user created has role Y ? How would you do that ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using different profiles based on the user role
June 29, 2010, 03:05:10 am
Quote
Is there a way to say profile X is on the user registration only if the user created has role Y ?
I don't think you can do this.

Quote
How would you do that ?
I think you will have to modify civicrm.module

Kurund
Found this reply helpful? Support CiviCRM

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Using different profiles based on the user role
June 29, 2010, 03:13:01 am
Thx,

will try to add a bit of jquery to hide the profile I don't need when it's the role guest, see how it goes.

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Using different profiles based on the user role
June 29, 2010, 03:17:43 am
Ya might work :), but instead of hiding I would recommend you should remove those elements from dom object so that they are not submitted.

Kurund
Found this reply helpful? Support CiviCRM

marc

  • Guest
Re: Using different profiles based on the user role
July 22, 2010, 06:38:24 am
We are not going down the jQuery road after all. So how would I go about changing this?

Where I got so far:

Drupal uses autoassignrole to show different registration forms based on the URL, so .../register/activist gives one registration form, .../register/guest another. There is a function in the module that allows to easily get the id (inside drupal) of the role while we are on the form.

Now civicrm kicks in via civicrm_user hook, with type 'register' which goes through a bunch of stuff. It seems to me that all the work gets done in CRM_Core_BAO_UFGroup::getEditHTML, which calls both:
  • $controller = & new CRM_Core_Controller_Simple( 'CRM_Profile_Form_Dynamic',
                                                               ts('Dynamic Form Creator'),
                                                               $action );
  •             $template =& CRM_Core_Smarty::singleton( );

                return trim( $template->fetch( 'CRM/Profile/Form/Dynamic.tpl' ) );

When I dump the variables in Dynamic.tpl, I find that all the civicrm profiles are in the array $fields, but I have no clue where $template gets them from, so I assume they come from the $controller.

My question now is, how can I switch some civicrm_profiles off and others on, depending on the id of the role? The only way I can see right now is to hack the Dynamic.tpl and say something like 'if groupname = $civicrmProfileWeDontWant then skip else as normal'. Which is well ugly, will require multiple hardcoded profile names and ids in a smarty template.

The other option should be to find out where the $fields array gets loaded and keep it from loading some profiles. But I really can't figure out where that happens. I assume in the $controller.

Any takers? Or am I going about this in the totally wrong way?

Marc

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: Using different profiles based on the user role
July 22, 2010, 10:15:33 am

the easiest place to hack this is: CRM/Profile/Form.php, approx line 173

you might have to fix a few follow on warnings also. i cant think of a clean way to do this right now

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

marc

  • Guest
Re: Using different profiles based on the user role
July 24, 2010, 06:41:43 am
That worked magic, it calls something in CRM_Core_BAO_UFGroup where I only had to put the following piece of code to get it done:

Code: [Select]
           
            $rid = autoassignrole_get_active_path_rid();

            if ( ($id == 10) && ($rid != 4)) {
                    continue;
            }

where $id is the profile id in civicrm and $rid the roleid in drupal. I've really been looking in the wrong places for that, thanks Lobo.

Marc

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Using different profiles based on the user role

This forum was archived on 2017-11-26.