How to change the usertype from the frontend?

14 years 10 months ago #98615 by ahf
I am promoting a user's access level (usertype) for example from "Registered" to "Author" by changing the columns usertype and gid in the #__users table.

with:
[code:1]
$sql = "UPDATE #__users SET usertype='Author', gid='19' WHERE id=" . (int) $uid ." AND gid < 19";
$_CB_database->SetQuery($sql);
$_CB_database->query();
[/code:1]
and it updates the database successfully.

However that seems not to be enough as for example the user is not recognised as "Author" in the backend.

What else has to be changed in order to achieve the desired promotion of a user?

I discovered that the #__core_acl_groups_aro_map table is out of sync but that has been for quite a while and did not cause any trouble so far as long as I used the backend to change the user's access levels.

Has someone the lines of code I need? :woohoo:
THANK YOU!

Please Log in to join the conversation.

14 years 10 months ago #99046 by ahf
It seems that nobody else had this (as a) problem. Just in case, here is the solution as I see it now:

In simple words: the change of usertype requests the update of two tables:
__users and
__core_acl_groups_aro_map

and uses the
__core_acl_aro table as a lookup.

[code:1]
$acl =& JFactory::getACL($uid);
$new_usertype = 'Author';
$new_group_id = $acl->get_group_id('',$new_usertype,'ARO');

// Update __users:
$sql = "UPDATE #__users SET usertype= '$new_usertype', gid=" . (int) $new_group_id ." WHERE id=" . (int) $uid ." AND gid < $new_group_id";
$_CB_database->SetQuery($sql);
$_CB_database->query();

// look up aro_id from __core_acl_aro:
$sql = "SELECT id FROM #__core_acl_aro users WHERE value=" . (int) $uid;
$_CB_database->SetQuery($sql);
$aro_id = $_CB_database->loadResult();

// use aro_id to update __core_acl_groups_aro_map:
$sql = "UPDATE #__core_acl_groups_aro_map SET group_id = $new_group_id WHERE aro_id =$aro_id";
$_CB_database->SetQuery($sql);
$_CB_database->query();

[/code:1]
I reckon that one can get this done in involving the Joomla Framework more extensively but I felt more comfortable to do it this way.
Maybe a Joomla Expert is willing to post here his/her script doing it all on 3 lines of code ... B)

Please Log in to join the conversation.

14 years 10 months ago #99051 by Rapunzl
I'm not a coder, but I know if you want to allow all users to register as Author, you simply change the setting in Global Configuration of Joomla from Registered to Author.

If you're doing this on a case-by-case basis, I think sticking with the backend modification is more secure, but that's just my opinion.

;)

Jamie (Rapunzl)
Community Builder Team Member

Before posting on forums: Read all CB Articles | Specially the FAQ | Help us help you
CB links: Subscribe to CB documentation | [url=http://www.joomlapolis.com/content/view/7363/37/
]Our templates[/url] | [url=http://www.joomlapolis.com/content/blogcategory/61/74/
]Paid Subscriptions[/url] | Get Hosting | Our Forge
Visit my CB Profile

My personal site Rapunzl's Reality always under reconstruction

Please Log in to join the conversation.

14 years 9 months ago #101481 by krileon
This can be done with a plugin, but isn't necessary if you're using J1.5 as it's a Global Setting in Joomla.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

14 years 9 months ago #101495 by ahf
I guess I should have stressed clearly that I am NOT changing the usertype for ALL users. In my case it is changed when a user updates a particular field which makes re-approval (review by a moderator) necessary - hence the user gets demoted from author to registered. This is reversed at re-approval.

That's also the reason why I posted in the CB forum.

I supplied the way how I did it with a plugin in an earlier post. Happy to receive feedback to that solution.

Please Log in to join the conversation.

14 years 9 months ago #101509 by Rapunzl
CBSubs allows this.

Jamie (Rapunzl)
Community Builder Team Member

Before posting on forums: Read all CB Articles | Specially the FAQ | Help us help you
CB links: Subscribe to CB documentation | [url=http://www.joomlapolis.com/content/view/7363/37/
]Our templates[/url] | [url=http://www.joomlapolis.com/content/blogcategory/61/74/
]Paid Subscriptions[/url] | Get Hosting | Our Forge
Visit my CB Profile

My personal site Rapunzl's Reality always under reconstruction

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.247 seconds

Facebook Twitter LinkedIn