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
|
|
|
|
{
|
2021-11-09 09:11:35 +01:00
|
|
|
public $quickFilterFields = [['name' => true], 'uuid', ['scope' => true]];
|
2021-09-10 11:55:54 +02:00
|
|
|
public $filterFields = ['name', 'uuid', 'scope', 'namespace'];
|
|
|
|
public $containFields = ['MetaTemplateFields'];
|
2020-12-08 15:08:12 +01:00
|
|
|
|
2021-11-24 09:14:09 +01:00
|
|
|
public function update($template_id=false)
|
2020-09-28 01:25:07 +02:00
|
|
|
{
|
2021-11-24 09:14:09 +01:00
|
|
|
if (!empty($template_id)) {
|
|
|
|
$metaTemplate = $this->MetaTemplates->get($template_id);
|
|
|
|
}
|
2020-11-20 11:09:24 +01:00
|
|
|
if ($this->request->is('post')) {
|
2021-11-24 09:14:09 +01:00
|
|
|
$result = $this->MetaTemplates->update($template_id);
|
2020-11-20 11:09:24 +01:00
|
|
|
if ($this->ParamHandler->isRest()) {
|
|
|
|
return $this->RestResponse->viewData($result, 'json');
|
|
|
|
} else {
|
2021-11-24 09:14:09 +01:00
|
|
|
if ($result['success']) {
|
|
|
|
$message = __n('{0} templates updated.', 'The template has been updated.', empty($template_id), $result['updated']);
|
|
|
|
} else {
|
|
|
|
$message = __n('{0} templates could not be updated.', 'The template could not be updated.',empty($template_id), $result['updated']);
|
|
|
|
}
|
|
|
|
$this->CRUD->setResponseForController('update', $result['success'], $message, $metaTemplate, $metaTemplate->getErrors(), ['redirect' => $this->referer()]);
|
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
|
|
|
}
|
2020-11-20 11:09:24 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!$this->ParamHandler->isRest()) {
|
2021-11-24 09:14:09 +01:00
|
|
|
if (!empty($template_id)) {
|
|
|
|
$this->set('title', __('Update Meta Templates #{0}', h($template_id)));
|
|
|
|
$this->set('question', __('Are you sure you wish to update the Meta Template definitions of the template `{0}`?', h($metaTemplate->name)));
|
|
|
|
} else {
|
|
|
|
$this->set('title', __('Update Meta Templates'));
|
|
|
|
$this->set('question', __('Are you sure you wish to update the Meta Template definitions'));
|
|
|
|
}
|
2020-11-20 11:09:24 +01:00
|
|
|
$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([
|
2021-09-10 11:55:54 +02:00
|
|
|
'filters' => $this->filterFields,
|
|
|
|
'quickFilters' => $this->quickFilterFields,
|
2020-12-08 15:08:12 +01:00
|
|
|
'contextFilters' => [
|
|
|
|
'fields' => ['scope'],
|
|
|
|
'custom' => [
|
|
|
|
[
|
2021-11-09 09:11:35 +01:00
|
|
|
'label' => __('Default Templates'),
|
|
|
|
'filterCondition' => ['is_default' => true]
|
2020-12-08 15:08:12 +01:00
|
|
|
],
|
|
|
|
]
|
|
|
|
],
|
2021-09-10 11:55:54 +02:00
|
|
|
'contain' => $this->containFields
|
2020-09-28 01:25:07 +02:00
|
|
|
]);
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|
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']
|
|
|
|
]);
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|
|
|
|
$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 17:18:17 +01:00
|
|
|
if ($this->request->is('POST') && $fieldName == 'is_default') {
|
|
|
|
$template = $this->MetaTemplates->get($id);
|
|
|
|
$this->MetaTemplates->removeDefaultFlag($template->scope);
|
|
|
|
$this->CRUD->toggle($id, $fieldName, ['force_state' => !$template->is_default]);
|
|
|
|
} else {
|
|
|
|
$this->CRUD->toggle($id, $fieldName);
|
|
|
|
}
|
2021-06-29 16:15:05 +02:00
|
|
|
$responsePayload = $this->CRUD->getResponsePayload();
|
|
|
|
if (!empty($responsePayload)) {
|
|
|
|
return $responsePayload;
|
2020-11-20 11:09:24 +01:00
|
|
|
}
|
|
|
|
}
|
2020-09-28 01:25:07 +02:00
|
|
|
}
|