Skip to content
Open
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
23 changes: 22 additions & 1 deletion Util/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ protected function _applyDefaults()
}
}

/**
* Looks up a request parameter the same way the deprecated Request::get()
* did: attributes, then query, then request (POST) parameters.
*/
private function _requestGet(Request $request, string $key, mixed $default = null): mixed
{
if ($request->attributes->has($key))
{
return $request->attributes->get($key);
}
if ($request->query->has($key))
{
return $request->query->get($key);
}
if ($request->request->has($key))
{
return $request->request->get($key);
}
return $default;
}

/**
* add join
*
Expand Down Expand Up @@ -188,7 +209,7 @@ public function execute()
});
}
$output = array(
"sEcho" => intval($request->get('sEcho')),
"sEcho" => intval($this->_requestGet($request, 'sEcho')),
"iTotalRecords" => $total_count,
"iTotalDisplayRecords" => $total_count,
"aaData" => $data
Expand Down
42 changes: 30 additions & 12 deletions Util/Factory/Query/DoctrineBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ public function __construct(EntityManagerInterface $em)
$this->query_hints = [];
}

/**
* Looks up a request parameter the same way the deprecated Request::get()
* did: attributes, then query, then request (POST) parameters.
*/
private function _requestGet(string $key, mixed $default = null): mixed
{
if ($this->request->attributes->has($key))
{
return $this->request->attributes->get($key);
}
if ($this->request->query->has($key))
{
return $this->request->query->get($key);
}
if ($this->request->request->has($key))
{
return $this->request->request->get($key);
}
return $default;
}

/**
* get the search dql
*
Expand All @@ -96,11 +117,10 @@ protected function _addSearch(\Doctrine\ORM\QueryBuilder $queryBuilder, array $f
{
if ($this->search == TRUE)
{
$request = $this->request;
$search_fields = array_values($this->fields);
foreach ($search_fields as $i => $search_field)
{
$search_param = $request->get("sSearch_{$i}");
$search_param = $this->_requestGet("sSearch_{$i}");

$filter = $filter_fields[$i] ?? null;
$is_required_date_filter = $filter instanceof DateTimeFilter && $filter->isRequired();
Expand Down Expand Up @@ -408,14 +428,14 @@ public function getTotalRecords(array $filter_fields=[])
*/
public function addSorting()
{
$request = $this->request;
$dql_fields = array_values($this->fields);
$sort_col = $this->_requestGet('iSortCol_0');

// add sorting
if ($request->get('iSortCol_0') !== null)
if ($sort_col !== null)
{

$order_field = current(explode(' as ', $dql_fields[$request->get('iSortCol_0')]));
$order_field = current(explode(' as ', $dql_fields[$sort_col]));
}
else
{
Expand All @@ -425,14 +445,14 @@ public function addSorting()

if ($order_field !== null)
{
$field = $dql_fields[$request->get('iSortCol_0')];
$field = $dql_fields[$sort_col];
if ($field instanceof DQLDatatableField)
{
$qb->orderBy($field->getAlias(), $request->get('sSortDir_0', 'asc'));
$qb->orderBy($field->getAlias(), $this->_requestGet('sSortDir_0', 'asc'));
}
else
{
$qb->orderBy($order_field, $request->get('sSortDir_0', 'asc'));
$qb->orderBy($order_field, $this->_requestGet('sSortDir_0', 'asc'));
}
}
else
Expand Down Expand Up @@ -498,8 +518,6 @@ public function getParameters()
*/
public function getData(array $filter_fields=[])
{
$request = $this->request;

$qb = $this->addSorting();

// extract alias selectors
Expand Down Expand Up @@ -527,8 +545,8 @@ public function getData(array $filter_fields=[])
// add search
$this->_addSearch($qb, $filter_fields);

$display_length = (int) $request->get('iDisplayLength');
$display_start = (int) $request->get('iDisplayStart');
$display_length = (int) $this->_requestGet('iDisplayLength');
$display_start = (int) $this->_requestGet('iDisplayStart');
if($display_length > 10000) //Magic!
{
$display_length = 10000;
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"doctrine/orm": ">=2.3",
"doctrine/dbal": ">=2.13",
"doctrine/doctrine-bundle": "~1.0|~2.0",
"symfony/framework-bundle": "^5.4|^6.4",
"symfony/form": "^5.4|^6.4",
"symfony/translation": "^5.4|^6.4",
"symfony/framework-bundle": "^6.4|^7.4",
"symfony/form": "^6.4|^7.4",
"symfony/translation": "^6.4|^7.4",
"shipmonk/doctrine-mysql-index-hints": "^3.0"
},
"target-dir": "Ali/DatatableBundle",
Expand Down