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.

 

How to display code for Date and Time Recipes?

How to display code for Date and Time Recipes?

Hi

I'm trying to have the correct code to display Module through MetaMod. I have added the code below so it displays different modules during different times of the day.

I am looking to show random modules show the user refresh the page. In this case, I want to have a sequence of modules to be showed between 1-11PM and another sequence to be showed between 7AM to 5PM etc.

Additionally, what I'm looking is if the modules are within the time frame I have selected they can be randomly be chosen, should the user refresh the page.

Please see below:

$r = mt_rand(1,3); // get a random number: 1-3 inclusive; // between 1-11PM Sunday to Friday
if ($r == 1) return 286;
if ($r == 2) return 284;
if ($r == 3) return 285;
if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "13:00 - 23:00" ) ) {
return 286;
return 284;
return 285;
}
$r = mt_rand(1,4); // get a random number: 1-3 inclusive; // between 7-5PM Sunday to Friday
if ($r == 1) return 295;
if ($r == 2) return 293;
if ($r == 3) return 292;
if ($r == 4) return 294;
if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "07:00 - 17:00" ) ) {
return 295;
return 293;
return 292;
return 294;
}
$r = mt_rand(1,5); // get a random number: 1-3 inclusive; // between 11PM-10AM Sunday to Friday
if ($r == 1) return 290;
if ($r == 2) return 289;
if ($r == 3) return 288;
if ($r == 4) return 287;
if ($r == 5) return 291;
if ( $core_genius->inTimeSpan("sun- fri" )
   and $core_genius->inTimeSpan( "23:00 - 10:00" ) ) {
return 290;
return 289;
return 288;
return 287;
return 291;
}

If you could please let me know, I would appreciate it very much! smile

Cheers
Fabio

Plat4Trading
Beginner Modder
ranks
useravatar
Offline
2 Posts
User info in posts
Administrator has disabled public posting

Re: How to display code for Date and Time Recipes?

HI Fabio,

you're definitely heading in the right direction. I think we can just remove some of the code and shuffle some around, and it will be fine. Here's the 1st try:

Code:

if ( $core_genius->inTimeSpan("sun - fri" ) 

   and $core_genius->inTimeSpan( "13:00 - 23:00" ) ) {
  $r = mt_rand(1,3); // get a random number // between 1-11PM Sunday to Friday
  if ($r == 1) return 286;
  if ($r == 2) return 284;
  if ($r == 3) return 285;
}
if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "07:00 - 17:00" ) ) {
  $r = mt_rand(1,4); // get a random number // between 7-5PM Sunday to Friday
  if ($r == 1) return 295;
  if ($r == 2) return 293;
  if ($r == 3) return 292;
  if ($r == 4) return 294;
}
if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "23:00 - 10:00" ) ) {
  $r = mt_rand(1,5); // get a random number // between 11PM-10AM Sunday to Friday
  if ($r == 1) return 290;
  if ($r == 2) return 289;
  if ($r == 3) return 288;
  if ($r == 4) return 287;
  if ($r == 5) return 291;
}

Now I see a problem in that you have 3 overlapping time periods. Was that intentional? The way I structured it above, between 1300-2300 it will use one set, between 0700-1300 [note: not 1700 since that will have been caught by the 1st part] it will use the 2nd, and 2300-0700 it will use the 3rd [not to 1000 as that was caught by the 2nd].

So if during the overlap period you want to display more than one module, you have to structure it differently. Try it this way:

Code:

$mods = array();

if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "13:00 - 23:00" ) ) {
  $r = mt_rand(1,3); // get a random number // between 1-11PM Sunday to Friday
  if ($r == 1) $mods[] = 286;
  if ($r == 2) $mods[] = 284;
  if ($r == 3) $mods[] = 285;
}
if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "07:00 - 17:00" ) ) {
  $r = mt_rand(1,4); // get a random number // between 7-5PM Sunday to Friday
  if ($r == 1) $mods[] = 295;
  if ($r == 2) $mods[] = 293;
  if ($r == 3) $mods[] = 292;
  if ($r == 4) $mods[] = 294;
}
if ( $core_genius->inTimeSpan("sun - fri" )
   and $core_genius->inTimeSpan( "23:00 - 10:00" ) ) {
  $r = mt_rand(1,5); // get a random number // between 11PM-10AM Sunday to Friday
  if ($r == 1) $mods[] = 290;
  if ($r == 2) $mods[] = 289;
  if ($r == 3) $mods[] = 288;
  if ($r == 4) $mods[] = 287;
  if ($r == 5) $mods[] = 291;
}
return $mods;

This way, the code does not "return" immediately when each module is chosen. The module ids are added to something called an "array", and at the end the array is returned. It may contain some or none of the module ids, depending on the time of day.

Hope that helps,
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: How to display code for Date and Time Recipes?

Hi Stephen

Thank you for your help on this. Yes, I'm looking to overlap the period because I'm showing news from different news feeds to the users. I will test the last code and see if it works ;-).

Thanks again for the help,
Fabio

Plat4Trading
Beginner Modder
ranks
useravatar
Offline
2 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1689
Total Polls:
6
Total Posts:
5941
Posts this week:
1
User Info:
 
Total Users:
5348
Newest User:
towner4218
Members Online:
0
Guests Online:
132

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