solved profile ids to profile names

Melih
Melih
@melih
10 years ago
198 posts
Hello,

I need help again.

I made a module. I can write the profile ids to the db section "tag_id" via multiple select form field. There are profile ids in the "tag_id". In "tag_id" there are more than one profile ids seperated with commas. Like "1,2,3,12,32" Now i want to show profile names using these ids in template. But i don't know how can do it.

Thank you!
updated by @melih: 12/27/14 05:14:40AM
brian
@brian
10 years ago
10,148 posts
All you need to do is feed that value into a jrCore_list call for the jrProfile module - i.e. in your template (assuming it is being called in a jrCore_list call):

{capture name="template" assign="tag_tpl"}
{literal}
{foreach $_items as $item}
    {$item._profile_id}: {$item.profile_name}
{/foreach}
{/literal}
{/capture}

{jrCore_list module="jrProfile" search="_profile_id in `$item.tag_id`" template=$tag_tpl limit=10}

So the first part (everything between capture and /capture) basically is defining a small template - this will be shown ONCE for EVERY ITEM in the following jrCore_list call. You pass that little template into the jrCore_list call by saying:

template=$tag_tpl

the other pertinent part is this:

search="_profile_id in `$item.tag_id`"

This says "only return profiles whose _profile_id is IN the list contained in $item.tag_id - which when expanded would look like:

search="_profile_id in 1,2,3,12,32"

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 12/02/14 11:09:21AM
Melih
Melih
@melih
10 years ago
198 posts
Thank you Brian! You are a real saviour!
brian
@brian
10 years ago
10,148 posts
Melih:
Thank you Brian! You are a real saviour!

No problem ;)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
I have another question in the same subject,

Say, there are 3 ids in the tag_id like 2,1,3 but jrCore_list bring names in order numerical like 1,2,3. Is there a way to order them order by writing in db?
brian
@brian
10 years ago
10,148 posts
Melih:
I have another question in the same subject,

Say, there are 3 ids in the tag_id like 2,1,3 but jrCore_list bring names in order numerical like 1,2,3. Is there a way to order them order by writing in db?

If you do not provide an order_by parameter, then they will be ordered in the same order received in the "in" search clause - i.e. 2,1,3 would be ordered the same.

If you want, you can order by any other datastore field as well.

Let me know if that helps.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
But it's not doing that.

{jrCore_list module="jrProfile" search="_profile_id in `$item.tag_id`" template=$tag_tpl assign="tagnames"}

but output is ordered by _profile_id numerical asc
brian
@brian
10 years ago
10,148 posts
Melih:
But it's not doing that.

{jrCore_list module="jrProfile" search="_profile_id in `$item.tag_id`" template=$tag_tpl assign="tagnames"}

but output is ordered by _profile_id numerical asc

Hmm - yeah with no order by the IN clause uses an ORDER BY FIELD so that should be working - I will check it out and let you know what I find.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
brian
@brian
10 years ago
10,148 posts
I take that back - looks like there is specific "cases" for NOT doing it if the key is _profile_id OR _user_id. I'm not sure why that is but will check it out - most likely it has to do with how the user/profile info is brought in to the data.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
If you find a solution please let me know.

Thank you Brian!
brian
@brian
10 years ago
10,148 posts
Yep - I have it on my todo here to check out. The DS functions are fairly involved, so I'll probably spend time on this on Monday as it may take me some time to get to the bottom of it, but I will let you know.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
Of course, when you have time...

Thanks again!
Melih
Melih
@melih
10 years ago
198 posts
Hello Brian,

Did you have chance to look at it?
updated by @melih: 11/21/14 03:00:14PM
michael
@michael
10 years ago
7,714 posts
a smarty function might be of use here, not sure.

You could pass in the variable from the templates to the smarty function the do whatever processing you need and pass it back. It might be more flexiable than trying to do it all in the templates.

if your module was xxSomething, then in include.php
function smarty_function_xxSomething_special($params, $smarty)
{ //do stuff return the output // $params['tag_ids'] = "1,2,3" return ''; }

then in the templates pass in your 1,2,3 or 3,8,4 inside tag_id
{xxSomething_special tag_ids="1,2,3"}
Melih
Melih
@melih
10 years ago
198 posts
Hello Michael,

I am not sure how can i do that. I don't understant :(
michael
@michael
10 years ago
7,714 posts
Melih:...I am not sure how can i do that. I don't understant :( ...

Hi Melih, sorry. From the first part of the thread:

Melih:
Hello,

I need help again.

I made a module. ........


I thought you were more comfortable working in PHP than in the templates.

What I've outlined above is a way to pass the template variables back to the module so you can work with them at that level instead of the template level. Its just another way of doing the same thing.

If you look in the templates you see {jrCore_list} around alot, right? Well that is just a smarty function. It allows you to pass in something and get something else back.

{jrCore_list module="jrAudio"} in the templates is just a smarty function that goes and searches the datastore of the jrAudio module and returns some pre-formatted items.

So from what I understand, the problem is: You have a variable that when put into your template will output "1,2,3,12,32". I don't know what the name of that variable is so I'll call it {$wanted_ids}.


I would have expected that the order would be preserved too, but if you wanted to take control of the order you could do it by passing that variable into a custom function in your module and then once the results came back add an extra bit of sorting to it.

-- just went to check--
Its working for me
{jrCore_list module="jrProfile" search="profile_id IN 2,1,3"}
{jrCore_list module="jrProfile" search="profile_id IN 1,2,3"}
{jrCore_list module="jrProfile" search="profile_id IN 3,2,1"}

all produce different results. They show in the order the numbers come. Are they not for you @Melih ?

-- update --
Remove the _ before profile.
{jrCore_list module="jrProfile" search="_profile_id IN 2,1,3"}
{jrCore_list module="jrProfile" search="_profile_id IN 1,2,3"}
{jrCore_list module="jrProfile" search="_profile_id IN 3,2,1"}
all produce the SAME order. So remove the _ before _profile and the order works. Not sure why, I would have expected they would be the same searches. mmmm.
updated by @michael: 11/22/14 10:19:39PM
brian
@brian
10 years ago
10,148 posts
Good catch Michael - the reason it works this way is that "_profile_id" is a key on EVERY item, but "profile_id" is basically a special "flag" that the Profile module watches for (via the db_search_params listener) and does some extra work, so that's how it keeps the order correctly. Not sure if there is a fix at the profile level to make them work the same, but I will check it out.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
But if i remove "_" jrCore_list call only profile names has user account. Brian you know i am using Genosis and there are lots of profiles without user.
brian
@brian
10 years ago
10,148 posts
Melih:
But if i remove "_" jrCore_list call only profile names has user account. Brian you know i am using Genosis and there are lots of profiles without user.

As long as you are searching on jrProfile that shouldn't matter - maybe I'm not fully understanding the issue, but the user account shouldn't matter in this case.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
Ok, i tried again and i take it back it's not about user account but some of names shown. With _ all of names comes but without it some of names doesn't.
brian
@brian
10 years ago
10,148 posts
Melih:
Ok, i tried again and i take it back it's not about user account but some of names shown. With _ all of names comes but without it some of names doesn't.

Hmmm - that should work for all of them. Can you paste here the exact {jrCore_list} call you are using so I can test it here?

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
{capture name="template" assign="tag_tpl"}
{literal}
{foreach $_items as $item}
{if ! $item@first}, {/if}{$item.profile_name}{/foreach}
{/literal}
{/capture}
{jrCore_list module="jrProfile" search="_profile_id in `$item.tag_id`" template=$tag_tpl assign="tagnames"}
updated by @melih: 11/23/14 11:02:00AM
Melih
Melih
@melih
10 years ago
198 posts
actually it's almost same what you wrote to me before.
brian
@brian
10 years ago
10,148 posts
Melih:
actually it's almost same what you wrote to me before.

OK - and the issue is that it's not coming in the order you have it in the "in" search - correct? Just want to be sure we're still talking about that.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
Yes, i want to order them by db field but they are coming numerical. If i remove _ they are coming order by field but some of them shown. I couldn't find difference between profiles
brian
@brian
10 years ago
10,148 posts
Melih:
Yes, i want to order them by db field but they are coming numerical. If i remove _ they are coming order by field but some of them shown. I couldn't find difference between profiles

OK - let me check out why there is a difference.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
Thank you!
brian
@brian
10 years ago
10,148 posts
I've got this fixed for the next Core release.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Melih
Melih
@melih
10 years ago
198 posts
Thank you Brian!
Melih
Melih
@melih
10 years ago
198 posts
It's working great. Thanks again Brian!
brian
@brian
10 years ago
10,148 posts
Melih:
It's working great. Thanks again Brian!

Glad to hear it - thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags