Skip to content

Use string values in DateFilter null-management constants #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.0 beta 4

* Use string values for `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter` null-management constants

## 1.0.0 beta 3

* The Hydra documentation URL is now `/apidoc` (was `/vocab`)
Expand Down
6 changes: 3 additions & 3 deletions Doctrine/Orm/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class DateFilter extends AbstractFilter
{
const PARAMETER_BEFORE = 'before';
const PARAMETER_AFTER = 'after';
const EXCLUDE_NULL = 0;
const INCLUDE_NULL_BEFORE = 1;
const INCLUDE_NULL_AFTER = 2;
const EXCLUDE_NULL = 'exclude_null';
const INCLUDE_NULL_BEFORE = 'include_null_before';
const INCLUDE_NULL_AFTER = 'include_null_after';

/**
* @var array
Expand Down
16 changes: 8 additions & 8 deletions Resources/doc/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ As others filters, the date filter must be explicitly enabled:
# app/config/services.yml

services:
# Enable date filter for for the property "dateProperty" of the resource "resource.offer"
# Enable date filter for the property "dateProperty" of the resource "resource.offer"
resource.date_filter:
parent: "api.doctrine.orm.date_filter"
arguments: [ { "dateProperty": ~ } ]
Expand All @@ -110,12 +110,12 @@ services:
The date filter is able to deal with date properties having `null` values.
Four behaviors are available at the property level of the filter:

| Description | Strategy to set |
|--------------------------------------|-------------------------------------------------------------------------------|
| Use the default behavior of the DBMS | `null` |
| Exclude items | `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter::EXCLUDE_NULL` (`0`) |
| Consider items as oldest | `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE` (`1`) |
| Consider items as youngest | `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_AFTER` (`2`) |
| Description | Strategy to set |
|--------------------------------------|-------------------------------------------------------------------------------------------------|
| Use the default behavior of the DBMS | `null` |
| Exclude items | `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter::EXCLUDE_NULL` (`exclude_null`) |
| Consider items as oldest | `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_BEFORE` (`include_null_before`) |
| Consider items as youngest | `Dunglas\ApiBundle\Doctrine\Orm\Filter\DateFilter::INCLUDE_NULL_AFTER` (`include_null_after`) |

For instance, exclude entries with a property value of `null`, with the following service definition:

Expand All @@ -126,7 +126,7 @@ For instance, exclude entries with a property value of `null`, with the followin
services:
resource.date_filter:
parent: "api.doctrine.orm.date_filter"
arguments: [ { "dateProperty": ~ } ]
arguments: [ { "dateProperty": exclude_null } ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not letting the default value settable with ~?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok with Theo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null value is for using database default (i.e. no special null handling). That has not been changed.

What I'm doing here is correcting the example for excluding null values (view the full file to see the text above it).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense


resource.offer:
parent: "api.resource"
Expand Down