Commit 7c03595b by Frédéric

Update CustomQueriesExtension.php

parent ecd5a399
...@@ -23,6 +23,8 @@ class CustomQueriesExtension extends SimpleExtension ...@@ -23,6 +23,8 @@ class CustomQueriesExtension extends SimpleExtension
{ {
return [ return [
'queriesResults' => ['getQueriesResults', ['is_safe' => ['html']]], 'queriesResults' => ['getQueriesResults', ['is_safe' => ['html']]],
'queriesArrayResults' => ['queriesArrayResults'],
'countResults' => ['countResults'],
]; ];
} }
...@@ -105,7 +107,89 @@ class CustomQueriesExtension extends SimpleExtension ...@@ -105,7 +107,89 @@ class CustomQueriesExtension extends SimpleExtension
return $this->getContainer()['twig']->render("custom_queries.twig", ['records' => $records]); return $this->getContainer()['twig']->render("custom_queries.twig", ['records' => $records]);
} }
/**
* @return false|mixed
*/
public function queriesArrayResults($input)
{
if($input == '') {
return '';
}
$json = json_decode($input, true);
if(!$json || empty($json)) {
return '';
}
$records = [];
$storage = $this->getContainer()['storage'];
foreach ($json as $contentType => $fields) {
$query = $this->_buildQuery($contentType, $fields);
if(!empty($query))
{
$rows = $this->getContainer()['db']->fetchAll($query);
$ids = array_map(function($rows) {
return $rows['id'];
}, $rows);
$contents = $storage->getContent($contentType, ['id' => implode(' || ', $ids), 'paging' => true, 'limit' => 99999]);
if(is_array($contents)) {
$records = array_merge($records, $contents);
} else {
$records = array_merge($records, [$contents]);
}
}
}
return ['records' => $records];
}
/**
* @return false|mixed
*/
public function countResults($input)
{
if($input == '') {
return '';
}
$json = json_decode($input, true);
if(!$json || empty($json)) {
return '';
}
$records = [];
$storage = $this->getContainer()['storage'];
foreach ($json as $contentType => $fields) {
$query = $this->_buildQuery($contentType, $fields);
if(!empty($query))
{
$rows = $this->getContainer()['db']->fetchAll($query);
$ids = array_map(function($rows) {
return $rows['id'];
}, $rows);
$contents = $storage->getContent($contentType, ['id' => implode(' || ', $ids), 'paging' => true, 'limit' => 99999]);
if(is_array($contents)) {
$records = array_merge($records, $contents);
} else {
$records = array_merge($records, [$contents]);
}
}
}
return count($records);
}
/** /**
* @param array $fields * @param array $fields
* @return string * @return string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment