cgcalendar: WHERE clause in foreach

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
cfra2701
Forum Members
Forum Members
Posts: 11
Joined: Sat Dec 03, 2011 5:21 pm

cgcalendar: WHERE clause in foreach

Post by cfra2701 »

Hi mates,
I'm struggling finding a solution for a quite simple problem but I guess I'm making wrong.
I'm using the cgcalendar module to manage a basketball club.
I want to display the training sessions of the current day and the ones of the day after, which works fine when using $smarty.now.
My problem occurs when I want to display a message saying "Nothing more today"
An I quickly figured out this was because my if condition was inside the foreach loop:
{foreach from=$events key=key item=event}
{if $event.event_date_start|date_format:"%Y-%m-%d" == "tomorrow"|date_format:"%Y-%m-%d"}
Training session info
{else}
No training today
{/if}
{/foreach}
So if I have 40 events in the calendar with only 4 granting the if condition, it displays 36 times "No training today"
Which is the most logical reaction in the world.
I thought about a "where" clause in the foreach but t does not exist.
So, I believe I have to create a sql query and generate an object like $training_events and then use {foreach from=$training_events key=key item=event}
If I'm right, can someone tell me in which file I have to do so and if I'm wrong, is there another solution?

Anyway, kind regards to all of you who took time to read that question.



----------------------------------------------

Cms Version: 1.12.2

Installed Modules:

CMSMailer: 5.2.14
CMSPrinting: 1.0.5
FileManager: 1.4.5
MenuManager: 1.8.7
MicroTiny: 1.2.9
ModuleManager: 1.5.8
News: 2.15.2
Search: 1.7.13
ThemeManager: 1.1.8
TinyMCE: 2.9.12
FormBuilder: 0.7.3
FormBrowser: 0.4.2
CGSimpleSmarty: 1.10
CGExtensions: 1.53.6
CGCalendar: 1.16.1
Captcha: 0.5.3


Config Information:

php_memory_limit:
process_whole_template:
max_upload_size: 64000000
url_rewriting: mod_rewrite
page_extension: .html
query_var: p
image_manipulation_prog: GD
auto_alias_content: true
locale:
default_encoding: utf-8
admin_encoding: utf-8
set_names: true


Php Information:

phpversion: 5.6.21
md5_function: On (Vrai)
gd_version: 2
tempnam_function: On (Vrai)
magic_quotes_runtime: Off (Faux)
E_STRICT: 2048
E_DEPRECATED: 8192
memory_limit: 512M
max_execution_time: 300
output_buffering: 4096
safe_mode: Off (Faux)
file_uploads: On (Vrai)
post_max_size: 64M
upload_max_filesize: 64M
session_save_path: /tmp (0700)
session_use_cookies: On (Vrai)
xml_function: On (Vrai)
xmlreader_class: On (Vrai)


Server Information:

Server Api: fpm-fcgi
Server Db Type: MySQL (mysqli)
Server Db Version: 5.5.49
Server Db Grants: Impossible de trouver un privilège "GRANT ALL". Cela peut signifier que vous pourriez avoir des problèmes pour installer ou retirer des modules, ou encore l 'ajout et la suppression d'éléments, y compris les pages.
Server Time Diff: Aucune différence de date du système de fichiers trouvées


----------------------------------------------
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: cgcalendar: WHERE clause in foreach

Post by velden »

Code: Select all

{$displayedMessage=false}
{foreach from=$events key=key item=event}
  {if $event.event_date_start|date_format:"%Y-%m-%d" == "tomorrow"|date_format:"%Y-%m-%d"}
    Training session info
  {elseif !$displayedMessage}
    No training today
   {$displayedMessage=true}
  {/if}
{/foreach}
cfra2701
Forum Members
Forum Members
Posts: 11
Joined: Sat Dec 03, 2011 5:21 pm

Re: cgcalendar: WHERE clause in foreach

Post by cfra2701 »

Thank you velden, it works.
I tried to do so but I probably screwed up at one point :-)
You saved the situation.
Kind regards.
Post Reply

Return to “Modules/Add-Ons”