Forum Discussion

SamuelS1's avatar
SamuelS1
Contributor
6 years ago

LiQL Post Count, Kudo count, an solution count for user

Hi,   I try to show post count, kudo count and solution count for specific user on View Profile Page. I create custom component and I'm using query SELECT messages.count(*), solutions_authored.cou...
  • VikasB's avatar
    6 years ago

    SamuelS1 
    ** Updated
    Use this one and make sure you are checking it on the profile page, not in preview. It will not work in the preview as you are using page.context.user.id in your component.  If you want to check it in preview then replace page.context.user.id with a hard-coded user id. 

    <#attempt>
        <#assign userViewProfileUserId = page.context.user.id />
        <#assign userQuery = "SELECT messages.count(*), kudos_received.sum(weight), solutions_authored.count(*) FROM users WHERE id='${userViewProfileUserId}'" />
        <#assign userData = restadmin("2.0","/search?q=" + userQuery?url).data.items[0] />
        <div class="view-profile-user-details">
            <div class="user-statistics">
                <div class="user-statistics__item">
                    <span class="user-statistics__value">${userData.kudos_received.sum.weight}</span> likes</div>
                <div class="user-statistics__item">
                    <span class="user-statistics__value">${userData.solutions_authored.count}</span> solutions</div>
                <div class="user-statistics__item">
                    <span class="user-statistics__value">${userData.messages.count}</span> posts</div> 
            </div>
        </div>
        <#recover>
    </#attempt>