class ChadoField

Hierarchy

Expanded class hierarchy of ChadoField

File

tripal_chado/includes/TripalFields/ChadoField.inc, line 3

View source
class ChadoField extends TripalField {

  // The default lable for this field.
  public static $default_label = 'Chado Field';

  // The default description for this field.
  public static $default_description = 'The generic base class for all Chado fields. Replace this text as appropriate for the child implementation.';

  // A list of global settings. These can be accessed within the
  // globalSettingsForm.  When the globalSettingsForm is submitted then
  // Drupal will automatically change these settings for all fields.
  // Once instances exist for a field type then these settings cannot be
  // changed.
  public static $default_settings = array(
    'storage' => 'field_chado_storage',
  );

  // Provide a list of instance specific settings. These can be access within
  // the instanceSettingsForm.  When the instanceSettingsForm is submitted
  // then Drupal with automatically change these settings for the instnace.
  // It is recommended to put settings at the instance level whenever possible.
  // If you override this variable in a child class be sure to replicate the
  // term_name, term_vocab, term_accession and term_fixed keys as these are
  // required for all TripalFields.
  public static $default_instance_settings = array(
    // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
    'term_vocabulary' => 'schema',
    // The name of the term.
    'term_name' => 'Thing',
    // The unique ID (i.e. accession) of the term.
    'term_accession' => 'Thing',
    // Set to TRUE if the site admin is allowed to change the term
    // type. This will create form elements when editing the field instance
    // to allow the site admin to change the term settings above.
    'term_fixed' => FALSE,
    // The table in Chado that the instance maps to.
    'chado_table' => '',
    // The column of the table in Chado where the value of the field comes from.
    'chado_column' => '',
    // The base table.
    'base_table' => '',
  );

  // Indicates the download formats for this field.  The list must be the
  // name of a child class of the TripalFieldDownloader.
  public static $download_formatters = array(
    'TripalTabDownloader',
    'TripalCSVDownloader',
  );

  // The module that manages this field.
  public static $module = 'tripal_chado';

  /**
   * @see TripalField::query()
   *
   * In addition to the rules to follow for the TripalField::query function
   * these should also be followed for the ChadoField::query implementation.
   *
   * - When giving alias to joined tables be sure to use aliases that are
   *   unique to avoid conflicts with other fields.
   * - When joining with the base table its alias is 'base'.
   * - You may join to materialized views if need be to help speed queries.
   */
  public function query($query, $condition) {
    // If we are here it is because the child class did not implement the
    // query function.  So, we will do our best to make the query work.
    $chado_table = $this->instance['settings']['chado_table'];
    $base_table = $this->instance['settings']['base_table'];
    $bschema = chado_get_schema($base_table);
    $bpkey = $bschema['primary key'][0];
    $alias = 'dbx_linker';
    $operator = $condition['operator'];

    // If the chado_table and the base_table are the same then this is easy.
    if ($chado_table == $base_table) {
      // Get the base table column that is associated with the term
      // passed as $condition['column'].
      $base_field = chado_get_semweb_column($chado_table, $condition['column']);
      $query->condition('base.' . $base_field, $condition['value'], $operator);
    }
    else {
      // If the two are not the same then we expect that the child class
      // will implement a query() function.
    }
  }

  /**
   * @see TripalField::queryOrder()
   */
  public function queryOrder($query, $order) {


    // If we are here it is because the child class did not implement the
    // queryOrder function.  So, we will do our best to make the query work.
    $chado_table = $this->instance['settings']['chado_table'];
    $base_table = $this->instance['settings']['base_table'];
    $bschema = chado_get_schema($base_table);
    $bpkey = $bschema['primary key'][0];
    $alias = 'dbx_linker';
    $operator = $condition['operator'];

    // If the chado_table and the base_table are the same then this is easy.
    if ($chado_table == $base_table) {
      // Get the base table column that is associated with the term
      // passed as $condition['column'].
      $base_field = chado_get_semweb_column($chado_table, $order['column']);
      $query->orderBy('base.' . $base_field, $order['direction']);
    }
    else {
      // If the two are not the same then we expect that the child class
      // will implement a query() function.
    }
  }

  /**
   * A convient way to join a table to a query without duplicates.
   *
   * @param $query
   *   The SelectQuery object.
   * @param $table
   *   The table to join.
   * @param $alias
   *   The table alias to use.
   * @param $condition
   *   The join condition.
   * @param $type
   *   The type of join: INNER, LEFT OUTER, or RIGHT OUTER.
   */
  protected function queryJoinOnce($query, $table, $alias, $condition, $type = 'INNER') {
    $joins = $query->getTables();

    // If this join is already present then don't add it again.
    if (in_array($alias, array_keys($joins))) {
      return;
    }

    switch ($type) {
      case 'LEFT OUTER':
        $query->leftjoin($table, $alias, $condition);
        break;
      case 'RIGHT OUTER':
        $query->rightjoin($table, $alias, $condition);
        break;
      default:
        $query->innerjoin($table, $alias, $condition);
    }
  }

  /**
   * @see TripalField::instanceSettingsForm()
   */
  public function instanceSettingsForm() {
    // Make sure we don't lose our Chado table mappings when the settings
    // are updated.  Setting them as values in the form ensures they don't
    // get accidentally overwritten.
    $element['base_table'] = array(
      '#type' => 'value',
      '#value' => $this->instance['settings']['base_table'],
    );
    $element['chado_table'] = array(
      '#type' => 'value',
      '#value' => $this->instance['settings']['chado_table'],
    );
    $element['chado_column'] = array(
      '#type' => 'value',
      '#value' => $this->instance['settings']['chado_column'],
    );
    return $element;
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
ChadoField::$default_description public static property Overrides TripalField::$default_description
ChadoField::$default_instance_settings public static property Overrides TripalField::$default_instance_settings
ChadoField::$default_label public static property Overrides TripalField::$default_label
ChadoField::$default_settings public static property Overrides TripalField::$default_settings
ChadoField::$download_formatters public static property Overrides TripalField::$download_formatters
ChadoField::$module public static property Overrides TripalField::$module
ChadoField::instanceSettingsForm public function Overrides TripalField::instanceSettingsForm
ChadoField::query public function In addition to the rules to follow for the TripalField::query function these should also be followed for the ChadoField::query implementation. Overrides TripalField::query
ChadoField::queryJoinOnce protected function A convient way to join a table to a query without duplicates.
ChadoField::queryOrder public function Overrides TripalField::queryOrder
TripalField::$default_formatter public static property
TripalField::$default_widget public static property
TripalField::$field protected property
TripalField::$instance protected property
TripalField::$no_data public static property
TripalField::$no_ui public static property
TripalField::$term protected property
TripalField::createInstance public function After a field instance is created the following function is run.
TripalField::elementInfo public function Provides the list of elements returned by the 'value' of the field.
TripalField::getField public function
TripalField::getFieldName public function Retrives the name of this field.
TripalField::getFieldTerm public function
TripalField::getFieldTermID public function
TripalField::getInstance public function
TripalField::getPagerElementID protected function When constructing a pager for use by a field, all pagers must have a unique ID
TripalField::info public static function Provides default information about this field type
TripalField::instanceSettingsFormValidate public function Provides validation of the instance settings form.
TripalField::load public function Loads the field values from the underlying data store.
TripalField::settingsForm public function Provides a form for the 'Field Settings' of the field management page.
TripalField::settingsFormValidate public function _state
TripalField::validate public function Perform validation of the field regardless how it is updated.
TripalField::viewsData public function Describes this field to Views.
TripalField::webServicesData public function Describes this field to Tripal web services.
TripalField::_addViewsDataElement protected function
TripalField::_addWebServiceElement protected function
TripalField::__construct public function Instantiates a new TripalField object.