removeDate and hidden field names

7 posts by 2 authors in: Forums > CMS Builder
Last Post: March 5, 2020   (RSS)

By shawn - March 3, 2020

Good day everyone

I was hoping someone would be able to assist. I am using a checkbox with the 'hidden' field name. I'm looking to also use the 'removeDate' field name so that you can either hide content by checking hidden or by date. I want it so that if its hidden using the checkbox, then the date field is irrelevant. However, if it's visible (unchecked), then it must only show if within the date period. 

I have the  checkbox working fine the following:

'tableName'   => 'bhs_promo',
'where'    => " hidden = '0' ", 
'orWhere'    => " hidden = '1' ",
'loadUploads' => true,
'allowSearch' => false,
'limit'       => '1',
<?php foreach ($bhs_promoRecords as $record): ?>
<?php if ($record['hidden'] == '0' ||  $record['hidden'] == ''): ?>
Content here...
<?php endif ?>
<?php endforeach ?>

I have no idea how to include the 'removeDate' field syntax? 

Thank you

By daniel - March 3, 2020

Hi shawn,

Is there a reason you'd prefer to do the filtering in the code? The hidden and removeDate fields can both be handled automatically by getRecords. If you have a date field named "removeDate" then getRecords should exclude any records A) with a date set, and B) where the date is in the past. As well, if you remove the "where" and "orWhere" parameters it should also handle removing any records marked hidden.

Thanks,

Daniel
Technical Lead
interactivetools.com

By daniel - March 5, 2020

Hi Shawn,

Thanks for clarifying, I understand more clearly what you're trying to do now.

My first suggestion would be to change the name of the "removeDate" field so that it doesn't trigger the automatic removal in getRecords; for the sake of example I'll call it "removeAfter". It should still be a date type field. (Alternatively, if you want to keep the field name so that you can selectively use the automatic removal, there is an "ignoreRemoveDate" parameter that can be used with getRecords to ignore removeDate as needed).

You can then use something like the following to manually filter the date:

<?php foreach ($bhs_promoRecords as $record): ?>
<?php if (($record['hidden'] == '0' ||  $record['hidden'] == '') && strtotime($record['removeAfter']) > time()): ?>
Content here...
<?php endif ?>
<?php endforeach ?>

This will require both conditions to be true: the record is not hidden, and the removeAfter date is in the future.

Let me know if you have any further questions, or run into any issues setting this up.

Thanks!

Daniel
Technical Lead
interactivetools.com

By shawn - March 5, 2020

Hi Daniel,

Firstly thank you for this, I appreciate it. I have tested this and it works as long as the date is in the past, however if the time is in the past, it still remains visible.

So for example, I set the removeAfter date to yesterday and everything works perfectly. I change the removeAfter to today but a few minutes into the past and it does nothing. 

Any thoughts?

By shawn - March 5, 2020

Sorry I noticed it is working, but the time coming through is 2 hours behind my time. I think I just need to set the correct time zone?

By shawn - March 5, 2020

Nevermind Daniel, thank you again! I got it sorted - my timezone settings in the CMS Builder admin settings were incorrect. All good now!