chg: [tags] Transformed feature into a pluging - WiP
parent
eed5b9226a
commit
a14dc2e8fe
|
@ -11,7 +11,6 @@
|
|||
"cakephp/cakephp": "^4.0",
|
||||
"cakephp/migrations": "^3.0",
|
||||
"cakephp/plugin-installer": "^1.2",
|
||||
"dereuromark/cakephp-tags": "^1.2",
|
||||
"erusev/parsedown": "^1.7",
|
||||
"mobiledetect/mobiledetectlib": "^2.8"
|
||||
},
|
||||
|
@ -30,12 +29,14 @@
|
|||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "src/"
|
||||
"App\\": "src/",
|
||||
"Tags\\": "plugins/Tags/src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"App\\Test\\": "tests/",
|
||||
"Tags\\Test\\": "plugins/Tags/tests/",
|
||||
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
use Cake\Routing\Route\DashedRoute;
|
||||
use Cake\Routing\RouteBuilder;
|
||||
|
||||
$routes->plugin(
|
||||
'Tags',
|
||||
['path' => '/tags'],
|
||||
function ($routes) {
|
||||
$routes->setRouteClass(DashedRoute::class);
|
||||
|
||||
$routes->connect(
|
||||
'/{action}/*',
|
||||
['controller' => 'Tags']
|
||||
);
|
||||
|
||||
// $routes->get('/', ['controller' => 'Tags']);
|
||||
// $routes->get('/{id}', ['controller' => 'Tags', 'action' => 'view']);
|
||||
// $routes->put('/{id}', ['controller' => 'Tags', 'action' => 'edit']);
|
||||
}
|
||||
);
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tags\Controller;
|
||||
|
||||
use App\Controller\AppController as BaseController;
|
||||
|
||||
class AppController extends BaseController
|
||||
{
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
// $this->loadComponent('RequestHandler');
|
||||
// $this->loadComponent('ParamHandler', [
|
||||
// 'request' => $this->request
|
||||
// ]);
|
||||
// $this->loadComponent('CRUD', [
|
||||
// 'request' => $this->request,
|
||||
// 'table' => $this->{$this->modelClass},
|
||||
// 'MetaFields' => $this->MetaFields,
|
||||
// 'MetaTemplates' => $this->MetaTemplates
|
||||
// ]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Tags\Controller;
|
||||
|
||||
use Tags\Controller\AppController;
|
||||
use Cake\Utility\Hash;
|
||||
use Cake\Utility\Inflector;
|
||||
use Cake\Utility\Text;
|
||||
use Cake\Database\Expression\QueryExpression;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
use Cake\Http\Exception\MethodNotAllowedException;
|
||||
use Cake\Http\Exception\ForbiddenException;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
class TagsController extends AppController
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->CRUD->index([
|
||||
'filters' => ['label', 'colour'],
|
||||
'quickFilters' => [['label' => true], 'colour']
|
||||
]);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->CRUD->add();
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$this->CRUD->view($id);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->CRUD->edit($id);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
$this->render('add');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->CRUD->delete($id);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
}
|
||||
|
||||
// public function tag($model, $id)
|
||||
// {
|
||||
// $controller = $this->getControllerBeingTagged($model);
|
||||
// $controller->CRUD->tag($id);
|
||||
// $responsePayload = $controller->CRUD->getResponsePayload();
|
||||
// if (!empty($responsePayload)) {
|
||||
// return $responsePayload;
|
||||
// }
|
||||
// return $controller->getResponse();
|
||||
// }
|
||||
|
||||
// public function untag($model, $id)
|
||||
// {
|
||||
// $controller = $this->getControllerBeingTagged($model);
|
||||
// $controller->CRUD->untag($id);
|
||||
// $responsePayload = $controller->CRUD->getResponsePayload();
|
||||
// if (!empty($responsePayload)) {
|
||||
// return $responsePayload;
|
||||
// }
|
||||
// return $controller->getResponse();
|
||||
// }
|
||||
|
||||
// public function viewTags($model, $id)
|
||||
// {
|
||||
// $controller = $this->getControllerBeingTagged($model);
|
||||
// $controller->CRUD->viewTags($id);
|
||||
// $responsePayload = $controller->CRUD->getResponsePayload();
|
||||
// if (!empty($responsePayload)) {
|
||||
// return $responsePayload;
|
||||
// }
|
||||
// return $controller->getResponse();
|
||||
// }
|
||||
|
||||
// private function getControllerBeingTagged($model)
|
||||
// {
|
||||
// $modelName = Inflector::camelize($model);
|
||||
// $controllerName = "\\App\\Controller\\{$modelName}Controller";
|
||||
// if (!class_exists($controllerName)) {
|
||||
// throw new MethodNotAllowedException(__('Model `{0}` does not exists', $model));
|
||||
// }
|
||||
// $controller = new $controllerName;
|
||||
// // Make sure that the request is correctly assigned to this controller
|
||||
// return $controller;
|
||||
// }
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model\Behavior;
|
||||
namespace Tags\Model\Behavior;
|
||||
|
||||
use Cake\ORM\Behavior;
|
||||
use Cake\ORM\Entity;
|
||||
|
@ -9,20 +9,18 @@ use Cake\ORM\Table;
|
|||
|
||||
class TagBehavior extends Behavior
|
||||
{
|
||||
|
||||
protected $_defaultConfig = [
|
||||
'finderField' => 'label',
|
||||
'tagsAssoc' => [
|
||||
'className' => 'Tags',
|
||||
// 'joinTable' => 'tagged', // uncomment me!
|
||||
'joinTable' => 'tags_tagged', // remove me!
|
||||
'className' => 'Tags.Tags',
|
||||
'joinTable' => 'tags_tagged',
|
||||
'foreignKey' => 'fk_id',
|
||||
'targetForeignKey' => 'tag_id',
|
||||
'propertyName' => 'tags',
|
||||
],
|
||||
'tagsCounter' => ['counter'],
|
||||
'taggedAssoc' => [
|
||||
'className' => 'Tagged',
|
||||
'className' => 'Tags.Tagged',
|
||||
'foreignKey' => 'fk_id'
|
||||
],
|
||||
'implementedEvents' => [
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model\Table;
|
||||
namespace Tags\Model\Table;
|
||||
|
||||
use App\Model\Table\AppTable;
|
||||
use Cake\Validation\Validator;
|
||||
|
@ -13,10 +13,9 @@ class TaggedTable extends AppTable
|
|||
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
// $this->setTable('tagged');
|
||||
$this->setTable('tags_tagged');
|
||||
$this->belongsTo('Tags', [
|
||||
'className' => 'Tags',
|
||||
'className' => 'Tags.Tags',
|
||||
'foreignKey' => 'tag_id',
|
||||
'propertyName' => 'tag',
|
||||
]);
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Model\Table;
|
||||
namespace Tags\Model\Table;
|
||||
|
||||
use App\Model\Table\AppTable;
|
||||
use Cake\Validation\Validator;
|
||||
|
@ -13,7 +13,6 @@ class TagsTable extends AppTable
|
|||
|
||||
public function initialize(array $config): void
|
||||
{
|
||||
// $this->setTable('tags');
|
||||
$this->setTable('tags_tags');
|
||||
$this->setDisplayField('label'); // Change to name?
|
||||
$this->addBehavior('Timestamp');
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Tags;
|
||||
|
||||
use Cake\Core\BasePlugin;
|
||||
use Cake\Core\PluginApplicationInterface;
|
||||
use Cake\Console\CommandCollection;
|
||||
use Cake\Http\MiddlewareQueue;
|
||||
|
||||
class Plugin extends BasePlugin
|
||||
{
|
||||
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue
|
||||
{
|
||||
// Add middleware here.
|
||||
$middleware = parent::middleware($middleware);
|
||||
|
||||
return $middleware;
|
||||
}
|
||||
|
||||
public function console(CommandCollection $commands): CommandCollection
|
||||
{
|
||||
// Add console commands here.
|
||||
$commands = parent::console($commands);
|
||||
|
||||
return $commands;
|
||||
}
|
||||
|
||||
public function bootstrap(PluginApplicationInterface $app): void
|
||||
{
|
||||
// Add constants, load configuration defaults.
|
||||
// By default will load `config/bootstrap.php` in the plugin.
|
||||
parent::bootstrap($app);
|
||||
}
|
||||
|
||||
public function routes($routes): void
|
||||
{
|
||||
// Add routes.
|
||||
// By default will load `config/routes.php` in the plugin.
|
||||
parent::routes($routes);
|
||||
}
|
||||
}
|
|
@ -29,6 +29,9 @@ use Authentication\AuthenticationServiceInterface;
|
|||
use Authentication\AuthenticationServiceProviderInterface;
|
||||
use Authentication\Middleware\AuthenticationMiddleware;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
use Tags\Plugin as TagsPlugin;
|
||||
|
||||
/**
|
||||
* Application setup class.
|
||||
*
|
||||
|
@ -59,7 +62,7 @@ class Application extends BaseApplication implements AuthenticationServiceProvid
|
|||
$this->addPlugin('DebugKit');
|
||||
}
|
||||
$this->addPlugin('Authentication');
|
||||
$this->addPlugin('Tags');
|
||||
$this->addPlugin('Tags', ['routes' => true]);
|
||||
// Load more plugins here
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,10 @@ class AppController extends Controller
|
|||
]);
|
||||
$this->loadModel('MetaFields');
|
||||
$this->loadModel('MetaTemplates');
|
||||
$table = $this->getTableLocator()->get($this->modelClass);
|
||||
$this->loadComponent('CRUD', [
|
||||
'request' => $this->request,
|
||||
'table' => $this->{$this->modelClass},
|
||||
'table' => $table,
|
||||
'MetaFields' => $this->MetaFields,
|
||||
'MetaTemplates' => $this->MetaTemplates
|
||||
]);
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller\AppController;
|
||||
use Cake\Utility\Hash;
|
||||
use Cake\Utility\Inflector;
|
||||
use Cake\Utility\Text;
|
||||
use Cake\Database\Expression\QueryExpression;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
use Cake\Http\Exception\MethodNotAllowedException;
|
||||
use Cake\Http\Exception\ForbiddenException;
|
||||
use Cake\ORM\TableRegistry;
|
||||
|
||||
class TagsController extends AppController
|
||||
{
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
parent::initialize();
|
||||
$this->Table = TableRegistry::getTableLocator()->get('Tags.Tags');
|
||||
$this->CRUD->Table = $this->Table;
|
||||
$this->CRUD->TableAlias = $this->CRUD->Table->getAlias();
|
||||
$this->CRUD->ObjectAlias = Inflector::singularize($this->CRUD->TableAlias);
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->CRUD->index([
|
||||
'filters' => ['label', 'colour'],
|
||||
'quickFilters' => [['label' => true], 'colour']
|
||||
]);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->CRUD->add();
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$this->CRUD->view($id);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->CRUD->edit($id);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||
$this->render('add');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->CRUD->delete($id);
|
||||
$responsePayload = $this->CRUD->getResponsePayload();
|
||||
if (!empty($responsePayload)) {
|
||||
return $responsePayload;
|
||||
}
|
||||
$this->set('metaGroup', $this->isAdmin ? 'Administration' : 'Cerebrate');
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ class IndividualsTable extends AppTable
|
|||
{
|
||||
parent::initialize($config);
|
||||
$this->addBehavior('UUID');
|
||||
$this->addBehavior('Tag');
|
||||
$this->addBehavior('Tags.Tag');
|
||||
$this->hasMany(
|
||||
'Alignments',
|
||||
[
|
||||
|
|
|
@ -18,7 +18,7 @@ class OrganisationsTable extends AppTable
|
|||
public function initialize(array $config): void
|
||||
{
|
||||
parent::initialize($config);
|
||||
$this->addBehavior('Tag');
|
||||
$this->addBehavior('Tags.Tag');
|
||||
$this->hasMany(
|
||||
'Alignments',
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue