Search

So, I'm new to Symphony. I love (LOVE) the free form structuring of the content and am finding it really addicting to have this sort of control. So, I'm pretty excited, but on to my question...

I'm setting up a simple blog. I would like for each post to have a publish date and an optional expiration date and I have my section data structure set up that way.

I have set up my data source right now, so that it filters and only returns entries that have a publish date earlier than the current date and time. I am having trouble, though, trying to set up the filter for the expiration date.

The difficultly is that I need for it to match an empty expiration date field (it's optional) OR a date that is still in the future.

I've tried:

later than {$today} {$current-time}

This works, but won't return true for empty expiration date fields.

later than {$today} {$current-time},

I added the comma to see if it would match the date range OR nothing, but this doesn't return anything.

I've tried adding a space, "none", "empty"... etc and not found anything that works.

Anyone able to help me out? Thanks...

I've faced the similar trouble. Having two fields 'audio' and 'video' in section i'd like to filter by empty field (say user entered only audio link or only video). i've tried everything, but nothing helps :-(

Have you tried

later than {$today} {$current-time}, ''

or

later than {$today} {$current-time}, null

I've tried both of those to no avail.

Oh, and the other thing I thought I would try to get around the issue, is have a default value for the expiration date field be 0000-00-00 00:00 (or something) then test against that, but I have also not figured out how to have a default value on a date field other than the current time, which doesn't work.

...frustrating.

Will the filter work against just 2050 in the expiration date field? If so it would be easy to enter that for entries that you don't want to expire. And it would be easier if you uncheck the "Pre-populate this field with today's date" checkbox in the section form. (But, then you would have to change all these entries in 2050.)

If this doesn't work for you it looks like a good candidate for a custom data source, which is quite easy to create.

Hi, I have a similar situation, in which I have a Publish date and a Expiry date.

I filtered the datasource as "earlier than {$today}" for publish date and "later than {$today}" for expiry date.

It works fine except the fact that an article with a publish date, for instance for 2011-03-20, only gets published on the 2011-03-21.

I would need to use today plus 1 and today minus 1 and I've tried lots of ways and none of them worked.

Can someone help me on this one? I'm only using Symphony for 3 days so I'm a big newbie on this.

You should be able to use anything that works with PHPs strtotime function, so "yesterday" and "today" should both work:

later than yesterday

It works fine except the fact that an article with a publish date, for instance for 2011-03-20, only gets published on the 2011-03-21.

nick's right. in this instance, you can also use earlier than tomorrow for your publish date.

@wisolman

You said,

If this doesn't work for you it looks like a good candidate for a custom data source, which is quite easy to create.

I've made custom data sources, but I am struggling to figure out how that would help with the expiration date thing. I'm kind of new to this, so I might be missing something obvious, but could you give a high-level overview of how that would work? I can figure out specifics, but I am not getting the logic of how that would work...

Thanks everyone for the feedback.

@nickdunn and fawx

It worked, thanks a lot!

Try this data source grab function:

  public function grab(&$param_pool=NULL){
        $result = new XMLElement($this->dsParamROOTELEMENT);
        $entries = $this->_Parent->Database->fetch(
            "SELECT title.entry_id, title.value AS title_value, 
                expire.value AS expire_value, publish.value AS publish_value
            FROM sym_entries_data_12 AS title, sym_entries_data_13 AS expire, 
                sym_entries_data_14 AS publish
            WHERE expire.entry_id = title.entry_id 
                AND title.entry_id = publish.entry_id
                AND (expire.value IS NULL OR expire.value > DATE(NOW()))
                AND publish.value < DATE(NOW())");
        foreach($entries as $entry){
            $entry_node = new XMLElement("entry");
            $entry_node->setAttributeArray(array("entry_id" => $entry["entry_id"]));
            $title_node = new XMLElement("title", $entry["title_value"]);
            $entry_node->appendChild($title_node);
            $expire_node = new XMLElement("expire", $entry["expire_value"]);
            $entry_node->appendChild($expire_node);
            $publish_node = new XMLElement("publish", $entry["publish_value"]);
            $entry_node->appendChild($publish_node);
            $result->appendChild($entry_node);
        }
        return $result;
    }

I tested it with a section that contains only a title field and an expiration date field. I created entries with null expiration dates, future expiration dates and past expiration dates. It returned all entries except the entries with past expiration dates.

EDIT: Added a publish date field.

@wisolman,

Great! Thanks for the code.

Seems like maybe this should be easier to do, but that's cool. I can use this for now.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details