Skip to content
Permalink
Browse files

Merge pull request #1234 from ezsystems/impl-EZP-24270-indexable-date

Implement EZP-24270: Indexable Date field type
  • Loading branch information...
pspanja committed May 5, 2015
2 parents 394b73b + 09271fc commit c0cbecac07ee51325d8913fad10119307a9805d7
@@ -20,7 +20,7 @@
* @group integration
* @group field-type
*/
class DateIntegrationTest extends BaseIntegrationTest
class DateIntegrationTest extends SearchBaseIntegrationTest
{
/**
* Get name of tested field type
@@ -339,4 +339,38 @@ public function providerForTestIsNotEmptyValue()
),
);
}
protected function getValidSearchValueOne()
{
$date = new DateTime( "1970-01-02" );
return $date->getTimestamp();
}
protected function getValidSearchValueTwo()
{
$date = new DateTime( "1970-01-03" );
return $date->getTimestamp();
}
protected function getSearchTargetValueOne()
{
// Handling Legacy Search Engine, which stores Date value as timestamp
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' )
{
return $this->getValidSearchValueOne();
}
return "1970-01-02T00:00:00Z";
}
protected function getSearchTargetValueTwo()
{
// Handling Legacy Search Engine, which stores Date value as timestamp
if ( ltrim( get_class( $this->getSetupFactory() ), '\\' ) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy' )
{
return $this->getValidSearchValueTwo();
}
return "1970-01-03T00:00:00Z";
}
}
@@ -0,0 +1,72 @@
<?php
/**
* This file is part of the eZ Publish Kernel package
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/
namespace eZ\Publish\Core\FieldType\Date;
use eZ\Publish\SPI\Persistence\Content\Field;
use eZ\Publish\SPI\FieldType\Indexable;
use eZ\Publish\SPI\Search;
use DateTime;
/**
* Indexable definition for Date field type
*/
class SearchField implements Indexable
{
/**
* Get index data for field for search backend
*
* @param Field $field
*
* @return \eZ\Publish\SPI\Search\Field[]
*/
public function getIndexData( Field $field )
{
// The field type stores date value as a timestamp of the start of the day in the
// environment's timezone.
// We format this as Y-m-d and add Z to signify UTC (zero offset).
$dateTime = new DateTime();
$dateTime->setTimestamp( $field->value->data["timestamp"] );
return array(
new Search\Field(
'value',
$dateTime->format( "Y-m-d\\Z" ),
new Search\FieldType\DateField()
),
);
}
/**
* Get index field types for search backend
*
* @return \eZ\Publish\SPI\Search\FieldType[]
*/
public function getIndexDefinition()
{
return array(
'value' => new Search\FieldType\DateField(),
);
}
/**
* Get name of the default field to be used for query and sort.
*
* As field types can index multiple fields (see MapLocation field type's
* implementation of this interface), this method is used to define default
* field for query and sort. Default field is typically used by Field
* criterion and sort clause.
*
* @return string
*/
public function getDefaultField()
{
return "value";
}
}
@@ -9,6 +9,7 @@ parameters:
ezpublish.fieldType.indexable.ezmedia.class: eZ\Publish\Core\FieldType\Media\SearchField
ezpublish.fieldType.indexable.ezobjectrelation.class: eZ\Publish\Core\FieldType\Relation\SearchField
ezpublish.fieldType.indexable.ezbinaryfile.class: eZ\Publish\Core\FieldType\BinaryFile\SearchField
ezpublish.fieldType.indexable.ezdate.class: eZ\Publish\Core\FieldType\Date\SearchField
ezpublish.fieldType.indexable.ezprice.class: eZ\Publish\Core\FieldType\Price\SearchField
ezpublish.fieldType.indexable.ezgmaplocation.class: eZ\Publish\Core\FieldType\MapLocation\SearchField
ezpublish.fieldType.indexable.ezcountry.class: eZ\Publish\Core\FieldType\Country\SearchField
@@ -38,6 +39,11 @@ services:
tags:
- {name: ezpublish.fieldType.indexable, alias: ezcountry}

ezpublish.fieldType.indexable.ezdate:
class: %ezpublish.fieldType.indexable.ezdate.class%
tags:
- {name: ezpublish.fieldType.indexable, alias: ezdate}

ezpublish.fieldType.indexable.ezinteger:
class: %ezpublish.fieldType.indexable.ezinteger.class%
tags:
@@ -115,7 +121,6 @@ services:
tags:
- {name: ezpublish.fieldType.indexable, alias: ezuser}
- {name: ezpublish.fieldType.indexable, alias: ezkeyword}
- {name: ezpublish.fieldType.indexable, alias: ezdate}
- {name: ezpublish.fieldType.indexable, alias: ezinisetting}
- {name: ezpublish.fieldType.indexable, alias: ezpackage}
- {name: ezpublish.fieldType.indexable, alias: ezurl}

0 comments on commit c0cbeca

Please sign in to comment.
You can’t perform that action at this time.