We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22446
    • 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.
      • 3749
      • 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;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38290
        • 712 Posts
        Bob do you think it would be helpful to hook a MODX snippet up to a Cron job for this?
          jpdevries
          • 3749
          • 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.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 38290
            • 712 Posts
            True. Simple snippet no harm in calling uncached I suppose
              jpdevries
              • 22446
              • 181 Posts
              BobRay,

              Thanks for the snippet. Is there a way to randomly select these image TV's from resources with your snippet? I have more than 7 images and with the snippet that you wrote for me below would only allow for 7 images to be displayed and each of those images would be displayed the same day of each week.

              Is there a way I can use getResources in the snippet below. I could then code the getResources snippet to randomly select an image each day of the week. Just a suggestion. Thank you again for your help.



              Quote from: BobRay at Dec 06, 2012, 09:27 PM
              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;
              -->
                • 3749
                • 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.

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 4172
                  • 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.

                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 22446
                    • 181 Posts
                    Bruno17

                    Currently I have a parent resource (webpage) that is called web cam network. Under the parent webpage there are 17 child resources (webpages) that have a Template Variable assigned to those pages. Each page has a different URL to an image on the web. These images are of others webcams that people have shared with me and they are allowing me to post their image on my website. These images are not on my webserver they are a picture from a web camera that has a URL. These images are continually updated throughout the day.

                    On my homepage I would like to randomly choose one of the 17 webpages that have this template variable and display the image of this template variable on my homepage. I would then like for the image to change every day to a different image.

                    I hope this helps answer your questions. If you have more, please let me know.

                    Thank you.

                    Quote from: Bruno17 at Dec 10, 2012, 06:46 PM
                    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.

                      • 4172
                      • 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.]
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!