We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    Is there a way to track a user's joined date? I would need it to (ideally) show up in the manager area and be stored in the user attributes table for download. Pretty much identical to how the Last Login Date is working, just with the joined date instead.

    Thanks for any help! [ed. note: firebot6 last edited this post 12 years, 7 months ago.]
      • 3749
      • 24,544 Posts
      I think that would best be done with an extended user field set by a postHook with the ConfirmRegister snippet.

      The code to set the field would look something like this (untested):

      $profile = $user->getOne('Profile');
      $extended = $profile->get('extended');
      
      $extended['joined_date'] = time();
      $profile->set('extended', $extended);
      $profile->save();
      

      You could also use an unused field in the user profile (e.g., zip) to store the date, which might be somewhat faster and easier.

      $profile = $user->getOne('profile');
      $date = time();
      $profile->set('zip', $date);
      $profile->save();
      [ed. note: BobRay last edited this post 12 years, 7 months ago.]
        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
        • 36760
        • 136 Posts
        Your first example seems to be working for the most part, although it returns times like 1317708463 and
        1317708793.

        The date settings in the Modx system settings are correct from what I can tell.

        Does the position in the ConfirmRegister snippet make a difference? Here's what I have: http://pastebin.com/JiFZfquV

        Did I even need to edit the snippet directly, or can I use the postHooks property on ConfirmRegister?
          • 3749
          • 24,544 Posts
          Those are unix timestamps (the number of seconds since January 1 1970), but you can use output modifiers to format them when you need to display them -- e.g.,

          :strtotime:date=`%m-%d-%Y`


          You should definitely use a postHook rather than modifying the snippet code. Your changes to the snippet code would be overwritten every time you update the snippet.
            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
            • 36760
            • 136 Posts
            Is postHooks something I can use on ConfirmRegister? It doesn't seem to be passing the time on anymore. Though it was working with the snippet directly edited.

            [[!ConfirmRegister? &redirectTo=`691` &postHooks=`joinedDate`]]


            joinedDate snippet looks like this:

            <?php
            $profile = $user->getOne('Profile');
            $extended = $profile->get('extended');
             
            $extended['joined_date'] = time();
            $profile->set('extended', $extended);
            $profile->save();
              • 3749
              • 24,544 Posts
              I can't tell from the docs whether ConfirmRegister does postHooks or not, but it does fire the OnUserActivate event, so if you put that exact code in a plugin connected to OnUserActivate, it should work fine.

              Note that if you deactivate and reactivate a user, it may (or may not) reset the joined date.

                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
                • 36760
                • 136 Posts
                Using a plugin did the trick. I completely missed that line in the documentation.

                Thanks!
                  • 3749
                  • 24,544 Posts
                  I'm glad it worked for you. smiley
                    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