We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12352
    • 101 Posts
    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?
      Don't believe anything you read on the net. Except this.
      • 35850
      • 1 Posts
      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.
        • 3749
        • 24,544 Posts
        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.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting