chg: [decaying] Added default models to selection when fetching

associated models
pull/5032/head
mokaddem 2019-08-29 12:23:18 +02:00
parent c39c168962
commit 9baafffc7a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 24 additions and 4 deletions

View File

@ -189,6 +189,17 @@ class DecayingModel extends AppModel
$decaying_model['DecayingModel']['isEditable'] = $this->isEditableByCurrentUser($user, $decaying_model);
}
public function fetchAllDefaultModel($user)
{
$default_models = $this->fetchAllAllowedModels($user, false);
foreach ($default_models as $i => $model) {
if (!$default_models[$i]['DecayingModel']['isDefault']) {
unset($default_models[$i]);
}
}
return $default_models;
}
public function fetchAllAllowedModels($user, $full=true, $filters=array())
{
$conditions = array();
@ -521,7 +532,6 @@ class DecayingModel extends AppModel
} else {
$models[] = $this->fetchModel($user, $model_id, false, array());
}
foreach ($models as $i => $model) {
if (!empty($model_overrides)) {
$this->overrideModelParameters($model, $model_overrides);

View File

@ -69,14 +69,14 @@ class DecayingModelMapping extends AppModel
return $associated_types;
}
public function getAssociatedModels($user, $attribute_type = array()) {
public function getAssociatedModels($user, $attribute_type = false) {
$conditions = array(
'OR' => array(
'DecayingModel.org_id' => $user['org_id'],
'DecayingModel.all_orgs' => true
)
);
if (!empty($attribute_type)) {
if ($attribute_type !== false) {
$conditions['attribute_type'] = $attribute_type;
}
$associated_models = $this->find('all', array(
@ -94,8 +94,18 @@ class DecayingModelMapping extends AppModel
)
)
));
// Also add default models to selection
$default_models = $this->DecayingModel->fetchAllDefaultModel($user);
$associated_default_models = array();
foreach ($default_models as $i => $model) {
$intersection = array_intersect($model['DecayingModel']['attribute_types'], array($attribute_type));
if (count($intersection) > 0) {
$associated_default_models[$attribute_type][] = $model['DecayingModel']['id'];
}
}
$associated_models = Hash::combine($associated_models, '{n}.DecayingModelMapping.model_id', '{n}.DecayingModelMapping.model_id', '{n}.DecayingModelMapping.attribute_type');
return $associated_models;
$models = array_merge_recursive($associated_default_models, $associated_models);
return $models;
}
}