chg: [requestProcessor] Moved templates files in libraries/default folder
parent
b52048c760
commit
80a07f9138
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
|
||||
class BroodRequestProcessor extends GenericRequestProcessor
|
||||
{
|
|
@ -3,6 +3,7 @@ use Cake\ORM\TableRegistry;
|
|||
use Cake\Filesystem\File;
|
||||
use Cake\Utility\Inflector;
|
||||
use Cake\Validation\Validator;
|
||||
use Cake\View\ViewBuilder;
|
||||
|
||||
interface GenericProcessorActionI
|
||||
{
|
||||
|
@ -17,7 +18,7 @@ class GenericRequestProcessor
|
|||
protected $registeredActions = [];
|
||||
protected $validator;
|
||||
private $processingTemplate = '/genericTemplates/confirm';
|
||||
private $processingTemplatesDirectory = ROOT . '/templates/RequestProcessors';
|
||||
private $processingTemplatesDirectory = ROOT . '/libraries/default/RequestProcessors/templates';
|
||||
|
||||
public function __construct($registerActions=false) {
|
||||
$this->Inbox = TableRegistry::getTableLocator()->get('Inbox');
|
||||
|
@ -27,7 +28,7 @@ class GenericRequestProcessor
|
|||
$processingTemplatePath = $this->getProcessingTemplatePath();
|
||||
$file = new File($this->processingTemplatesDirectory . DS . $processingTemplatePath);
|
||||
if ($file->exists()) {
|
||||
$this->processingTemplate = $processingTemplatePath;
|
||||
$this->processingTemplate = str_replace('.php', '', $processingTemplatePath);
|
||||
}
|
||||
$file->close();
|
||||
}
|
||||
|
@ -53,10 +54,19 @@ class GenericRequestProcessor
|
|||
|
||||
public function getProcessingTemplate()
|
||||
{
|
||||
if ($this->processingTemplate == '/genericTemplates/confirm') {
|
||||
return '/genericTemplates/confirm';
|
||||
}
|
||||
return DS . 'RequestProcessors' . DS . str_replace('.php', '', $this->processingTemplate);
|
||||
return $this->processingTemplate;
|
||||
}
|
||||
|
||||
public function render($request=[])
|
||||
{
|
||||
$processingTemplate = $this->getProcessingTemplate();
|
||||
$viewVariables = $this->getViewVariables($request);
|
||||
$builder = new ViewBuilder();
|
||||
$builder->disableAutoLayout()
|
||||
->setClassName('Monad')
|
||||
->setTemplate($processingTemplate);
|
||||
$view = $builder->build($viewVariables);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
protected function generateRequest($requestData)
|
||||
|
@ -96,18 +106,20 @@ class GenericRequestProcessor
|
|||
$this->{$action} = $reflection->newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
protected function setViewVariablesConfirmModal($controller, $id, $title='', $question='', $actionName='')
|
||||
|
||||
protected function getViewVariablesConfirmModal($id, $title='', $question='', $actionName='')
|
||||
{
|
||||
$controller->set('title', !empty($title) ? $title : __('Process request {0}', $id));
|
||||
$controller->set('question', !empty($question) ? $question : __('Confirm request {0}', $id));
|
||||
$controller->set('actionName', !empty($actionName) ? $actionName : __('Confirm'));
|
||||
$controller->set('path', ['controller' => 'inbox', 'action' => 'process', $id]);
|
||||
return [
|
||||
'title' => !empty($title) ? $title : __('Process request {0}', $id),
|
||||
'question' => !empty($question) ? $question : __('Confirm request {0}', $id),
|
||||
'actionName' => !empty($actionName) ? $actionName : __('Confirm'),
|
||||
'path' => ['controller' => 'inbox', 'action' => 'process', $id]
|
||||
];
|
||||
}
|
||||
|
||||
public function setViewVariables($controller, $request)
|
||||
public function getViewVariables($request)
|
||||
{
|
||||
$this->setViewVariablesConfirmModal($controller, $request->id);
|
||||
return $this->getViewVariablesConfirmModal($request->id, '', '', '');
|
||||
}
|
||||
|
||||
protected function genActionResult($data, $success, $message, $errors=[])
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
|
||||
class ProposalRequestProcessor extends GenericRequestProcessor
|
||||
{
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
|
||||
class SynchronisationRequestProcessor extends GenericRequestProcessor
|
||||
{
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
|
||||
class SCOPE_RequestProcessor extends GenericRequestProcessor
|
||||
{
|
||||
protected $scope = '~to-be-defined~';
|
||||
protected $action = 'not-specified'; //overriden when extending
|
||||
protected $description = ''; // overriden when extending
|
||||
protected $registeredActions = [
|
||||
'ACTION'
|
||||
];
|
||||
|
||||
public function __construct($loadFromAction=false) {
|
||||
parent::__construct($loadFromAction);
|
||||
}
|
||||
|
||||
public function create($requestData)
|
||||
{
|
||||
return parent::create($requestData);
|
||||
}
|
||||
}
|
||||
|
||||
class SCOPE_ACTION_Processor extends ProposalRequestProcessor implements GenericProcessorActionI {
|
||||
public $action = 'ACTION';
|
||||
protected $description;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->description = __('~to-be-defined~');
|
||||
$this->Users = TableRegistry::getTableLocator()->get('Users');
|
||||
}
|
||||
|
||||
protected function addValidatorRules($validator)
|
||||
{
|
||||
return $validator;
|
||||
}
|
||||
|
||||
public function create($requestData) {
|
||||
$this->validateRequestData($requestData);
|
||||
$requestData['title'] = __('~to-be-defined~');
|
||||
return parent::create($requestData);
|
||||
}
|
||||
|
||||
public function process($id, $requestData)
|
||||
{
|
||||
$proposalAccepted = false;
|
||||
$saveResult = [];
|
||||
if ($proposalAccepted) {
|
||||
$this->discard($id, $requestData);
|
||||
}
|
||||
return $this->genActionResult(
|
||||
$saveResult,
|
||||
$proposalAccepted,
|
||||
$proposalAccepted ? __('success') : __('fail'),
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
public function discard($id, $requestData)
|
||||
{
|
||||
return parent::discard($id, $requestData);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
|
||||
|
||||
class UserRequestProcessor extends GenericRequestProcessor
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ class UserRequestProcessor extends GenericRequestProcessor
|
|||
protected $registeredActions = [
|
||||
'Registration'
|
||||
];
|
||||
protected $Users;
|
||||
|
||||
public function __construct($loadFromAction=false) {
|
||||
parent::__construct($loadFromAction);
|
||||
|
@ -50,7 +51,7 @@ class RegistrationProcessor extends UserRequestProcessor implements GenericProce
|
|||
return parent::create($requestData);
|
||||
}
|
||||
|
||||
public function setViewVariables($controller, $request)
|
||||
public function getViewVariables($request)
|
||||
{
|
||||
$dropdownData = [
|
||||
'role' => $this->Users->Roles->find('list', [
|
||||
|
@ -72,9 +73,11 @@ class RegistrationProcessor extends UserRequestProcessor implements GenericProce
|
|||
'role_id' => !empty($request['data']['role_id']) ? $request['data']['role_id'] : '',
|
||||
'disabled' => !empty($request['data']['disabled']) ? $request['data']['disabled'] : '',
|
||||
]);
|
||||
$controller->set('individualEntity', $individualEntity);
|
||||
$controller->set('userEntity', $userEntity);
|
||||
$controller->set(compact('dropdownData'));
|
||||
return [
|
||||
'dropdownData' => $dropdownData,
|
||||
'userEntity' => $userEntity,
|
||||
'individualEntity' => $individualEntity
|
||||
];
|
||||
}
|
||||
|
||||
public function process($id, $requestData)
|
|
@ -87,7 +87,8 @@ class InboxController extends AppController
|
|||
$processResult = $processor->process($id, $this->request->getData());
|
||||
return $processor->genHTTPReply($this, $processResult);
|
||||
} else {
|
||||
$this->requestProcessor->render($this, $processor, $request);
|
||||
$renderedView = $processor->render($request);
|
||||
return $this->response->withStringBody($renderedView);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use Cake\Filesystem\Folder;
|
|||
|
||||
class RequestProcessorTable extends AppTable
|
||||
{
|
||||
private $processorsDirectory = ROOT . '/libraries/RequestProcessors';
|
||||
private $processorsDirectory = ROOT . '/libraries/default/RequestProcessors';
|
||||
private $requestProcessors;
|
||||
private $enabledProcessors = [ // to be defined in config
|
||||
'Brood' => [
|
||||
|
@ -45,15 +45,6 @@ class RequestProcessorTable extends AppTable
|
|||
throw new \Exception(__('Processor not found'), 1);
|
||||
}
|
||||
|
||||
public function render($controller, $processor, $request=[])
|
||||
{
|
||||
$controller->set('request', $request);
|
||||
$controller->viewBuilder()->setLayout('ajax');
|
||||
$processingTemplate = $processor->getProcessingTemplate();
|
||||
$processor->setViewVariables($controller, $request);
|
||||
$controller->render($processingTemplate);
|
||||
}
|
||||
|
||||
public function listProcessors($scope=null)
|
||||
{
|
||||
if (is_null($scope)) {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
||||
* @link https://cakephp.org CakePHP(tm) Project
|
||||
* @since 3.0.4
|
||||
* @license https://opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
namespace App\View;
|
||||
|
||||
/**
|
||||
* A view class that is used for AJAX responses.
|
||||
* Currently only switches the default layout and sets the response type -
|
||||
* which just maps to text/html by default.
|
||||
*/
|
||||
class MonadView extends AppView
|
||||
{
|
||||
private $additionalTemplatePaths = [
|
||||
ROOT . '/libraries/default/RequestProcessors/templates/',
|
||||
];
|
||||
|
||||
protected function _paths(?string $plugin = null, bool $cached = true): array
|
||||
{
|
||||
$paths = parent::_paths($plugin, $cached);
|
||||
$paths = array_merge($paths, $this->additionalTemplatePaths);
|
||||
return $paths;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue