Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
59 posts Page 6 of 6
Previous 1, 2, 3, 4, 5, 6 Next
I guess, we should create the filter with years correctly.
So let's check template 'members/documents.php' and get all distinct years consecutively from its pages (via publish date).

I know that there is this tag - <cms:archives />, which shows time period (year, month, day) and displays number of pages in each period.
Obviously, if there are no pages in period, then it is skipped. It can be tried out with following code:
Code: Select all
<cms:archives masterpage='members/documents.php' type='monthly' >
    <cms:dump />
</cms:archives>

It displays something like that (note, how k_archive_count shows number of pages in the month starting with k_archive_date and ending before k_next_archive_date).

archives
k_archive_date: 2016-10-01
k_next_archive_date: 2016-11-01
k_archive_link: http://www.site.com/index.php?d=201610
k_archive_count: 10
k_count: 1

archives
k_archive_date: 2016-09-01
k_next_archive_date: 2016-10-01
k_archive_link: http://www.site.com/index.php?d=201609
k_archive_count: 90
k_count: 2

archives
k_archive_date: 2016-07-01
k_next_archive_date: 2016-08-01
k_archive_link: http://www.site.com/index.php?d=201607
k_archive_count: 9
k_count: 3


Once we understand how tag works, let's make it 'yearly' for our purpose.
Output would be similar to following:
archives
k_archive_date: 2016-01-01
k_next_archive_date: 2017-01-01
k_archive_link: http://www.site.com/index.php?d=2016
k_archive_count: 109
k_count: 1

archives
k_archive_date: 2015-01-01
k_next_archive_date: 2016-01-01
k_archive_link: http://www.site.com/index.php?d=2015
k_archive_count: 23
k_count: 2


This way we can see the years of our pages by k_archive_date. Format is 'Y-m-d', and to get only year it's necessary to convert it with 'Y' format, using <cms:date /> tag -
Code: Select all
<cms:date date=k_archive_date format='Y' />


What we want to achieve - submitted form should send to backend 2 dates - starting date and ending date. We have both, so let's assign a special value to each year - like year = start date # stop date, sample: 2016 = 2016-01-01 # 2017-01-01.
So, frm_year will have 2 dates and we can split it to feed our listing.

k_success block in the form would split it:
Code: Select all
         
<cms:if frm_years!='-' >
    <cms:each var=frm_years sep='#' >
       <cms:if k_count='0' ><cms:set start_date = item scope='global' />
       <cms:else_if k_count='1' /><cms:set end_date = item scope='global'  />
       </cms:if>
    </cms:each>
</cms:if>


Now, listing will be changed very slightly:
<cms:pages masterpage='members/documents.php' custom_field=my_search_str order='asc' paginate='1' limit='20' start_on=start_date stop_before=end_date >


If year is not selected and variables start_date / end_date do not exist, listing will ignore empty values and show without year constraint.

So, finally, modify your input dropdown for years. It was like this:
Code: Select all
      <div>
         <label>Year:</label><br />
         <cms:input type="dropdown"
               opt_values="All=- | <cms:pages masterpage='members/years.php' order='asc'><cms:show year /><cms:if k_paginated_bottom='0' >|</cms:if></cms:pages>"
               opt_selected='All'
               name="years" id="years" />
      </div>     

And we can change it to display only existing years, as planned.
Code: Select all
     
      <div>
         <label>Year:</label><br />
         <cms:input type="dropdown"
               opt_values="All=- | <cms:archives masterpage='members/documents.php' type='yearly' ><cms:date date=k_archive_date format='Y' /> = <cms:concat k_archive_date ' # ' k_next_archive_date />|</cms:archives>"
               opt_selected='-'
               name="years" id="years" />
      </div>     
     



Ask any questions.

:)
@trendoman
Wowwww, what a brilliant solution! Million thanks, trendoman! It's working as expected ;)

Attila
Hi Guys,

Sorry to resuscitate this topic again for the umpteenth time, but this topic has helped me get very close to my end goal in regards to search, and I need a tiny bit of help to get the final part there.

So the site I'm creating is more of a web application, which stores personal information (name, age, driving license boolean, qualifications e.t.c.) and so to search the database I've added a search bar using <cms:search_form> which uses a template named search.php as the processor.

This is brilliant for searching for anything in plain text, but it didn't look to be showing results for anything stored as a dropdown or checkbox (likely because they're stored as arrays?).

As a workaround to this issue I managed to find this topic, and implemented the filters using the example, which was working absolutely perfectly - I had managed to make every filter work, and it did also work with the search until I added a second test user in.

The problem now is that sometimes it's duplicating the results, and other times it isn't.

I have a feeling I know exactly what the problem is, and you'll likely agree it's the following:

Code: Select all
      <cms:search masterpage="candidates.php">
        <cms:pages masterpage="candidates.php" custom_field="<cms:show my_search_str/>">


So I have 2 questions really as follows:
1. Is there a way to use <cms:search_form> to also include content from dropdowns/checkboxes?
2. What is the best way of implementing an actual search along with the <cms:pages> filtering?

Many Thanks,
Nathan
Hi, to avoid duplication it might be helpful to exclude pages found with 'cms:search' from filters?
Samples from docs:
Code: Select all
<cms:pages masterpage='blog.php' id='NOT 14, 13'></cms:pages>

<cms:pages masterpage='blog.php' page_name='NOT my_first_entry, my_another_entry'></cms:pages>

It is hard to provide a solution based on little info from the post. If you can provide an online playground, would be best.
Hi Trendoman,

Thanks for your response.

After a bit of rethinking I've ended up removing the <cms:search> tag completely and are relying on <cms:pages> instead.
This now looks to be working perfectly, and is pulling the user's input into the filter string to be checked against the full_name field.
Hi guys!

There are situations when after filtering the results using KK solution, a report has to be printed. In order to help people recognize, as much as possible, what kind of data are shown in the report, would be grate to display in the report every search criteria used for obtaining the displayed data.
Is this possible?

Thanks!
????
@atisz, more details please.
display in the report every search criteria used for obtaining the displayed data.

Please post a dummy sample of such a display showing exactly what you'd want to show.
KK wrote: @atisz, more details please.
display in the report every search criteria used for obtaining the displayed data.

Please post a dummy sample of such a display showing exactly what you'd want to show.


Ok. Let's say we have a snippet file called product-filter.html with 2 dropdown used for filtering the data in product-report.php:
- madeyears
- productstatus

On selecting some options and filtering the data, we obtain an URL like this:
Code: Select all
http://domain.com/members/product-report.php?madeyears=2017-01-01+%23+2018-01-01&productstatus=Available&submit=Generate+report&k_hid_quicksearch=quicksearch&nc=1

and product-report.php will list the according data:
- product name
- price
- producer
- warranty

On printing this results, the report should contain:
1. report title (Product report)
2. what kind of data are displayed after filtering (Products listed bellow were made in 2017 and their status is Available)
3. the table containing products data: (product name, price, producer, warranty)

Everything is set up and working accept
2. what kind of data are displayed after filtering (Products listed bellow were made in 2017 and their status is Available)

This is what I would like to know how can be done.
Previous 1, 2, 3, 4, 5, 6 Next
59 posts Page 6 of 6

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest