CORE POS - Fannie
The CORE POS back end
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
BasicModel Class Reference
Inheritance diagram for BasicModel:
AccountClassesModel ArEomSummaryModel ArHistoryModel ArHistorySumModel AttendeesModel AutoCouponsModel BatchBarcodesModel BatchCutPasteModel BatchesModel BatchListModel BatchMergeTableModel BatchTypeModel CalendarsModel CalendarSubscriptionsModel CapturedSignatureModel CashPerformDayModel CCredConfigModel CCredHistoryBackupModel CCredHistoryModel CCredHistorySumModel CCredMembershipsModel CCredProgramsModel CoreWarehouseModel CronBackupModel CustAvailablePrefsModel CustdataModel CustomerAccountSuspensionsModel CustomReceiptModel CustomReportsModel CustPreferencesModel CustReceiptMessageModel DailyChecksModel DailyCountsModel DailyDepositModel DailyNotesModel DateRestrictModel DeliInventoryCatModel DepartmentsModel DisableCouponModel DTransactionsModel EfsnetRequestModel EfsnetRequestModModel EfsnetResponseModel EfsnetTokensModel EmailUsageLogModel EmployeesModel EquityHistorySumModel GumDividendPayoffMapModel GumDividendsModel GumEmailLogModel GumEquityPayoffMapModel GumEquitySharesModel GumLoanAccountsModel GumLoanDefaultInterestRatesModel GumLoanLedgerModel GumLoanPayoffMapModel GumLoanValidTermsModel GumPayoffsModel GumSettingsModel GumTaxIdentifiersModel HouseCouponItemsModel HouseCouponsModel HouseVirtualCouponsModel InternalSKUsModel LikeCodesModel MemberCardsModel MemberNotesModel MemContactModel MemContactPrefsModel MemDatesModel MeminfoModel MemtypeModel MonthviewEventsModel ObfCategoriesModel ObfCategorySuperDeptMapModel ObfLaborModel ObfQuartersModel ObfSalesCacheModel ObfWeeksModel OriginCountryModel OriginCustomRegionModel OriginsModel OriginStateProvModel OverShortsLogModel ParametersModel PatronageModel PaycardTransactionsModel PayPeriodsModel PendingSpecialOrderModel PermissionsModel ProdDepartmentHistoryModel ProdExtraModel ProdFlagsModel ProdPhysicalLocationModel ProdPriceHistoryModel ProductExpiresModel ProductOriginsMapModel ProductsModel ProductSummaryLastQuarterModel ProductUserModel ProductWeeklyLastQuarterModel ProdUpdateModel PurchaseOrderItemsModel PurchaseOrderModel PurchaseOrderSummaryModel ReasoncodesModel ReportDataCacheModel ReportModel SaInventoryModel ScaleItemsModel ServiceScaleItemMapModel ServiceScalesModel ShelftagsModel ShiftsModel ShrinkReasonsModel SpecialDeptMapModel SpecialOrderDeptMapModel SpecialOrderHistoryModel SpecialOrdersModel StaffArAccountsModel StaffArDatesModel StockpurchasesModel StoresModel SubDeptsModel SuperDeptEmailsModel SuperDeptNamesModel SuperDeptsModel SuspensionHistoryModel SuspensionsModel TaxRatesModel TendersModel TimesheetModel UpcLikeModel UsageStatsModel VendorBreakdownsModel VendorContactModel VendorDeliveriesModel VendorDepartmentsModel VendorItemsModel VendorSKUtoPLUModel VendorsModel VendorSRPsModel ViewModel VoidTransHistoryModel WeeksLastQuarterModel WfcHtCuspingModel WfcHtDepartmentsModel WfcHtEmployeesModel WfcHtEmpWeeklyNotesModel WfcHtEvalCommentsModel WfcHtEvalInfoModel WfcHtEvalScoresModel WfcHtEvalTypesModel WfcHtFirstPayPeriodModel WfcHtFullTimeStatusModel WfcHtHoursAllTimeModel WfcHtHoursYearlyModel WfcHtHoursYTDModel WfcHtImportedHoursDataModel WfcHtOldPTOModel WfcHtPayPeriodsModel WfcHtPTOLevelsModel WfcHtPTOModel WfcHtSalaryHoursModel WfcHtSalaryPTOYTDModel WfcHtStartYearMonthModel WfcHtUTOModel WfcHtWeeklyHoursModel WfcHtZipCodesModel

Public Member Functions

 db ()
 
 preferredDB ()
 
 setConfig ($c)
 
 __construct ($con)
 
 whichDB ($db_name)
 
 getDefinition ()
 
 create ()
 
 createIfNeeded ($db_name)
 
 load ()
 
 reset ()
 
 getColumns ()
 
 getName ()
 
 getFullQualifiedName ()
 
 find ($sort='', $reverse=false)
 
 delete ()
 
 save ()
 
 pushToLanes ()
 
 deleteFromLanes ()
 
 normalize ($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK, $doCreate=False)
 
 doc ()
 
 generate ($filename)
 
 newModel ($name, $as_view=false)
 
 getModels ()
 
 toJSON ()
 

Public Attributes

const NORMALIZE_MODE_CHECK = 1
 
const NORMALIZE_MODE_APPLY = 2
 

Protected Member Functions

 getMeta ($type, $dbms)
 
 validateOp ($operator)
 
 insertRecord ()
 
 updateRecord ()
 
 normalizeLanes ($db_name, $mode=BasicModel::NORMALIZE_MODE_CHECK, $doCreate=False)
 
 loadHooks ()
 

Protected Attributes

 $name
 
 $fq_name
 
 $columns = array()
 
 $unique = array()
 
 $meta_types
 
 $connection = false
 
 $record_changed = false
 
 $instance = array()
 
 $filters = array()
 
 $normalize_lanes = false
 
 $currently_normalizing_lane = false
 
 $cached_definition = false
 
 $config
 
 $preferred_db = ''
 
 $hooks = array()
 

Constructor & Destructor Documentation

BasicModel::__construct (   $con)

Constructor

Parameters
$cona SQLManager object

Member Function Documentation

BasicModel::create ( )

Create the table

Returns
boolean

Clear out any cached definition

BasicModel::createIfNeeded (   $db_name)

Create structure only if it does not exist

Parameters
$db_name[string] database name
Returns
[keyed array] db => database name struct => table/view name error => [int] error code error_msg => error details
BasicModel::delete ( )

Delete record from the database. Requires a uniqueness constraint. Assign those columns before calling delete().

Returns
boolean
BasicModel::doc ( )

Return information about the table/view this model deals with

BasicModel::find (   $sort = '',
  $reverse = false 
)

Find records that match this instance

Parameters
$sortarray of columns to sort by
Returns
an array of controller objects
BasicModel::generate (   $filename)

Rewrite the given file to create accessor functions for all of its columns

BasicModel::getMeta (   $type,
  $dbms 
)
protected

Get database-specific type

Parameters
$typea "meta-type" with different underlying type depending on the DB
$dbmsstring DB name
Returns
string
BasicModel::getModels ( )

Experiment using lambdas. I was curious if I could do recursion without having a named function.

BasicModel::insertRecord ( )
protected

Helper. Build & execute insert query

Returns
SQL result object or boolean false

if the insert succeeded and the table contains an incrementing id column, that value will most likely be more useful than the result object

BasicModel::load ( )

Populate instance with database values Requires a uniqueness constraint. Assign those columns before calling load().

Returns
boolean
BasicModel::loadHooks ( )
protected

Search available classes to load applicable hook objects into this instance

BasicModel::normalize (   $db_name,
  $mode = BasicModel::NORMALIZE_MODE_CHECK,
  $doCreate = False 
)

Compare existing table to definition Add any columns that are missing from the table structure Extra columns that are present in the table but not in the controlelr class are left as-is.

Parameters
$db_namename of the database containing the table
$modethe normalization mode. See above.
Returns
number of columns added or False on failure

FannieDB only manages server connections. If normalize is called in lane mode, the calling function is responsible for initializing the connection.

BasicModel::reset ( )

Clear object values.

BasicModel::save ( )

Save current record. If a uniqueness constraint is defined it will INSERT or UPDATE appropriately.

Returns
[boolean] false on failure [SQL result] object or [int] ID on success

The only time save() will not return a result object on success is on an insert into a table containing an incrementing ID column. In most cases this is more useful. Databases typically start counting from 1 rather than 0 so it should still work to write: if ($model->save()) But it would be slightly safer to write: if ($model->save() !== false)

BasicModel::updateRecord ( )
protected

Helper. Build & execute update query

Returns
SQL result object or boolean false
BasicModel::validateOp (   $operator)
protected

Validate SQL binary operator

Parameters
$operator[string] operator
Returns
[string] valid operator or [boolean] false
BasicModel::whichDB (   $db_name)

Manually set which database contains this table. Normally this is autodetected by the constructor.

Parameters
$db_name[string] database name
Returns
[boolean] success/failure
doesn't work

$this->fq_name = $this->connection->identifier_escape($db_name) . $this->connection->sep() . $this->connection->identifier_escape($this->name);

Member Data Documentation

BasicModel::$cached_definition = false
protected

Cache table definition internally so that repeated calls to find(), save(), etc don't involve multiple extra queries checking table existence and structure every single time

BasicModel::$columns = array()
protected

Definition of columns. Keyed by column name. Values should be arrays with keys for:

  • type (required)
  • default (null if omitted)
  • primary_key (optional, boolean)
  • index (optional, boolean)
  • not_null (optional, boolean)
  • increment (optional, boolean)
  • ignore_updates (optional, boolean)
  • replaces (optional, string previous column name)
BasicModel::$config
protected

Configuration object

BasicModel::$connection = false
protected

Database connection

BasicModel::$currently_normalizing_lane = false
protected

Status variable. Besides normalize() itself some hook functions may need to know if the current update is on the server vs on the lane.

BasicModel::$filters = array()
protected

List of WHERE clauses

BasicModel::$fq_name
protected

Fully qualified table name Typically database.table Provided only if it can be detected If found, this name is more reliable since the connection is shared and outside code may change its state including the currently selected database.

If the database cannot be detected, $fq_name and $name will be identical.

BasicModel::$hooks = array()
protected

Array of hook objects associated with this table

BasicModel::$instance = array()
protected

List of column names => values

BasicModel::$meta_types
protected
Initial value:
= array(
'MONEY' => array('default'=>'DECIMAL(10,2)','mssql'=>'MONEY'),
'BIGINT UNSIGNED' => array('default'=>'BIGINT UNSIGNED', 'mssql'=>'BIGINT'),
)

Type transalations for different DB backends.

BasicModel::$name
protected

Name of the table

BasicModel::$normalize_lanes = false
protected

When updating server-side tables, apply the same updates to lane-side tables. Default is false.

BasicModel::$preferred_db = ''
protected

Name of preferred database

BasicModel::$record_changed = false
protected

boolean flag indicating at least one column record has been updated and the instances currently differs from the underlying database. Columns flagged as ignore_upates will not be considered a record change when their value is altered.

BasicModel::$unique = array()
protected

List of columns that should be unique per record. Only necessary if the table has no primary key.

const BasicModel::NORMALIZE_MODE_APPLY = 2

apply changes

const BasicModel::NORMALIZE_MODE_CHECK = 1

check for potential changes


The documentation for this class was generated from the following file: