Publication Period Add-on


#1

Taking in consideration the questions in https://discourse.getcockpit.com/t/delayed-publication/165 created a new add-on that may help on the situations we need to set one or more collections entries only available in a particular day or period.


#2

One improvement:

use the collections.find.before event and extend the filter option

Greets,
Artur


#3

Humm, not sure if got it, on the collections.find.before don’t have access to the collection entries!


#4

you don’t have to, you extend the filter option to let the db do the filtering:

$app->on('collections.find.before', function ($name, &$options) use ($app) {

  // Get the collection.
  $collection = $this->module('collections')->collection($name);

  foreach ($collection['fields'] as $field) {

    if ($field['type'] == 'publicationperiod') {

      $name = $field['name'];

      $options['filter']['$or'] = [
         ["{$name}" => ['$exists' => false]],
         ["{$name}" => ''],
         ["{$name}" => ['$gte' => DATE, '$lte' => DATE]]
      ];      

      break;
    }
  }
});



#5

Ok, will check, it seems a clever way