PHP code example of colybri / criteria
1. Go to this page and download the library: Download colybri/criteria library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
colybri / criteria example snippets
new Criteria(
Filters::from([
Filter::from(
FilterField::from(CountryName::class),
FilterOperator::Contains,
FilterValue::from('Samoa')
),
Filter::from(
FilterField::from(CountryAlpha2Code::class),
FilterOperator::Contains,
FilterValue::from('WS')
)
...
]),
Order::from(OrderBy::from(CountryName::class), OrderType::Desc),
0,
100
);
Order::from(OrderBy::from(CountryName::class), OrderType::Desc),
new Criteria(
Filters::from(
Conjunction::fromfilters(
Disjunction::fromfilters(
Filter::from(
FilterField::from(CountryAlpha2Code::class),
FilterOperator::Equal,
FilterValue::from('SW')
),
Filter::from(
FilterField::from(CountryAlpha2Code::class),
FilterOperator::Equal,
FilterValue::from('WS')
)
...
),
Filter::from(
FilterField::from(CountryName::class),
FilterOperator::Contains,
FilterValue::from('Samoa')
),
...
)
),
Order::none(),
null,
null
);
$query = $this->dbalConnection->createQueryBuilder()
->select('*')->from('countries');
(new CriteriaDbalAdapter($query, new CountryMap()))->build($criteria);
$countries = $query->executeQuery()->fetchAllAssociative();
final class CountryMap implements EntityMap
{
private const FIELDS = [
CountryName::class => 'en_short_name',
CountryAlpha2Code::class => 'alpha_2_code'
];
private const TABLE = 'countries';
public function map(string $attribute): string
{
return self::FIELDS[$attribute];
}
public static function table(): string
{
return self::TABLE;
}
}