From 893dd617c810688128a6f1476df3c247badb0180 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Fri, 6 Sep 2019 11:32:54 +0200 Subject: [PATCH] chg: [attribute:restSearch] New paramter `includeFullModel` to attach full model information --- app/Controller/AttributesController.php | 2 +- app/Model/Attribute.php | 6 ++++-- app/Model/DecayingModel.php | 8 ++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/Controller/AttributesController.php b/app/Controller/AttributesController.php index 1bf986acd..88886b1c6 100644 --- a/app/Controller/AttributesController.php +++ b/app/Controller/AttributesController.php @@ -1892,7 +1892,7 @@ class AttributesController extends AppController 'timestamp', 'enforceWarninglist', 'to_ids', 'deleted', 'includeEventUuid', 'event_timestamp', 'threat_level_id', 'includeEventTags', 'includeProposals', 'returnFormat', 'published', 'limit', 'page', 'requested_attributes', 'includeContext', 'headerless', 'includeWarninglistHits', 'attackGalaxy', 'object_relation', 'includeSightings', 'includeCorrelations', 'includeDecayScore', - 'decayingModel', 'excludeDecayed', 'modelOverrides' + 'decayingModel', 'excludeDecayed', 'modelOverrides', 'includeFullModel' ); $filterData = array( 'request' => $this->request, diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index f7f5643d1..3c7212ee1 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -3279,7 +3279,8 @@ class Attribute extends AppModel } if ($options['includeDecayScore']) { $this->DecayingModel = ClassRegistry::init('DecayingModel'); - $this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel'], $options['modelOverrides']); + $include_full_model = isset($options['includeFullModel']) && $options['includeFullModel'] ? 1 : 0; + $this->DecayingModel->attachScoresToAttribute($user, $results[$key]['Attribute'], $options['decayingModel'], $options['modelOverrides'], $include_full_model); if ($options['excludeDecayed']) { // filter out decayed attribute $decayed_flag = true; foreach ($results[$key]['Attribute']['decay_score'] as $decayResult) { // remove attribute if ALL score results in a decay @@ -4263,7 +4264,8 @@ class Attribute extends AppModel 'includeContext' => !empty($filters['includeContext']) ? $filters['includeContext'] : 0, 'includeSightings' => !empty($filters['includeSightings']) ? $filters['includeSightings'] : 0, 'includeCorrelations' => !empty($filters['includeCorrelations']) ? $filters['includeCorrelations'] : 0, - 'includeDecayScore' => !empty($filters['includeDecayScore']) ? $filters['includeDecayScore'] : 0 + 'includeDecayScore' => !empty($filters['includeDecayScore']) ? $filters['includeDecayScore'] : 0, + 'includeFullModel' => !empty($filters['includeFullModel']) ? $filters['includeFullModel'] : 0 ); if (!empty($filters['attackGalaxy'])) { $params['attackGalaxy'] = $filters['attackGalaxy']; diff --git a/app/Model/DecayingModel.php b/app/Model/DecayingModel.php index 1178a8735..fbebf8f16 100644 --- a/app/Model/DecayingModel.php +++ b/app/Model/DecayingModel.php @@ -510,7 +510,7 @@ class DecayingModel extends AppModel } } - public function attachScoresToAttribute($user, &$attribute, $model_id=false, $model_overrides=array()) + public function attachScoresToAttribute($user, &$attribute, $model_id=false, $model_overrides=array(), $include_full_model=0) { $models = array(); if ($model_id === false) { // fetch all allowed and associated models @@ -530,7 +530,11 @@ class DecayingModel extends AppModel } $score = $this->getScore($attribute, $model, $user); $decayed = $this->isDecayed($attribute, $model, $score); - $attribute['decay_score'][] = array('DecayingModel' => $model['DecayingModel'], 'score' => $score, 'decayed' => $decayed); + $to_attach = array('score' => $score, 'decayed' => $decayed, 'DecayingModel' => array('id' => $model['DecayingModel']['id'])); + if ($include_full_model) { + $to_attach['DecayingModel'] = $model['DecayingModel']; + } + $attribute['decay_score'][] = $to_attach; } }