use override table trait to allow for easily customzing table a controller uses
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s
Details
CI / Coding Standard & Static Analysis (push) Failing after 0s
Details
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s
Details
CI / Coding Standard & Static Analysis (push) Failing after 0s
Details
This commit is contained in:
parent
b868cc11fb
commit
8229722779
|
@ -8,6 +8,7 @@ use Cake\Log\Log;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use CakeProducts\Controller\AppController;
|
use CakeProducts\Controller\AppController;
|
||||||
|
use CakeProducts\Controller\Traits\OverrideTableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ExternalProductCatalogs Controller
|
* ExternalProductCatalogs Controller
|
||||||
|
@ -16,26 +17,16 @@ use CakeProducts\Controller\AppController;
|
||||||
*/
|
*/
|
||||||
class ExternalProductCatalogsController extends AppController
|
class ExternalProductCatalogsController extends AppController
|
||||||
{
|
{
|
||||||
/**
|
use OverrideTableTrait;
|
||||||
* @var Table|null
|
|
||||||
*/
|
|
||||||
protected ?Table $_table = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the table instance
|
* @return void
|
||||||
*
|
|
||||||
* @return Table
|
|
||||||
*/
|
*/
|
||||||
public function getTable()
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
if ($this->_table instanceof Table) {
|
parent::initialize(); // TODO: Change the autogenerated stub
|
||||||
return $this->_table;
|
$this->_defaultTable = 'CakeProducts.ExternalProductCatalogs';
|
||||||
}
|
$this->_tableConfigKey = 'CakeProducts.ExternalProductCatalogs.table';
|
||||||
$this->_table = TableRegistry::getTableLocator()->get(
|
|
||||||
Configure::read('CakeProducts.ExternalProductCatalogs.table', 'CakeProducts.ExternalProductCatalogs')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->_table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,8 +10,8 @@ use Cake\Log\Log;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use CakeProducts\Controller\AppController;
|
use CakeProducts\Controller\AppController;
|
||||||
|
use CakeProducts\Controller\Traits\OverrideTableTrait;
|
||||||
use CakeProducts\Model\Table\ProductCatalogsTable;
|
use CakeProducts\Model\Table\ProductCatalogsTable;
|
||||||
use CakeProducts\Service\CatalogManagerService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductCatalogs Controller
|
* ProductCatalogs Controller
|
||||||
|
@ -20,7 +20,17 @@ use CakeProducts\Service\CatalogManagerService;
|
||||||
*/
|
*/
|
||||||
class ProductCatalogsController extends AppController
|
class ProductCatalogsController extends AppController
|
||||||
{
|
{
|
||||||
protected ?Table $_table = null;
|
use OverrideTableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function initialize(): void
|
||||||
|
{
|
||||||
|
parent::initialize(); // TODO: Change the autogenerated stub
|
||||||
|
$this->_defaultTable = 'CakeProducts.ProductCatalogs';
|
||||||
|
$this->_tableConfigKey = 'CakeProducts.ProductCatalogs.table';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index method
|
* Index method
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Cake\Log\Log;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use Cake\Utility\Text;
|
use Cake\Utility\Text;
|
||||||
|
use CakeProducts\Controller\Traits\OverrideTableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductCategories Controller
|
* ProductCategories Controller
|
||||||
|
@ -16,27 +17,18 @@ use Cake\Utility\Text;
|
||||||
*/
|
*/
|
||||||
class ProductCategoriesController extends AppController
|
class ProductCategoriesController extends AppController
|
||||||
{
|
{
|
||||||
/**
|
use OverrideTableTrait;
|
||||||
* @var Table|null
|
|
||||||
*/
|
|
||||||
protected ?Table $_table = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the table instance
|
* @return void
|
||||||
*
|
|
||||||
* @return Table
|
|
||||||
*/
|
*/
|
||||||
public function getTable()
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
if ($this->_table instanceof Table) {
|
parent::initialize(); // TODO: Change the autogenerated stub
|
||||||
return $this->_table;
|
$this->_defaultTable = 'CakeProducts.ProductCategories';
|
||||||
}
|
$this->_tableConfigKey = 'CakeProducts.ProductCategories.table';
|
||||||
$this->_table = TableRegistry::getTableLocator()->get(
|
|
||||||
Configure::read('CakeProducts.ProductCategories.table', 'CakeProducts.ProductCategories')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->_table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Index method
|
* Index method
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Cake\Log\Log;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use CakeProducts\Controller\AppController;
|
use CakeProducts\Controller\AppController;
|
||||||
|
use CakeProducts\Controller\Traits\OverrideTableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductCategoryAttributeOptions Controller
|
* ProductCategoryAttributeOptions Controller
|
||||||
|
@ -16,26 +17,16 @@ use CakeProducts\Controller\AppController;
|
||||||
*/
|
*/
|
||||||
class ProductCategoryAttributeOptionsController extends AppController
|
class ProductCategoryAttributeOptionsController extends AppController
|
||||||
{
|
{
|
||||||
/**
|
use OverrideTableTrait;
|
||||||
* @var Table|null
|
|
||||||
*/
|
|
||||||
protected ?Table $_table = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the table instance
|
* @return void
|
||||||
*
|
|
||||||
* @return Table
|
|
||||||
*/
|
*/
|
||||||
public function getTable()
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
if ($this->_table instanceof Table) {
|
parent::initialize(); // TODO: Change the autogenerated stub
|
||||||
return $this->_table;
|
$this->_defaultTable = 'CakeProducts.ProductCategoryAttributeOptions';
|
||||||
}
|
$this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributeOptions.table';
|
||||||
$this->_table = TableRegistry::getTableLocator()->get(
|
|
||||||
Configure::read('CakeProducts.ProductCategoryAttributeOptions.table', 'CakeProducts.ProductCategoryAttributeOptions')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->_table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,9 +10,9 @@ use Cake\Log\Log;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use CakeProducts\Controller\AppController;
|
use CakeProducts\Controller\AppController;
|
||||||
|
use CakeProducts\Controller\Traits\OverrideTableTrait;
|
||||||
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
use CakeProducts\Model\Enum\ProductCategoryAttributeTypeId;
|
||||||
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
use CakeProducts\Model\Table\ProductCategoryAttributesTable;
|
||||||
use CakeProducts\Service\CatalogManagerService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProductCategoryAttributes Controller
|
* ProductCategoryAttributes Controller
|
||||||
|
@ -21,26 +21,16 @@ use CakeProducts\Service\CatalogManagerService;
|
||||||
*/
|
*/
|
||||||
class ProductCategoryAttributesController extends AppController
|
class ProductCategoryAttributesController extends AppController
|
||||||
{
|
{
|
||||||
/**
|
use OverrideTableTrait;
|
||||||
* @var Table|null
|
|
||||||
*/
|
|
||||||
protected ?Table $_table = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the table instance
|
* @return void
|
||||||
*
|
|
||||||
* @return Table
|
|
||||||
*/
|
*/
|
||||||
public function getTable()
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
if ($this->_table instanceof Table) {
|
parent::initialize(); // TODO: Change the autogenerated stub
|
||||||
return $this->_table;
|
$this->_defaultTable = 'CakeProducts.ProductCategoryAttributes';
|
||||||
}
|
$this->_tableConfigKey = 'CakeProducts.ProductCategoryAttributes.table';
|
||||||
$this->_table = TableRegistry::getTableLocator()->get(
|
|
||||||
Configure::read('CakeProducts.ProductCategoryAttributes.table', 'CakeProducts.ProductCategoryAttributes')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->_table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Cake\Log\Log;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
use Cake\ORM\TableRegistry;
|
use Cake\ORM\TableRegistry;
|
||||||
use CakeProducts\Controller\AppController;
|
use CakeProducts\Controller\AppController;
|
||||||
|
use CakeProducts\Controller\Traits\OverrideTableTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Products Controller
|
* Products Controller
|
||||||
|
@ -16,26 +17,16 @@ use CakeProducts\Controller\AppController;
|
||||||
*/
|
*/
|
||||||
class ProductsController extends AppController
|
class ProductsController extends AppController
|
||||||
{
|
{
|
||||||
/**
|
use OverrideTableTrait;
|
||||||
* @var Table|null
|
|
||||||
*/
|
|
||||||
protected ?Table $_table = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the table instance
|
* @return void
|
||||||
*
|
|
||||||
* @return Table
|
|
||||||
*/
|
*/
|
||||||
public function getTable()
|
public function initialize(): void
|
||||||
{
|
{
|
||||||
if ($this->_table instanceof Table) {
|
parent::initialize(); // TODO: Change the autogenerated stub
|
||||||
return $this->_table;
|
$this->_defaultTable = 'CakeProducts.Products';
|
||||||
}
|
$this->_tableConfigKey = 'CakeProducts.Products.table';
|
||||||
$this->_table = TableRegistry::getTableLocator()->get(
|
|
||||||
Configure::read('CakeProducts.Products.table', 'CakeProducts.Products')
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->_table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace CakeProducts\Controller\Traits;
|
||||||
|
|
||||||
|
use Cake\Core\Configure;
|
||||||
|
use Cake\ORM\Table;
|
||||||
|
use Cake\ORM\TableRegistry;
|
||||||
|
|
||||||
|
trait OverrideTableTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Table|null
|
||||||
|
*/
|
||||||
|
protected ?Table $_table = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected string $_defaultTable = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected string $_tableConfigKey = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the table instance
|
||||||
|
*
|
||||||
|
* @return Table
|
||||||
|
*/
|
||||||
|
public function getTable(string $tableName = null)
|
||||||
|
{
|
||||||
|
if ($this->_table instanceof Table) {
|
||||||
|
return $this->_table;
|
||||||
|
}
|
||||||
|
$table = $tableName;
|
||||||
|
if (!isset($table)) {
|
||||||
|
$table = $this->_tableConfigKey && Configure::read($this->_tableConfigKey) ? Configure::read($this->_tableConfigKey) : $this->_defaultTable;
|
||||||
|
}
|
||||||
|
$this->_table = TableRegistry::getTableLocator()->get($table);
|
||||||
|
|
||||||
|
return $this->_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the users table
|
||||||
|
*
|
||||||
|
* @param Table $table table
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTable(Table $table)
|
||||||
|
{
|
||||||
|
$this->_table = $table;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue