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
b5459140
Commit
b5459140
authored
Dec 05, 2018
by
Van
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix conditions count bis bis bis
parent
aeda2e0a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
24 deletions
+52
-24
CustomQueriesExtension.php
src/CustomQueriesExtension.php
+50
-21
app.js
web/js/app.js
+2
-3
No files found.
src/CustomQueriesExtension.php
View file @
b5459140
...
@@ -47,7 +47,8 @@ class CustomQueriesExtension extends SimpleExtension
...
@@ -47,7 +47,8 @@ class CustomQueriesExtension extends SimpleExtension
$fieldJson
=
$subject
->
get
(
$field
);
$fieldJson
=
$subject
->
get
(
$field
);
if
(
$fieldJson
)
{
if
(
$fieldJson
)
{
$jsonArray
=
\json_decode
(
$fieldJson
,
true
);
$jsonArray
=
\json_decode
(
$fieldJson
,
true
);
$jsonArray
[
'count'
]
=
$this
->
countGroupedByContent
(
$fieldJson
);
$jsonArray
[
'count'
]
=
$this
->
countGroupedByContent
(
$jsonArray
,
$fieldJson
);
$newFieldJson
=
\json_encode
(
$jsonArray
);
$newFieldJson
=
\json_encode
(
$jsonArray
);
$subject
->
set
(
$field
,
$newFieldJson
);
$subject
->
set
(
$field
,
$newFieldJson
);
...
@@ -126,26 +127,6 @@ class CustomQueriesExtension extends SimpleExtension
...
@@ -126,26 +127,6 @@ class CustomQueriesExtension extends SimpleExtension
}
}
/**
/**
* @param $input
* @return array
*/
public
function
countGroupedByContent
(
$input
)
{
$recordsCounted
=
[];
$records
=
$this
->
getResultsAsArray
(
$input
);
/** @var \Bolt\Legacy\Content $record */
foreach
(
$records
as
$record
)
{
$slug
=
$record
->
contenttype
[
'slug'
];
if
(
!
isset
(
$recordsCounted
[
$slug
]))
{
$recordsCounted
[
$slug
]
=
0
;
}
$recordsCounted
[
$slug
]
++
;
}
return
$recordsCounted
;
}
/**
* @return false|mixed
* @return false|mixed
*/
*/
public
function
countResults
(
$input
)
public
function
countResults
(
$input
)
...
@@ -199,6 +180,39 @@ class CustomQueriesExtension extends SimpleExtension
...
@@ -199,6 +180,39 @@ class CustomQueriesExtension extends SimpleExtension
}
}
/**
/**
* @param array $jsonArray
* @param string $json
* @return array
*/
protected
function
countGroupedByContent
(
array
$jsonArray
=
[],
$json
=
''
)
{
$recordsCounted
=
[];
$records
=
$this
->
getResultsAsArray
(
$json
);
if
(
isset
(
$jsonArray
[
'all'
]))
{
unset
(
$jsonArray
[
'all'
]);
}
if
(
isset
(
$jsonArray
[
'count'
]))
{
unset
(
$jsonArray
[
'count'
]);
}
$keys
=
array_keys
(
$jsonArray
);
foreach
(
$keys
as
$key
)
{
$recordsCounted
[
$key
]
=
0
;
}
/** @var \Bolt\Legacy\Content $record */
foreach
(
$records
as
$record
)
{
$slug
=
$this
->
_getContentTypeNameBySlug
(
$record
->
contenttype
[
'slug'
]);
if
(
!
isset
(
$recordsCounted
[
$slug
]))
{
$recordsCounted
[
$slug
]
=
0
;
}
$recordsCounted
[
$slug
]
++
;
}
return
$recordsCounted
;
}
/**
* @param array $json
* @param array $json
* @param $contentType
* @param $contentType
* @param array $fields
* @param array $fields
...
@@ -333,4 +347,19 @@ class CustomQueriesExtension extends SimpleExtension
...
@@ -333,4 +347,19 @@ class CustomQueriesExtension extends SimpleExtension
$value
=
"'"
.
$value
.
"'"
;
$value
=
"'"
.
$value
.
"'"
;
return
[
$operator
,
$value
];
return
[
$operator
,
$value
];
}
}
/**
* @param $slug
* @return int|string
*/
protected
function
_getContentTypeNameBySlug
(
$slug
)
{
$contentTypes
=
$this
->
getContainer
()[
'config'
]
->
get
(
'contenttypes'
);
foreach
(
$contentTypes
as
$key
=>
$contentType
)
{
if
(
$contentType
[
'slug'
]
===
$slug
)
{
return
$key
;
}
}
return
''
;
}
}
}
web/js/app.js
View file @
b5459140
...
@@ -80,6 +80,7 @@ class CustomQueries {
...
@@ -80,6 +80,7 @@ class CustomQueries {
if
(
this
.
config
[
contentType
]
&&
this
.
config
[
contentType
][
'fields'
]
&&
this
.
config
[
contentType
][
'fields'
][
index
]
&&
this
.
config
[
contentType
][
'fields'
][
index
].
label
)
{
if
(
this
.
config
[
contentType
]
&&
this
.
config
[
contentType
][
'fields'
]
&&
this
.
config
[
contentType
][
'fields'
][
index
]
&&
this
.
config
[
contentType
][
'fields'
][
index
].
label
)
{
text
=
this
.
config
[
contentType
][
'fields'
][
index
].
label
;
text
=
this
.
config
[
contentType
][
'fields'
][
index
].
label
;
}
}
if
(
json
[
contentType
]
&&
json
[
contentType
][
index
]
&&
json
[
contentType
][
index
][
'joinFields'
])
{
if
(
json
[
contentType
]
&&
json
[
contentType
][
index
]
&&
json
[
contentType
][
index
][
'joinFields'
])
{
joinField
=
json
[
contentType
][
index
][
'joinFields'
]
joinField
=
json
[
contentType
][
index
][
'joinFields'
]
...
@@ -133,9 +134,7 @@ class CustomQueries {
...
@@ -133,9 +134,7 @@ class CustomQueries {
if
(
!
this
.
usedContentType
[
contentType
]
&&
contentType
)
{
if
(
!
this
.
usedContentType
[
contentType
]
&&
contentType
)
{
this
.
usedContentType
[
contentType
]
=
[];
this
.
usedContentType
[
contentType
]
=
[];
console
.
log
(
this
.
json
[
'count'
]);
let
count
=
(
this
.
json
[
'count'
]
!==
'undefined'
&&
this
.
json
[
'count'
][
contentType
]
!==
'undefined'
)
?
this
.
json
[
'count'
][
contentType
]
:
0
;
console
.
log
(
this
.
json
[
'count'
][
contentType
]);
let
count
=
(
this
.
json
[
'count'
]
!==
undefined
&&
this
.
json
[
'count'
][
contentType
]
!==
undefined
)
?
this
.
json
[
'count'
][
contentType
]
:
0
;
let
checked
=
""
;
let
checked
=
""
;
if
(
jQuery
.
inArray
(
contentType
,
this
.
json
[
'all'
])
!==
-
1
)
{
if
(
jQuery
.
inArray
(
contentType
,
this
.
json
[
'all'
])
!==
-
1
)
{
...
...
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