Help me clean my code
Permalink
I needed to have certain (news) entries listed in a page list only during a certain period as defined by the editor. I've added two attribute fields, date format, named pub_date and exp_date ("publish on date" and "expiry date"). Also made a custom page-list template, adding the following code:
While this seems to work as intended I'm slightly annoyed by having to introduce "strtotime" in order to make the selection work. I have a feeling it could be made to work in a slightly more "stream lined" manner, but I'm a novice with PHP. Any suggestions for improvements?
Thanks in advance for any assistance
Søren, Denmark
$pubdate=$cobj->getCollectionAttributeValue('pub_date'); $expdate=$cobj->getCollectionAttributeValue('exp_date'); $datetoday=date("Ymd",(strtotime($date->getLocalDateTime('now')))); if ($pubdate=='' || $pubdate==NULL) { ($pubdate=$datetoday); } else { $pubdate=date("Ymd",strtotime($cobj->getCollectionAttributeValue('pub_date'))); } if ($expdate=='' || $expdate==NULL) { ($expdate=$datetoday); } else { $expdate=date("Ymd",strtotime($cobj->getCollectionAttributeValue('exp_date'))); } $title = $textHelper->entities($cobj->getCollectionName()); if (($expdate>=$datetoday) && ($pubdate<=$datetoday)) {
Viewing 15 lines of 16 lines. View entire code block.
While this seems to work as intended I'm slightly annoyed by having to introduce "strtotime" in order to make the selection work. I have a feeling it could be made to work in a slightly more "stream lined" manner, but I'm a novice with PHP. Any suggestions for improvements?
Thanks in advance for any assistance
Søren, Denmark
http://www.weblicating.com/c5/cheat-sheet/...