Commit 3c415c6c authored by jensschuppe's avatar jensschuppe
Browse files

Remove unnecessary json_encode and json_decode calls

parent 0fe67c68
......@@ -86,7 +86,7 @@ class CMRFViews {
}
if (!empty($dataset['params'])) {
$base_data['table']['base']['params'] = json_encode(isset($dataset['params']) ? $dataset['params'] : '');
$base_data['table']['base']['params'] = $dataset['params'];
}
return $base_data;
......@@ -382,31 +382,10 @@ class CMRFViews {
* @return array
*/
public function getDatasets() {
// Return init.
$return = [];
// Get entities ids.
$query = \Drupal::entityQuery('cmrf_dataset');
$results = $query->execute();
$ids = array_keys($results);
// Load entities by id.
$loaded = CMRFDataset::loadMultiple($ids);
if (!empty($loaded)) {
foreach ($loaded as $entity) {
$return[$entity->id()] = [
'label' => $entity->label(),
'connector' => $entity->connector,
'entity' => $entity->entity,
'action' => $entity->action,
'getcount' => $entity->getcount,
];
$params = json_decode($entity->params, TRUE);
$return[$entity->id()]['params'] = empty($params) ? [] : $params;
}
foreach (CMRFDataset::loadMultiple() as $dataset_id => $dataset) {
$return[$dataset_id] = $dataset->toArray();
}
return $return;
}
......
......@@ -39,4 +39,11 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
*/
class CMRFDataset extends ConfigEntityBase implements CMRFDatasetInterface {
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
if (($this->params = json_decode($values['params'], TRUE)) === FALSE) {
$this->params = [];
}
}
}
......@@ -109,7 +109,7 @@ class API extends QueryPluginBase {
$api_action = $table_data['table']['base']['action'];
$api_count_action = $table_data['table']['base']['getcount'];
$connector = $table_data['table']['base']['connector'];
$dataset_params = json_decode($table_data['table']['base']['params'], TRUE);
$dataset_params = $table_data['table']['base']['params'];
if (!is_array($dataset_params)) {
$dataset_params = [];
}
......@@ -203,9 +203,7 @@ class API extends QueryPluginBase {
$result = $call->getReply();
if ((!empty($result['values'])) && (is_array($result['values']))) {
$index = 0;
foreach ($result['values'] as $value) {
// Row data.
$row = json_decode(json_encode($value), TRUE);
foreach ($result['values'] as $row) {
// Mandatory field for views rows.
$row['index'] = $index++;
// Add row to view result.
......
Supports Markdown
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