We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I don't know what to suggest. What you're describing seems impossible.

    This getCollection() call will only get messages for the current user:

    $modx->getCollection('modUserMessage', array('recipient' => $uid));


    The result is used to create the checkboxes in the form, so there will only be checkboxes for messages sent to the current user.

    As a result, $_POST['messages'] can only contain IDs for messages for the current user that are checked in the form, and looping through them with getObject() and remove() will only get and remove one message per iteration, so it can't possibly remove messages that are not shown in the form or are not checked.

    FYI, I'm working on an extra to do this, though it may be a while before it's released.

      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
      • 40088
      • 708 Posts
      Ok Bob, it's working. I had a typo. Thank you very much.

      Will your extra allow for member-to-member messaging in addition to Admin-to-member? [ed. note: todd.b last edited this post 11 years, 8 months ago.]
        Todd
        • 3749
        • 24,544 Posts
        I think at first it will just allow replies, but it might allow messages between members down the road.

        Messages between members is a royal pain because you have to show a dropdown list of usernames to select from and if there are a lot of them, there should be pagination and a search option.
          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
          • 40088
          • 708 Posts
          I suspect it's even more complicated because the member should be able to opt-in/out from being contacted by other members. Like a preference-type setting.
            Todd
            • 3749
            • 24,544 Posts
            You're right. That makes it *way* more complicated. Not only does it complicate the code for the form, you need somewhere to store the user's preference and a UI to let them set/change it.
              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
              • 40088
              • 708 Posts
              Is this sort of thing difficult to code in general, or is it more so because of how MODX works? I'm just wondering if it would be easier to implement in other systems.
                Todd
                • 3749
                • 24,544 Posts
                No, I think MODX makes it easier because the modUserMessage object is an xPDO object, though there are some systems where it's easier to add new fields to the user object. If there's a user field you're not using (e.g., gender), you could store the information there. The Subscribe snippet also has a system for storing and managing user preferences, so you could use that since it has a built-in UI for it. Of course Notify lets you leverage that system to send emails to the user (from an admin), but there's no way for the user to reply to them or email other users.

                I think Discuss has a PM option (like the forums), but again, it's not very convenient and I don't think you can opt out.

                You can send other users a message in the Manager but the UI is kind of clunky.

                It's just a tough problem.
                  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
                  • 40088
                  • 708 Posts
                  Using the ShowMessages snippet Bob posted above I've been trying to sort messages by the date_sent (db row). Using &sortby and &sortdir don't seem to do anything. Do they only work with getResources or getPage?
                    Todd
                    • 3749
                    • 24,544 Posts
                    $uid = $modx->user->get('id');
                    
                    $c = $modx->newQuery('modUserMessage');
                    $c->sortby('date_sent', 'ASC');  // or 'DESC'
                    $c->where(array(
                        'recipient' => $uid;
                    ));
                    
                    $messages = $modx->getCollection('modUserMessage', $c);


                    BTW, this will be released -- hopefully soon: https://github.com/BobRay/MessageManager
                      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