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

Public Member Functions

 __construct (array $configuration, $plugin_id, $plugin_definition, ChadoConnection $connection)
 
 label ()
 
 description ()
 

Static Public Member Functions

static create (ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
 

Public Attributes

ChadoConnection $connection
 

Protected Member Functions

 getTableColumns (array $chado_tables, string $filter='all')
 
 getTableCache ()
 
 addTableToCache (string $chado_table, array &$cached_tables)
 
 makeUpsertConditions (array $values, array $key_columns)
 
 makeAlias (string $name)
 
 unmakeAlias (string $name)
 
 removeTablePrefix (array $values)
 
 addConditions (object &$query, array $conditions, array $options)
 
 validateInput (array $user_values, array $valid_values)
 
 dereferenceBuddyRecord (array $values)
 
 subsetInput (array $user_values, array $valid_tables)
 
 validateOutput ($output_records, array $values)
 

Detailed Description

Base class for chado_buddy plugins.

Constructor & Destructor Documentation

◆ __construct()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::__construct ( array  $configuration,
  $plugin_id,
  $plugin_definition,
ChadoConnection  $connection 
)

{}

Member Function Documentation

◆ addConditions()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::addConditions ( object &  $query,
array  $conditions,
array  $options 
)
protected

Adds the conditions to the database query. Implements case insensitive queries if requested.

Parameters
object$queryAssociative array where keys are table name+dot+table column.
array$conditionsAssociative array of conditions to add to the query.
object$optionsAssociative array of options as passed to the calling buddy function. The option 'case_insensitive' can contain a single key string, or an array of multiple keys for which a case insensitive query is desired.

◆ addTableToCache()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::addTableToCache ( string  $chado_table,
array &  $cached_tables 
)
protected

Add a chado table to the cache, used only by getTableColumns()

Parameters
string$chado_tableName of the table to add
array$cached_tablesSchema information will be inserted in this array for the table indicated above. The array follows this format:
    • 'all':
      • <field name>: TRUE
    • 'required':
      • <field name>: TRUE|FALSE depending on if this field is not null and doesn't have a default.
    • 'unique':
      • <field name>: TRUE|FALSE depending on if this field is in a unique constraint.
Returns
void

◆ create()

static Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::create ( ContainerInterface  $container,
array  $configuration,
  $plugin_id,
  $plugin_definition 
)
static

Implements ContainerFactoryPluginInterface->create().

Since we have implemented the ContainerFactoryPluginInterface this static function will be called behind the scenes when a Plugin Manager uses createInstance(). Specifically this method is used to determine the parameters to pass to the constructor.

Parameters
\Symfony\Component\DependencyInjection\ContainerInterface$container
array$configuration
string$plugin_id
mixed$plugin_definition
Returns
static

Reimplemented in Drupal\tripal_chado\Plugin\ChadoBuddy\ChadoCvtermBuddy, and Drupal\tripal_chado\Plugin\ChadoBuddy\ChadoPropertyBuddy.

◆ dereferenceBuddyRecord()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::dereferenceBuddyRecord ( array  $values)
protected

Used to dereference a ChadoBuddyRecord in the $values array into its component values.

Parameters
array$valuesAn associative array to be validated. Keys are table+dot+column name, values are the database table values. The special case value of 'buddy_record' => ChadoBuddyRecord will have its component values appended to the values. In the case of a duplicated key, if the value in the ChadoBuddyRecord is different from the one in the array, then an exception is thrown.
Returns
array Merged associative array of values
Exceptions
Drupal

tripal_chado\ChadoBuddy\Exceptions\ChadoBuddyException If the key 'buddy_record' does not have a ChadoBuddyRecord as its value. If a value inside the ChadoBuddyRecord is different than one in the $values array.

◆ description()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::description ( )

{}

◆ getTableCache()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::getTableCache ( )
protected

Retrieves the chado table definition cache used by getTableColumns().

Returns
array An array describing the fields of any cached tables. The array follows this format:
    • 'all':
      • <field name>: TRUE
    • 'required':
      • <field name>: TRUE|FALSE depending on if this field is not null and doesn't have a default.
    • 'unique':
      • <field name>: TRUE|FALSE depending on if this field is in a unique constraint.

◆ getTableColumns()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::getTableColumns ( array  $chado_tables,
string  $filter = 'all' 
)
protected

Retrieve a list of table columns for one or more chado tables. Schema information is cached for better performance.

Parameters
array$chado_tablesOne or more chado table names.
string$filter'required' = return columns that [1]: have a NOT NULL constraint, and [2]: do not have a default value and are not serial, such as a primary key. In other words, a column with a NOT NULL constraint but with some form of a default value is considered to be not required. 'unique' = return only columns that are part of any unique constraint. 'all' (default) or anything else = return all columns.
Returns
array An array of table+dot+column name, e.g. for 'db' table: ['db.db_id', 'db.name', 'db.description', 'db.urlprefix', 'db.url']
Exceptions
Drupal

tripal_chado\ChadoBuddy\Exceptions\ChadoBuddyException For invalid table name.

◆ label()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::label ( )

{Returns the translated plugin label.}

Implements Drupal\tripal_chado\ChadoBuddy\Interfaces\ChadoBuddyInterface.

◆ makeAlias()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::makeAlias ( string  $name)
protected

Replace the first period with a double underscore This makes the string valid as a table column alias.

Parameters
string$nametable name+dot+table column
Returns
string The first period is replaced with double underscore.

◆ makeUpsertConditions()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::makeUpsertConditions ( array  $values,
array  $key_columns 
)
protected

Used by upsert functions to generate a subset of values using only key columns, e.g. 'name' for cv table. The key columns are those which are present in any of the unique constraints that the table may have.

Parameters
array$valuesAn associative array where the key is the table.column_name.
array$key_columnsOnly column keys in this list should be returned.
Returns
array The subset of the passed $values array.

◆ removeTablePrefix()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::removeTablePrefix ( array  $values)
protected

Removes the table prefix from $values keys so that they can be used directly in an INSERT. The prefix is anything up to and including the first period.

Parameters
array$valuesAssociative array where keys are table name+dot+table column.
Returns
array The keys have had the table name prefix removed, values are unchanged.

◆ subsetInput()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::subsetInput ( array  $user_values,
array  $valid_tables 
)
protected

Used to return a subset of values applicable to a single chado table, e.g. remove db table columns when inserting a new dbxref.

Parameters
array$user_valuesAn associative array to be filtered. Keys are table+dot+column name, values are for that table+column.
array$valid_tablesAn array listing which tables should have keys returned.
Returns
array The subset of passed $user_values with table prefixes present in the $valid_tables array.
Exceptions
Drupal

tripal_chado\ChadoBuddy\Exceptions\ChadoBuddyException If after subsetting there is nothing left.

◆ unmakeAlias()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::unmakeAlias ( string  $name)
protected

Replace the first double underscore with a period. This reverts the change made by the makeAlias() function.

Parameters
string$nametable name+__+table column
Returns
string The first __ is replaced with a period.

◆ validateInput()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::validateInput ( array  $user_values,
array  $valid_values 
)
protected

Used to validate input arrays to various buddy functions.

Parameters
array$user_valuesAn associative array to be validated. Keys are table+dot+column name, values are the database table values.
array$valid_valuesAn array listing all valid keys for $user_values.
Exceptions
Drupal

tripal_chado\ChadoBuddy\Exceptions\ChadoBuddyException If $user_values array is empty. If a key in $user_values is not in $valid_values.

◆ validateOutput()

Drupal\tripal_chado\ChadoBuddy\ChadoBuddyPluginBase::validateOutput (   $output_records,
array  $values 
)
protected

Used to validate results from a buddy function, to ensure there is exactly one record present.

Parameters
mixed$output_recordsAn array of zero or more ChadoBuddyRecords. To be valid, it must contain exactly one ChadoBuddyRecord.
array$valuesPass query values to print if an exception is thrown.
Exceptions
Drupal

tripal_chado\ChadoBuddy\Exceptions\ChadoBuddyException If not exactly one record is present.


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