Class RSDTable

Description

This is the superclass for all RSDTable classes created for a specific table.

Located in /code/framework/RSDEngine/RSDTable.php (line 65)

PEAR
   |
   --RSDTable
Variable Summary
mixed $app
DB $db
String $name
Method Summary
RSDTable RSDTable ()
void canInsert ([Array $inserts = array()])
boolean checkUniqueConstraints (Array $assignments)
int count ([mixed $conditions = false], [String $selectMethod = "select"], [boolean $checkRight = true])
mixed delete (String $whereConditions)
int exist ([mixed $conditions = false], [String $selectMethod = "select"], [boolean $checkRight = true])
void generateWhereClause (mixed $conditions)
mixed get ([mixed $conditions = false], [String $selectMethod = "select"], [String $orderByClause = ""], [String $columns = "*"], [mixed $from = null], [mixed $to = null], [boolean $checkRight = true])
array &getAll (string $query, [array $params = null], [integer $fetchmode = DB_FETCHMODE_DEFAULT], [mixed $from = null], [mixed $to = null])
String getColumnValue (mixed $value)
String getIsValidMethodName (String $columnName, [mixed $columnPrefix = 'f_'])
void getLabelColumn ()
mixed getOne ([conditions $conditions = false], [selectMethod $selectMethod = "select"], [columns $columns = "*"], [boolean $checkRight = true])
void getPage ([mixed $pageNumber = 1], [mixed $perPage = 10], [mixed $conditions = false], [mixed $selectMethod = "select"], [mixed $orderByClause = ""], [mixed $columns = "*"], [mixed $checkRight = true])
mixed getRow ([mixed $conditions = false], [String $selectMethod = "select"], [String $columns = "*"], [boolean $checkRight = true])
void getSmartyHTMLOptionsArray ($primaryKeyColumn $primaryKeyColum, [String $labelColumn = false])
mixed insert (Array $inserts, [boolean $hypothetical = false])
boolean isValidColumnValue (column $column, value $value, [boolean $forceReferentialIntegrityCheck = false], [String $negativeConditions = false])
boolean isValidForeignKey ($foreignKey $foreignKey, $primaryKey $primaryKey)
An recordArrayToSmartyHTMLOptionsArray ($primaryKeyColumn $primaryKeyColum, mixed &$records, mixed $labelColumnName, String $labelColumn)
Array select ([String $whereClause = ''], [String $orderByClause = ''], [mixed $columns = '*'], [int $from = null], [int $to = null], [mixed $checkRight = true])
Array selectIncludingAll ([String $whereClause = ''], [String $orderByClause = ''], [mixed $columns = '*'], [int $from = null], [int $to = null], [mixed $checkRight = true])
Array selectIncludingDirectlyRelated ([String $whereClause = ''], [String $orderByClause = ''], [mixed $columns = '*'], [int $from = null], [int $to = null], [mixed $checkRight = true])
mixed update (Array $updates, mixed $whereConditions)
void updateRow (mixed $updates, mixed $whereConditions, [mixed $checkRight = true])
void _generateAssignment (String $column, String $value, [String $prepareString = '?'])
Variables
mixed $app = null (line 75)

An instance of the generated Application Child Class

DB $db = null (line 70)

An instance of PEAR::DB

String $name = null (line 80)

The name of the table.

Methods
Constructor RSDTable (line 84)

Constructor that calls the base class constructor PEAR().

RSDTable RSDTable ()
canInsert (line 904)

Returns whether the currently logged in user has the permission to perform an insert operation.

void canInsert ([Array $inserts = array()])
  • Array $inserts: An associative array of column-value pairs. This argument is optional.
checkUniqueConstraints (line 549)

Must be overwritten. Should return true if no unique constraints would be violated by using the array of assignments passed as argument for a INSERT or a UPDATE operation. Otherwise false should be returned.

boolean checkUniqueConstraints (Array $assignments)
  • Array $assignments: An array of key-value pairs.
count (line 457)

Returns an integer representing the number of records that matched the conditions passed as first argument.

  • return: The number of records that matched the conditions.
int count ([mixed $conditions = false], [String $selectMethod = "select"], [boolean $checkRight = true])
  • mixed $conditions: Any value valid for generateWhereClause.
  • String $selectMethod: Valid values are the names of all methods stating with "selectIncluding..." and "select". This argument is optional. The default is 'select'.
  • boolean $checkRight: Whether to check if the current user has the right to perform this operation. The default is true.
delete (line 321)

Deletes records from this table.

mixed delete (String $whereConditions)
  • String $whereConditions: A SQL-WHERE clause like 'WHERE table.filed=1' or any other argument valid for generateWhereClause.
exist (line 478)

Whether records that matched the conditions passed as first argument exist.

  • return: The number of records that matched the conditions.
int exist ([mixed $conditions = false], [String $selectMethod = "select"], [boolean $checkRight = true])
  • mixed $conditions: Any value valid for generateWhereClause.
  • String $selectMethod: Valid values are the names of all methods stating with "selectIncluding..." and "select". This argument is optional. The default is 'select'.
  • boolean $checkRight: Whether to check if the current user has the right to perform this operation. The default is true.
generateWhereClause (line 642)

Returns a WHERE clause generated from the array passed as argument.

void generateWhereClause (mixed $conditions)
  • mixed $conditions: An array from which to generate the WHERE clause. The first way is to construct $conditions from column-value assignments as in the following example:

    1 $table->generateWhereClause(
    2 array(
    3 "f_title" => "Peters's",
    4 "f_date" => new RSDColumnValue("NOW()", "!"),
    5 "f_file" => RSDColumnValue("test.txt", "&"),
    6 "f_description" => RSDColumnValue("This is a test.", "?"),
    7 "f_data" => RSDColumnValue("test", "%")
    8 )
    9 );
    The element key represents the column name. The value that should be 'assigned' to the column can either be specified directly as the element value or as an instance of RSDColumnValue. Note that "f_title" => "My Title" is equal to "f_title" => RSDColumnValue('My Title', '?') because '?' is the default. The column name, the column value and the 'prepareString' ('!','&','?' or '%') are passed to the method $this->_generateAssignment. The example above would result in the following where clause (if oracle is used; ' is escaped with ''):

    1 WHERE
    2 f_title='Peters''s'
    3 AND
    4 f_date=NOW()
    5 AND
    6 f_file='The contents of the file test.txt with quotes('') escaped.'
    7 AND
    8 f_data LIKE '%test%'
    If you wish to connect the conditions differently than by AND, use the following format:

    1 $table->generateWhereClause(
    2 array(
    3 array(
    4 "f_title" => "Peters's",
    5 "f_date" => RSDColumnValue("NOW()", "!"),
    6 "f_file" => RSDColumnValue("test.txt", "&"),
    7 "f_description" => RSDColumnValue("This is a test.", "?"),
    8 "f_data" => RSDColumnValue("test", "%")
    9 ),
    10 "%s1 AND %s2 AND (%s3 OR %s4 OR %s5)"
    11 )
    12 );
    Note that the the conditions-array from the previous example is now itself placed in an array (as the first element. The second element is a string that defines the format. %s1 is replaced with the first condition, %s2 with the second condition, and so on... If $conditions is a string this string will be returned without modifications. If $conditions is an array and has has a length of 0 or is (===) the boolean value false, an empty string will be returned. NOTE: this might be dangerous if the where clause is used in a DELETE or UPDATE statement! If $conditions is not an array and not a string the string "WHERE 1=2" will be returned. This is because if it's not a string nor an array something must have gone wrong; and in in that case we do not want to risk to cause unexpected results.
get (line 345)

Returns an associative Array with all records from the specified select matching the conditions passed as first arguement.

The select-method to invoke can be specified by the second argument. Valid values are the names of all methods stating with "selectIncluding..." and "select". The default is to invoke the method select.

  • return: An array of records or an instance of PEAR_Error.
  • see: generatedWhereClause
mixed get ([mixed $conditions = false], [String $selectMethod = "select"], [String $orderByClause = ""], [String $columns = "*"], [mixed $from = null], [mixed $to = null], [boolean $checkRight = true])
  • mixed $conditions: Any argument valid vor generatedWhereClause.
  • String $selectMethod: Valid values are the names of all methods stating with "selectIncluding..." and "select". This argument is optional. The default is 'select'.
  • String $orderByClause: A ORDER BY clause like "ORDER BY f_date".
  • String $columns: The columns to select. The default is "*" (all).
  • boolean $checkRight: Whether to check if the current user has the right to perform this operation. The default is true.
getAll (line 821)

Fetch all the rows returned from a query.

This method is just like the method DB::getAll. But it adds the possibility to limit the result by specifying the arguments $from and $to.

  • return: an nested array, or a DB error
  • access: public
array &getAll (string $query, [array $params = null], [integer $fetchmode = DB_FETCHMODE_DEFAULT], [mixed $from = null], [mixed $to = null])
  • string $query: the SQL query
  • array $params: array if supplied, prepare/execute will be used with this array as execute parameters
  • integer $fetchmode: the fetch mode to use
getColumnValue (line 725)

Returns the value of what ever was specified as column value.

If an instance of RSDColumnValue was passed as argument the property value will be returned; if a string was passed, this string will be returned.

String getColumnValue (mixed $value)
  • mixed $value: A string or an instance of RSDColumnValue
getIsValidMethodName (line 494)

Returns the name of the method that checks if a value is valid for the column supplied as argument.

  • return: The name of the isValid-Method.
String getIsValidMethodName (String $columnName, [mixed $columnPrefix = 'f_'])
  • String $columnName: The column name.
getLabelColumn (line 737)

Returns an sql statement that can be used in a select query to retrieve a literal representation of this record.

This method should be overwritten in the child class!

void getLabelColumn ()
getOne (line 440)

Returns just one field of one record from this table.

This method uses getRow to get one record from this table. array_shift is used to extract the first column.

  • return: A string holding value of the first field of the retrieved column or an instance of PEAR_Error on failure.
  • see: RSDTable::getRow()
mixed getOne ([conditions $conditions = false], [selectMethod $selectMethod = "select"], [columns $columns = "*"], [boolean $checkRight = true])
  • boolean $checkRight: Whether to check if the current user has the right to perform this operation. The default is true.
  • conditions $conditions: mixed Any argument valid vor generatedWhereClause.
  • selectMethod $selectMethod: String Valid values are the names of all methods stating with "selectIncluding..." and "select". This argument is optional. The default is 'select'.
  • columns $columns: String The columns to select. The default is "*" (all).
getPage (line 356)
void getPage ([mixed $pageNumber = 1], [mixed $perPage = 10], [mixed $conditions = false], [mixed $selectMethod = "select"], [mixed $orderByClause = ""], [mixed $columns = "*"], [mixed $checkRight = true])
getRow (line 414)

Returns just one record from this table.

  • return: An array holding the first record retrieved from the database or an instance of PEAR_Error on failure.
  • see: RSDTable::get()
mixed getRow ([mixed $conditions = false], [String $selectMethod = "select"], [String $columns = "*"], [boolean $checkRight = true])
  • mixed $conditions: Any argument valid vor generatedWhereClause.
  • String $selectMethod: Valid values are the names of all methods stating with "selectIncluding..." and "select". This argument is optional. The default is 'select'.
  • String $columns: The columns to select. The default is "*" (all).
  • boolean $checkRight: Whether to check if the current user has the right to perform this operation. The default is true.
getSmartyHTMLOptionsArray (line 756)

Returns an array for use with a SMARTY {html_options} statement.

In this example getSmartyHTMLOptionsArray would return the array $cust_options.


1 <select name=customer_id>
2 {html_options options=$cust_options selected=$customer_id}
3 </select>

void getSmartyHTMLOptionsArray ($primaryKeyColumn $primaryKeyColum, [String $labelColumn = false])
  • String $labelColumn: This string can be any valid sql like CONCAT(f_lastname, ', ', f_firstname). This argument is optional. The default is to use the return value of getLabelColumn.
  • $primaryKeyColumn $primaryKeyColum: The column which should be used as value in the option tags.
insert (line 165)

Inserts a record into the table.

The argument $inserts contains a variable number of values assigned to fields. The key is always the clumn name. The value can be just a string as it is the case for f_title in the following example. But it is as well possible to specify the value as an instance of RSDColumnValue containing two properties. These properties are set by the contructor of RSDColumnValue. The first constructor argument specifies the value, the second specifies the prepare string (i.e. the way this value should be treated). You can set the second field to the string '!' as it is the case for f_date to prevent the value to be quoted. You can as well set it to '&' which means the value is a filename and its contents should be inserted. Note that the assignment for f_title is equivalent to the assignment for f_description because '?' is assumed if the value is not specified as an instance of RSDColumnValue.


1 $table->insert(
2 array(
3 "f_title" => "My Title",
4 "f_date" => new RSDColumnValue("NOW()", "!"),
5 "f_file" => new RSDColumnValue("test.text", "&"),
6 "f_description" => new RSDColumnValue("This is a test.", "?")
7 )
8 );

  • return: True on success or an instance of PEAR_Error on failure.
mixed insert (Array $inserts, [boolean $hypothetical = false])
  • Array $inserts: Contains the columns and the values as key-value pairs.
  • boolean $hypothetical: If set to true this method will return true if the user has the right to perform this operation. Otherwise an instance of RSError will be returned. This argument is optional. The default is false.* @return mixed True on success, an instance of PEAR_Error on failure.
isValidColumnValue (line 519)

Returns true if the value passed as second argument is valid for the column passed as first argument.

  • return: True if the value is valid an instance of PEAR_Error otherwise.
boolean isValidColumnValue (column $column, value $value, [boolean $forceReferentialIntegrityCheck = false], [String $negativeConditions = false])
  • boolean $forceReferentialIntegrityCheck: Whether to force a referential integrity check. This argument is optional. The default is false.
  • String $negativeConditions: A string containing conditions that are used to solve the following problem: A record with the unique username 'tom' gets updated with a new password and the username is again set to 'tom'. When asking this method if the username 'tom' already exists the answer would be yes and our update operation would fail. The negative conditions allow us to exclude this very record and find out if there any other records with username='tom'. This argument is optional.
  • column $column: The name of the column. It can be passed in absolute notation ("table.column") or relativ to this table (just "culumn").
  • value $value: The value to check.
isValidForeignKey (line 560)

Returns true if such a primary key exists in the specified table otherwise a new PEAR_Error.

  • return: True if the value is a valid foreign key.
boolean isValidForeignKey ($foreignKey $foreignKey, $primaryKey $primaryKey)
  • $foreignKey $foreignKey: String The value of the foreign key.
  • $primaryKey $primaryKey: String The column that holds the primary keys in ablsolute notation ("table.column").
recordArrayToSmartyHTMLOptionsArray (line 782)

Transforms an array of records to an array for use with a SMARTY {html_options} statement.

This method is static! Be aware of the difference to getSmartyHTMLOptionsArray.

  • return: array of records.
  • static:
An recordArrayToSmartyHTMLOptionsArray ($primaryKeyColumn $primaryKeyColum, mixed &$records, mixed $labelColumnName, String $labelColumn)
  • String $labelColumn: This string can be any valid sql like CONCAT(f_lastname, ', ', f_firstname). This argument is optional. The default is to use the return value of getLabelColumn.
  • $primaryKeyColumn $primaryKeyColum: The column which should be used as value in the option tags.
select (line 100)

Returns a two-demensional Array of records. One record is hold by one array.

All arguments are optional.

Array select ([String $whereClause = ''], [String $orderByClause = ''], [mixed $columns = '*'], [int $from = null], [int $to = null], [mixed $checkRight = true])
  • String $whereClause: Any value valid for generateWhereClause.
  • String $orderByClause: A SQL-ORDER BY clause like 'ORDER BY table.column1 AND table.column2'
  • int $from: If $from and $to are specified only the records from $from to $to are fechted and returened.
  • int $to: See $from
selectIncludingAll (line 119)

This method should be overwritten in a child class. It should perform a join over all related tables.

  • return: An array of records.
Array selectIncludingAll ([String $whereClause = ''], [String $orderByClause = ''], [mixed $columns = '*'], [int $from = null], [int $to = null], [mixed $checkRight = true])
  • String $whereClause: Any value valid for generateWhereClause.
  • String $orderByClause: A SQL-ORDER BY clause like 'ORDER BY table.column1 AND table.column2'
  • int $from: If $from and $to are specified only the records from $from to $to are fechted and returened.
  • int $to: See $from
selectIncludingDirectlyRelated (line 132)

This method should be overwritten in a child class. It should perform a join over all tables that referenced by a foreign key define in this table.

  • return: An array of records.
Array selectIncludingDirectlyRelated ([String $whereClause = ''], [String $orderByClause = ''], [mixed $columns = '*'], [int $from = null], [int $to = null], [mixed $checkRight = true])
  • String $whereClause: Any value valid for generateWhereClause.
  • String $orderByClause: A SQL-ORDER BY clause like 'ORDER BY table.column1 AND table.column2'
  • int $from: If $from and $to are specified only the records from $from to $to are fechted and returened.
  • int $to: See $from
update (line 241)

Updates records in this table.

The argument $updates contains a variable number of values assigned to fields. The key is always the column name. The value can be just a string as it is the case for f_title in the following example. But it is as well possible to specify the value as an instance of RSDColumnValue containing two properties. These properties are set by the contructor of RSDColumnValue. The first constructor argument specifies the value, the second specifies the prepare string (i.e. the way this value should be treated). You can set the second field to the string '!' as it is the case for f_date to prevent the value to be quoted. You can as well set it to '&' which means the value is a filename and its contents should be inserted. Note that the assignment for f_title is equivalent to the assignment for f_description because '?' is assumed if the value is not specified as an instance of RSDColumnValue.


1 $table->update(
2 array(
3 "f_title" => "My Title",
4 "f_date" => new RSDColumnValue("NOW()", "!"),
5 "f_file" => new RSDColumnValue("test.text", "&"),
6 "f_description" => new RSDColumnValue("This is a test.", "?")
7 )
8 );

mixed update (Array $updates, mixed $whereConditions)
  • Array $updates
  • mixed $whereConditions: Any argument valid for generateWhereClause.
updateRow (line 296)
void updateRow (mixed $updates, mixed $whereConditions, [mixed $checkRight = true])
_generateAssignment (line 692)

Generates an SQL-assignment of a value to a column usable in a where clause.

void _generateAssignment (String $column, String $value, [String $prepareString = '?'])
  • String $column: The name of the column the value should be assigned to.
  • String $value: The value to assign.
  • String $prepareString: If this argument is '?' the $value will be quoted using $this->db->quote; if it is '!' it will not be quoted; if it is '&' $value will be treated as a filename and the file's content will be quoted and assigned; if it is '%' the generated statement will be generated like this:

    1 return "$column LIKE " . $this->db->quote("%$value%");

Documentation generated on Mon, 8 Dec 2003 13:13:02 +0100 by phpDocumentor 1.2.3