<![CDATA[ Messages to other backend users - MODX Community Forums]]> https://forums.modx.com/thread/?thread=95946 <![CDATA[Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519285 ottogal Jan 27, 2015, 03:53 AM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519285 <![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519525
I think adding this line between lines 8 and 9 would do it for the snippet above:

$query->sortby('date_sent', 'DESC');


You could also add that line below line 32 of the core\model\modx\processors\security\message\getlist.class.php file to have them sorted in the Manager.]]>
BobRay Jan 30, 2015, 02:10 AM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519525
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519522 http://forums.modx.com/thread/95945/package-manager-grid-columns-not-sortable), it would be helpful if at least they would be sorted by date_sent in DESC order by default.

* Perhaps this is fixed in 2.3.3-pl?]]>
ottogal Jan 30, 2015, 01:40 AM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519522
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519503
BTW, I'm working on an extra to let users see and delete their messages in the front end (and possibly reply to them). It may be a while before it's released, though.]]>
BobRay Jan 30, 2015, 12:30 AM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519503
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519426
$messages = $modx->getCollection('modUserMessage');

Here's the complete snippet code:
$output = '';
$messages = $modx->getCollection('modUserMessage');
foreach ($messages as $message) {
    /** @var $message xPDOObject */
    $fields = $message->toArray ('', true);
    $query = $modx->newQuery('modUser', array(
        'id' => $fields['sender'],
    ));
    $query->select('username');
    $username = $modx->getValue($query->prepare());
    $fields['sender'] = $username;
    $fields['class'] = $fields['read']? 'read' : 'unread';
    $fields['read'] = $fields['read'] ? 'Yes' : 'No';
    $output .= $modx->getChunk('messageTpl', $fields);
};
return $output;

It works like a charm. Thanks Bob, I learnt something about xPDO!]]>
ottogal Jan 28, 2015, 11:07 PM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519426
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519423
$output = '';
foreach ($messages as $message) {
    /** @var $message xPDOObject */
    $fields = $message->toArray ('', true);
    $query = $modx->newQuery('modUser', array(
        'id' => $fields['sender'],
    ));
    $query->select('username');
    $username = $modx->getValue($query->prepare());
    $fields['sender'] = $username;
    $fields['class'] = $fields['read']? 'read' : 'unread';
    $fields['read'] = $fields['read'] ? 'Yes' : 'No';
    $output .= $modx->getChunk('messageTpl', $fields);
};
return $output;

To test the query, I tried
$output = '';
foreach ($messages as $message) {
    /** @var $message xPDOObject */
    $fields = $message->toArray ('', true);
    $query = $modx->newQuery('modUser', array(
        'id' => $fields['sender'],
    ));
    $query->select('username');
    $username = $modx->getValue($query->prepare());
    $output .= $username . ' ';
};
return $output;
The output remains empty.
]]>
ottogal Jan 28, 2015, 10:48 PM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519423
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519419

foreach ($messages as $message) {
    /** @var $message xPDOObject */
    $fields = $message->toArray ('', true);
    $query = $modx->newQuery('modUser', array(
        'id' => $fields['sender'],
    ));
    $query->select('username');
    $username = $modx->getValue($query->prepare());
    $fields['sender'] = $username;
    $fields['class'] = $fields['read']? 'read' : 'unread';
    $fields['read'] = $fields['read'] ? 'Yes' : 'No';
    $inner .= $modx->getChunk($tpl, $fields);
}


]]>
BobRay Jan 28, 2015, 10:03 PM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519419
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519370 I would like to have the author of the message in the output. Adding [[+sender]] to the messageTpl of course gives just his id.
How do I get his username? (Tried a few things, but to no avail.)
]]>
ottogal Jan 28, 2015, 05:30 AM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519370
<![CDATA[Re: Messages to other backend users]]> https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519341
This snippet would show them all:

$messages = $modx->getCollection('modUserMessage');
$output = '';
foreach ($messages as $message) {
    $fields = $message->toArray();
    $output .= $modx->getChunk('messageTpl', $fields);
}

return $output;



messageTpl chunk:

<p>[[+id]] -- [[+subject]] -- [[+message]]</p>


]]>
BobRay Jan 27, 2015, 05:41 PM https://forums.modx.com/thread/95946/messages-to-other-backend-users#dis-post-519341