Class: DatabaseTable

  • Package: saf.Database
  • Author: John Luxford <lux@simian.ca>
  • Copyright: Copyright (C) 2001-2003, Simian Systems Inc.
  • License: http://www.sitellite.org/index/license Simian Open Software License
  • Version: 1.4, 2002-01-14, $Id: Table.php,v 1.4 2007/10/06 00:06:30 lux Exp $
  • Access: public

DatabaseTable is an extension of the Database class, which provides
high-level functions, such as fetchAll(), that aim to lessen the need
to type common queries out each time you use them.

Note: This class does not worry about database abstraction, since that will
be handled by subclassing the I18n class and calling its get() method on
each query automatically in the Database class.

New in 1.2:
- Added the following properties: $info, $columns, $pkey, $alt, $datefield,
$statusfield, $queryfield, $orderfield, $treefield, $accessfield,
$add_form_template, $add_form_message, $edit_form_template, and
$edit_form_message.
- Added the following methods: getInfo(), getPkey(), _makeWidget(), and
changeType().
- This class is now not accessed directly, but through the saf.Database
driver system. This is done transparently however, since table objects
are always created using the saf.Database table() method.

New in 1.4:
- Added the addFacet() method.


Usage Example


<?php

$dt 
= new DatabaseTable ($db'tablename''pkeycolumn');

if (
$res $dt->fetchAll ()) {
    
// do something with $res
} else {
    echo 
$dt->error;
}

?>

Return to Top



Properties


$connection = ''

  • Access: public

Contains a local copy of the database connection resource.


$path

  • Access: public

Path to the Berkeley Database.


$mode

  • Access: public

Mode to use when opening the database (corresponds to
the modes available to the dba_open () function.


$handler

  • Access: public

The database implementation used (db2, db3, gdbm, etc.).


$persistent

  • Access: public

A 1 or 0 (true or false, and true by default), specifying whether
to establish a persistent connection or not.


$transactions = 0

  • Access: public

Boolean value denoting whether to enable transactions in the
current database.


$driver

  • Access: public

Contains the name of the database driver being used.


$host

  • Access: public

Contains the name of the database host.


$name

  • Access: public

The name of the table.


$user

  • Access: public

Contains the username used to connect to the current database.


$pass

  • Access: public

Contains the password used to connect to the current database.


$dbd

  • Access: private

Contains the loaded database driver.


$error

  • Access: public

Contains the error message if there is one, or false otherwise.


$sql

  • Access: public

The sql from the previous query, if an error occurred.


$rows

  • Access: public

The number of rows returned by the previous query.


$lastid

  • Access: public

Contains the lastid() of the last insert query sent to the execute()
method.


$tables = false

  • Access: public

Contains a list of tables in the database. Set by getTables().


$pearEmu = false


$sequenceFormat = '%s_seq'


$fetchMode = DB_FETCHMODE_OBJECT


$result = ''

  • Access: public

Contains the result identifier for the current execution.


$field = ''

  • Access: public

Currently unused.


$_fetchModeFunctions = array ()

  • Access: private


$typemap = array ()

  • Access: public

Contains a key/value list of database types (regular
expressions are used here to save repeating ourselves) and their
corresponding MailForm widget types. Used internally by the drivers.


$column

  • Access: public

Column name of the facet.


$title

  • Access: public

Dispaly name of the facet.


$extra

  • Access: public

Extra info about the facet.


$tableObj

  • Access: public

DatabaseTable object.


$items = array ()

  • Access: public

List of options in the facet.


$type = 'normal'

  • Access: public

Type of the facet. Possible values are 'normal', 'self_ref', 'date', and 'time'.
This value is auto-determined by compile(), but can be customized as well.


$table

  • Access: public

Table name.


$fields = array ()

  • Access: public

Field list.


$pkey = false

  • Access: public

The name of the primary key field. This property is also duplicated
in the $primary_key property, which is a reference to this one.


$fkey = ''

Optional name of a foreign key field, for use in simplified find() calls.


$listFields = '*'

The list of fields to return on find(). Default is '*' to return all fields.


$isAuto = true

Whether the pkey is auto-incrementing or not.


$orderBy = ''

Contains the "order by" clause value (ie. "name asc") for calls to find().


$groupBy = ''

Contains the "group by" clause value (ie. "name asc") for calls to find().


$limit = false

Contains the "limit" clause value for calls to find().


$offset = false

Contains the "offset" clause value for calls to find().


$invalid = array ()

A list of invalid fields and their corresponding error messages,
from the previous validate() call.


$usePermissions = false

Determines whether to automatically add access control to find(), count(),
and get() calls.


$multilingual = false

Enables automatic translation of items pulled from the database through
Sitellite's new multilingual capabilities.


$_cascade = array ()

This is the list of external types to cascade deletions across. In the
case of external objects, the keys are the object names and the values
are the referencing field in the external object's table. In the case
of join tables for many-to-many relationships, the keys are simply
numeric and the value is an array containing the join table name and the
name of the field referring to the current object's primary key field.

Ordinarily, these values are set automatically via the load() method,
and the relationships are defined in an INI file.


$server

  • Access: public

The name of the server to connect to.


$port

  • Access: public

The port to use to connect to the server.


$rdn

  • Access: public

The rdn (username, essentially) to use to bind to
the connection.


$password

  • Access: public

The password to use to bind to the connection.


$secure

  • Access: public

Whether to use TLS for LDAP connections.


$resource

  • Access: public

The current search resource.


$firstCalled

  • Access: public

Says whether or not the first search result entry has
been returned.


$errno

  • Access: public

Contains the error number if there is one, or false otherwise.


$connections = array ()

  • Access: public

Connection list.


$current

  • Access: public

Active tree root ID.


$key

  • Access: public

Primary key field name.


$root

  • Access: public

Root field name.


$left

  • Access: public

Left field name.


$right

  • Access: public

Right field name.


$order

  • Access: public

Sorting order field name.


$level

  • Access: public

Level field name.


$indexes = array ()

  • Access: public

Index list.


$collection

Name of the collection PropertySet should map onto. Usually this is
the name of another database table.


$entity

ID of the item from the collection which properties should map onto.
This is usually the value of the primary key of a database record.


$db

  • Access: public

Contains a reference to the database connection resource.


$info = false

  • Access: public

The unparsed info from the database about this table and
its columns.


$columns = array ()

  • Access: public

An array of MailForm widgets created based on the $info data.


$alt = ''

  • Access: public

An alternate name to display for this table, which makes it nicer to
read for people. By default the $alt is the $name with underscores
converted to spaces and the first letter (of the first word only)
capitalized.


$datefield = ''

  • Access: public

Contains the column to search for date values in the Sitellite CMS
database manager.


$statusfield = ''

  • Access: public

Contains the column to search for status values in the Sitellite CMS
database manager.


$queryfield = ''

  • Access: public

Contains the column to search for any string values in the Sitellite
CMS database manager.


$orderfield = ''

  • Access: public

Contains the column to order search results by in the Sitellite CMS
database manager.


$treefield = ''

  • Access: public

Contains the column that makes a self-reference (a reference to
the primary key of its own table), which can be used in the Sitellite CMS
database manager to show a tree representation of this table.


$accessfield = ''

  • Access: public

Contains the column to search for access level values in the Sitellite
CMS database manager.


$add_form_template = ''

  • Access: public

Contains the template to use for displaying the Add Record form
in the Sitellite CMS.


$add_form_message = ''

  • Access: public

Contains the message to use for displaying the Add Record form
in the Sitellite CMS.


$edit_form_template = ''

  • Access: public

Contains the template to use for displaying the Edit Record form
in the Sitellite CMS.


$edit_form_message = ''

  • Access: public

Contains the message to use for displaying the Edit Record form
in the Sitellite CMS.


$facets = array ()

Return to Top



Methods


DatabaseTable (&$db, $name, $pkey)

  • Access: public

Constructor method.


fetch ($keyval, $columns = '', $order = '', $ascdesc = '')

  • Access: public
  • Return: mixed

Creates a SELECT query based on the key given to it.
$keyval may be a value to query against the primary key column
or an associative array of values to be
placed in the WHERE clause of the SELECT query. $columns is an
optional array of columns to return. $ascdesc can be either
'asc' or 'desc'. Returns an object if the query returns a
single result (ie. for queries against the primary key column),
or an array of objects, or false.


fetchAll ($columns = '', $order = '', $ascdesc = '')

  • Access: public
  • Return: array

Creates a SELECT query without a WHERE clause, returning
all columns from the table. $columns is an
optional array of columns to return. $ascdesc can be either
'asc' or 'desc'. Returns an array of objects, or false on failure.


insert ($columns)

  • Access: public
  • Return: mixed

Creates an INSERT query from the columns provided. Returns the
lastid() of the query, or the $columns[$this->pkey] value if there is
no sequential key in this table, or false on failure.


update ($keyval, $columns)

  • Access: public
  • Return: boolean

Creates an UPDATE query from the $keyval and $columns provided.
Returns true if successful, false on failure.


delete ($keyval)

  • Access: public
  • Return: boolean

Creates an DELETE query from the key value or values provided.


getPkey ()

  • Access: public
  • Return: string

Gets the name of the primary key field for this table using the
results of getInfo() (see below). Used by the constructor method to
set the $pkey property if a primary key column was not specified.
Returns false on failure. This method is left entirely to the drivers
to implement, as its workings will always be database-specific.


getInfo ()

  • Access: public
  • Return: boolean

Gets all the info it can from the database about this table and
its columns, stores it in the $info property, and parses it into an
associative array ($columns) of MailForm widgets. This method is left
entirely to the drivers to implement, as its workings will always be
database-specific.


getRefInfo ($name, $table)

  • Access: public
  • Return: boolean

Uses the global $tables array (Sitellite CMS specific) to get
the primary key, referencing column, display column, and a true or false
self-reference value, when given a Ref column name and its corresponding
table. This method is left to the drivers to implement, since some of
it may be database-specific, namely the logic that the display column
should be a concatenation of the first two columns that are not of the
types Hidden, File, or Password.


_makeWidget ($col)

  • Access: private
  • Return: object

Takes an object with at least $name and $type properties and
converts it into a MailForm widget. Additional properties are also
transfered. Returns the new MailForm widget.


changeType ($name, $type, $extra = array ())

  • Access: public
  • Return: boolean

PLEASE NOTE: This method is deprecated in favour of the built-in
changeType() method in the base MF_Widget class.

Takes a widget name, a new type, and any extra properties
that should be set immediately, and translates one MailForm widget
(from the $columns list) into another type. This is the new way
to change types of columns in the columns.php configuration file
in the Sitellite CMS.


&addFacet ($column, $title, $extra = '')

  • Access: public
  • Return: object reference

Creates a "facet" about this widget based on one of its
columns. See saf.Database.Facet for more info about those.

Return to Top

Copyright © 2008 Sitellite CMS Project

Powered by Sitellite 5.0 Content Management System