Class: PropertySet
Simple class for adding arbitrary properties to existing data structures,
usually properties that change frequently (ie. new properties are added
or removed or updated a lot).
Schema:
CREATE TABLE sitellite_property_set (
collection CHAR(48) NOT NULL,
entity CHAR(48) NOT NULL,
property CHAR(48) NOT NULL,
data_value CHAR(255) NOT NULL,
UNIQUE (collection, property, entity),
UNIQUE (collection, property)
);
Usage Example
<?php
// note: this example is not necessarily practical, because one might use
// session_pref(), session_pref_set(), and session_pref_list() instead.
loader_import ('saf.Database.PropertySet');
$ps = new PropertySet ('sitellite_user', 'some_user');
// set the preference
$ps->add ('some_preference', 'yes');
// change their preference
$ps->update ('some_preference', 'no');
// get their preference
info ($ps->get ('some_preference'));
// add another preference
$ps->add ('pref2', 'yes');
// list all preferences
info ($ps->get ());
// remove all preferences
$ps->delete ();
?>
Return to Top
Properties
$connection
The current connection resource.
$path
Path to the Berkeley Database.
$mode
Mode to use when opening the database (corresponds to
the modes available to the dba_open () function.
$handler
The database implementation used (db2, db3, gdbm, etc.).
$persistent
A 1 or 0 (true or false, and true by default), specifying whether
to establish a persistent connection or not.
$transactions = 0
Boolean value denoting whether to enable transactions in the
current database.
$driver
Contains the name of the database driver being used.
$host
Contains the name of the database host.
$name
Contains the name of the database being used.
$user
Contains the username used to connect to the current database.
$pass
Contains the password used to connect to the current database.
$dbd
Contains the loaded database driver.
$error
Will contain an error message if one occurs.
$sql = ''
Contains the SQL query to be executed.
$rows
Contains the number of rows returned by the previous fetch() call.
$lastid
Contains the lastid() of the last insert query sent to the execute()
method.
$tables = false
Contains a list of tables in the database. Set by getTables().
$pearEmu = false
$sequenceFormat = '%s_seq'
$fetchMode = DB_FETCHMODE_OBJECT
$result = ''
Contains the result identifier for the current execution.
$field = ''
Currently unused.
$_fetchModeFunctions = array (
DB_FETCHMODE_ASSOC => 'mysql_fetch_array',
DB_FETCHMODE_OBJECT => 'mysql_fetch_object',
)
$typemap = array (
'bpchar' => 'text',
'char' => 'text',
'varchar' => 'text',
'text' => 'textarea',
'date' => 'date',
'time' => 'time',
'timestamp' => 'datetime',
'.*' => 'text',
// arrays
// booleans
// blobs
)
Contains a key/value list of database types (regular
expressions are used here to save repeating ourselves) and their
corresponding MailForm widget types.
$column
Column name of the facet.
$title
Dispaly name of the facet.
$extra
Extra info about the facet.
$tableObj
DatabaseTable object.
$items = array ()
List of options in the facet.
$type = 'normal'
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
Table name.
$fields = array ()
Field list.
$pkey = ''
Primary key field.
$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
The name of the server to connect to.
$port
The port to use to connect to the server.
$rdn
The rdn (username, essentially) to use to bind to
the connection.
$password
The password to use to bind to the connection.
$secure
Whether to use TLS for LDAP connections.
$resource
The current search resource.
$firstCalled
Says whether or not the first search result entry has
been returned.
$errno
The errno of the previous error.
$connections = array ()
Connection list.
$current
Active tree root ID.
$key
Primary key field name.
$root
Root field name.
$left
Left field name.
$right
Right field name.
$order
Sorting order field name.
$level
Level field name.
$indexes = array ()
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.
Return to Top
Methods
PropertySet ($collection, $entity)
Constructor method.
get ($property = false)
- Access: public
- Return: mixed
Retrieves the specified property, or all properties for the current
entity, if $property is not specified. If there are no properties
and $properties is unspecified, it will return an empty array. If
there _are_ values, it returns an associative array of the key/value
pairs (ie. array ('property1' => 'value1', 'property2' => 'value2')).
add ($property, $data_value)
- Access: public
- Return: boolean
Adds the specified property.
update ($property, $data_value)
- Access: public
- Return: boolean
Updates the specified property.
set ($property, $data_value)
- Access: public
- Return: boolean
Adds or updates (if already exists) the specified property.
This is a convenience method for when you're not sure if
a property is set, however add() and update() are faster.
delete ($property = false)
- Access: public
- Return: boolean
Deletes the specified property, or all properties for the current
entity, if $properties is unspecified.
Return to Top