XF 2.0 Need help in creating link in custom addon

I am developing ab addon which display conversation, but having an issue i.e. conversation title (alias) and conversation_id is not adding to the link
When I write following in template

Code:
<a href="{{ link('UserConv/message', $userConv) }}"

the link always remain "UserConv/message" but the alias of conversation is not adding after it.

As I have seen here that the generated thread link have the proper alias after the word "thread/" but in my case it is not showing..

Could anybody please let me know what I am missing here?

I will really appreciate if someone can help
 
FYI i have following data in $userConv veriable
PHP:
array:3 [▼
  3 => array:53 [▼
    "conversation_id" => 3
    "title" => "Hi ravi.. Its a new conversation.. Please continue it"
    "user_id" => 4
    "username" => "prem"
    "start_date" => 1515054932
    "open_invite" => 0
    "conversation_open" => 1
    "reply_count" => 1
    "recipient_count" => 2
    "first_message_id" => 13
    "last_message_date" => 1515055002
    "last_message_id" => 14
    "last_message_user_id" => 3
    "last_message_username" => "ravi"
    "recipients" => "a:1:{i:3;a:2:{s:7:"user_id";i:3;s:8:"username";s:4:"ravi";}}"
    "owner_user_id" => 4
    "is_unread" => 1
    "is_starred" => 0
    "email" => "admin@site.com"
    "custom_title" => ""
    "language_id" => 1
    "style_id" => 0
    "timezone" => "Europe/London"
    "visible" => 1
    "activity_visible" => 1
    "user_group_id" => 2
    "secondary_group_ids" => ""
    "display_style_group_id" => 2
    "permission_combination_id" => 8
    "message_count" => 0
    "conversations_unread" => 1
    "register_date" => 1514973249
    "last_activity" => 1515054964
    "trophy_points" => 0
    "alerts_unread" => 0
    "avatar_date" => 0
    "avatar_width" => 0
    "avatar_height" => 0
    "avatar_highdpi" => 0
    "gravatar" => ""
    "user_state" => "valid"
    "is_moderator" => 0
    "is_admin" => 0
    "is_banned" => 0
    "like_count" => 0
    "warning_points" => 0
    "is_staff" => 0
    "secret_key" => "Frsw2QT057AvaXEv-Zx3AKsqS6er3rv9"
    "recipient_state" => "active"
    "last_read_date" => 1515054932
    "isNew" => true
    "lastPageNumbers" => 1
    "last_message" => array:4 [▼
      "message_id" => 14
      "message_date" => 1515055002
      "user_id" => 3
      "username" => "ravi"
    ]
  ]
]
 
First, you should generally be working with entities rather than an array that combines multiple tables worth of data into one flat value.

Second, how is your UserConv route defined? You need to look at the conversations route to see what's necessary to get data into the URL.
 
1. Yes, I am fetching data with Joining tables in one array and then displaying as conversion shows. Will the data be different, if I fetch it through entities? BTW I am Joning tables conversation_master, conversation_user, conversation_starter, conversation_recipient and conversation_user.

2. Thank you for the suggestion, Yes I got it from conversation routes.
 
3. And how can I pass the message_id into the link
i.e.
Code:
<a href="{{ link('UserConv/message', $userConv, 'message_id={$UserConv.last_message_id}'}) }}"

Actually I want URL to be
Code:
www.domain.com/community/UserConv/hello-this-test-message.334/message?message_id=790
 
1. Yes, I am fetching data with Joining tables in one array and then displaying as conversion shows. Will the data be different, if I fetch it through entities? BTW I am Joning tables conversation_master, conversation_user, conversation_starter, conversation_recipient and conversation_user.
Yes, it will be quite different. There are good details in the dev docs: https://xenforo.com/xf2-docs/dev/

3. And how can I pass the message_id into the link
Code:
link('UserConv/message', $userConv, {'message_id': $UserConv.last_message_id})
 
@Mike

Yes, it will be quite different.
I trying this with entities.

link('UserConv/message', $userConv, {'message_id': $UserConv.last_message_id})
Thank you for this help

There are good details in the dev docs: https://xenforo.com/xf2-docs/dev/
For dev doc, I have a feedback. I am developing my first plugin with XF2 and I do not have knowledge of xf1. I have feel that the xf2 doc is easy for those who already knew the XF1. Actually, there should be a proper detailed guide for using the things (e.g. I even didn't find that how to collect URL params in xf2).
 
Could you please help in making the query using finder (entities) for the following mysql query:
Actaully I am trying to fetch all private conversation of users with this.

Code:
$db->fetchAllKeyed(
            'SELECT conversation_master.*,
                    conversation_user.*,
                    conversation_starter.*,
                    conversation_recipient.recipient_state, conversation_recipient.last_read_date
                FROM xf_conversation_user AS conversation_user
                INNER JOIN xf_conversation_master AS conversation_master ON
                    (conversation_user.conversation_id = conversation_master.conversation_id)
                INNER JOIN xf_conversation_recipient AS conversation_recipient ON
                    (conversation_user.conversation_id = conversation_recipient.conversation_id
                    AND conversation_user.owner_user_id = conversation_recipient.user_id)
                LEFT JOIN xf_user AS conversation_starter ON
                    (conversation_starter.user_id = conversation_master.user_id)
                ORDER BY conversation_user.last_message_date DESC limit 10
            ', 'conversation_id');

I have tried to join but it giving me error of "Unknown relation". I have tried to place the relation variable in the entity controller but still no luck..

Really appreciate for the guidance..
 
Last edited:
That query looks very similar to the sort of query that lists a user's conversations. I think the best thing for you would be to start looking at the conversation controller, particularly where we get a list of conversations, and look at the code there. You may be able to repurpose it, though I'm really confused as to what you're doing as it looks like you're just reimplementing the conversation system.
 
@Mike

Sorry for the confusion. but I just want to develop a plugin which is able to display the private conversations of all users of website, only to the admin.
 
I'd definitely look at how we display the conversation list and a conversation then (in the conversation controller). Your code would be essentially identical, just changing the user you're retrieving conversations for.
 
There isn't really much else I can suggest in general. The majority of the code and approach you need is in the controller I mentioned.
 
Back
Top Bottom