hi.. apart from displaying how many new messages (custom menu), how can i create a block or snippet to display the last 5 or less/more latest messages?

anyone done this before? any help is appreciated. thanks.

Comments

sadist’s picture

anyone done or came across this feature before? no one? :(

litwol’s picture

Version: 6.x-1.0-rc2 » 6.x-1.x-dev

Take a look at code how blocks are created and how we create the inbox list. combine the two methods for your purpoess.

timofey’s picture

I've spent a good 8 hours trying to figure this out. I'm new to this.
Can someone please, please hint us?

How do you display the subject of the five latest messages in a block?

Thank you!

naheemsays’s picture

Have a look at privatemsg_list in privatemsg.module file. To get the data you need to do:

  $query = _privatemsg_assemble_query('list', $account, 'list');
  $result = pager_query($query['query'], 5, 0, $query['count']);

where $account is the user account for the person for who you want to list the messages. Replace the number 5 with however many threads you want to show.

After that, if you want the same layout as in the normal listings, copt the form creation code from after the query in the same function.

berdir’s picture

For a block, I assume you just want a list of titles and no paging, you can do that with the following code

$query = _privatemsg_assemble_query('list', $account, 'list');
 $result = db_query_range($query['query'], 0, 5);
$list = array();
while ($thread = db_fetch_array($result)) {
  $list[] = l($thread['subject'], 'messages/view/'. $thread['thread_id']);
}
return theme('item_list', $list);

If you just want to display the content of the inbox, replace 'list' with 'inbox'.

timofey’s picture

So I click on "Add Block" from the admin menu, I put in the code, change the input code to PHP and save it.
Do I add "echo $result;"?

The block is either empty or showing "Resource id #140".

berdir’s picture

The code was supposed to be used in a module. With a few small changes, it should work with the php code input format too..

- Add a global $user before the first line and replace $account with $user
- Replace "return theme... " with "echo theme..."

timofey’s picture

That solves the problem!
You guys are wonderful!

berdir’s picture

Status: Active » Fixed
sadist’s picture

so, is this what i'm supposed to place on my custom block?

$query = _privatemsg_assemble_query('list', $user, 'list');
$result = db_query_range($query['query'], 0, 5);
$list = array();
while ($thread = db_fetch_array($result)) {
  $list[] = l($thread['subject'], 'messages/view/'. $thread['thread_id']);
}
echo theme('item_list', $list);

The Block is working but nothing is being listed there. There's definitely at least 1 message inside my Privatemsg. At the top of the page, there's error message.

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 5' at line 1 query: LIMIT 0, 5 in D:\Http\drupal\includes\common.inc(1655) : eval()'d code on line 3.

What could be possibly my problem here? Thanks guys!

naheemsays’s picture

read comment 7:

- Add a global $user before the first line

global $user;
sadist’s picture

thanks so much!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Michsk’s picture

i tried a lot, but just cant figure out how to recreate the messages page where you see the titles, participants and the dates... its giving me a headache :P

I use the above code

global $user;

$query = _privatemsg_assemble_query('list', $user, 'list');
$result = db_query_range($query['query'], 0, 25);

$list = array();

  while ($thread = db_fetch_array($result)) {
    $list[] = l($thread['subject'], 'messages/view/'. $thread['thread_id']);
  }

echo theme('item_list', $list);

print_r($list);

coulde someone maybe help me out with this?

sadist’s picture

Status: Closed (fixed) » Active

i have to get this working with the imagecache_profile too. so i'm opening this back again. hope there'll be some help here.

naheemsays’s picture

@lasac - if you want all the fields in the normal display, why not simple call privatemsg list in the first place?

global $user;
echo drupal_get_form('privatemsg_list', 'list', $user->uid);

@ people developing custom functionality - you WILL need to understand atleast a little php and also read the code of the module to see what it does.

Michsk’s picture

Status: Active » Closed (fixed)

@nbz: you naild it that is exactly what i need, and for the global comment i do know a bit of php but not much. I tried looking in the module but could not find the info i needed, may i ask how you got that snippet?