refactor: Add getters for protected model properties

- Create BaseModel with getters for $table, $primaryKey, $allowedFields
- All models now extend BaseModel instead of CodeIgniter\Model
- Add type declarations to protected properties

Closes #4489
This commit is contained in:
Ollama
2026-04-15 12:40:24 +00:00
parent 905b58ca6e
commit e17e85bc4c
29 changed files with 194 additions and 304 deletions

View File

@@ -3,22 +3,16 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use ReflectionException;
/**
* Appconfig class
*
*
*/
class Appconfig extends Model
class Appconfig extends BaseModel
{
protected $table = 'app_config';
protected $primaryKey = 'key';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'app_config';
protected string $primaryKey = 'key';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'key',
'value'
];

View File

@@ -5,7 +5,6 @@ namespace App\Models;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Database\Query;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use CodeIgniter\Database\RawSql;
use Config\OSPOS;
use DateTime;
@@ -13,16 +12,13 @@ use InvalidArgumentException;
use stdClass;
use ReflectionClass;
/**
* Attribute class
*/
class Attribute extends Model
class Attribute extends BaseModel
{
protected $table = 'attribute_definitions';
protected $primaryKey = 'definition_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [ // TODO: This model may not be well designed... The model accesses three different tables (attribute_definitions, attribute_links, attribute_values). Should that be more than one model? According to CodeIgniter, these are meant to model a single table https://codeigniter.com/user_guide/models/model.html#models
protected string $table = 'attribute_definitions';
protected string $primaryKey = 'definition_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'definition_name',
'definition_type',
'definition_unit',

33
app/Models/BaseModel.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
abstract class BaseModel extends Model
{
public function getTableName(): string
{
return $this->table;
}
public function getPrimaryKeyName(): string
{
return $this->primaryKey;
}
public function getAllowedFields(): array
{
return $this->allowedFields;
}
public function getUseAutoIncrement(): bool
{
return $this->useAutoIncrement;
}
public function getUseSoftDeletes(): bool
{
return $this->useSoftDeletes;
}
}

View File

@@ -3,21 +3,16 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use stdClass;
/**
* Cashup class
* Cashups are used to report actual cash on hand, expenses and transactions at the end of a period.
*/
class Cashup extends Model
class Cashup extends BaseModel
{
protected $table = 'cash_up';
protected $primaryKey = 'cashup_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'cash_up';
protected string $primaryKey = 'cashup_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'open_date',
'close_date',
'open_cash_amount',

View File

@@ -6,16 +6,13 @@ use CodeIgniter\Database\ResultInterface;
use Config\OSPOS;
use stdClass;
/**
* Customer class
*/
class Customer extends Person
{
protected $table = 'customers';
protected $primaryKey = 'person_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'customers';
protected string $primaryKey = 'person_id';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'account_number',
'taxable',
'tax_id',

View File

@@ -3,18 +3,14 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
/**
* Customer_rewards class
*/
class Customer_rewards extends Model
class Customer_rewards extends BaseModel
{
protected $table = 'customer_packages';
protected $primaryKey = 'package_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'customer_packages';
protected string $primaryKey = 'package_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'package_name',
'points_percent',
'deleted'

View File

@@ -3,18 +3,14 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
/**
* Dinner_table class
*/
class Dinner_table extends Model
class Dinner_table extends BaseModel
{
protected $table = 'dinner_tables';
protected $primaryKey = 'dinner_table_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'dinner_tables';
protected string $primaryKey = 'dinner_table_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'name',
'status',
'deleted'

View File

@@ -6,20 +6,14 @@ use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Session\Session;
use stdClass;
/**
* Employee class
*
* @property session session
*
*/
class Employee extends Person
{
public Session $session;
protected $table = 'Employees';
protected $primaryKey = 'person_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'Employees';
protected string $primaryKey = 'person_id';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'username',
'password',
'deleted',

View File

@@ -3,20 +3,16 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use stdClass;
/**
* Expense class
*/
class Expense extends Model
class Expense extends BaseModel
{
protected $table = 'expenses';
protected $primaryKey = 'expense_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'expenses';
protected string $primaryKey = 'expense_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'date',
'amount',
'payment_type',

View File

@@ -3,19 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use stdClass;
/**
* Expense_category class
*/
class Expense_category extends Model
class Expense_category extends BaseModel
{
protected $table = 'expense_categories';
protected $primaryKey = 'expense_category_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'expense_categories';
protected string $primaryKey = 'expense_category_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'category_name',
'category_description',
'deleted'

View File

@@ -3,19 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use stdClass;
/**
* Giftcard class
*/
class Giftcard extends Model
class Giftcard extends BaseModel
{
protected $table = 'giftcards';
protected $primaryKey = 'giftcard_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'giftcards';
protected string $primaryKey = 'giftcard_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'giftcard_number',
'value',
'deleted',

View File

@@ -3,21 +3,14 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
/**
* Inventory class
*
* @property employee employee
*
*/
class Inventory extends Model
class Inventory extends BaseModel
{
protected $table = 'inventory';
protected $primaryKey = 'trans_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'inventory';
protected string $primaryKey = 'trans_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'trans_items',
'trans_user',
'trans_date',

View File

@@ -3,18 +3,11 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use ReflectionException;
use stdClass;
/**
* Item class
*
* @property inventory inventory
* @property item_quantity item_quantity
*/
class Item extends Model
class Item extends BaseModel
{
public const ALLOWED_SUGGESTIONS_COLUMNS = ['name', 'item_number', 'description', 'cost_price', 'unit_price'];
@@ -31,11 +24,11 @@ class Item extends Model
'allow_alt_description',
'is_serialized'
];
protected $table = 'items';
protected $primaryKey = 'item_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'items';
protected string $primaryKey = 'item_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'name',
'category',
'supplier_id',

View File

@@ -3,20 +3,16 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use stdClass;
/**
* Item_kit class
*/
class Item_kit extends Model
class Item_kit extends BaseModel
{
protected $table = 'item_kits';
protected $primaryKey = 'item_kit_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'item_kits';
protected string $primaryKey = 'item_kit_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'item_kit_number',
'name',
'description',

View File

@@ -2,18 +2,13 @@
namespace App\Models;
use CodeIgniter\Model;
/**
* Item_kit_items class
*/
class Item_kit_items extends Model
class Item_kit_items extends BaseModel
{
protected $table = 'item_kit_items';
protected $primaryKey = 'item_kit_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'item_kit_items';
protected string $primaryKey = 'item_kit_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'kit_sequence'
];

View File

@@ -2,19 +2,15 @@
namespace App\Models;
use CodeIgniter\Model;
use stdClass;
/**
* Item_quantity class
*/
class Item_quantity extends Model
class Item_quantity extends BaseModel
{
protected $table = 'item_quantities';
protected $primaryKey = 'item_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'item_quantities';
protected string $primaryKey = 'item_id';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'quantity'
];

View File

@@ -2,18 +2,13 @@
namespace App\Models;
use CodeIgniter\Model;
/**
* Item_taxes class
*/
class Item_taxes extends Model
class Item_taxes extends BaseModel
{
protected $table = 'item_taxes';
protected $primaryKey = 'item_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'item_taxes';
protected string $primaryKey = 'item_id';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'name',
'percent'
];

View File

@@ -3,18 +3,14 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
/**
* Module class
*/
class Module extends Model
class Module extends BaseModel
{
protected $table = 'modules';
protected $primaryKey = 'module_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'modules';
protected string $primaryKey = 'module_id';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'name_lang_key',
'desc_lang_key',
'sort'

View File

@@ -3,19 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use stdClass;
/**
* Base class for People classes
*/
class Person extends Model
class Person extends BaseModel
{
protected $table = 'people';
protected $primaryKey = 'person_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'people';
protected string $primaryKey = 'person_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'first_name',
'last_name',
'phone_number',

View File

@@ -3,20 +3,16 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use ReflectionException;
/**
* Receiving class
*/
class Receiving extends Model
class Receiving extends BaseModel
{
protected $table = 'receivings';
protected $primaryKey = 'receiving_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'receivings';
protected string $primaryKey = 'receiving_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'receiving_time',
'supplier_id',
'employee_id',

View File

@@ -3,33 +3,18 @@
namespace App\Models\Reports;
use CodeIgniter\HTTP\Response;
use CodeIgniter\Model;
use App\Models\BaseModel;
/**
*
*
* @property response response
*
*/
abstract class Report extends Model
abstract class Report extends BaseModel
{
public function __construct()
{
parent::__construct();
}
/**
* Returns the column names used for the report
*/
public abstract function getDataColumns(): array;
/**
* Returns all the data to be populated into the report
*/
public abstract function getData(array $inputs): array;
/**
* Returns key=>value pairing of summary data for the report
*/
public abstract function getSummaryData(array $inputs): array;
}

View File

@@ -2,19 +2,13 @@
namespace App\Models;
use CodeIgniter\Model;
/**
* Rewards class
*/
class Rewards extends Model // TODO: This class is named with plural while the general practice is to name models singular
class Rewards extends BaseModel
{
protected $table = 'sales_reward_points';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'sales_reward_points';
protected string $primaryKey = 'id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'sale_id',
'earned',
'used'

View File

@@ -4,21 +4,17 @@ namespace App\Models;
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use App\Libraries\Sale_lib;
use Config\OSPOS;
use ReflectionException;
/**
* Sale class
*/
class Sale extends Model
class Sale extends BaseModel
{
protected $table = 'sales';
protected $primaryKey = 'sale_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'sales';
protected string $primaryKey = 'sale_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'sale_time',
'customer_id',
'employee_id',

View File

@@ -3,24 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use CodeIgniter\Session\Session;
/**
* Stock_location class
*
* @property employee employee
* @property item item
* @property session session
*
*/
class Stock_location extends Model
class Stock_location extends BaseModel
{
protected $table = 'stock_locations';
protected $primaryKey = 'location_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'stock_locations';
protected string $primaryKey = 'location_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'location_name',
'deleted'
];

View File

@@ -4,16 +4,13 @@ namespace App\Models;
use CodeIgniter\Database\ResultInterface;
/**
* Supplier class
*/
class Supplier extends Person
{
protected $table = 'suppliers';
protected $primaryKey = 'person_id';
protected $useAutoIncrement = false;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'suppliers';
protected string $primaryKey = 'person_id';
protected bool $useAutoIncrement = false;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'company_name',
'account_number',
'tax_id',

View File

@@ -3,19 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use stdClass;
/**
* Tax class
*/
class Tax extends Model
class Tax extends BaseModel
{
protected $table = 'tax_rates';
protected $primaryKey = 'tax_rate_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'tax_rates';
protected string $primaryKey = 'tax_rate_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'rate_tax_code_id',
'rate_tax_category_id',
'rate_jurisdiction_id',

View File

@@ -3,20 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use stdClass;
/**
* Tax Category class
*/
class Tax_category extends Model
class Tax_category extends BaseModel
{
protected $table = 'tax_categories';
protected $primaryKey = 'tax_category_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'tax_categories';
protected string $primaryKey = 'tax_category_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'tax_category',
'tax_group_sequence',
'deleted'

View File

@@ -3,20 +3,16 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use Config\OSPOS;
use stdClass;
/**
* Tax Code class
*/
class Tax_code extends Model
class Tax_code extends BaseModel
{
protected $table = 'tax_codes';
protected $primaryKey = 'tax_code_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'tax_codes';
protected string $primaryKey = 'tax_code_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'tax_code',
'tax_code_name',
'city',

View File

@@ -3,20 +3,15 @@
namespace App\Models;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use stdClass;
/**
* Tax Jurisdiction class
*/
class Tax_jurisdiction extends Model
class Tax_jurisdiction extends BaseModel
{
protected $table = 'tax_jurisdictions';
protected $primaryKey = 'cashup_id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $allowedFields = [
protected string $table = 'tax_jurisdictions';
protected string $primaryKey = 'cashup_id';
protected bool $useAutoIncrement = true;
protected bool $useSoftDeletes = false;
protected array $allowedFields = [
'jurisdiction_name',
'tax_group',
'tax_type',