Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Time Recipe

Time Recipe

Hello,

I haven't purchased or used MetaMod but I would like to know if it's possible to do the following.

I have 4 weekly menus. I want the first menu to start Friday at midnight, display for one week and then display the other 3 menus on a weekly basis in the same way. After week 4 has displayed, I want to start over with week 1 and continue this process until the end of time.

Is there a recipe for this? Can someone point me in the right direction to learn how to do this?

Thank you.

fettabachi
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Time Recipe

Hi,

I think I would do it like this:

1 - calculate the unix time stamp of the 1st day of the cycle (friday midnight)
2 - subtract that from the current timestamp, leaving the number of seconds since the start point
3 - divide that by the number of seconds in a week, and round down. That gives the number of weeks since the start point
4 - take that number "modulo 4" (the remainder after dividing by 4). This becomes a week number, 0 to 3, that you can use to trigger the appropriate module.

Note: You need to enter your correct GMT time zone offset in the $offset variable.

$offset = "GMT-5";
$startdate = "2 April 2011 00:00:00";// midnight at end of friday 1 April
$startdate = $startdate . " " . $offset;
$difference = time() - strtotime( $startdate );
$weeks = round( $difference / 7 / 24 / 60 / 60 );
$modulo = $weeks % 4;
// replace WWW, XXX, YYY and ZZZ with the modules to use for the 4 weeks.
if ( $modulo == 0 ) return WWW;
if ( $modulo == 1 ) return XXX;
if ( $modulo == 2 ) return YYY;
if ( $modulo == 3 ) return ZZZ;


Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Time Recipe

I am so happy to have found this fantastic application of yours. Thank you for the recipe too! I intend to show my appreciation by going Pro today and by posting a review at the extensions directory.

fettabachi
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Time Recipe

Thanks for the feedback smile

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Time Recipe

Hi Stephen,

Your welcome for the feedback.

I've run into a snafu with the time recipe. I changed the date that you used originally in order to show the proper menu for the current week as shown here;

Code:

$offset = "GMT-4"; 

$startdate = "11 March 2011 00:00:00";// midnight at end of friday 11 March
$startdate = $startdate . " " . $offset;
$difference = time() - strtotime( $startdate );
$weeks = round( $difference / 7 / 24 / 60 / 60 );
$modulo = $weeks % 4;
// replace WWW, XXX, YYY and ZZZ with the modules to use for the 4 weeks.
if ( $modulo == 0 ) return 68;
if ( $modulo == 1 ) return 69;
if ( $modulo == 2 ) return 70;
if ( $modulo == 3 ) return 71;

This caused the Week 3 Menu to display yesterday, which, is what I wanted and should display it until midnight Friday when the Week 4 Menu should begin. However, today the Week 4 Menu is displaying.

Could you please advise me on how to correct the code?

Thanks,
Tim

fettabachi
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Time Recipe

ok, there's only 1 error I can see, which needs to be corrected. However I am not sure that it's the same problem that you experienced.

The problem I can *see* is the startdate. In my original recipe I stated this:

$startdate = "2 April 2011 00:00:00";// midnight at end of friday 1 April

Notice how 00:00:00 on the 2nd of April is equivalent to midnight at the end of the 1st of April?

So in your version you put this:

$startdate = "11 March 2011 00:00:00";// midnight at end of friday 11 March

... but that's incorrect: 00:00:00 on 11 March is midnight on the 10th of March.

So you need to change it to:

$startdate = "12 March 2011 00:00:00";// midnight at end of friday 11 March


Now as I said, I don't know how this would have caused the "$modulo" variable to switch over on an earlier day of the week (tuesday?)

But can you fix the date above, try it again and see if just now it shows up as week 3 again?

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Time Recipe

I checked the weekly menu today and it has not changed since yesterday. My issue was most likely caused by an operator error. I think, as I was manipulating the start date to coincide with the proper menu, that my browsers cache must have played a role in the deception.

Aside from that, and as you stated, the fact that the start date I'm using is already in the past shouldn't have any bearing on how the module is functioning now. Because, come Saturday, the code you provided will have a date in the past also.

Anyway, I've reset the date (still in the past - March 18) to display this weeks menu. I'll keep you posted on the outcome.

Thanks again,
Tim

fettabachi
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Time Recipe

Hi Tim - the start date can be any time in the past, and simply gives a date to start counting the cycle of 4 weeks. I did some tests on my test site and as far as can see it should work - but keep me posted if it doesn't.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Time Recipe

Hi Stephen,
Bad news. The module didn't change last night at midnight.

Here's my code:

Code:

$offset = "GMT-4"; 

$startdate = "18 March 2011 00:00:00";// midnight at end of friday 18 March
$startdate = $startdate . " " . $offset;
$difference = time() - strtotime( $startdate );
$weeks = round( $difference / 7 / 24 / 60 / 60 );
$modulo = $weeks % 4;
// replace WWW, XXX, YYY and ZZZ with the modules to use for the 4 weeks.
if ( $modulo == 0 ) return 68;
if ( $modulo == 1 ) return 69;
if ( $modulo == 2 ) return 70;
if ( $modulo == 3 ) return 71;

It is possible to change the module by changing the start date in the code. For instance last weeks menu was Week 3 (module ID 70). I got that by setting the start date to March 18. Because the module didn't change last night, in order to display the correct menu for this week, I set the start date to March 11 to display Week 4 (module ID 71).

Screen captures of my settings http://timfetter.net46.net/images
Did your test work?

Thanks,
Tim

fettabachi
Beginner Modder
ranks
useravatar
Offline
7 Posts
Administrator has disabled public posting

Re: Time Recipe

Tim,

midnight at the end of friday march 18 has to be written as "19 March 2011 00:00:00". You still had the time/date wrong by 24 hours.

You know what though... I'm an idiot. In the recipe above I used "round" to round the number of weeks downwards to the nearest integer. "round" actually rounds things to the nearest integer, up or down, so it was making the cutoff point some time in the middle of the week. D'Oh!

So please also try replacing this line:

$weeks = round( $difference / 7 / 24 / 60 / 60 );

with this line:

$weeks = (int)( $difference / 7 / 24 / 60 / 60 );


It's still important to get that date right (00:00:00 on the Saturday rather than 00:00:00 on the Friday in order to get midnight at the end of Friday).

Really hope this works this time... sorry again.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
7
User Info:
 
Total Users:
5418
Newest User:
outsd2
Members Online:
0
Guests Online:
124

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked