Tripal
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Drupal\tripal_chado\TripalStorage\ChadoRecords Class Reference
Collaboration diagram for Drupal\tripal_chado\TripalStorage\ChadoRecords:
Collaboration graph
[legend]

Public Member Functions

 __construct (ChadoFieldDebugger $field_debugger, TripalLogger $logger, ChadoConnection $connection)
 
 addColumn (array $elements, bool $is_link=FALSE, bool $read_only=FALSE)
 
 addCondition (array $elements, bool $is_or_condition=FALSE)
 
 setConditionValue (string $base_table, string $table_alias, int $delta, string $column_alias, $value, $is_or_condition=FALSE)
 
 addJoin (array &$elements)
 
 addJoinColumn (array $elements)
 
 setLinks (string $base_table)
 
 getRecordID (string $base_table)
 
 hasRecordID (string $base_table)
 
 getBaseTables ()
 
 getTableFromAlias (string $base_table, string $table_alias)
 
 getAncillaryTables (string $base_table)
 
 getAncillaryTablesWithCond (string $base_table)
 
 getTables (string $base_table)
 
 getNumTableItems (string $base_table, string $table_alias)
 
 getTableFields (string $base_table, string $table_alias)
 
 getFieldAliasColumn (string $base_table, string $table_alias, int $delta, string $column_alias)
 
 getColumnFieldAliases (string $base_table, string $table_alias, int $delta, string $chado_column)
 
 getColumnValue (string $base_table, string $table_alias, int $delta, string $column_alias)
 
 getRecordsArray ()
 
 copyRecords (ChadoRecords $records)
 
 validate ()
 
 insertRecords (string $base_table, string $table_alias)
 
 findRecords (string $base_table, string $base_table_alias, array $record_ids)
 
 updateRecords ($base_table, $table_alias)
 
 deleteRecords (string $base_table, string $table_alias, bool $graceful=FALSE)
 
 selectItems (string $base_table, string $table_alias, array $options=[])
 
 getChadoTableDef (string $table_name)
 
 getPrimaryKey (string $table_name)
 

Protected Member Functions

 checkElement ($elements, $key, $method, $what)
 
 initTable ($elements)
 
 getJoinAliases (array $elements)
 
 generateJoinHash (int $length=20)
 
 setRecordID (string $base_table, int $record_id)
 
 getTableItems (string $base_table, string $table_alias)
 
 addEmptyTableItem (string $base_table, string $table_alias)
 
 setColumnValue (string $base_table, string $table_alias, int $delta, string $column_alias, $value, $set_value=TRUE,)
 
 validateFKs ($base_table, $delta, $record_id, $record)
 
 validateTypes ($base_table, $delta, $record_id, $record)
 
 validateSize ($base_table, $delta, $record_id, $record)
 
 validateUnique ($base_table, $delta, $record_id, $record)
 
 validateRequired ($base_table, $delta, $record_id, $record)
 
 isSkipInsert (array $record)
 
 addConditions (Select &$select, array $record, string $table_alias)
 
 hasValidConditions ($record)
 
 isEmptyRecord ($record)
 

Protected Attributes

array $records = []
 
array $violations = []
 
array $join_aliases = []
 
ChadoFieldDebugger $field_debugger
 
ChadoConnection $connection
 
TripalLogger $logger
 

Detailed Description

A helper class for use by the ChadoStorage Plugin.

Constructor & Destructor Documentation

◆ __construct()

Drupal\tripal_chado\TripalStorage\ChadoRecords::__construct ( ChadoFieldDebugger  $field_debugger,
TripalLogger  $logger,
ChadoConnection  $connection 
)

Constructor.

Parameters
\Drupal\tripal_chado\Services\ChadoFieldDebugger$field_debuggerThe chado field debugger object.
Drupal\tripal\Services\TripalLogger$loggerThe Tripal logger object for logging debugging messages.
Drupal\tripal_chado\Database\ChadoConnection$connectionThe current connection to chado.

Member Function Documentation

◆ addColumn()

Drupal\tripal_chado\TripalStorage\ChadoRecords::addColumn ( array  $elements,
bool  $is_link = FALSE,
bool  $read_only = FALSE 
)

Adds a field to this ChadoRecords object.

A field here corresponds to a column in a Chado table.

Parameters
array$elementsThe list of key/value pairs describing the element. These keys are required:
  • base_table: the base table the field should be added to.
  • chado_table: the chado table the field should be added to. This can be the base table or an ancillary table.
  • table_alias: the alias fo the table. A base table alias will always be the same as the as the base table name.
  • delta: the delta index of the field item being added.
  • chado_column: the name of the column that the field is for.
  • column_alias: an alias for the column.
  • value: a value for the column. If the value is not known this should be NULL. These keys are optional:
  • delete_if_empty: for updates, if the "value" is empty then delete the item.
  • empty_value: only used if "delete_if_empty" is used. It indicates the value to use to determine if the field is empty.
bool$is_linkIndicates if this field stores a link (or foreign key) to the base table. If TRUE, and if the "value" key is NULL then a placeholder will be used to fill in the record. The value will be set automatically once it's known. Defaults to FALSE.
bool$read_onlyIf the column requested has a read-only value then we want to make sure that the column is present in the query and we get results for it but any value that might be set coming in should be ignored.
Exceptions

Exception If the any required fields are missing an error is thrown.

◆ addCondition()

Drupal\tripal_chado\TripalStorage\ChadoRecords::addCondition ( array  $elements,
bool  $is_or_condition = FALSE 
)

Adds a condition to this ChadoRecords object.

A condition is used when querying to limit the set of records returned.

Parameters
array$elementsThe list of key/value pairs describing the element.

These keys are required:

  • base_table: the base table the field should be added to.
  • chado_table: the chado table the field should be added to. This can be the base table or an ancillary table.
  • table_alias: the alias fo the table. A base table alias will always be the same as the as the base table name.
  • delta: the delta index of the field item being added.
  • column_alias: the alias used for the column (set via the setField() function.
  • value: a value for the column to use as the condition.
    Parameters
    bool$is_or_conditionIndicates that this condition should be wrapped inside an OR condition group along with any others with this flag set.
    Exceptions
    Exception If the any required fields are missing an error is thrown.

◆ addConditions()

Drupal\tripal_chado\TripalStorage\ChadoRecords::addConditions ( Select &  $select,
array  $record,
string  $table_alias 
)
protected

Adds conditions to the join.

Checks if there is more than one OR condition with a value, and if so creates an or condition group. If only one, and for remaining conditions with a value, added directly, i.e. as an AND condition.

Parameters
\Drupal\pgsql\Driver\Database\pgsql\Select&$selectAn existing database select query.
array$recordThe record being considered.
string$table_aliasThe alias of the table used in the condition.
Returns
void Changes are made to the select.

◆ addEmptyTableItem()

Drupal\tripal_chado\TripalStorage\ChadoRecords::addEmptyTableItem ( string  $base_table,
string  $table_alias 
)
protected

This function adds a new item to the table.

This function gets called internally during a find operation when we need to add recrods beyond the original element used for searching. It simply copies the item for delta 0 and clears the values so they can get set.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.

◆ addJoin()

Drupal\tripal_chado\TripalStorage\ChadoRecords::addJoin ( array &  $elements)

Adds a join to this ChadoRecords object.

Parameters
array$elementsThe list of key/value pairs describing the element.

These keys are required:

  • base_table: the base table the field should be added to.
  • chado_table: the chado table the field should be added to. This can be the base table or an ancillary table.
  • table_alias: the alias fo the table. A base table alias will always be the same as the as the base table name.
  • delta: the delta index of the field item being added.
  • join_path: the path from the StoragePropertyType that indicates the sequences of tables joined together.
  • join_type: corresponds to 'inner', 'outer', etc. Currently, only 'outer' is supported.
  • left_table: the left table in the join.
  • left_column: the left column in the join.
  • right_table: the right table in the join.
  • right_column: the right column in the join.
  • left_alias: the alias of the left column in the join.
  • right_alias: the alias of the right column in the join.
Exceptions

Exception If the any required fields are missing an error is thrown.

◆ addJoinColumn()

Drupal\tripal_chado\TripalStorage\ChadoRecords::addJoinColumn ( array  $elements)

Adds a fields to extract from a join in this ChadoRecords object.

This function is used after an addJoin() function to indicate the fields (or table columns) that should be added to the fields retrieved after a query.

Parameters
array$elementsThe list of key/value pairs describing the element.

These keys are required:

  • base_table: the base table the field should be added to.
  • chado_table: the chado table the field should be added to. This can be the base table or an ancillary table.
  • table_alias: the alias fo the table. A base table alias will always be the same as the as the base table name.
  • delta: the delta index of the field item being added.
  • join_path: the path from the StoragePropertyType that indicates the sequences of tables joined together.
  • chado_column: the column name in the table to add as a field.
  • column_alias: the alias of the column.
  • field_name: the name of the TripalFieldItemBase field. that requested the join.
  • key: The property key of the StoragePropertyType. that requested the join.
Exceptions

Exception If the any required fields are missing an error is thrown.

◆ checkElement()

Drupal\tripal_chado\TripalStorage\ChadoRecords::checkElement (   $elements,
  $key,
  $method,
  $what 
)
protected

A helper function used to check incoming $elements for various functions.

Parameters
array$elementsThe array of elements to check.
string$keyThe array key to check.
string$methodThe method being formed (e.g.. Initalzing, Adding, Setting, etc.)
string$whatThe type of element being added (e.g., 'field', 'condition', etc.)
Exceptions

Exception

◆ copyRecords()

Drupal\tripal_chado\TripalStorage\ChadoRecords::copyRecords ( ChadoRecords  $records)

Allows the caller to copy the records from another ChadoRecords object.

Parameters
ChadoRecords$recordsThe ChadoRecords object whose records should be copied.

◆ deleteRecords()

Drupal\tripal_chado\TripalStorage\ChadoRecords::deleteRecords ( string  $base_table,
string  $table_alias,
bool  $graceful = FALSE 
)

Deletes record for a given table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
bool$gracefulSet to TRUE to not throw an exception if valid conditions are not set. If TRUE then it skips the record rather than performs the delete.
Exceptions

Exception

◆ findRecords()

Drupal\tripal_chado\TripalStorage\ChadoRecords::findRecords ( string  $base_table,
string  $base_table_alias,
array  $record_ids 
)

Queries for multiple records in Chado for a given table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$base_table_aliasThe alias of the base table.
array$record_idsWhen specified, only return records where the primary key is present in this array. Used by publish to publish in batches.
Returns
array An array of \Drupal\tripal_chado\TripalStorage\ChadoRecords objects.
Exceptions

Exception

◆ generateJoinHash()

Drupal\tripal_chado\TripalStorage\ChadoRecords::generateJoinHash ( int  $length = 20)
protected

Generates a random character string.

Parameters
int$lengthThe length of the unique string.
Returns
string A hash that uniquely identifies the join.

◆ getAncillaryTables()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getAncillaryTables ( string  $base_table)

For the given base table, returns non base tables.

Parameters
string$base_tableThe name of the Chado table used as a base table.
Returns
array The list of tables linked to the base table but does not include the base table.

◆ getAncillaryTablesWithCond()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getAncillaryTablesWithCond ( string  $base_table)

For the given base table, returns non base tables that have conditions set.

Parameters
string$base_tableThe name of the Chado table used as a base table.
Returns
array The list of tables linked to the base table but does not include the base table.

◆ getBaseTables()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getBaseTables ( )

Returns the list of base tables.

Returns
array a list of base tables.

◆ getChadoTableDef()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getChadoTableDef ( string  $table_name)

Get a table definition from the chado schema.

Parameters
string$table_nameThe table name.
Returns
array The table schema.

◆ getColumnFieldAliases()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getColumnFieldAliases ( string  $base_table,
string  $table_alias,
int  $delta,
string  $chado_column 
)

Retrieves all of the column aliases for a given chado column.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
int$deltaThe numeric index of the item.
string$chado_columnThe chado column to retrieve an alias for.
Returns
array An array containing all of the alias mappings for fields in the table whose column name matches the $chado_column provided.

◆ getColumnValue()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getColumnValue ( string  $base_table,
string  $table_alias,
int  $delta,
string  $column_alias 
)

Gets a value for a given field.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
int$deltaThe numeric index of the item.
string$column_aliasThe alias for the column.
Returns
mixed The value of the field.

◆ getFieldAliasColumn()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getFieldAliasColumn ( string  $base_table,
string  $table_alias,
int  $delta,
string  $column_alias 
)

Retrieves the Chado column for a given base table and table alis.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
int$deltaThe numeric index of the item.
string$column_aliasThe alias for the column.
Returns
string The name of the chado column

◆ getJoinAliases()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getJoinAliases ( array  $elements)
protected

Generates unique aliases for tables used in joins.

This function will generate unique aliases if the callee did not provide them.

Parameters
array$elementsThe array of elements passed to the addJoin() function.
Returns
array An array of two strings: the left table alias and the right table alias.

◆ getNumTableItems()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getNumTableItems ( string  $base_table,
string  $table_alias 
)

Gets an array of records (one per field item)

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
Returns
mixed The value of the field.

◆ getPrimaryKey()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getPrimaryKey ( string  $table_name)

Retrieves the name of the primary key for a Chado table.

Parameters
string$table_nameThe chado table to look up the primary key for.
Returns
string|null The table primary key name.

◆ getRecordID()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getRecordID ( string  $base_table)

Gets the record ID for a given base table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
Returns
int A numeric record ID for the base table. If the value is 0 then the value has not been set.

◆ getRecordsArray()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getRecordsArray ( )

Returns the records object as an array.

Returns
array An array representation of this ChadoRecords object.
See also
self::records

◆ getTableFields()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getTableFields ( string  $base_table,
string  $table_alias 
)

Returns the list of fields that require values from the given table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.

◆ getTableFromAlias()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getTableFromAlias ( string  $base_table,
string  $table_alias 
)

Gets the true Chado table name from an alias.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
Returns
string The Chado table name.

◆ getTableItems()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getTableItems ( string  $base_table,
string  $table_alias 
)
protected

Gets an array of records (one per field item)

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
Returns
mixed The value of the field.

◆ getTables()

Drupal\tripal_chado\TripalStorage\ChadoRecords::getTables ( string  $base_table)

Returns the list of tables currently handled by this object.

Parameters
string$base_tableThe name of the Chado table used as a base table.
Returns
array The list of tables linked to the base table and including the base table.

◆ hasRecordID()

Drupal\tripal_chado\TripalStorage\ChadoRecords::hasRecordID ( string  $base_table)

Indicates if the given base table has a record ID.

Parameters
string$base_tableThe name of the Chado table used as a base table.
Returns
bool TRUE if the record ID is set, otherwise FALSE

◆ hasValidConditions()

Drupal\tripal_chado\TripalStorage\ChadoRecords::hasValidConditions (   $record)
protected

Indicates if the record has any valid conditions.

For the record to have valid conditions it must first have at least one condition, and the value on which that condition relies is not empty.

Parameters
array$recordThe field item to validate.
Returns
bool Return TRUE if the conditions are valid. FALSE otherwise.

◆ initTable()

Drupal\tripal_chado\TripalStorage\ChadoRecords::initTable (   $elements)
protected

Initalizes the records.

Parameters
array$elementsAn array of items used to initalize the internal records array.
Exceptions

Exception

Returns
bool TRUE if the table and delta were initalized. FALSE otherwise. The base table can only be initialized once. This function will return FALSE if there is an attempt to initalize it with a delta higher than 1.

◆ insertRecords()

Drupal\tripal_chado\TripalStorage\ChadoRecords::insertRecords ( string  $base_table,
string  $table_alias 
)

Inserts all records for a single Chado table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
Exceptions

Exception

◆ isEmptyRecord()

Drupal\tripal_chado\TripalStorage\ChadoRecords::isEmptyRecord (   $record)
protected

Indicates if we should keep this record for inserts/updates.

Parameters
array$recordThe field item to validate.
Returns
bool Return TRUE if the record is empty. FALSE otherwise.

◆ isSkipInsert()

Drupal\tripal_chado\TripalStorage\ChadoRecords::isSkipInsert ( array  $record)
protected

A helper function for the insetTable() function.

Checks to see if the record should not be inserted.

Parameters
array$recordThe record being considered for insertion.
Returns
bool Returns TRUE if the record should be skipped, FALSE otherwise.

◆ selectItems()

Drupal\tripal_chado\TripalStorage\ChadoRecords::selectItems ( string  $base_table,
string  $table_alias,
array  $options = [] 
)

Selects the items for a given table in a record object.

This function is used for the findValues() and loadValues() functions so it needs to be able to find multiple records from the base table and multiple items from an ancillary table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
array$options
  • global_max_delta = Maximum number of linked records from a single table to return, zero for no limit.
  • cardinalities = associative array of cardinalities on a per-table basis, key is table name. If present, these override global_max_delta.
  • inhibit = Publish no records if the number exceeds max_delta.
Exceptions

Exception

Returns
int Returns the number of items for this table that were found.

◆ setColumnValue()

Drupal\tripal_chado\TripalStorage\ChadoRecords::setColumnValue ( string  $base_table,
string  $table_alias,
int  $delta,
string  $column_alias,
  $value,
  $set_value = TRUE 
)
protected

Sets a value for a field that has already been added.

This is useful for after a query is run and the value needs to be set.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
int$deltaThe numeric index of the item.
string$column_aliasThe alias for the column.
mixed$valueThe value to set for the field.
bool$set_valueThe value that is being set is a valid value. Set to FALSE when clearing a value by setting it to zero.
Exceptions

Exception If the base_table, table_alias or delta don't exist then an error is thrown.

Returns
bool TRUE if the value was set, FALSE otherwise

◆ setConditionValue()

Drupal\tripal_chado\TripalStorage\ChadoRecords::setConditionValue ( string  $base_table,
string  $table_alias,
int  $delta,
string  $column_alias,
  $value,
  $is_or_condition = FALSE 
)

Sets the value for a condition that has been added.

A condition is used when querying to limit the set of records returned. A condition should not be added if the field for the same field has not been added first.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table.
int$deltaThe numeric index of the item.
string$column_aliasThe alias for the column.
mixed$valueThe value to set for the condition.
bool$is_or_conditionTrue if part of an OR condition group.
Exceptions

Exception If the item has not yet been added for the base table, table alias and delta then an exception is thrown.

◆ setLinks()

Drupal\tripal_chado\TripalStorage\ChadoRecords::setLinks ( string  $base_table)

Sets the record ID for all fields.

Record IDs may not be known when ChadoRecords is setup. For example, a field may be added that needs a link to a base table, but it may not yet be known, especially before an insert of the base record. This function should be run before a database operation like an insert, select, update, or delete, this function can be used to populate IDs that may have been set somewhere along the way for base tables.

Parameters
string$base_tableThe name of the Chado table used as a base table.

◆ setRecordID()

Drupal\tripal_chado\TripalStorage\ChadoRecords::setRecordID ( string  $base_table,
int  $record_id 
)
protected

Sets the record ID for a given base table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
int$record_idThe numeric record ID.
Exceptions

Exception If the base table is unknown then an error is thrown.

◆ updateRecords()

Drupal\tripal_chado\TripalStorage\ChadoRecords::updateRecords (   $base_table,
  $table_alias 
)

Updates all records for a single Chado table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
string$table_aliasThe alias of the table. For the base table, use the same table name as base tables don't have aliases.
Exceptions

Exception

◆ validate()

Drupal\tripal_chado\TripalStorage\ChadoRecords::validate ( )

Provides a series of validation checks on the ChadoRecord records.

If any of the records do not pass a validation check then these are returned as an array of violations.

Returns
array An array of ConstraintViolation objects.

◆ validateFKs()

Drupal\tripal_chado\TripalStorage\ChadoRecords::validateFKs (   $base_table,
  $delta,
  $record_id,
  $record 
)
protected

Checks that foreign key fields exist in the record for the given table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
int$deltaThe numeric index of the item.
int$record_idThe record ID for the base table.
array$recordThe field item to validate.

◆ validateRequired()

Drupal\tripal_chado\TripalStorage\ChadoRecords::validateRequired (   $base_table,
  $delta,
  $record_id,
  $record 
)
protected

Checks that required fields have values.

Parameters
string$base_tableThe name of the Chado table used as a base table.
int$deltaThe numeric index of the item.
int$record_idThe record ID for the base table.
array$recordThe field item to validate.

◆ validateSize()

Drupal\tripal_chado\TripalStorage\ChadoRecords::validateSize (   $base_table,
  $delta,
  $record_id,
  $record 
)
protected

Checks that size of the value isn't too large.

Parameters
string$base_tableThe name of the Chado table used as a base table.
int$deltaThe numeric index of the item.
int$record_idThe record ID for the base table.
array$recordThe field item to validate.

◆ validateTypes()

Drupal\tripal_chado\TripalStorage\ChadoRecords::validateTypes (   $base_table,
  $delta,
  $record_id,
  $record 
)
protected

Checks that foreign key values exist.

Parameters
string$base_tableThe name of the Chado table used as a base table.
int$deltaThe numeric index of the item.
int$record_idThe record ID for the base table.
array$recordThe field item to validate.

◆ validateUnique()

Drupal\tripal_chado\TripalStorage\ChadoRecords::validateUnique (   $base_table,
  $delta,
  $record_id,
  $record 
)
protected

Checks the unique constraint of the table.

Parameters
string$base_tableThe name of the Chado table used as a base table.
int$deltaThe numeric index of the item.
int$record_idThe record ID for the base table.
array$recordThe field item to validate.

The documentation for this class was generated from the following file: