Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
customQueries
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bolt Extensions
customQueries
Commits
7c03595b
Commit
7c03595b
authored
Nov 30, 2018
by
Frédéric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update CustomQueriesExtension.php
parent
ecd5a399
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
CustomQueriesExtension.php
src/CustomQueriesExtension.php
+84
-0
No files found.
src/CustomQueriesExtension.php
View file @
7c03595b
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment