solved Combined Videos Category Search

gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Hey Guys

Using a cloned version of MediaPro I have category search on each of the video pages, ie Videos & Youtube Videos. I can filter down each of these sections by category.

Early this morning I started to tackle something I have kept putting off, making a combined video list that looks like the afore mentioned sections in MediaPro.

Well I know have it looking the same and filtering by alphabet, by plays, album etc works.

What I am having trouble with is the category search. How does one get a combined list of categories across Video and Youtube and list them so there is no duplicates.

Getting them for indivudal modules is easy ie.

{jrCore_list module="jrVideo" group_by="video_category" template="video_category2.tpl"}

I have tried using things like this to no avail

        {jrSeamless_list modules="jrVideo,jrYouTube" template="video_category2.tpl" group_by="*_category"}


        {jrSeamless_list modules="jrVideo,jrYouTube" template="video_category2.tpl" group_by="video_category || youtube_category"}


Any ideas?

Thanks
updated by @garymoncrieff: 08/18/15 07:41:52AM
michael
@michael
9 years ago
7,715 posts
did you try
group_by="*_category"
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Yes it returns none.
michael
@michael
9 years ago
7,715 posts
Might need to run the returned results through a quick loop then. Not sure of the syntax for doing it in .tpl files, but in php syntax

foreach($stuff as $v){
  $wanted[$v] = $v;
}
That way any double ups in value will be over-written since they are used as the key to the array and array keys must be unique.
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Had been trying a loop as well but kept getting a white page so I was doing something wrong.
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Trying most of the day and still no luck.
brian
@brian
9 years ago
10,148 posts
This is not supported in Seamless - it can't take a wildcard on a group_by as that's not possible to get it to work correctly in the SQL query.

Sorry!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
michael
@michael
9 years ago
7,715 posts
If its just to reduce the categories to unique ones, then here's the loop structure:
{$stuff = array('one', 'one', 'two', 'three', 'four', 'five', 'five', 'five', 'six')}

{foreach $stuff as $v}
    -:{$v}<br>
    {$wanted[$v] = $v}
{/foreach}

<hr>
{foreach $wanted as $v}
    -:{$v}<br>
{/foreach}
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
I think this is proving to be beyond me, even the display area is acting up. But back to this problem.

My thinking was to have two seamless list calls and assign variables to each ie.

        {jrSeamless_list modules="jrVideo,jrYouTube" template="video_category2.tpl" group_by="youtube_category" order_by="youtube_category asc" assign="ycats"}
        {jrSeamless_list modules="jrVideo,jrYouTube" template="video_category2.tpl" group_by="video_category" order_by="video_category asc" assign="vcats"}

Then somehow combine these and output them into the block. But as of yet not having any success.

I am beginning to think my plans are too complicated for my skill level lol
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
I suppose an easier way might to limit the categories across modules to be the same, using a select field.

Then use something like this

            {$allcats = array('Film & Animation',
                         'Autos & Vehicles',
                         'Music',
                         'Pets & Animals',
                         'Sports',
                         'Travel & Events',
                         'Gaming',
                         'People & Blogs',
                         'Comedy',
                        'Entertainment',
                        'News & Politics',
                        'Howto & Style',
                        'Education',
                        'Science & Technology')}

            {foreach $allcats as $v}
                <li><a href="{$jamroom_url}/videos2/search_area=video_category/search_string={$v}">{$v}</a></li>       
            {/foreach}

Problem with that method I suppose would be it will list all categories rather than just those with videos in.
michael
@michael
9 years ago
7,715 posts
It should be working:
{jrSeamless_list modules="jrVideo,jrYouTube" template="video_category2.tpl" limit=500}

in video_category2.tpl
{foreach $_items as $item}
    {$_cats[$item['category'] = $item['category']}
{/foreach}

{foreach $_cats as $cat}
  {$cat}<br>
{/foreach}
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
I tried for days with that method and couldnt get it to work so I ended up going with the method in my last post. Problem I am now having with this is videos in categorys with more than one word dont show as everything after the first word is getting cut off.
michael
@michael
9 years ago
7,715 posts
Try this one, it works:
{capture name="row_template" assign="template"}
    {literal}
        {foreach $_items as $item}
             {$_cats[$item["`$item.seamless_module_prefix`_category"]] = $item["`$item.seamless_module_prefix`_category"]}
        {/foreach}

        {foreach $_cats as $cat}
          {$cat}<br>
        {/foreach}

    {/literal}
{/capture}

OUTPUT:
{jrSeamless_list modules="jrVideo,jrYouTube" template=$template limit=500}

The only limitation is that it will only get all the categories that exist within the scope of the LIMIT, so limit 500 will get all the categories in the first 500. Not great, but hopefully acceptable.

The next option would be to create a custom function that queries the datastores individually to get all the options, then combines them. Little bit more fiddley but then you know you'll get what you need.
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Thanks I now have that working but still having the same problem with categories with more than one work returning nothing.
michael
@michael
9 years ago
7,715 posts
gary.moncrieff:....What I am having trouble with is the category search. How does one get a combined list of categories across Video and Youtube and list them so there is no duplicates....

That's what that code above does. It filters the list of categories so there are no duplicates.
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
I have the list showing but when I click on Howto & Style the page comes back with just howto and returns no videos. Its the same for every category that contains more than one word.
michael
@michael
9 years ago
7,715 posts
might need to use a different, setup then for the keys.

What is the code your using?
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Currently what you posted above. I have all my orginal code commented out.

		
<div class="title_block" style="margin-bottom: 5px;">Categories</div>
	<div class="sub_section_menu">
        <ul>
            {capture name="row_template" assign="template"}
            {literal}
                {foreach $_items as $item}
                {$_cats[$item["`$item.seamless_module_prefix`_category"]] = $item["`$item.seamless_module_prefix`_category"]}
                {/foreach}

                {foreach $_cats as $cat}
                <li><a href="{$jamroom_url}/videos/{if isset($_post.option) && strlen($_post.option) > 0}{$_post.option}/{/if}search_area=video_category/search_string={$cat}">{$cat}</a></li>
                {/foreach}

            {/literal}
            {/capture}

            {jrSeamless_list modules="jrVideo,jrYouTube" template=$template limit=500}
        </ul>
	</div>

Would it be down to how I have entered the options for the category fields?

Film & Animation|Film & Animation
Autos & Vehicles|Autos & Vehicles
Music|Music
Pets & Animals|Pets & Animals
Sports|Sports
Travel & Events|Travel & Events
Gaming|Gaming
People & Blogs|People & Blogs
Comedy|Comedy
Entertainment|Entertainment
News & Politics|News & Politics
Howto & Style|Howto & Style
Education|Education
Science & Technology|Science & Technology

I had also tried

Film|Film & Animation
Autos|Autos & Vehicles
Music|Music
Pets|Pets & Animals
Sports|Sports
Events|Travel & Events
Gaming|Gaming
People|People & Blogs
Comedy|Comedy
Entertainment|Entertainment
News|News & Politics
Howto|Howto & Style
Education|Education
Technology|Science & Technology
michael
@michael
9 years ago
7,715 posts
could be, but probably not a problem. Let me get setup here to test with your category fields and we can find a solution.

--edit--
This is the structure your after:
your-site.com//videos/search_area=video_category/search_string=Howto+%26+Style

So it will be a urlencode thats needed. will get the exact code in a sec.
updated by @michael: 07/15/15 12:36:40AM
michael
@michael
9 years ago
7,715 posts
This works.

In a file called junk.tpl (hence the /junk/ reference in the link) this code will produce the categories, then when clicked on only videos from that category will be shown.
<div class="title_block" style="margin-bottom: 5px;">Categories</div>
<div class="sub_section_menu">
    <ul>
        {capture name="row_template" assign="template"}
        {literal}
            {foreach $_items as $item}
            {$_cats[$item["`$item.seamless_module_prefix`_category"]] = $item["`$item.seamless_module_prefix`_category"]}
            {/foreach}

            {foreach $_cats as $cat}
            <li>
                <a href="{$jamroom_url}/junk/{if isset($_post.option) && strlen($_post.option) > 0}{$_post.option}/{/if}search_area=*_category/search_string={$cat|urlencode}">{$cat}</a>
            </li>
            {/foreach}

        {/literal}
        {/capture}

        {jrSeamless_list modules="jrVideo,jrYouTube" template=$template limit=500 }
    </ul>
</div>
<hr>
        {jrSeamless_list modules="jrVideo,jrYouTube" limit=500 search1="*_category like %`$_post.search_string`%"}
gary.moncrieff
gary.moncrieff
@garymoncrieff
9 years ago
865 posts
Cheers Michael, works like a charm.

Tags