Skip to content

Commit

Permalink
Initial commit dynamic construct of Index filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis Igoumenos committed May 2, 2022
1 parent 54f7680 commit 8532a45
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions app/src/Lib/Traits/TableMetaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

namespace App\Lib\Traits;

use Cake\Utility\Inflector;

trait TableMetaTrait {
// Does this Table represent Registry objects or configuration?
private $confTable = false;
Expand All @@ -54,4 +56,63 @@ public function getIsConfigurationTable() {
public function setIsConfigurationTable(bool $confTable) {
$this->confTable = $confTable;
}


/**
* Filter metadata fields.
*
* @since COmanage Registry v5.0.0
* @return array An array of columns distinguished in metadata and non-metadata
*/

protected function filterMetadataFields() {
// Get the list of columns
$coltype = $this->getSchema()->typeMap();
$entity = $this->getEntityClass();
$entity_namespace = explode('\\', $entity);
$modelName = end($entity_namespace);

// Get the list of belongs_to associations and construct an exclude array
$assc_keys = [];
foreach ($this->associations() as $assc) {
if($assc->type() === "manyToOne") {
$assc_keys[] = Inflector::underscore(Inflector::classify($assc->getClassName())) . "_id";
}
}
// Map the model (eg: Person) to the changelog key (person_id)
$mfk = Inflector::underscore($modelName) . "_id";


$meta_fields = [
...$assc_keys,
$mfk,
'actor_identifier',
// 'provisioning_target_id',
'created', // todo: I might need to revisit this. We might want to filter according to date in some occassions. Like petitions
'deleted',
'id',
'modified',
'revision',
// 'source_ad_hoc_attribute_id',
// 'source_address_id',
// 'source_email_address_id',
// 'source_identifier_id',
// 'source_name_id',
// 'source_external_identity_id',
// 'source_telephone_number_id',
];

$newa = array();
foreach($coltype as $clmn => $type) {
if(in_array($clmn, $meta_fields,true)) {
// Move the value to metadata
$newa['meta'][$clmn] = $type;
} else {
// Just copy the value
$newa[$clmn] = $type;
}
}

return $newa ?? [];
}
}

0 comments on commit 8532a45

Please sign in to comment.