CMS Made Simple Forums
https://forum.cmsmadesimple.org/

CGCalendar change interval of event times from 15 minutes
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=64063
Page 1 of 1

Author:  paulbaker [ Thu Nov 22, 2012 2:59 pm ]
Post subject:  CGCalendar change interval of event times from 15 minutes

Edited 18 Dec 2012 to use the better method described in the first few replies below. Edited 5 Dec 2018 to use "assets" folder.

CGCalendar is very lovely for displaying events in different ways on your website. The default granularity when you add/edit events is every 15 mintes: so 00, 15, 30, 45 minutes past the hour. The time is entered as a dropdown box.

What if you have an event that starts at 15:10? You then need to change the time dropdown box to show every 5 minutes: so 00, 05, 10, 15, 20....through to 55.

Here's how. (See the Customizing Admin templates page of the docs area for the general method.)

Create a new directory assets/module_custom/CGCalendar/templates/

Copy the 3 files admin_add_event.tpl, orig_editevent_template.tpl, settings.tpl from modules/CGCalendar/templates/ across to your new directory.

Open assets/module_custom/CGCalendar/templates/admin_add_event.tpl
Search for "interval=" and around line 105 you will see
\$1:
<span id="starttime"{if $event.all_day_event == 1} style="display: none;"{/if}> @ {html_select_time use_24_hours=$use24 prefix=$tmp time=$event.event_date_start_ut minute_interval=15 display_seconds=false}</span>

Change the 15 to 5 (or whatever)

Search for "interval=" and around line 117 you will see
\$1:
{html_select_date prefix=$tmp  time=$event.event_date_end_ut start_year=$start_year end_year=$end_year}<span id="endtime"{if $event.all_day_event == 1} style="display: none;"{/if}><br/>@ {html_select_time use_24_hours=$use24 time=$event.event_date_end_ut prefix=$tmp minute_interval=15 display_seconds=false}</span>

Change the 15 to 5 (or whatever)


Open assets/module_custom/CGCalendar/templates/orig_editevent_template.tpl
Search for "interval=" and around line 47 you will see
\$1:
<span id="starttime"{if $event.all_day_event == 1} style="display: none;"{/if}> at {html_select_time use_24_hours=$use24 prefix=$tmp time=$event.event_date_start_ut minute_interval=15 display_seconds=false}</span>

Change the 15 to 5 (or whatever)

Search for "interval=" and around line 58 you will see
\$1:
<span id="endtime"{if $event.all_day_event == 1} style="display: none;"{/if}> at {html_select_time use_24_hours=$use24 time=$event.event_date_end_ut prefix=$tmp minute_interval=15 display_seconds=false}</span>

Change the 15 to 5 (or whatever)


Open assets/module_custom/CGCalendar/templates/settings.tpl
Search for "interval=" and around line 108 you will see
\$1:
{html_select_time prefix=$tmp display_seconds=false time=$dflt_starttime minute_interval=15}

Change the 15 to 5 (or whatever)

And you're done ;D

$1:
File comment: Time drop down showing 5 minute intervals
5minutes.jpg
5minutes.jpg [ 35.31 KiB | Viewed 4576 times ]

Author:  calguy1000 [ Thu Nov 22, 2012 3:14 pm ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Please revise this post to use the module_custom technique instead of modifying distributed files :)

Author:  paulbaker [ Thu Nov 22, 2012 3:20 pm ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Sorry, I thought we were allowed to modify template files. I will modify the solution and post again when I have done so.

Author:  manuel [ Fri Nov 23, 2012 8:39 am ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Dear Paul,

You will need to create the folder "module_custom/modules/CGCalendar/templates/"
Then, create blank files named "admin_add_event.tpl", "orig_editevent_template.tpl" & "settings.tpl"

In the content of these files you will need to search & replace the stuff you want to change by using regex_replace.

Below an example for the blank admin_add_event.tpl file:
\$1:
{include file='file:##REPLACE_WITH_YOUR_SERVER_PATH##/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate'}
{$capturedtemplate|regex_replace:"/(##STUFF TO SEARCH FOR##)/":"##REPLACE WITH##"}
(note: i think that by including the file, the smarty code will aready be parsed... maybe you will need to use fetch? http://www.smarty.net/docsv2/en/languag ... .fetch.tpl )

I usually like to test regex_replace in http://gskinner.com/RegExr/

ps: When you convert it for usage in CMSMS you will need to "escape" some stuff with a backslash! (/ becomes \/)

The big advantage of using module_custom to make template changes is that can upgrade the modules without overwriting your changes! ;D

Greetings,
Manuel

Author:  paulbaker [ Sat Nov 24, 2012 3:28 am ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Thanks for the reply Manuel. I found a help document in docs about module_custom:
http://docs.cmsmadesimple.org/customizi ... -templates

In that, the suggestion is you paste the standard template in to your custom one, and alter it as necessary.

I suppose your method of grabbing the standard template each time and altering it with a regex is even better because if the standard template changes in future versions the changes will be preserved (unless the standard template changes the exact bit your regex is searching for, of course).

\$1:
You will need to create the folder "module_custom/modules/CGCalendar/templates/"


I don't think you need "modules/" in there?

I tried your method but I can't get it working.

In new file /home/cthuk/public_html/stmarys/module_custom/CGCalendar/templates/admin_add_event.tpl I have put:

\$1:
{include file='file:/home/cthuk/public_html/stmarys/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate'}
{$capturedtemplate|regex_replace:"/(minute_interval=15)/":"minute_interval=1"}


(I have put the original standard template files back so "minute_interval=15" does appear). The system is grabbing the .tpl file OK but the regex is not replacing the text.

I tried "{fetch file=..." but that didn't seem to work at all - just gave me a blank screen.

What am I doing wrong? ???

Author:  manuel [ Thu Nov 29, 2012 11:51 am ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Dear Paul,

Below a quick test you can perform:
\$1:
{include file='file:/home/cthuk/public_html/stmarys/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate'}
INCLUDE: {$capturedtemplate|@debug_print_var:0:600}
<br><br>
{fetch file='/home/cthuk/public_html/stmarys/modules/CGCalendar/templates/admin_add_event.tpl' assign='capturedtemplate2'}
FETCH: {$capturedtemplate2|@debug_print_var:0:600}
When you "fetch" the file, you will need to "eval" the template to execute the smarty inside ;)
\$1:
{eval var=$capturedtemplate2}


Greetings,
Manuel

Author:  psy [ Fri Dec 07, 2012 11:20 pm ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Manuel

IMHO, it seems to me like an lot of extra, unnecessary work. With module_custom, all you need do is create the comparable path, eg

\$1:
module_custom/MyModule/templates


Then create your customised template. Easiest way is to copy/paste the original then edit it as you wish.

Yes, module developers occasionally change templates in new versions, but that is an issue for us all anyway, whether frontend or admin, and hardly seems worth the additional overhead in 99.9% of cases. As Paul says, chances are the template change will affect the REGEX anyway so you'd still have to update the module_custom version.

I prefer to keep it simple. :)

Author:  paulbaker [ Tue Dec 18, 2012 5:18 pm ]
Post subject:  Re: CGCalendar change interval of event times from 15 minute

Thanks manuel but I agree with psy on this, keep it simple. ;D

I have now edited the original post to use the module_custom technique; copying the template files and editing the copies.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/