-
- 181 Posts
Hello modx community. I am looking for some help.
I have a bunch of pages that have TV's that have URL's to live pictures (snowmobile trail webcam's). I am trying to create a "daily" webcam photo on the homepage but I am not sure how to approach or even code something like this. Does anyone have suggestions on how to go about this? I was initially thinking of trying to use getResources.
Any help would be much appreciated. Thanks.
-
- 24,544 Posts
Probably the most efficient thing would be a custom snippet that checks the day of the week and returns the appropriate link or image -- something like this.
<?php
$dayOfWeek = date('w'); // 0 - 6, 0 is Sunday
switch($dayOfWeek) {
case 0:
$output = $something
break;
case 1:
$output = $somethingElse
break;
// etc.
}
return $output;
-
- 712 Posts
Bob do you think it would be helpful to hook a MODX snippet up to a Cron job for this?
jpdevries
-
- 24,544 Posts
I don't see any advantage to that (a cron job). The first user to visit the page on a given day will see the new image, no?
Maybe there's something I'm missing.
-
- 712 Posts
True. Simple snippet no harm in calling uncached I suppose
jpdevries
-
- 24,544 Posts
That gets trickier. Pulling a random image for each page visit is easy, but if you want to randomly assign images to days and make sure that you don't have the same image for different days, it gets more complicated.
You'd also have to decide how often you want to re-assign the images (if ever).
This might be a good job for MIGx.
-
- 5,888 Posts
I have a bunch of pages that have TV's that have URL's to live pictures (snowmobile trail webcam's).
Can you tell us a bit more about that?
I am trying to create a "daily" webcam photo on the homepage
and perhaps also about this.
-
- 5,888 Posts
wouldn't this be an option:
Put all urls into a MIGX - TV with this fields:
url,date,active..... and what you need else
use this logic:
1. is there an active item for the current date?
yes -> goto 7
no ->
2. empty all dates and active-states which are older than today
3. are there more than 7 urls which have empty dates
no -> goto 6
yes -> get a random list of all this urls (with an empty date)
4. search for the latest date
5. replace all empty dates of the random list with coming dates (later than the latest date found or later than today) and save the result as json-records back to the MIGX-TV
6. set the item with the current date to active
7. display the active item with the current date
1 2012/12/10 active
3 2012/12/11
5 2012/12/12
9 2012/12/13
2 2012/12/14
8 2012/12/15
6 2012/12/16
4 2012/12/17
7 2012/12/18
17 2012/12/19
11 2012/12/20
15 2012/12/21
10 2012/12/22
14 2012/12/23
12 2012/12/24
16 2012/12/25
13 2012/12/26
7 days later:
1
3
5
9
2
8
6
4 2012/12/17 active
7 2012/12/18
17 2012/12/19
11 2012/12/20
15 2012/12/21
10 2012/12/22
14 2012/12/23
12 2012/12/24
16 2012/12/25
13 2012/12/26
8 days later:
2 2012/12/27
3 2012/12/28
1 2012/12/29
5 2012/12/30
6 2012/12/31
4 2013/01/01
9 2013/01/02
8 2012/12/03
7 2012/12/18 active
17 2012/12/19
11 2012/12/20
15 2012/12/21
10 2012/12/22
14 2012/12/23
12 2012/12/24
16 2012/12/25
13 2012/12/26
[ed. note: Bruno17 last edited this post 11 years, 5 months ago.]