Class DBRow

Description

Object representing a database row (and extensible to represent joined rows)

Typical usage:

  1.    #set database connection parameters
  2.       $obj new DBRow("users"14"userid");
  3.    #set the fields required and their attributes
  4.       $obj->addElement(....);
  5.    #connect to the database
  6.       $obj->fill();
  7.    #check to see if user data changes some values
  8.       $obj->update($POST);
  9.    $obj->checkValid();
  10.    #synchronise with database
  11.       $obj->sync();

Located in /inc/formslib/dbrow.php (line 42)

DBO
   |
   --DBRow
Direct descendents
Class Description
BookingEntry Booking entry object for creating/editing booking
Consumable Consumables object
ConsumableUse Use of Consumables object
ClassCost User/Instrument class matrix
Group Group editing object
Instrument Instrument object (extends dbo), with extra customisations for other links
InstrumentClass Instrument class name
Project Project object (extends dbo), with extra customisations for other links
SpecialCost Special costs for project/instrument usage editing
User User object (extends dbo), with extra customisations for other links
UserClass User class name
Variable Summary
boolean $autonumbering
array $extrarows
boolean $insertRow
boolean $isDeleted
boolean $newObject
string $recNum
string $recStart
string $restriction
string $use2StepSync
Method Summary
DBRow DBRow (string $table, integer $id, [string $idfield = 'id'])
void addElement (Field $el)
void addElements (array $els)
boolean checkValid ()
integer delete ([mixed $extraUpdates = NULL])
void display ()
void displayAsTable ([ $cols = 2])
string displayInTable (integer $j)
void fill ()
void setId (integer $newId)
integer sync ()
void text_dump ()
boolean update (array $data)
string _sqlvals ([boolean $force = 0])
void _twoStageSync ()
void __clone ()
Variables
boolean $autonumbering = 1 (line 50)
  • var: automatically number new objects (i.e. the database will do it for us)
string $deleteFromTable = 1 (line 64)
  • var: this object can be deleted from the table (using DELETE); otherwise set the delete column to 1 for delete
array $extrarows (line 60)
  • var: additional rows to be included at the end of the display table
boolean $includeAllFields = 0 (line 48)
  • var: include all fields in the SQL statement not just ones that have changed or have values
boolean $insertRow = 0 (line 46)
  • var: this row should be inserted into the db
boolean $isDeleted = false (line 62)
  • var: row is marked as deleted in the table (but not actually deleted)
boolean $newObject = 0 (line 44)
  • var: this is a new object the form for which has not yet been shown to the user
string $recNum = '' (line 56)
  • var: number of the stop record number for a LIMIT statement
string $recStart = '' (line 54)
  • var: number of the start record number for a LIMIT statement
string $restriction = '' (line 52)
  • var: a restriction that is included in the WHERE statement for all queries
string $use2StepSync (line 58)
  • var: do a two-step synchronisation routine whereby the record is created first then updated second

Inherited Variables

Inherited from DBO

DBO::$changed
DBO::$DEBUG
DBO::$deletable
DBO::$dumpheader
DBO::$editable
DBO::$errorMessage
DBO::$fatal_sql
DBO::$fields
DBO::$id
DBO::$idfield
DBO::$idfieldreal
DBO::$ignoreId
DBO::$isValid
DBO::$namebase
DBO::$oob_errorMessage
DBO::$oob_status
DBO::$suppressValidation
DBO::$table
Methods
Constructor DBRow (line 73)

Create a new database row object

DBRow DBRow (string $table, integer $id, [string $idfield = 'id'])
  • string $table: name of the table to be used
  • integer $id: row id number in the table (-1 for new object)
  • string $idfield: (optional) the column in the table for the primary key (id)
addElement (line 334)

Add a new field to the row

Add an element into the fields[] array. The element must conform to the Fields class (or at least its interface!) as that will be assumed elsewhere in this object. Inheritable attributes are also set here.

void addElement (Field $el)
  • Field $el: the field to add
addElements (line 358)

Add multiple new fields to the row

Adds multiple elements into the fields[] array.

void addElements (array $els)
  • array $els: array of Field objects
checkValid (line 137)

check the validity of the data

  • return: data is valid
boolean checkValid ()

Redefined in descendants as:
  • BookingEntry::checkValid() : override the default checkValid() method with a custom one that also checks that the booking is permissible (i.e. the instrument is indeed free)
delete (line 256)

Delete this object's row from the database.

  • return: from statuscodes
integer delete ([mixed $extraUpdates = NULL])
  • mixed $extraUpdates: (optional) string or array of column => value added to the UPDATE statement objects are only to be marked as deleted not actually deleted.

Redefined in descendants as:
displayAsTable (line 460)
void displayAsTable ([ $cols = 2])
  • $cols

Redefined in descendants as:
displayInTable (line 442)

Display the row as a form in a table

  • return: html table
string displayInTable (integer $j)
  • integer $j: (optional) number of columns in the table (will pad as necessary)
fill (line 371)

Perform the SQL lookup to fill the object with the current data

Fill this object (i.e. its fields) from the SQL query

void fill ()

Redefined in descendants as:
fillWithDefaults (line 411)
void fillWithDefaults ()
setId (line 83)

Set the value of the primary key (id) for this object

void setId (integer $newId)
  • integer $newId: the id value to use
sync (line 170)

Synchronise this object's fields with the database

If the object is new, then INSERT the data, if the object is pre-existing then UPDATE the data. Fancier fields that are only pretending to do be simple fields (such as JOINed data) should perform their updates during the _sqlvals() call

  • return: from statuscodes
integer sync ()

Redefined in descendants as:
text_dump (line 423)

Quick and dirty dump of fields (values only, not a full print_r

void text_dump ()

Redefinition of:
DBO::text_dump()
Create a quick text representation of the object
update (line 102)

Update the object with the user-submitted data

update the value of each of the objects fields according to the user input data, and validate the data if appropriate

  • return: data is valid
boolean update (array $data)
  • array $data: user supplied data (field => $value)

Redefined in descendants as:
_sqlvals (line 300)

Generate name='value' data for the SQL statement

  • return: of data statements
string _sqlvals (boolean $force)
  • boolean $force: (optional) force all fields to be included
_twoStageSync (line 226)

An alternative way of synchronising this object's fields with the database.

Using this approach, we:

  • If the object is new, then INSERT a temp row first.
  • Then, trip the sqlvals() calls.
  • Then, UPDATE the data.
Here, we to the 'create temp row' part.

void _twoStageSync ()
__clone (line 470)

PHP5 clone method

PHP5 clone statement will perform only a shallow copy of the object. Any subobjects must also be cloned

void __clone ()

Redefinition of:
DBO::__clone()
PHP5 clone method

Inherited Methods

Inherited From DBO

DBO::DBO()
DBO::display()
DBO::log()
DBO::setEditable()
DBO::setNamebase()
DBO::text_dump()
DBO::__clone()

Documentation generated on Tue, 06 Mar 2007 10:01:22 +0000 by phpDocumentor 1.3.0