We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10449
    • 956 Posts
      • 34017
      • 898 Posts
      My favorites are tizag.com and a list of scripts to view, run, edit like snipplr.com
        Chuck the Trukk
        ProWebscape.com :: Nashville-WebDesign.com
        - - - - - - - -
        What are TV's? Here's some info below.
        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
        • 19132
        • 199 Posts
        Hi Susan,

        I’ve run into a problem with the snippet you so graciously provided me. To refresh your memory, the snippet checked the date: If it was before 12 noon of the unpublished date, so this chunk. If it’s after, show this other chunk.

        It’s not working as I previously led myself to believe. I think the issue is that the unpublished date isn’t a date but a timestamp.

        So shouldn’t the `date` be `timestamp` or whatever modx calls that? Variable d needs to check the time, not the date. And Variable u needs to grab the time of the unpublish date.

        <?php
        $d = date(’z’); // get today’s day of the year
        $u = date(’z’, $modx->documentObject[’unpub_date’]); // get unpublished day of the year
        $h = date(’G’);
        if($h < 12 || $d < $u ) {
        $c = $modx->getChunk(’earlyBird’);
        } else {
        $c = $modx->getChunk(’lateBird’);
        }
        return($c);
        ?>

        ANy help you can offer is much appreciated. I hate to come across as a taker. I’ve been slammed silly with 5 concurrent MODx sites and my partner is breathing down my necks to get bookkeeping up to date. Urk!

        Peter
          MySQL: 5.0.45
          PHP: 5.2.6
          Linux 2.6.9-023stab048.6-enterprise #1
          cURL enabled
          PDO enabled
          FFox Apple 3.6.8
          Firebug DIS-abled
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The date() function works on a timestamp. It returns various formatted date elements based on a timestamp. By default it uses the results of time(), i.e. the current timestamp, or you can feed it a second parameter consisting of a timestamp.

          I hope somebody else can see what’s wrong with this, as that’s my best shot at it. Somebody better at math could probably come up with some rather trivial (to them) calculations with the timestamps without using the date() function at all.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 19132
            • 199 Posts
            Thanks for explaining that. That helps me troubleshoot it. I’m going to check the dbase table because I think that the timestamp that I’ve copied and pasted into the unpublish box is incorrect. I’m going to check it now...

            My timestamps are formatted correctly. For example: April 16th’s Daily To Go items is unpublished at 10pm on April 16th: 1208394000.

            Checking out the tizag.com php tutorials to help me figure this out. I’m going to trial and error my way through this and if anyone wants to throw in their two cents, please do. Here’s what I want to know:
            if ’z’ is the day of the year, how can G the hour know what time it is?
            Wouldn’t it be better to use the actual timestamp so to make a more accurate argument:
            Get the server’s current timestamp
            Get the docs unpublish timestamp
            If the unpublish timestamp is less than 86400 of the server’s timestamp, show this form,
            else, show this other form.

              MySQL: 5.0.45
              PHP: 5.2.6
              Linux 2.6.9-023stab048.6-enterprise #1
              cURL enabled
              PDO enabled
              FFox Apple 3.6.8
              Firebug DIS-abled
              • 3749
              • 24,544 Posts
              It might be easier (and a little faster) to actually put the "day of year" you want it to go unpublished into your document, either as a custom Template Variable, or just typed into one of the unused fields (summary?). That would bypass all the date arithmetic.

              Bob
                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
                • 19132
                • 199 Posts
                I should mention that the parameters have changed:
                If it’s 12 noon or later, make tomorrow’s daily item cost $14.00:
                Get the unpublish timestamp (which is 8pm for all Daily items)
                If it’s less than 32 hours away from the current timestamp, show form lateBird ($14.00)
                If it’s more than 32 hours away, show form earlyBird ($12.00)
                  MySQL: 5.0.45
                  PHP: 5.2.6
                  Linux 2.6.9-023stab048.6-enterprise #1
                  cURL enabled
                  PDO enabled
                  FFox Apple 3.6.8
                  Firebug DIS-abled
                  • 19132
                  • 199 Posts
                  Progress to report. I picked up one of my dusty old PHP books and did some rewriting:
                  <?php
                  $noon = mktime(12,00,0);
                  $unpub = date(’U’, $modx->documentObject[’unpub_date’]); // get unpublished unix timestamp
                  $which = $unpub-$noon;
                  if($which <= 115200) {
                  $c = $modx->getChunk(’lateBird’);
                  } else {
                  $c = $modx->getChunk(’earlyBird’);
                  }
                  return($c);
                  ?>


                  I tested it in my sandbox site which had this code:
                  <?php
                  $noon = mktime(12,00,0);
                  $unpub = date(’U’, $modx->documentObject[’unpub_date’]); // get unpublished unix timestamp
                  $which = $unpub-$noon;
                  if($which <= 115200) {
                  print "too late for that, dude";
                  } else {
                  print "You still have time to get more for less";
                  }
                  ?>

                  The sandbox version works flawlessly. The get chunk version (the first one in this post) doesn’t and it might be because of how ditto calls it. I’ll check that out before peak activity in these parts picks up.
                    MySQL: 5.0.45
                    PHP: 5.2.6
                    Linux 2.6.9-023stab048.6-enterprise #1
                    cURL enabled
                    PDO enabled
                    FFox Apple 3.6.8
                    Firebug DIS-abled
                    • 19132
                    • 199 Posts
                    This issue has ben solved. I contacted a MODx core developer and am paying for his help (I still owe you a pint Susan) and even though I’m paying for it I thought those of you who chipped in should also reap the rewards. That main issue wasn’t math, but MODx. You might have already known this:
                    "$modx->documentObject[’unpub_date’] always applies to the document from which Ditto was called rather than each individual document."

                    Here’s how it all came together:
                    1) I have a container document that has cache deselected (important) with this Ditto call:
                    [[Ditto? &parents=`136` &display=`33` &tpl=`chefmenu` &sortDir=`ASC`]]

                    2) The snippet `LateEarly` call resides in the tpl called above:
                    {{chunk1}} [+content+] {{chunk2}} [[LateEarly? &unpub=`[+unpub_date+]`]]

                    (chunk1 and chunk2 are just divs with page title placeholder where needed because there’s no way I’m going to use a calendar app. Too much work and they can never approach the niceties that of rolling your own divs can. Also this frees my client from extra work. He merely has to copy and paste into the content pane. He’s not only an accomplished Chef but understands technology pretty well)

                    The Snippet is called `LateEarly`:
                    <?php
                    $unpub = isset($unpub) ? $unpub : $modx->documentObject[’unpub_date’];
                    $noon = mktime(12,0,0);
                    $which = ($unpub - $noon);
                    if ($which <= 118800) {
                    $c = $modx->getChunk(’fourteen’);
                    } else {
                    $c = $modx->getChunk(’twelve’);
                    }
                    return($c);
                    ?>

                    3) `fourteen` and `twelve` are simply the bottom half of the form with the price $14 and $12.

                    You can see this in action at http://www.chefsbasketcolorado.com/daily-to-go-meals.html

                    This is Foxycart+MODx. I can’t tell you how nice it is to use both.

                      MySQL: 5.0.45
                      PHP: 5.2.6
                      Linux 2.6.9-023stab048.6-enterprise #1
                      cURL enabled
                      PDO enabled
                      FFox Apple 3.6.8
                      Firebug DIS-abled