PHP 클래스 DatabaseObject

파일 보기 프로젝트 열기: sourcefabric/newscoop 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$m_columnNames array Redefine this in the subclass.
$m_data array An array of (ColumnName => Value).
$m_dbTableName string Redefine this in the subclass.
$m_exists boolean TRUE if the object exists in the database, FALSE if not, NULL if unknown.
$m_keyColumnNames array Redefine this in the subclass.
$m_keyIsAutoIncrement boolean Whether or not the primary key is an auto-increment field.
$m_oldKeyValues array If the key values of an object are changed, we need to remember the old values in order to change to the new values. This is the array of the old values.

보호된 프로퍼티들

프로퍼티 타입 설명
$eventDispatcher Newscoop\EventDispatcher\EventDispatcher
$resourceNames array

공개 메소드들

메소드 설명
DatabaseObject ( array $p_columnNames = null ) DatabaseObject represents a row in a database table.
GetUseCache ( ) : boolean Returns true if cache use was enabled
ProcessOptions ( string $p_queryStr, array $p_sqlOptions ) : string This is used by subclasses to add extra SQL options to the end of a query.
Search ( $p_className, array $p_columns = null, array $p_sqlOptions = null ) : array Do a simple search.
SetUseCache ( boolean $p_useCache ) : void Sets cache enabled/disabled
commit ( array $p_ignoreColumns = null ) : boolean Commit the data stored in memory to the database.
create ( array $p_values = null ) : boolean Create the record in the database for this object.
delete ( ) : boolean Delete the row from the database.
dumpToHtml ( ) : void Output the raw values of this object so that it displays nice in HTML.
duplicateObject ( object $p_source ) : object Copies the given object
exists ( ) : boolean Return true if the object exists in the database.
fetch ( array $p_recordSet = null, boolean $p_forceExists = false ) : boolean Fetch a single record from the database for the given key.
getCacheKey ( $p_recordSet = null ) Generates the cache key for the object.
getColumnNames ( boolean $p_withTablePrefix = false ) : array Return the column names of this table.
getData ( ) : array Return the row as an array indexed by the column names.
getDbTableName ( ) : string Return the name of the database table.
getKey ( ) : array Return the key as an array indexed by column names.
getKeyColumnNames ( ) : array Return the column names used for the primary key.
getKeyWhereClause ( ) : string Return a string for the primary key of the table.
getProperty ( string $p_dbColumnName, boolean $p_forceFetchFromDatabase = false ) : mixed Return the data stored in the given column.
keyValuesExist ( $p_recordSet = null ) : boolean Return true if the object has all the values required to fetch a unique record from the table.
modifyKeyValue ( string $p_columnName, string $p_value ) : void Remember the old value of the key.
readFromCache ( array $p_recordSet = null ) : mixed Initializes the current object from cache if it exists
resetCache ( )
sameAs ( mix $p_otherObject ) : boolean Returns true if the current object is the same type as the given object then has the same value.
setColumnNames ( array $p_columnNames ) : void Initialize the column names for this object.
setEventDispatcher ( Newscoop\EventDispatcher\EventDispatcher $dispatcher ) : void Set event dispatcher.
setKey ( array $p_columnNames ) : void This function has two modes of operation: You can change the columns used for the key values, or you can change the key values themselves.
setProperty ( string $p_dbColumnName, string $p_value, boolean $p_commit = true, boolean $p_isSql = false ) : boolean Set the given column name to the given value.
setResourceNames ( array $names ) : void Set resource names.
update ( array $p_columns = null, boolean $p_commit = true, boolean $p_isSql = false ) : boolean Update the database row with the given values.
writeCache ( ) : boolean Writes the object to cache.

보호된 메소드들

메소드 설명
dispatchEvent ( string $event, string $subject, array $params = [] ) Dispatch event.
getResourceName ( ) : string Get resource name.
lockTables ( array $p_tables = [], $p_write = true ) fn getCacheKey
unlockTables ( )

메소드 상세

DatabaseObject() 공개 메소드

This class is meant to be subclassed in order to implement a specific table in the database.
public DatabaseObject ( array $p_columnNames = null )
$p_columnNames array The column names of this table. These are optional.

GetUseCache() 공개 메소드

Returns true if cache use was enabled
public GetUseCache ( ) : boolean
리턴 boolean

ProcessOptions() 공개 정적인 메소드

This is used by subclasses to add extra SQL options to the end of a query.
public static ProcessOptions ( string $p_queryStr, array $p_sqlOptions ) : string
$p_queryStr string The current SQL query.
$p_sqlOptions array
Available options:
'LIMIT' => [max_rows_to_fetch]
'LIMIT' => array('START'=>[Starting_index],'MAX_ROWS'=>[Max_rows_to_fetch]
'ORDER BY' => [column_name]
'ORDER BY' => array([column_name_1], [column_name_2], ...)
'ORDER BY' => array([column_name_1]=>[ASC|DESC], [column_name_2]=>[ASC|DESC], ...)
   
리턴 string Original SQL query with the options appended at the end.

SetUseCache() 공개 메소드

Sets cache enabled/disabled
public SetUseCache ( boolean $p_useCache ) : void
$p_useCache boolean
리턴 void

commit() 공개 메소드

This is useful if you make a bunch of setProperty() calls at once and you dont want to update the database every time. Instead you can set all the variables without committing them, then call this function.
public commit ( array $p_ignoreColumns = null ) : boolean
$p_ignoreColumns array Specify column names to ignore when doing the commit.
리턴 boolean Return TRUE if the database was updated, false otherwise.

create() 공개 메소드

This will use the currently set index values for the key. No other values are set unless they are passed in through the $p_values parameter.
public create ( array $p_values = null ) : boolean
$p_values array Extra values to be set at create time, in the form of: (DB Column Name) => (value)
리턴 boolean TRUE if the record was added, false if not.

delete() 공개 메소드

Delete the row from the database.
public delete ( ) : boolean
리턴 boolean TRUE if the record was deleted, false if not.

dispatchEvent() 보호된 정적인 메소드

Dispatch event.
protected static dispatchEvent ( string $event, string $subject, array $params = [] )
$event string
$subject string
$params array

dumpToHtml() 공개 메소드

Output the raw values of this object so that it displays nice in HTML.
public dumpToHtml ( ) : void
리턴 void

duplicateObject() 공개 메소드

Copies the given object
public duplicateObject ( object $p_source ) : object
$p_source object
리턴 object

exists() 공개 메소드

Return true if the object exists in the database.
public exists ( ) : boolean
리턴 boolean

fetch() 공개 메소드

Fetch a single record from the database for the given key.
public fetch ( array $p_recordSet = null, boolean $p_forceExists = false ) : boolean
$p_recordSet array If the record has already been fetched and we just need to assign the data to the object's internal member variable.
$p_forceExists boolean prevents to check for the object existence in the database, a performance thing for situations where we know it exists.
리턴 boolean TRUE on success, FALSE on failure

getCacheKey() 공개 메소드

Generates the cache key for the object.
public getCacheKey ( $p_recordSet = null )

getColumnNames() 공개 메소드

Return the column names of this table.
public getColumnNames ( boolean $p_withTablePrefix = false ) : array
$p_withTablePrefix boolean Set to true if you want to prefix the column names with the table name. Default is false.
리턴 array

getData() 공개 메소드

Return the row as an array indexed by the column names.
public getData ( ) : array
리턴 array

getDbTableName() 공개 메소드

Return the name of the database table.
public getDbTableName ( ) : string
리턴 string

getKey() 공개 메소드

Return the key as an array indexed by column names.
public getKey ( ) : array
리턴 array

getKeyColumnNames() 공개 메소드

Return the column names used for the primary key.
public getKeyColumnNames ( ) : array
리턴 array

getKeyWhereClause() 공개 메소드

Return a string for the primary key of the table.
public getKeyWhereClause ( ) : string
리턴 string

getProperty() 공개 메소드

Return the data stored in the given column.
public getProperty ( string $p_dbColumnName, boolean $p_forceFetchFromDatabase = false ) : mixed
$p_dbColumnName string
$p_forceFetchFromDatabase boolean Get the data from the database instead of cached value that is stored in the object.
리턴 mixed Return a string if the property exists, NULL if the value doesnt exist, or a PEAR_Error if $p_forceFetchFromDatabase is TRUE and there was a problem fetching the data.

getResourceName() 보호된 메소드

Get resource name.
protected getResourceName ( ) : string
리턴 string

keyValuesExist() 공개 메소드

Return true if the object has all the values required to fetch a unique record from the table.
public keyValuesExist ( $p_recordSet = null ) : boolean
리턴 boolean

lockTables() 보호된 메소드

fn getCacheKey
protected lockTables ( array $p_tables = [], $p_write = true )
$p_tables array

modifyKeyValue() 공개 메소드

Remember the old value of the key.
public modifyKeyValue ( string $p_columnName, string $p_value ) : void
$p_columnName string
$p_value string
리턴 void

readFromCache() 공개 메소드

Initializes the current object from cache if it exists
public readFromCache ( array $p_recordSet = null ) : mixed
$p_recordSet array
리턴 mixed object The cached object on success boolean FALSE if the object did not exist

resetCache() 공개 메소드

public resetCache ( )

sameAs() 공개 메소드

Returns true if the current object is the same type as the given object then has the same value.
public sameAs ( mix $p_otherObject ) : boolean
$p_otherObject mix
리턴 boolean

setColumnNames() 공개 메소드

All column values will be initialized to null.
public setColumnNames ( array $p_columnNames ) : void
$p_columnNames array The column names in the database.
리턴 void

setEventDispatcher() 공개 정적인 메소드

Set event dispatcher.
public static setEventDispatcher ( Newscoop\EventDispatcher\EventDispatcher $dispatcher ) : void
$dispatcher Newscoop\EventDispatcher\EventDispatcher
리턴 void

setKey() 공개 메소드

Changing key values is tricky because you have to remember the old values in order to set the new values.
public setKey ( array $p_columnNames ) : void
$p_columnNames array
Can be either:
[0] => 'column name 1', [1] => 'column name 2', ...
or:
['column name 1'] => 'value', ['column name 2'] => 'value',...
   
리턴 void

setProperty() 공개 메소드

The object's internal variable will also be updated. If the value hasnt changed, the database will not be updated. Note: You cannot set $p_commit to FALSE and $p_isSql to TRUE at the same time.
public setProperty ( string $p_dbColumnName, string $p_value, boolean $p_commit = true, boolean $p_isSql = false ) : boolean
$p_dbColumnName string The name of the column that is to be updated.
$p_value string The value to set.
$p_commit boolean If set to true, the value will be written to the database immediately. If set to false, the value will not be written to the database. Default is true.
$p_isSql boolean Set this to TRUE if p_value consists of SQL commands. There is no way to know what the result of the command is, so we will need to refetch the value from the database in order to update the internal variable's value.
리턴 boolean TRUE on success, FALSE on error.

setResourceNames() 공개 정적인 메소드

Set resource names.
public static setResourceNames ( array $names ) : void
$names array
리턴 void

unlockTables() 보호된 메소드

protected unlockTables ( )

update() 공개 메소드

Update the database row with the given values.
public update ( array $p_columns = null, boolean $p_commit = true, boolean $p_isSql = false ) : boolean
$p_columns array Array of (Column_Name => Value)
$p_commit boolean If set to true, the value will be written to the database immediately. If set to false, the value will not be written to the database. Default is true.
$p_isSql boolean Set this to TRUE if the values of p_columns contains SQL commands. There is no way to know what the result of the command is, so we will need to refetch the row from the database in order to update the internal variable's value.
리턴 boolean Return TRUE on success, FALSE on error.

writeCache() 공개 메소드

Writes the object to cache.
public writeCache ( ) : boolean
리턴 boolean TRUE on success, FALSE on failure

프로퍼티 상세

$eventDispatcher 보호되어 있는 정적으로 프로퍼티

protected static EventDispatcher,Newscoop\EventDispatcher $eventDispatcher
리턴 Newscoop\EventDispatcher\EventDispatcher

$m_columnNames 공개적으로 프로퍼티

Redefine this in the subclass.
public array $m_columnNames
리턴 array

$m_data 공개적으로 프로퍼티

An array of (ColumnName => Value).
public array $m_data
리턴 array

$m_dbTableName 공개적으로 프로퍼티

Redefine this in the subclass.
public string $m_dbTableName
리턴 string

$m_exists 공개적으로 프로퍼티

TRUE if the object exists in the database, FALSE if not, NULL if unknown.
public bool $m_exists
리턴 boolean

$m_keyColumnNames 공개적으로 프로퍼티

Redefine this in the subclass.
public array $m_keyColumnNames
리턴 array

$m_keyIsAutoIncrement 공개적으로 프로퍼티

Whether or not the primary key is an auto-increment field.
public bool $m_keyIsAutoIncrement
리턴 boolean

$m_oldKeyValues 공개적으로 프로퍼티

If the key values of an object are changed, we need to remember the old values in order to change to the new values. This is the array of the old values.
public array $m_oldKeyValues
리턴 array

$resourceNames 보호되어 있는 정적으로 프로퍼티

protected static array $resourceNames
리턴 array