We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38878
    • 255 Posts
    Has anyone tried to leverage the user messaging from the manager in the web context? I'd like to be able to messsage front end registered users w/o have to grant them access to the backend. I know there are addons that provide PM style messaging on the front end between users. I just was looking for a quick and dirty way to leverage the existing backend feature if possible.

    TIA.

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

    • discuss.answer
      • 42562
      • 1,145 Posts
      Yea, that indeed is a vital quality I hope MODx will devour soon. There is an addon, PersonalMessages, that tries to do that; I tried it once, it worked, but I did not persevere through to actually placing it in production.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 38878
        • 255 Posts
        Thanks much. I'll give it a shot.
          • 3749
          • 24,544 Posts
          The PersonalMessages extra looks good, but if you just want to show the user his or her messages, it looks really simple (assuming that we're talking about Revolution).

          This should get and display all messages for the logged-in user viewing a page (untested):

          [[!UserMessages]]


          <?php
          /* UserMessages snippet */
          
          /* initialize variables */
          $userId = $modx->user->get('id');
          $output = '';
          
          /* Get the current user's messages */
          $messages = $modx->getCollection('modUserMessage', array('recipient' => $userId));
          
          /* Loop through messages (if any) and add them to the output */
          if (! empty ($messages)) {
              $output = '<h3>You have Recieved these messages</h3>';
              foreach ($messages as $message) {
          
                  $fields = $message->toArray();
                  /* replace sender ID with username */
                  if (isset($fields['sender'])) {
                      $sender = $modx->getObject('modUser', (integer) $fields['sender']);
                      if ($sender) {
                          $fields['sender'] = $sender->get('username');
                      }
                  }
                  $output .= $modx->getChunk('messageTpl', $fields);
              }
          } else {
              $output = '<h3>You have no messages</h3>';
          }
          
          return $output;
          


          Here is the messageTpl chunk (formatting and CSS left as an exercise for the reader):

          <p>Subject: [[+subject]]</p>
          <p>Sender: [[+sender]]</p>
          <p>Message: [[+message]]</p>



          You can use any of these fields for placeholders in the Tpl chunk:

                type  (string)
                subject  (string)
                message  (string)
                sender  (integer)
                recipient  (integer)
                private  (integer)
                date_sent  (datetime)
                read  (integer)
            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
            • 38878
            • 255 Posts
            Thanks Bobray. I did play with personal messages a bit tonight and while it works it was a little lite on docs. It does allow for replies anew messages too which I like. Doesn't look like the author is actively supporting. Maybe I'll fork it and clean it up. Q