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.

 

Show a module 33% of time?

Show a module 33% of time?

How would I show a certain module only 33% of the time.  I basically want 3 banner modules to show in the same spot, but they will randomly appear at a 33% rate.  I was thinking about basing it on IP or time of day, but that would bias the modules shown.  I need a more random way.

Any help is appreciated!

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: Show a module 33% of time?

how about this.  can I use the time features to go by minutes or seconds?

if ($core_genius->inTimeSpan( "**:**:00 - **:**:02") )    return 1;
if ($core_genius->inTimeSpan( "**:**:03 - **:**:05") )    return 2;
if ($core_genius->inTimeSpan( "**:**:06 - **:**:09") )    return 3;

?

I could just load modules randomly based on the second of the load.

Does jomgenius allow variables like that?

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: Show a module 33% of time?

No, JomGenius doesn't do wildcards in the inTimeSpan method. However if you just want random numbers then do it like this:

$r = mt_rand(1, 3);// random number between 1 and 3
if ($r == 1) return XXX;
if ($r == 2) return YYY;
if ($r == 3) return ZZZ;
// replace XXX-ZZZ with the module number to use in each case.

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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Show a module 33% of time?

How about this instead:

$now_seconds = getdate("s");

if ($now_seconds ("00 - 19" ))    return 1;
else if ($now_seconds ("20 - 39" ))    return 2;
else if ($now_seconds ("40 - 59" ))    return 3;

Is that syntax valid?

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: Show a module 33% of time?

answer here:

$now_seconds = date('s');

if (($now_seconds >="00") && ($now_seconds <="19"))      return 71;   

else if (($now_seconds >="20") && ($now_seconds <="39"))      return 228; 

else if (($now_seconds >="40") && ($now_seconds <="59"))      return 269;

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: Show a module 33% of time?

Hi - just a quick note about times. What you have above probably works, but it's quite easy to mistakes with time and date calculations, particularly where there are leading zeros.

For the record, I'd do it like this to be on the safe side, without any leading zeros, doing everything as integers instead of strings:

$sec = (int)date("s");
if ($sec < 20) return 71;
if ($sec >= 20 and $sec < 40) return 228;
return 269; // it only gets here if it's not one of the other 2.

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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Show a module 33% of time?

thanks - should the last line be:

else return 269;

?

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: Show a module 33% of time?

No, that's unnecessary (though not wrong). The seconds can only be 0-59, so all possible values are covered in the 3 statements.

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
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10778
Newest User:
negina4qx
Members Online:
0
Guests Online:
133

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