Commit b5459140 by Van

fix conditions count bis bis bis

parent aeda2e0a
...@@ -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 '';
}
} }
...@@ -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) {
......
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