Skip to content
Snippets Groups Projects
Commit 72e21c8a authored by Pascal Crott's avatar Pascal Crott Committed by Dominik Wille
Browse files

Issue #3485489 by hydra: Extends the API to allow loading the raw data from database

parent c61723db
No related branches found
No related tags found
1 merge request!13#3485489 Make getItemsDataByConditionConfiguration public.
......@@ -18,6 +18,14 @@ class ConditionsFieldService implements ConditionsFieldServiceInterface {
use ConditionAccessResolverTrait;
/**
* Stores the loaded data by entity_type_id and configuration checksum.
*
* @var array
* The data from database.
*/
protected array $itemsData = [];
/**
* Constructs an ConditionsFieldService object.
*
......@@ -74,18 +82,15 @@ class ConditionsFieldService implements ConditionsFieldServiceInterface {
}
/**
* Loads the field data for a given condition configuration from database.
*
* @param string $entity_type_id
* The entity_type_id to load from.
* @param array $condition_configuration
* The condition configuration to check for.
*
* @return array
* The database rows with the condition configuration by entity_type_id.
* {@inheritdoc}
*/
protected function getItemsDataByConditionConfiguration(string $entity_type_id, array $condition_configuration): array {
$items_data = [];
public function getItemsDataByConditionConfiguration(string $entity_type_id, array $condition_configuration): array {
$cache_id = md5(serialize($condition_configuration));
// Early return if already built.
if (isset($this->itemsData[$entity_type_id][$cache_id])) {
return $this->itemsData[$entity_type_id][$cache_id];
}
// Check for every possible field.
foreach ($this->getConditionsFieldDefinitions($entity_type_id) as $field_name => $field_definition) {
......@@ -122,7 +127,7 @@ class ConditionsFieldService implements ConditionsFieldServiceInterface {
foreach ($result->fetchAll() as $item) {
$value = JSON::decode($item->{"{$field_name}_value"});
$items_data[$item->entity_id][$item->delta] = [
$this->itemsData[$entity_type_id][$cache_id][$item->entity_id][$item->delta] = [
'entity_id' => $item->entity_id,
'delta' => $item->delta,
'value' => $value,
......@@ -132,7 +137,7 @@ class ConditionsFieldService implements ConditionsFieldServiceInterface {
}
}
return $items_data;
return $this->itemsData[$entity_type_id][$cache_id] ?? [];
}
}
......@@ -35,4 +35,17 @@ interface ConditionsFieldServiceInterface {
*/
public function getConditionsFieldDefinitions(string $entity_type_id = NULL): array;
/**
* Loads the field data for a given condition configuration from database.
*
* @param string $entity_type_id
* The entity_type_id to load from.
* @param array $condition_configuration
* The condition configuration to check for.
*
* @return array
* The database rows with the condition configuration by entity_type_id.
*/
public function getItemsDataByConditionConfiguration(string $entity_type_id, array $condition_configuration): array;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment