Hi we're using channel ratings module, and want to run a routine that basically closes a comment if its rank is 1 at 30 days of age, rank 2 at 60 days etc.

The {comment_date} is yeilding a 0 whenever any method or php function is attempted on it. I have everything working except this piece and I can't figure out what the problem is.

Here's what I have:

    function GetComment_Interval($comment_date,$current_date)

      $intervalSeconds = $current_date - $comment_date;
       $intervalDays = round($intervalSeconds / 86400); // days since
       return $intervalDays;

{exp:switchee variable="{rating:overall:rating}" parse="inward"}
            // 1 star reviews" expire in 30 days,
            {case value="1"}
              EE->localize->string_to_timestamp($commD); // this throws error of 'invalid date format'
              $currD = $this->EE->localize->now;
              $interval = GetComment_Interval($commD2,$currD); // find days between
              echo $interval." days";
               if ($interval >= 30){



            // 2 star reviews after 60 days
            {case value="2" default="Yes"}

               if ($interval >= 60){


            // 3 star reviews after 120 days
            {case value="3"}

               if ($interval >= 120){


           //It must be 4 or 5 start therefore always show it.
           {case default="Yes"}{/case}


[Just a note to add here that the real solution was in achieving workable EE parse order, dealt with in the comments to this answer.]

Thanks, Brandon, for putting this here from previous tweets.

From what you show, I would guess the problem is that you're trying to evaluate {comment_date} outside the template code range where it can be valid. That would be only within the {exp:comment:entries} tag pair.

For a simple check, just put a non-php {comment_date} in your template near your attempted use of it, surrounded by some text you'll recognize. You'll see a big integer number if it's in a valid place; blank otherwise. Something like,

<p>Here's my comment_date: |{comment_date}|.</p>

Once you have this working, I think you're also trying to access comment_date in a way that won't work, within your php code as shown. You need to use a form like the following to do it, setting your own php var from the tag - I've included a proof echo as well.

<?php $mycdate = "{comment_date}"; echo 'php comment_date is |'.$mycdate."|"; ?>

If it helps to know, what I did as mentioned to work sensibly with a like situation was make a (very) simple plug-in, passing across the template variables to it. This allows you to do anything you want in PHP without having inline code, or permitting it.

I was chasing another issue which I thought you might have had, which was to have both {entry_date} and {comment_date} be valid to compare them (the ...minutes/days/months-later presentation). The EE exp:entries-exp:comment:entries tags work very strangely together, as we've long known, and the variables you want aren't ever both valid at any possible location.

To solve this, I used croxton's Stash. This gets complicated, though, to have the right combination of parse='inward' parameters so that you actually get the variables passed across. So let's not get into that unless you need it.

Does locating your code within the {exp:comment:entries} loop not solve your problem? You should certainly have {comment_date} valid there, and can prove it simply with the tests and EE-php variable access mentioned above.

  • I think this form is munging the code. I don't see some of it now that i inspect it closely. BUT what you've stated I have tried and the comment date does work as well as the conversion using: pastebin.com/0gdxLNmi whenever I try and set the comment_date to a php variable that works, but when I try and perform any conversion function it breaks completely. The reason I'm trying to convert it is that the db comment_date also a string will not allow math functions. – brandrich May 2 '13 at 18:18
  • Ok, much clearer with the better code block. The correction needed is setting PHP Parsing Stage to Output, in Template Manager Preferences on your template. Then you will find that your (uncommented) echo will show a proper timezone-localized integer value for commD2, and the rest of your code should proceed. The underlying issue, as so often, is parse order - when your values are present vs. when the embedded php localize function runs, in this case. It's not on the surface here, loweblog.com/downloads/ee-parse-order.pdf, but note 5. - comments are a module. Cheers, Brandon, hope good. – narration_sd May 2 '13 at 21:41
  • Well there are some other items in this page that require php on input. So then, would the parse order be correct if I used an embedded template here? – brandrich May 3 '13 at 17:51
  • * Yes, this works with multiple nested embedded templates, thanks for helping me understand the parse order! – brandrich May 3 '13 at 18:13
  • Glad you're up and running, and if the embeds are not causing performance issues, would be confident they're fine. Those who winkle deep on these things often use Stash to 'move' resolved items to a later parsing stage to work -- it's an alternative, but again, only necessary if you need it. EE is pretty mind and patience-consuming on these things ;) Cheers, Brandon – narration_sd May 3 '13 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.