PHP code example of adt / query-object-data-source
1. Go to this page and download the library: Download adt/query-object-data-source 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/ */
adt / query-object-data-source example snippets
/** @var \ADT\QueryObjectDataSource\IQueryObjectDataSourceFactory @autowire */
protected $queryObjectDataSourceFactory;
$qo = /* create query object */;
$dataSource = $this->queryObjectDataSourceFactory->create($qo, "id")
->setSortCallback(function($queryObject, \Ublaboo\DataGrid\Utils\Sorting $sorting) {
$sort = $sorting->getSort();
if (!empty($sort)) {
foreach ($sort as $order => $by) {
$queryObject->order("e.$order", $by);
}
}
})
->setFilterCallback(function ($queryObject, array $filter) {
foreach ($filter as $field => $value) {
switch ($column) {
case 'dateRange':
$queryObject->byDateRange(QueryObjectDataSource::parseFilterDateRange($fieldSet));
break;
case 'date':
$queryObject->byDate(QueryObjectDataSource::parseFilterDate($fieldSet));
break;
default:
$queryObject->{'by' . $field}($value);
}
}
})
->setLimitCallback(function ($offset, $limit, $defaultCallback) use ($query, $itemRepository) {
// This callback is not necessary, but you can do your stuff with $offset and $limit here.
$defaultCallback(); // Run the default action
});
$grid->setDataSource($queryObjectDataSource);
$datagrid->addColumnText('email', 'entity.user.email')
->setSortable()
->setSortableCallback(function (UserQueryObject $userQuery, $email) {
$userQuery->orderByEmail($email);
})
->setFilterText()
->setCondition(function (UserQueryObject $userQuery, $email) {
$userQuery->searchInEmail($email);
});