Overview

Packages

  • akismet
  • None
  • PHP
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • plugins
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Signatures
    • Signed
    • Transport
  • wa-apps
    • blog
      • actions
        • backend
        • blog
        • comment
        • cron
        • design
        • frontend
        • page
        • plugin
        • post
      • api
        • v1
      • cli
      • layout
      • model
      • plugin
        • aksimet
        • category
        • emailsubscription
        • favorite
        • gravatar
        • import
        • markdown
        • myposts
        • tag
        • troll
      • settings
    • checklists
      • backend
      • json
    • contacts
      • backend
    • developer
    • dummy
    • guestbook
    • guestbook2
    • photos
      • album
      • api
        • v1
      • backend
      • design
      • dialog
      • frontend
      • page
      • photo
      • plugin
        • comment
        • imageeffects
        • import
        • publicgallery
        • watermark
      • search
      • settings
      • stack
      • tag
      • upload
    • site
      • backend
      • blocks
      • config
      • design
      • domains
      • files
      • frontend
      • helper
      • layout
      • pages
      • routing
      • setting
    • stickies
      • api
        • v1
      • sheet
      • stiky
  • wa-plugin
    • payment
    • shipping
    • sms
  • wa-plugins
    • shipping
      • usps
  • wa-system
    • API
    • Auth
      • Adapters
    • Autoload
    • Cache
      • Adapter
    • Captcha
    • Config
    • Contact
    • controller
    • currency
    • database
    • datetime
    • design
    • event
    • exception
    • files
    • image
    • layout
    • locale
    • log
    • mail
    • page
      • action
      • model
    • payment
    • plugin
    • request
    • response
    • routing
    • shipping
    • sms
    • storage
    • user
    • util
    • validator
    • view
    • webasyst
      • api
      • backend
      • cli
      • config
      • layout
      • login
      • model
      • password
      • payment
      • profile
      • settings
      • shipment
    • widget
    • workflow
  • waPlugins
    • Payment
  • webasyst
    • wa-system
      • helper

Classes

  • waDbAdapter
  • waDbCacheIterator
  • waDbConnector
  • waDbIbaseAdapter
  • waDbMySQLAdapter
  • waDbMysqliAdapter
  • waDbPostgresAdapter
  • waDbQuery
  • waDbQueryAnalyzer
  • waDbRecord
  • waDbResult
  • waDbResultDelete
  • waDbResultIbaseIterator
  • waDbResultInsert
  • waDbResultIterator
  • waDbResultReplace
  • waDbResultSelect
  • waDbResultUpdate
  • waDbSqlite3Adapter
  • waDbStatement
  • waModel
  • waNestedSetModel

Exceptions

  • waDbException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

Class waDbRecord

Instances of this class represent database records. Can be subclassed for complicated cases, e.g. with attached files.

// representation of an existing row by id $r = new waDbRecord(new appSomeModel(), $id);

// read info from database // (read is lazy: no queries is performed at constructor time) echo $r->field;

// update existing database row $r->field = 'new value'; $r->save();

// create new database row $r = new waDbRecord(new appSomeModel()); $r->field = 'value'; $new_id = $r->save();

You may use array access instead of field access: $r->field is the same as $r['field']

waArrayObject implements ArrayAccess, IteratorAggregate, Countable
Extended by waArrayObjectDiff
Extended by waDbRecord
Package: wa-system\database
Located at wa-system/database/waDbRecord.class.php
Methods summary
public
# __construct( waModel $m, mixed $id = null )

Parameters

$m
waModel
$m model to use for saving
$id
mixed
$id id of existing record, as accepted by model; omit to create new record.

Overrides

waArrayObjectDiff::__construct()
public string|integer|null
# getId( )

Id of current record as was passed to constructor.

Id of current record as was passed to constructor.

Note that when ->exists() finds out that record does not exist in DB, it sets internal id to null and never tries to access DB again. $this['id'] and $this->id are still accessable though and allow to create record with any id.

Returns

string|integer|null
id of the record
public mixed
# save( )

Save this record to database: insert or update depending on whether record exists in DB. Silently ignores all keys that have no corresponding fields in database table.

Save this record to database: insert or update depending on whether record exists in DB. Silently ignores all keys that have no corresponding fields in database table.

Returns

mixed
this record id

Throws

waException
when values fail validation
public mixed
# load( mixed $field_or_db_row = null )

Load data if not loaded yet.

Load data if not loaded yet.

Called lazily when array or field access is used.

When $field_or_db_row is an array then it is used as data source and no database queries are made. Array structure is the same as returned by $this->toArray().

When $field_or_db_row is a field name (string) then this function ensures that this field is loaded (when possible). It's not guaranteed to load the rest of the fields. This gets called lazily when field/array access interface is used.

When $field_or_db_row is empty, all available data is fetched from database using id given to a constructor.

Parameters

$field_or_db_row
mixed
$field_or_db_row

Returns

mixed
$this

Throws

waException
public
# delete( )

Delete this record from database. $this is not guaranteed to be accessable via array or field access after deletion.

Delete this record from database. $this is not guaranteed to be accessable via array or field access after deletion.

public boolean
# exists( )

Returns

boolean
whether this record has corresponding row in database
protected array
# getDefaultValues( )

Generates default values for new record.

Generates default values for new record.

To be overriden in subclasses. Default implementation returns array(field => '') for each field from model.

Returns

array
same structure as $this->toArray() returns
protected
# getLoadableKeys( )

List of keys that are guaranteed by $this->load() to set.

List of keys that are guaranteed by $this->load() to set.

To be overriden in subclasses. Default implementation uses field names from $this->m->getMetadata()

protected
# beforeSave( )

Called by save() before writing to DB.

Called by save() before writing to DB.

Subclasses may override this method to tune save() behavior, e.g. to validate and prepare $this->db_row.

Throws

waException
if validation fails
protected
# afterSave( )

Called by save() after writing to DB when $this->id is already created and available. $this->rec_data still contains values just written to DB. When this function returns, remaining values from $this->rec_data will be moved to $this->persistent.

Called by save() after writing to DB when $this->id is already created and available. $this->rec_data still contains values just written to DB. When this function returns, remaining values from $this->rec_data will be moved to $this->persistent.

Subclasses may override this method to tune save() behavior, e.g. to move attachments to appropriate place using record id.

protected
# doLoad( array $field_or_db_row = null )

Called by $this->load() to populate data into $this->persistent

Called by $this->load() to populate data into $this->persistent

Subclasses may override this method to tune load() behavior, e.g. to load data lazily by field name passed in $field_or_db_row. Subclasses overriding this should also call parent::doLoad() since the base class uses it to load data from $this->m model.

Parameters

$field_or_db_row
array
$field_or_db_row see $this->load()

Throws

waException
protected
# afterLoad( array $field_or_db_row = null )

Called by $this->load() after data has been added to $this->persistent either from $field_or_db_row (if it's an array), or from $this->m model.

Called by $this->load() after data has been added to $this->persistent either from $field_or_db_row (if it's an array), or from $this->m model.

Subclasses may override this method to tune load()'s behavior, e.g. to populate additional data into class fields or modify data fetched from DB.

Parameters

$field_or_db_row
array
$field_or_db_row see $this->load()
protected
# beforeDelete( )

Called by $this->delete() before removing record from $this->m

Called by $this->delete() before removing record from $this->m

protected
# afterDelete( )

Called by $this->delete() after removing record from $this->m

Called by $this->delete() after removing record from $this->m

public array
# toArray( )

Convert this object to a native array. Will currently cause infinite recursion for self-containing structures.

Convert this object to a native array. Will currently cause infinite recursion for self-containing structures.

Returns

array

Overrides

waArrayObjectDiff::toArray()
public &
# __get( mixed $name )

Overrides

waArrayObjectDiff::__get()
public
# __isset( mixed $name )

Overrides

waArrayObjectDiff::__isset()
public
# keyExists( mixed $name )

same as array_key_exists for native arrays

same as array_key_exists for native arrays

Overrides

waArrayObjectDiff::keyExists()
Methods inherited from waArrayObjectDiff
__clone(), __set(), __unset(), clear(), clearPersistent(), count(), diff(), getIterator(), getPersistent(), merge(), removeStubs(), restorePersistentInvariant(), revert(), setPersistent()
Methods inherited from waArrayObject
__toString(), convert(), ifempty(), ifset(), offsetExists(), offsetGet(), offsetSet(), offsetUnset(), setAll(), stub()
Properties summary
protected waModel $m
#

Model to use for saving and loading data.

Model to use for saving and loading data.

protected string|integer|null $id null
#

id of a row as accepted by model

id of a row as accepted by model

Properties inherited from waArrayObjectDiff
$persistent, $removed
Properties inherited from waArrayObject
$rec_data, $stub
My fork of Webasyst Framework API documentation generated by ApiGen 2.8.0