2020-09-28 01:25:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Controller\AppController;
|
|
|
|
use Cake\Utility\Hash;
|
|
|
|
use Cake\Utility\Text;
|
|
|
|
use \Cake\Database\Expression\QueryExpression;
|
|
|
|
|
|
|
|
class MetaTemplatesController extends AppController
|
|
|
|
{
|
2020-12-08 15:08:12 +01:00
|
|
|
|
2020-09-28 01:25:07 +02:00
|
|
|
public function update()
|
|
|
|
{
|
2020-11-20 11:09:24 +01:00
|
|
|
if ($this->request->is('post')) {
|
|
|
|
$result = $this->MetaTemplates->update();
|
|
|
|
if ($this->ParamHandler->isRest()) {
|
|
|
|
return $this->RestResponse->viewData($result, 'json');
|
|
|
|
} else {
|
|
|
|
$this->Flash->success(__('{0} templates updated.', count($result)));
|
|
|
|
$this->redirect($this->referer());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!$this->ParamHandler->isRest()) {
|
|
|
|
$this->set('title', __('Update Meta Templates'));
|
|
|
|
$this->set('question', __('Are you sure you wish to update the Meta Template definitions?'));
|
|
|
|
$this->set('actionName', __('Update'));
|
|
|
|
$this->set('path', ['controller' => 'metaTemplates', 'action' => 'update']);
|
|
|
|
$this->render('/genericTemplates/confirm');
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->CRUD->index([
|
2020-12-08 15:08:12 +01:00
|
|
|
'filters' => ['name', 'uuid', 'scope', 'namespace'],
|
2020-09-28 01:25:07 +02:00
|
|
|
'quickFilters' => ['name', 'uuid', 'scope'],
|
2020-12-08 15:08:12 +01:00
|
|
|
'contextFilters' => [
|
|
|
|
'allow_all' => true,
|
|
|
|
'fields' => ['scope'],
|
|
|
|
'custom' => [
|
|
|
|
[
|
|
|
|
'label' => __('Contact DB'),
|
|
|
|
'filterCondition' => ['scope' => ['individual', 'organisation']]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => __('Namespace CNW'),
|
|
|
|
'filterCondition' => ['namespace' => 'cnw']
|
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
2020-09-28 01:25:07 +02:00
|
|
|
'contain' => ['MetaTemplateFields']
|
|
|
|
]);
|
|
|
|
if ($this->ParamHandler->isRest()) {
|
|
|
|
return $this->restResponsePayload;
|
|
|
|
}
|
2020-12-10 16:50:46 +01:00
|
|
|
$this->set('defaultTemplatePerScope', $this->MetaTemplates->getDefaultTemplatePerScope());
|
2020-09-28 01:25:07 +02:00
|
|
|
$this->set('alignmentScope', 'individuals');
|
|
|
|
$this->set('metaGroup', 'Administration');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function view($id)
|
|
|
|
{
|
|
|
|
$this->CRUD->view($id, [
|
|
|
|
'contain' => ['MetaTemplateFields']
|
|
|
|
]);
|
|
|
|
if ($this->ParamHandler->isRest()) {
|
|
|
|
return $this->restResponsePayload;
|
|
|
|
}
|
|
|
|
$this->set('metaGroup', 'Administration');
|
|
|
|
}
|
2020-11-20 11:09:24 +01:00
|
|
|
|
2020-12-10 15:18:02 +01:00
|
|
|
public function toggle($id, $fieldName = 'enabled')
|
2020-11-20 11:09:24 +01:00
|
|
|
{
|
2020-12-10 15:18:02 +01:00
|
|
|
$this->CRUD->toggle($id, $fieldName);
|
2020-11-20 11:09:24 +01:00
|
|
|
if ($this->ParamHandler->isRest()) {
|
2020-12-07 14:17:10 +01:00
|
|
|
return $this->restResponsePayload;
|
|
|
|
} else if($this->ParamHandler->isAjax() && $this->request->is(['post', 'put'])) {
|
|
|
|
return $this->ajaxResponsePayload;
|
2020-11-20 11:09:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-10 16:50:46 +01:00
|
|
|
|
|
|
|
public function getDefaultTemplatePerScope($scope = '')
|
|
|
|
{
|
|
|
|
$defaultTemplate = $this->MetaTemplates->getDefaultTemplatePerScope($scope);
|
|
|
|
return $this->RestResponse->viewData($defaultTemplate, 'json');
|
|
|
|
}
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|