class TripalTabDownloader

Hierarchy

Expanded class hierarchy of TripalTabDownloader

5 string references to 'TripalTabDownloader'
ChadoField.inc in tripal_chado/includes/TripalFields/ChadoField.inc
data__protein_sequence.inc in tripal_chado/includes/TripalFields/data__protein_sequence/data__protein_sequence.inc
data__sequence.inc in tripal_chado/includes/TripalFields/data__sequence/data__sequence.inc
TripalField.inc in tripal/includes/TripalFields/TripalField.inc
tripal_get_field_field_formatters in tripal/api/tripal.fields.api.inc
Retrieves a list of field formatters compatible with a given field.

File

tripal/includes/TripalFieldDownloaders/TripalTabDownloader.inc, line 3

View source
class TripalTabDownloader extends TripalFieldDownloader {
  /**
   * Sets the label shown to the user describing this formatter.  It
   * should be a short identifier. Use the $full_label for a more
   * descriptive label.
   */
  static public $label = 'TAB';

  /**
   * A more verbose label that better describes the formatter.
   */
  static public $full_label = 'Tab delimeted';

  /**
   * Indicates the default extension for the outputfile.
   */
  static public $default_extension = 'txt';

  /**
   * @see TripalFieldDownloader::isFieldSupported()
   */
  public function isFieldSupported($field, $instance) {
    $is_supported = parent::isFieldSupported($field, $instance);

    // For now all fields are supported.
    return TRUE;
  }

  /**
   * @see TripalFieldDownloader::formatEntity()
   */
  protected function formatEntity($entity) {
    $bundle_name = $entity->bundle;
    $site = !property_exists($entity, 'site_id') ? 'local' : $entity->site_id;
    $col = array();

    // Iterate through all of the printable fields and add the value to
    // the row.
    foreach ($this->printable_fields as $accession => $label) {

      // If this field is not present for this entity then add an empty
      // element and move on.
      if (!array_key_exists($accession, $this->fields2terms[$site][$bundle_name]['by_accession'])) {
        $col[] = '';
        continue;
      }

      // Get the field from the class variables.
      $field_id = $this->fields2terms[$site][$bundle_name]['by_accession'][$accession];
      $field = $this->fields[$site][$bundle_name][$field_id]['field'];
      $instance = $this->fields[$site][$bundle_name][$field_id]['instance'];
      $field_name = $field['field_name'];

      // If we only have one item for this value then add it.
      if (count($entity->{$field_name}['und']) == 1) {
        $value = $entity->{$field_name}['und'][0]['value'];

        // If the single element is not an array then this is good.
        if (!is_array($value)) {
          $col[] = $value;
        }
        else {
          if (array_key_exists('rdfs:label', $value)) {
            $label = $entity->{$field_name}['und'][0]['value']['rdfs:label'];
            $col[] = strip_tags($label);
          }
          elseif (array_key_exists('schema:description', $value)) {
            $label = $entity->{$field_name}['und'][0]['value']['schema:description'];
            $col[] = strip_tags($label);
          }
          else {
            $col[] = '';
          }
          // TODO: What to do with fields that are arrays?
        }
      }
      // If we have multiple items then deal with that.
      else {
        $col[] = '';
        // TODO: What to do with fields that have multiple values?
      }
    }
    return array(implode("\t", $col));
  }

  /**
   * @see TripalFieldDownloader::getHeader()
   */
  protected function getHeader() {
    $row = array();
    foreach ($this->printable_fields as $accession => $label) {
      $row[] = $label;
    }
    return array(implode("\t", $row));
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
TripalFieldDownloader::$collection protected property The data collection assigned to this downloader.
TripalFieldDownloader::$collection_bundles protected property An array of collection_bundle records for the content types that belong to this data collection.
TripalFieldDownloader::$collection_id protected property The collection ID
TripalFieldDownloader::$fh protected property The file handle for an opeend file using during writing.
TripalFieldDownloader::$fields protected property A list of field and instance items, indexed first by site_id with 'local' being the key for local fields and the numeric site_id for remote fields. The second-levle key is the bundle_name and the the field_id. Below the field_id are the…
TripalFieldDownloader::$fields2terms protected property An array that associates a field ID with a term.
TripalFieldDownloader::$outfile protected property The output file URI.
TripalFieldDownloader::$printable_fields protected property An array of printable fields. Because fields can come from multiple bundles and those bundles can be from multiple sites, it is possible that 1) two bundles use the same field and we want to conslidate to a single printable field; and 2) that a…
TripalFieldDownloader::$remote_entity protected property The remote site json data returned for the entity
TripalFieldDownloader::delete public function Removes the downloadable file.
TripalFieldDownloader::download public function Setups a download stream for the file.
TripalFieldDownloader::getURL public function Retrieves the URL for the downloadable file.
TripalFieldDownloader::setFields protected function Sets the fields array
TripalFieldDownloader::setFields2Terms protected function Sets the fields2term array.
TripalFieldDownloader::setLocalFields private function A helper function for the setFields() function.
TripalFieldDownloader::setPrintableFields protected function Conslidates all the fields into a single list of accession numbers.
TripalFieldDownloader::setRemoteFields private function A helper function for the setFields() function.
TripalFieldDownloader::write public function Creates the downloadable file.
TripalFieldDownloader::writeDone public function Closes the output file once writing of all entities is completed.
TripalFieldDownloader::writeEntity public function Write a single entity to the file.
TripalFieldDownloader::writeInit public function
TripalFieldDownloader::__construct public function Constructs a new instance of the TripalFieldDownloader class.
TripalTabDownloader::$default_extension static public property Indicates the default extension for the outputfile. Overrides TripalFieldDownloader::$default_extension
TripalTabDownloader::$full_label static public property A more verbose label that better describes the formatter. Overrides TripalFieldDownloader::$full_label
TripalTabDownloader::$label static public property Sets the label shown to the user describing this formatter. It should be a short identifier. Use the $full_label for a more descriptive label. Overrides TripalFieldDownloader::$label
TripalTabDownloader::formatEntity protected function Overrides TripalFieldDownloader::formatEntity
TripalTabDownloader::getHeader protected function Overrides TripalFieldDownloader::getHeader
TripalTabDownloader::isFieldSupported public function Overrides TripalFieldDownloader::isFieldSupported