• Export users from a specific group in Revo#

  • Hori76 Reply #1, 11 months, 1 week ago

    Reply
    Hi, I have a website with a registration system (login add-on)

    Now I have about 200 registered users with some custom attributes within a certain group, is there a way to export these users to csv, excel, xml,...
    It would be nice that my client could do this within the modx manager, maybe there's already an add-on available?

    I can export the users directly from phpMyAdmin, but that's a bit too difficult for my client and I don't really know how to split up the extended attributes.

    Any ideas?


  • robbcapp Reply #2, 10 months, 1 week ago

    Reply
    Ditto. I am wanting to do the same for a client so he can export the users and the user group the user belongs to then have the ability to import it back as well.


  • BobRay Reply #3, 10 months, 1 week ago

    Reply
    It's tricky because the username and password are in one table and the profile is in another (and the extended fields are in JSON format). I'm shooting from the hip here, but this might get you started:


    <?php
    /* export users in a user group snippet */
    
    $csvFile = 'pathToCsvFile';  // full path to csv file here
    $groupName = 'NameOfUserGroup';
    
    $group = $modx->getObject('modUserGroup', array ('name'=>$groupName));
    
    $users = $group->getMany('UserGroupMembers');
    
    $fp = fopen($csvFile, 'w');
    
    foreach($users as $user) {
        if ($user->get('active') {
            $userdata = $user->toArray();
            $profile = $user->getOne('Profile');
            $profileData = $profile->toArray();
    
            $allData = array_merge($userData, $profileData);
    
            fputcsv($allData);
        }
            
    }
    fclose($fp);
    

    I'm not sure how the extended fields would be rendered, you'd have to try it and see.

    This would not allow re-importing, which would be more complicated.