Page 1 of 1

LISE hide categories with items ran out of date

Posted: Wed Sep 20, 2023 9:59 am
by antibart
Hi cmsms-lovers,

all modules and cmsms are running under the current version using PHP 8.1.

I've created 12 categories in a LISE instance. One for every month of the year: january, february and so on. Like an event calendar.

All items have an end date using time control. If the event is over, the item will disappear.

The normal behavior of categories seems to be: As long as an item is not completly deleted and still stored in the database, the category name will be displayed. Even if all events have reached the end date.

But for a calendar it would be better to hide a category when there are no items to be found.

Is there a way to hide a category when a month is over and/or all items have passed the end date ?

It may help to show my categories template. It not working as a navigation tree. Every category/month opens an accordion container.

Code: Select all

{foreach from=$categories item=category}

{if !empty($category->items|count)}  

<div class="accordion">
  <input type="checkbox" id="tab{$category->alias}" class="acco">
  <label class="acco-label" for="tab{$category->alias}">{$category->name}</label>
  <div class="acco-content">
{LISEEvents category=$category->alias}
                        </div>
        {/if}
{/foreach} 

Re: LISE hide categories with items ran out of date

Posted: Wed Sep 20, 2023 10:50 am
by Jo Morg
It possible, but will require some custom coding (probably an UDT or two). I had to do a weekly calendar for a restaurant that had special events, and used LISE as a event tracker. I recon the monthly calendar won't differ much, so I'll post some of the logic I used and you can adapt to you needs.
1. I used an array to store the unix timestamps of both start and end of each week day by playing with php strtotime. You'd probably have to do the same for each month as the logic won't different much, but here is what I've done for each day of the week:

Code: Select all

$week = [
  1 => [strtotime( 'monday this week'), strtotime('+1 day', strtotime('monday this week') ) - 1 ],
  2 => [strtotime( 'tuesday this week'), strtotime('+1 day', strtotime('tuesday this week') ) - 1 ],
  3 => [strtotime( 'wednesday this week'), strtotime('+1 day', strtotime('wednesday this week') ) - 1 ],
  4 => [strtotime( 'thursday this week'), strtotime('+1 day', strtotime('thursday this week') ) - 1 ],
  5 => [strtotime( 'friday this week' ), strtotime('+1 day', strtotime('friday this week') ) - 1 ],
  6 => [strtotime( 'saturday this week'), strtotime('+1 day', strtotime('saturday this week') ) - 1 ],
  7 => [strtotime( 'sunday this week' ), strtotime('+1 day', strtotime('sunday this week') ) - 1 ]
];

$smarty->assign('week', $week);
Having that will allow you to check if the month is current, in the past or in the future. Only show events from that month on with a simple template logic.
2. Inside a custom summary template for LISEEvents I'd check for the dates of each event to see if have expired or not (still, best to work with unix timestamps as the math is more workable).
3. All this will be easier to manage if that custom template for LISEEvents only has smarty logic and no html at all, so that it can return just an array of items, which can be empty thus allowing you not to show a month if no events exist.
4. That will mean that all the html will be in the categories template.

This is just an idea, as the implementation is possible but will need some planning. There are surely other ways to do it but this is the way I'd go about doing it. I just wouldn't use categories for the months as these can have other uses, but it should work as is anyway. as strtotime is very clever in the way it interprets English it allows for quite a bit of versatility in getting the correct timestamps to the second. Just as a note:

strtotime('+1 day', strtotime('sunday this week') ) - 1 is next day - 1 second to give the end of the day. You should be able to use the same logic to get the timestamp for the end of each month.
HTH

Re: LISE hide categories with items ran out of date

Posted: Wed Sep 20, 2023 11:30 am
by velden
Another suggestion which might work well for your case

A category template:

Code: Select all

<!-- categories -->
<ul>
{foreach from=$categories item=cat}
{LISEtest include_items=','|implode:$cat->items assign=out}
{if $out != ''}
	<li class="category-{$cat->alias}">
		<a class="category-name" href="{$cat->url}">{$cat->name} ({$cat->items|count})</a>
                {$out}
	</li>
{/if}
{/foreach}
<ul>
<!-- categories //-->
Make sure the Summary template doesn't output anything if there are no items (which is taken care of by the sample template).

Code: Select all

{if $items|@count > 0}
...
{/if}

Re: LISE hide categories with items ran out of date

Posted: Wed Sep 20, 2023 1:12 pm
by antibart
Jo Morg wrote: Wed Sep 20, 2023 10:50 am It possible, but will require some custom coding (probably an UDT or two).
Thank you very much for your effort.
But in the end, Velden's suggestion seemed a little easier for my needs (and my skillz).

After minor renovations and removing the {$out} from the template, it worked fine.


Thank you.