2019-04-03 11:51:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
App::uses('AppController', 'Controller');
|
|
|
|
|
|
|
|
class DecayingModelMappingController extends AppController
|
|
|
|
{
|
|
|
|
public $components = array('Security' ,'RequestHandler');
|
|
|
|
|
|
|
|
public $paginate = array(
|
|
|
|
'limit' => 50,
|
|
|
|
'order' => array(
|
|
|
|
'DecayingModel.name' => 'asc'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
public function viewAssociatedTypes($model_id) {
|
|
|
|
$associated_types = $this->DecayingModelMapping->getAssociatedTypes($this->Auth->user(), $model_id);
|
|
|
|
return $this->RestResponse->viewData($associated_types, $this->response->type());
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:17:11 +02:00
|
|
|
|
|
|
|
public function linkAttributeTypeToModel($model_id) {
|
2019-08-16 10:52:00 +02:00
|
|
|
$model = $this->DecayingModelMapping->DecayingModel->fetchModel($this->Auth->user(), $model_id);
|
2019-09-12 11:02:39 +02:00
|
|
|
if (empty($model)) {
|
|
|
|
throw new NotFoundException(__('No Decaying Model with the provided ID exists'));
|
|
|
|
}
|
2019-04-04 11:17:11 +02:00
|
|
|
|
2019-08-21 15:53:13 +02:00
|
|
|
if ($this->request->is('post') || $this->request->is('put')) {
|
|
|
|
$this->request->data['DecayingModelMapping']['model_id'] = $model_id;
|
2019-04-04 11:17:11 +02:00
|
|
|
if (!isset($this->request->data['DecayingModelMapping']['org_id'])) {
|
|
|
|
$this->request->data['DecayingModelMapping']['org_id'] = $this->Auth->user()['org_id'];
|
|
|
|
}
|
|
|
|
if (empty($this->request->data['DecayingModelMapping']['attributetypes'])) {
|
|
|
|
throw new MethodNotAllowedException(_("The model must link to at least one attribute type"));
|
|
|
|
} else {
|
|
|
|
$decoded = json_decode($this->request->data['DecayingModelMapping']['attributetypes'], true);
|
|
|
|
if ($decoded === null) {
|
|
|
|
throw new MethodNotAllowedException(_("Invalid JSON: attribute type"));
|
|
|
|
}
|
|
|
|
$this->request->data['DecayingModelMapping']['attribute_types'] = $decoded;
|
|
|
|
unset($this->request->data['DecayingModelMapping']['attributetypes']);
|
|
|
|
}
|
|
|
|
|
2019-08-22 11:31:50 +02:00
|
|
|
$response = $this->DecayingModelMapping->resetMappingForModel($this->request->data['DecayingModelMapping'], $this->Auth->user());
|
2019-04-04 11:17:11 +02:00
|
|
|
return $this->RestResponse->viewData($response, $this->response->type());
|
|
|
|
} else {
|
|
|
|
$this->set('model_id', $model_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 11:51:29 +02:00
|
|
|
}
|