We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43592
    • 97 Posts
    Hi Forum members,

    Slowly getting in love with Modx so this is my first XPDO question;)
    I'm trying to set an additional extended field in the profile by registering and later by updating but it wont work. It's called "blocker" and I want to use it that users can additionally unblock their profile for public listing themselves.

    Profile.register postHook:
    <?php
    $user = $hook->getValue('register.user');
    $userGroup = $hook->getValue('register.usergroup');
    $user->joinGroup("Members");
    $user->save();
    $profile = $user->getOne('Profile',array('internalKey'=>$internalkey));
    
    //from here there's something wrong
    $extended = array();
    $extended = $profile->get('extended');
    $extended[] 'blocker' => '1';
    $profile->set('extended', $extended);
    $profile->save();
    


    Profile.Update posthook
    $user = $modx->getUser();
    $profile = $user->getOne('Profile',array('internalKey'=>$internalkey));
    $extended = array();
    $extended = $profile->get('extended');
    $extended[] 'blocker' => '0';
    $profile->set('extended', $extended);
    $profile->save();
    

    This question has been answered by nuan88. See the first response.

    • discuss.answer
      • 46886
      • 1,154 Posts
      You are already way above my technical level, so I might be totally off base, but here is my suggestion:

      Create the 'blocker' extended field in the register snippet and fix it to 1, (default blocked), you perhaps do not need to let the user do anything yet. Nor do I think you need any posthook here, maybe I am wrong.

      Then, tell your users they can make their profile public when they wish, and then add in the option to the updateregister snippet to change the setting.

      Then in your other site codes, every time you want to get a list of public users, you can sort by the blocker field. And I guess when a user tries to read a profile, you would check the value of blocker field to know whether to show the contents, or even show the link to the profile at all.

      HTH

      PS I realized if your site is big it may slow things down a bit (the extended field data is in a JSON file which is a bit slower to read through the data), so you could consider to repurpose one of the default profile values, like fax number. Otherwise its the same, set it to default blocked on registration (maybe the user doesn't even see the value at registration), allow the user to change it, then sort by that field when you only want public users. [ed. note: nuan88 last edited this post 8 years ago.]
        • 43592
        • 97 Posts
        Dear HTH,

        you're totally right, I was totally wrong. Since I'm also pretty new to xPDO I got a little bit mixed up.
          • 46886
          • 1,154 Posts
          No worries Modx is a great system with lots of ways to get something done smiley

          I stick to simple stuff like profiles and extended fields. Modx does most of the heavy lifting for these areas, no need for too much custom coding, just making the forms and data to input with the Register or updateProfile snippets.

          It looks like you have one area (xPDO) you can see but you don't know how far you can extend it, it takes time to build a complete picture. You got a hammer and now everything looks like a nail! wink

          If you want have a lot of user data in addition to this field then you may consider ClassExtender. The native Modx profile after the default fields is a little weak, to be honest, the JSON file is not very scalable, when you have large amounts of data. ClassExtender would let you manage the profiles if there is to be a lot of data or fields. It creates a custom db for your user data and easy and fast access. There also might be some other tools that deal with this.