LISE filter template: how to handle with field definitions?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
antibart
Power Poster
Power Poster
Posts: 1155
Joined: Sun Aug 17, 2008 9:29 am

LISE filter template: how to handle with field definitions?

Post by antibart »

Hi,

I have two modest questions. The main thing I would be thankful to be answered is: how do I have to handle with field definitions in the LISE filter template? I did not found similar topics via search.

Here is a longer description:
I have a "select date" field in my instance. Items are displayed like this in the frontend:

-----------------------------------------
12 August 2019 (=select date)
Title 1
-----------------------------------------
14 September 2019
Title 2
-----------------------------------------
12 October 2019
Title 3
-----------------------------------------

So the filter form for "date" displays correctly:

-------------------
Choose date
12 August 2019
14 September 2019
12 October 2019
--------------------

As I have a lot of dates per month I would like to collect them like this

--------------------
Choose date
--------------------
Current month
September 2019
October 2019
November 2019
Decembre 2019
January 2020
--------------------

For the current month I have tried a lot of things as:

Code: Select all

{foreach from=$fielddef->values item=value}
              <option>
 {if $smarty.now|date_format:"%B %Y" eq $fielddef.date.value|date_format:"%B %Y"}
Current month
{else}
...
{/if}
</option>
</foreach>
... and also tested desperately with "$item->fielddefs.date.value" or "$value.date".

All has no effect.

The next thing is: I have no idea by now how to collect the following month/years. So I need a mathematical formal. I know this is more a problem of my intellect than a LISE or CMSMS thing.;)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3479
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE filter template: how to handle with field definitio

Post by velden »

So, how do you think when you get this filter ready, how the backend will find the specific items?

If I recall correctly LISE doesn't have a proper filter for finding items between date A and date B.

Last time I had to do such a list (it was about decades) I added a field where the editor had to choose the decade himself.

If you know how to work with the LISE api you may be able to fill a field automatically, based on the chosen date. You could then write in such a field for example: '2019 August'.
This would then be displayed in your filter.
antibart
Power Poster
Power Poster
Posts: 1155
Joined: Sun Aug 17, 2008 9:29 am

Re: LISE filter template: how to handle with field definitio

Post by antibart »

Thanks for your answer and time.
velden wrote:
Last time I had to do such a list (it was about decades) I added a field where the editor had to choose the decade himself.
But than every single items in august would be displayed as "August 2019" in the filter.

----------------
Choose date
August 2019
August 2019
August 2019
September 2019
September 2019
------------------
velden wrote:
If you know how to work with the LISE api you may be able to fill a field automatically, based on the chosen date. You could then write in such a field for example: '2019 August'.
This would then be displayed in your filter.
I did a lot with LISE but some things I do first.

I just had this little hope to generate it from the "select date" field as I need this field anway in the summary. My thinking was: Less fields, less issues for the editors. It was just an idea to simplify the editing.

I saw it on another website (in german. See filter "Ab aktuellem Datem").

But it's no problem if it will not work.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3479
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE filter template: how to handle with field definitio

Post by velden »

antibart wrote:
velden wrote:
Last time I had to do such a list (it was about decades) I added a field where the editor had to choose the decade himself.
But than every single items in august would be displayed as "August 2019" in the filter.

----------------
Choose date
August 2019
August 2019
August 2019
September 2019
September 2019
------------------
I guess LISE filter will show unique options
antibart
Power Poster
Power Poster
Posts: 1155
Joined: Sun Aug 17, 2008 9:29 am

Re: LISE filter template: how to handle with field definitio

Post by antibart »

Kay. Sorry. The heat. ;)
antibart
Power Poster
Power Poster
Posts: 1155
Joined: Sun Aug 17, 2008 9:29 am

Re: LISE filter template: how to handle with field definitio

Post by antibart »

velden wrote:
...you may be able to fill a field automatically, based on the chosen date. You could then write in such a field for example: '2019 August'.
This would then be displayed in your filter.
I'm still struggling and not sure if I understand you right. Sorry for my tenacity.

1. Did you mean: I simply should use a select box or a text input as custom field definition? This would work properly but the value would be a string. So as far as I know options would be listed in an alphabetical order instead of a chronological order starting with "April 2020" which is not optimal for a date filter.

2. Another try using "select datetime" as field definition:

Code: Select all

{foreach from=$fielddef->values item=value}
              <option>
{$value|date_format:"%B %Y"} 
</option>
            {/foreach}
It displays the options/dates exactly as wanted in a chronological order. But because the values are "not real" (only formatted) no matches will be found and double items of a same month will be listed in the filter form. I get results when I do not use any date formatting but the unformatted dates will be shown as 1548468800 e.g.. The jquery formatDate of the LISE field itself does not work in the filter form.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3479
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE filter template: how to handle with field definitio

Post by velden »

It will require a tiny bit of programming but it's not hard to do.

Example:

Create field definition with date picker, alias: eventdate
Create field definition of type: text input, alias: monthyear

The latter field should not be filled by editor, so you can add some hints to the 'helpful tip' field when creating the field definition. Or create a custom admin template which disables that specific field. Either way, if the editor fills in something it doesn't matter.

Then create a UDT and give it a name, let's say, EventDate2FilterDate

Below some example pseudo code:

Code: Select all

//use for pre-save item event
$item = $params['item_object'];

$item->monthyear = date_format($item->eventdate,'Y M');
I'm not sure if the date format of the LISE field definition works in date_format.

If not try:

Code: Select all

//use for pre-save item event
$item = $params['item_object'];

$item->monthyear = date_format(lise_datetime_utils::date_to_unix_ts($item->eventdate),'Y M');
If that doesn't work do some debugging after the last step :-)

Finally, in Extensions > Event Manager > find the 'PreItemSave' event of your specific LISE instance. Connect the UDT (EventDate2FilterDate) to it. Create of edit an item in LISE and Submit it (not Apply). Then reopen the item and check if the field is filled with the expected value.

It may need some fine tuning but I hope you get the point.
antibart
Power Poster
Power Poster
Posts: 1155
Joined: Sun Aug 17, 2008 9:29 am

Re: LISE filter template: how to handle with field definitio

Post by antibart »

Thank you. I'd never had the idea to go this way. :)
velden wrote:
It may need some fine tuning but I hope you get the point.
I think I got the point ... nearly. I fill the text input field automatically with a date value to use it in my filter so I don't produce double month options. With the date formatting in the UDT it has no effect by now. But without it works fine. So the formatting in the UDT may need a little tuning.

One point of interest: A text input field produces a string. When I use a string in my filter it will not be listed chronologically. Is the date formatting in the UDT needed to avoid this? To keep the state of a date value?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3479
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE filter template: how to handle with field definitio

Post by velden »

Yes, you got the point.

About the formatting of the date, I did some research. I expect this works for you:

Code: Select all

$item->monthyear = gmdate("Y M",lise_datetime_utils::date_to_unix_ts($item->eventdate));
I'm not absolutely sure about the consideration of the local time zone. But this may be less relevant for a month overview. You could however try with the first and last days of a month and do some checks.

Note that the field doesn't have to displayed in the overview itself. I assume you can use it for filtering only. But if you want to show it elsewhere that would be fine of course.
antibart
Power Poster
Power Poster
Posts: 1155
Joined: Sun Aug 17, 2008 9:29 am

Re: LISE filter template: how to handle with field definitio

Post by antibart »

velden wrote:Yes, you got the point.

About the formatting of the date, I did some research.
Thank you. That saved a lot of "searching, trial and error". ;)
velden wrote: I expect this works for you:
It works absolutely as wanted. Thanks again. Perfect.
velden wrote: Note that the field doesn't have to displayed in the overview itself. I assume you can use it for filtering only. But if you want to show it elsewhere that would be fine of course.
It is not nessecary to use it elsewhere. I will use the "useful hint".

Thanks a lot.
Locked

Return to “Modules/Add-Ons”