User subtype after the original register

Hey all.

This question has been raised a couple of times from a search I did but i couldn't find any solid solutions for it. Atm on my site i have  2 different kinds of "users". Let's call them "sub1" and "sub2" . By changing /engine/lin/users and /actions/useradd  i have managed to change user subtype during registration succesfully. My problem is that i already have 300+ members on my site and I need to change the subtypes on those as well. I know that $entity->subtype="BLAH" doesn't work after the initial creation (at least it didn't on my tests.I looped over all entities and tried to change the subtype that way but i got nowhere.).

So to the question. Is there a way to do that ? I could even go with some db manipulation or anything else someone can advise.

Thanks,

Nikolas

  • Use any of the following 4 plugins:

     

    1. usertype
    2. Profile Manager
    3. Forms and Related (specifically Flexprofile)
    4. WebGalli's premium users 
    (The above are not listed in any particular order)
    P.S. editing core = headaches. Create a plugin for what you want to do that extends core. Much simpler and safer.
  • Nikolas, This can be done as a plugin, its very easy. Get all the users and select the particular users, you want to change to subtype and assiign them the metadatas.

    Never edit the core. You can use any of the plugins trajan mentioned for this. (http://community.elgg.org/pg/plugins/webgalli/read/385045/featuredpremium-members)

    Regards, Team Webgalli

  • Thanks guys. I know changing the core isn't optimal at all but i am way past that point in my implementation :)  As i said the $entity->subtype="BLAH" doesn't do anything after a user is already registered /created on the system.

    Already using profile manager but that doesn't really help with User types...will take a look at your plugin team Webgalli. Thank you both for your input

  • Nikolas, you can add that metadata to already registered users by developing a custom module.

  • Yeah that's what i am using a custom module ...

    What i do is get an array with the users i want (let's call it $members then i do a foreach ($members as $member) and then i try to do $member->subtype="BLAH" inside the loop. This results to nothing. I can do other stuff in that loop fine eg. echo $member->name or set other metadata like $member->favcolour=blue.  the only thing i can't touch is the subtype :/ Also took a look at your plugin team webgalli but since it's hashed it isn't of much help other than it's default operation which is probably v useful to some people.

  • In the past at any rate, entity subtypes could not be updated after the entity is created. I'm not aware of this restriction changing.

    I've done several sites with multiple user types for clients and always use a metadata value (usually "user_profile_category") because my clients always want to allow admins to change the user type.

  • Nicolas, why do you want to change subtype? just assign metadata as you already done with favcolour.

  • Yeah Kevin that was my understanding as well I just thought to ask if someone had a workaround. The metadata value is what i use right now  I just wanted to use the subtype so i could utilize  list_entities and not  list_entities_from_metadata which sometimes works strangely for me ;)

     

    -Edit: Ok from ytour answers it seems i shouldn't really bother with the subtype :) thank you very much all for the quick responses

  • I'm solving this with a SQL query:

    $dbprefix = elgg_get_config('dbprefix');
    $subtype_id = add_subtype('object', 'desired_subtype');
    update_data("UPDATE {$dbprefix}entities
        set subtype='$subtype_id' WHERE guid=$entity->guid");

    // If memcache is available then delete this entry from the cache static $newentity_cache;
    if ((!$newentity_cache) && (is_memcache_available())) {
        $newentity_cache = new ElggMemcache('new_entity_cache');
    }
    if ($newentity_cache) {
        $newentity_cache->delete($guid);
    }

    Maybe is helpful for somebody.