class chado_linker__prop

Hierarchy

Expanded class hierarchy of chado_linker__prop

5 string references to 'chado_linker__prop'
chado_linker__prop_formatter.inc in tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_formatter.inc
chado_linker__prop_widget.inc in tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_widget.inc
tripal_chado_bundle_create_user_field in tripal_chado/includes/tripal_chado.fields.inc
Implements hook_bundle_create_user_field().
tripal_chado_bundle_fields_info_linker in tripal_chado/includes/tripal_chado.fields.inc
tripal_chado_form_field_ui_field_edit_form_alter in tripal_chado/tripal_chado.module
Implements hook_form_FORM_ID_alter().

File

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

View source
class chado_linker__prop extends ChadoField {


  // --------------------------------------------------------------------------
  //                     EDITABLE STATIC CONSTANTS
  //
  // The following constants SHOULD be set for each descendent class.  They are
  // used by the static functions to provide information to Drupal about
  // the field and it's default widget and formatter.
  // --------------------------------------------------------------------------

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

  // The default description for this field.
  public static $description = 'Add details about this property.';

  // 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' => 'local',
    // The name of the term.
    'term_name' => 'property',
    // The unique ID (i.e. accession) of the term.
    'term_accession' => 'property',
    // 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 primary key column of hte table in Dhado.
    'chado_column' => '',
    // The base table.
    'base_table' => '',
    // The number of default rows to show. The default is 1.
    'rows' => 1,
  );

  // The default widget for this field.
  public static $default_widget = 'chado_linker__prop_widget';

  // The default formatter for this field.
  public static $default_formatter = 'chado_linker__prop_formatter';

  // A boolean specifying that users should not be allowed to create
  // fields and instances of this field type through the UI. Such
  // fields can only be created programmatically with field_create_field()
  // and field_create_instance().
  public static $no_ui = FALSE;

  /**
   *
   * @see TripalField::load()
   */
  public function load($entity) {
    $field_name = $this->field['field_name'];
    $field_type = $this->field['type'];
    $field_table = $this->instance['settings']['chado_table'];
    $field_column = $this->instance['settings']['chado_column'];
    $base_table = $this->instance['settings']['base_table'];

    $vocabulary = $this->instance['settings']['term_vocabulary'];
    $accession = $this->instance['settings']['term_accession'];
    $cvterm = chado_get_cvterm(array(
      'dbxref_id' => array(
        'db_id' => array(
          'name' => $vocabulary,
        ),
        'accession' => $accession,
      ),
    ));
    $cvterm_id = $cvterm->cvterm_id;

    // Get the FK that links to the base record.
    $schema = chado_get_schema($field_table);
    $pkey = $schema['primary key'][0];
    if (!isset($schema['foreign keys'][$base_table]['columns'])) {
      return;
    }
    $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
    $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];

    // Set some defaults for the empty record.
    $chado_record = $entity->chado_record;
    $entity->{$field_name}['und'][0] = array(
      'value' => '',
      'chado-' . $field_table . '__' . $pkey => '',
      'chado-' . $field_table . '__' . $fkey_lcolumn => $chado_record->$fkey_lcolumn,
      'chado-' . $field_table . '__value' => '',
      'chado-' . $field_table . '__type_id' => $cvterm_id,
      'chado-' . $field_table . '__rank' => '',
    );

    // Get the properties associated with this record for the given type.
    $columns = array('*');
    $match = array(
      $fkey_lcolumn => $chado_record->{$fkey_lcolumn},
      'type_id' => $cvterm_id,
    );
    $options = array(
      'return_array' => TRUE,
      'order_by' => array('rank' => 'ASC')
    );
    $properties = chado_select_record($field_table, $columns, $match, $options);
    for ($i = 0; $i < count($properties); $i++) {
      $property = $properties[$i];
      foreach ($schema['fields'] as $fname => $details) {
        $entity->{$field_name}['und'][$i] = array(
          'value' => $property->value,
          'chado-' . $field_table . '__' . $pkey => $property->$pkey,
          'chado-' . $field_table . '__' . $fkey_lcolumn => $property->$fkey_lcolumn,
          'chado-' . $field_table . '__value' => $property->value,
          'chado-' . $field_table . '__type_id' => $property->type_id,
          'chado-' . $field_table . '__rank' => $property->rank,
        );
      }
    }

    // Ensure there are no values if there are no properties.
    // This is necessary to make sure the field is not rendered when there are no properies.
    // @todo: We should revisit this in the future as none of the other fields do this.
    //        It was added here to make it easier to detect when the field was empty
    //        but in hindsight, we would just check $entity->{$field_name}['und'][$i]['value']
    //        in the formatter.
    if (empty($properties)) {
      unset($entity->{$field_name});
    }
  }

  /**
   * @see ChadoField::query()
   */
  public function query($query, $condition) {
    $prop_linker = $this->instance['settings']['chado_table'];
    $base_table = $this->instance['settings']['base_table'];

    $bschema = chado_get_schema($base_table);
    $bpkey = $bschema['primary key'][0];
    $alias = $this->field['field_name'];
    $operator = $condition['operator'];

    $vocab = $this->instance['settings']['term_vocabulary'];
    $accession = $this->instance['settings']['term_accession'];

    $cvterm = chado_get_cvterm(array('id' => $vocab . ':' . $accession));

    $this->queryJoinOnce($query, $prop_linker, $alias, "base.$bpkey = $alias.$bpkey");
    $query->condition("$alias.type_id", $cvterm->cvterm_id);
    $query->condition("$alias.value", $condition['value'], $operator);

  }

  /**
   * @see ChadoField::query()
   */
  public function queryOrder($query, $order) {
    $prop_linker = $this->instance['settings']['chado_table'];
    $base_table = $this->instance['settings']['base_table'];

    $bschema = chado_get_schema($base_table);
    $bpkey = $bschema['primary key'][0];
    $alias = $this->field['field_name'];

    $vocab = $this->instance['settings']['term_vocabulary'];
    $accession = $this->instance['settings']['term_accession'];

    $cvterm = chado_get_cvterm(array('id' => $vocab . ':' . $accession));

    $this->queryJoinOnce($query, $prop_linker, $alias, "base.$bpkey = $alias.$bpkey AND $alias.type_id = $cvterm->cvterm_id", "LEFT OUTER");
    $query->orderBy("$alias.value", $order['direction']);
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
ChadoField::$default_description public static property Overrides TripalField::$default_description
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::queryJoinOnce protected function A convient way to join a table to a query without duplicates.
chado_linker__prop::$default_formatter public static property Overrides TripalField::$default_formatter
chado_linker__prop::$default_instance_settings public static property Overrides ChadoField::$default_instance_settings
chado_linker__prop::$default_label public static property Overrides ChadoField::$default_label
chado_linker__prop::$default_widget public static property Overrides TripalField::$default_widget
chado_linker__prop::$description public static property
chado_linker__prop::$no_ui public static property Overrides TripalField::$no_ui
chado_linker__prop::load public function Overrides TripalField::load
chado_linker__prop::query public function Overrides ChadoField::query
chado_linker__prop::queryOrder public function Overrides ChadoField::queryOrder
TripalField::$field protected property
TripalField::$instance protected property
TripalField::$no_data 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::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.