<?php

// This conditional is added to prevent errors in the biomaterial TOC admin page.
if (property_exists($variables['node'], 'biomaterial')) {
    $biomaterial = $variables['node']->biomaterial;
    $biomaterial = chado_expand_var($biomaterial, 'field', 'biomaterial.description');
    $ontology_terms = $variables['biomaterial_ontology_terms'];
    ?>

    <div class="tripal_biomaterial-data-block-desc tripal-data-block-desc"></div>

  <?php 
    $analysis_name = $variables['analysis_name'];
    $analysis_nid = $variables['analysis_nid'];
    $headers = array();
    $rows = array();
    // The biomaterial name.
    $rows[] = array(array('data' => 'Biomaterial', 'header' => TRUE, 'width' => '20%'), '<i>' . $biomaterial->name . '</i>');
    // The organism from which the biomaterial was collected
    if ($biomaterial->taxon_id) {
        $organism = '<i>' . $biomaterial->taxon_id->genus . ' ' . $biomaterial->taxon_id->species . '</i> (' . $biomaterial->taxon_id->common_name . ')';
        if (property_exists($biomaterial->taxon_id, 'nid')) {
            $organism = l('<i>' . $biomaterial->taxon_id->genus . ' ' . $biomaterial->taxon_id->species . '</i> (' . $biomaterial->taxon_id->common_name . ')', 'node/' . $biomaterial->taxon_id->nid, array('html' => TRUE));
        }
        $rows[] = array(array('data' => 'Organism', 'header' => TRUE, 'width' => '20%'), $organism);
    }
    // The analysis
    if ($analysis_name) {
        $analysis = $analysis_name;
        if ($analysis_nid) {
            $analysis = l($analysis_name, 'node/' . $analysis_nid, array('html' => TRUE));
<?php

// This line is added so that no errors show in the TOC admin page.
if (property_exists($variables['node'], 'arraydesign')) {
    $arraydesign = $variables['node']->arraydesign;
    $arraydesign = chado_expand_var($arraydesign, 'table', 'arraydesignprop', array('return_array' => 1));
    $properties = $arraydesign->arraydesignprop;
    // Check for properties.
    if (count($properties) > 0) {
        ?>
      <div class="tripal_arraydesign-data-block-desc tripal-data-block-desc">Additional information about this array design:</div><?php 
        $header = array('Property Name', 'Value');
        $rows = array();
        foreach ($properties as $property) {
            $rows[] = array(ucfirst(preg_replace('/_/', ' ', $property->type_id->name)), $property->value);
        }
        $table = array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => 'tripal_arraydesign-table-properties', 'class' => 'tripal-data-table'), 'sticky' => FALSE, 'caption' => '', 'colgroups' => array(), 'empty' => '');
        print theme_table($table);
    }
}
<?php

// This conditional is added to prevent errors in the array design TOC admin page.
if (property_exists($variables['node'], 'protocol')) {
    $protocol = $variables['node']->protocol;
    $protocol = chado_expand_var($protocol, 'field', 'protocol.protocoldescription');
    $protocol = chado_expand_var($protocol, 'field', 'protocol.hardwaredescription');
    $protocol = chado_expand_var($protocol, 'field', 'protocol.softwaredescription');
    //$protocol = chado_expand_var($protocol, 'field', 'arraydesign.description');
    ?>

    <div class="tripal_protocol-data-block-desc tripal-data-block-desc"></div>

  <?php 
    $headers = array();
    $rows = array();
    // The protocol name.
    $rows[] = array(array('data' => 'Protocol', 'header' => TRUE, 'width' => '20%'), '<i>' . $protocol->name . '</i>');
    // The protocol type
    $rows[] = array(array('data' => 'Protocol Type', 'header' => TRUE, 'width' => '20%'), '<i>' . $protocol->type_id->name . '</i>');
    // The protocol link.
    if ($protocol->uri) {
        $rows[] = array(array('data' => 'Protocol Link', 'header' => TRUE, 'width' => '20%'), '<i><a href="' . $protocol->uri . '"> Protocol </a></i>');
    }
    // The protocol link.
    if ($protocol->pub_id) {
        $rows[] = array(array('data' => 'Publication', 'header' => TRUE, 'width' => '20%'), '<i>' . l($protocol->pub_id->title, '/node/' . $protocol->pub_id->nid) . '</i>');
    }
    // allow site admins to see the protocol ID
    if (user_access('view ids')) {
        // Protocol ID
             $dbname_accession = $feature_dbxref->dbxref_id->db_id->name . ":" . $feature_dbxref->dbxref_id->accession;
             if ($feature_dbxref->dbxref_id->db_id->urlprefix) {
                 $references .= l($dbname_accession, $feature_dbxref->dbxref_id->db_id->urlprefix . $feature_dbxref->dbxref_id->accession, array('attributes' => array('target' => '_blank'))) . "<br>";
             } else {
                 $references .= $dbname_accession . "<Br>";
             }
         }
         // if closes
     }
     // foreach closes
 }
 // if cound closes
 // Dbxref row
 $references = !empty($references) ? $references : 'None';
 $rows[] = array(array('data' => 'Dbxref', 'header' => TRUE), $references);
 $feature = chado_expand_var($feature, 'table', 'analysisfeature', $options);
 $analyses = $feature->subject_id->analysisfeature;
 $src_values = array('feature_id' => $feature->subject_id->featureloc->feature_id->srcfeature_id->feature_id);
 $srcfeature = chado_generate_var('analysisfeature', $src_values, $options);
 //echo "<prE>"; print_r($analyses);	   echo "</prE>";
 // Analyses - if and else statements cause the anaylses having different array formats.
 $analysis_name = '';
 if (count($analyses) == 2) {
     foreach ($analyses as $analysis) {
         $a_name = $analysis->analysis_id->name;
         if (property_exists($analysis->analysis_id, 'nid')) {
             //$options['target'] = '_blank';
             $analysis_name .= l($a_name, "node/" . $analysis->analysis_id->nid) . "<bR>";
         }
     }
 } else {
<?php

// This line is added so that no errors show in the TOC admin page.
if (property_exists($variables['node'], 'biomaterial')) {
    $biomaterial = $variables['node']->biomaterial;
    $biomaterial = chado_expand_var($biomaterial, 'table', 'biomaterialprop', array('return_array' => 1));
    $properties = $biomaterial->biomaterialprop;
    // Check for properties.
    if (count($properties) > 0) {
        ?>
      <div class="tripal_biomaterial-data-block-desc tripal-data-block-desc">Additional information about this biomaterial:</div><?php 
        $headers = array('Property Name', 'Value');
        $rows = array();
        foreach ($properties as $property) {
            $rows[] = array(ucfirst(preg_replace('/_/', ' ', $property->type_id->name)), $property->value);
        }
        $table = array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => 'tripal_biomaterial-table-properties', 'class' => 'tripal-data-table'), 'sticky' => FALSE, 'caption' => '', 'colgroups' => array(), 'empty' => '');
        print theme_table($table);
    }
}
<?php

$node = $variables['node'];
$protocol = $variables['node']->protocol;
$protocol = chado_expand_var($protocol, 'field', 'protocol.protocoldescription');
?>

<div class="tripal_protocol-teaser tripal-teaser">
  <div class="tripal-protocol-teaser-title tripal-teaser-title"><?php 
print l($node->title, "node/{$node->nid}", array('html' => TRUE));
?>
  </div>
  <div class="tripal_protocol-teaser-text tripal-teaser-text"><?php 
print substr($protocol->protocoldescription, 0, 650);
if (strlen($protocol->protocoldescription > 650)) {
    print "... " . l("[more]", "node/{$node->nid}");
}
?>
  </div>
</div>

<?php

$node = $variables['node'];
$analysis = $variables['node']->analysis;
$analysis = chado_expand_var($analysis, 'table', 'analysisprop', array('return_array' => 1));
$properties = $analysis->analysisprop;
$expression = $node->analysis->tripal_analysis_expression;
if ($variables['assay_protocol'] != '' or $variables['acquisition_protocol'] != '' or $variables['quantification_protocol'] != 0) {
    ?>

<div class="tripal__analysis-data-block-desc tripal-data-block-desc">Protocols used in the process of the experiment.</div><?php 
    $header = array('Protocol', 'Type', 'Date Run');
    $rows = array();
    if ($variables['assay_protocol'] != '') {
        $rows[] = array($variables['assay_protocol'][0]->name, 'Assay', preg_replace("/^(\\d+-\\d+-\\d+) .*/", "\$1", $variables['assaydate']));
    }
    if ($variables['acquisition_protocol'] != '') {
        $rows[] = array($variables['acquisition_protocol'][0]->name, 'Acquistion', preg_replace("/^(\\d+-\\d+-\\d+) .*/", "\$1", $variables['acquisitiondate']));
    }
    if ($variables['quantification_protocol'] != '') {
        $rows[] = array($variables['quantification_protocol'][0]->name, 'Quantification', preg_replace("/^(\\d+-\\d+-\\d+) .*/", "\$1", $variables['quantificationdate']));
    }
    if (!empty($rows)) {
        $table = array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'tripal_protocol-table-properties', 'class' => 'tripal_data_table'), 'sticky' => FALSE, 'caption' => '', 'colgroups' => array(), 'empty' => '');
        print theme_table($table);
    }
}
?>

<?php

/*
 * phylotree analyis template
 */
$node = $variables['node'];
$phylotree = $node->phylotree;
$header = array('Name', 'Description', 'Metadata');
$analysis = $phylotree->analysis_id;
$rows = array();
if ($analysis) {
    $analysis = chado_expand_var($analysis, 'field', 'analysis.description');
    $rows[] = array($analysis->name, $analysis->description, sprintf('%s %s %s %s %s %s %s', $analysis->program, $analysis->programversion, $analysis->algorithm, $analysis->sourcename, $analysis->sourceversion, $analysis->sourceuri, $analysis->timeexecuted));
} else {
    // degrade gracefully if no analysis is present
    $rows[] = array('n/a', '', '');
}
$table = array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'tripal_phylotree-table-analysis', 'class' => 'tripal-data-table'), 'sticky' => FALSE, 'caption' => '', 'colgroups' => array(), 'empty' => '');
print theme_table($table);
<?php

// This conditional is added to prevent errors in the array design TOC admin page.
if (property_exists($variables['node'], 'arraydesign')) {
    $arraydesign = $variables['node']->arraydesign;
    $arraydesign = chado_expand_var($arraydesign, 'field', 'arraydesign.description');
    ?>
    
    <div class="tripal_arraydesign-data-block-desc tripal-data-block-desc"></div>
    
  <?php 
    $headers = array();
    $rows = array();
    // The array design name
    $rows[] = array(array('data' => 'Array Design', 'header' => TRUE, 'width' => '20%'), '<i>' . $arraydesign->name . '</i>');
    // The name of the manufacturer. The manufacturer is an entry in the contact table.
    $rows[] = array(array('data' => 'Manufacturer', 'header' => TRUE, 'width' => '20%'), '<i>' . $arraydesign->manufacturer_id->name . '</i>');
    // The version of the array design.
    if ($arraydesign->version) {
        $rows[] = array(array('data' => 'Version', 'header' => TRUE, 'width' => '20%'), '<i>' . $arraydesign->version . '</i>');
    }
    //The array dimensions, number of array columns and number of array rows are all displayed in a single field.
    if ($arraydesign->array_dimensions or $arraydesign->num_array_columns or $arraydesign->num_array_rows) {
        $afield = '';
        if ($arraydesign->array_dimensions) {
            $afield = $afield . $arraydesign->array_dimensions;
        }
        if ($arraydesign->array_dimensions and $arraydesign->num_array_columns and $arraydesign->num_array_rows) {
            $afield = $afield . ' - ';
        }
        if ($arraydesign->num_array_columns) {
<?php

$biomaterial = $variables['node']->biomaterial;
$references = array();
if ($biomaterial->dbxref_id) {
    $biomaterial->dbxref_id->is_primary = 1;
    $references[] = $biomaterial->dbxref_id;
}
$options = array('return_array' => 1);
$biomaterial = chado_expand_var($biomaterial, 'table', 'biomaterial_dbxref', $options);
$biomaterial_dbxrefs = $biomaterial->biomaterial_dbxref;
if (count($biomaterial_dbxrefs) > 0) {
    foreach ($biomaterial_dbxrefs as $biomaterial_dbxref) {
        $references[] = $biomaterial_dbxref->dbxref_id;
    }
}
if (count($references) > 0) {
    ?>
  <div class="tripal_biomaterial-data-block-desc tripal-data-block-desc">External references for this biomaterial:</div><?php 
    $headers = array('Database', 'Accession');
    $rows = array();
    foreach ($references as $dbxref) {
        $dbname = $dbxref->db_id->name;
        if ($dbxref->db_id->url) {
            $dbname = l($dbname, $dbxref->db_id->url, array('attributes' => array('target' => '_blank')));
        }
        $accession = $dbxref->accession;
        if ($dbxref->db_id->urlprefix) {
            $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => "_blank")));
        }
        if (property_exists($dbxref, 'is_primary')) {
 }
 // second add in the object relationships.
 foreach ($object_rels as $rel_type => $rels) {
     foreach ($rels as $subject_type => $subjects) {
         // the $headers array is an array of fields to use as the colum headers.
         // additional documentation can be found here
         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
         $headers = array('Name', 'Genome', 'Transcript', 'CDS', 'Protein');
         // the $rows array contains an array of rows where each row is an array
         // of values for each column of the table in that row.  Additional documentation
         // can be found here:
         // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
         $rows = array();
         foreach ($subjects as $subject) {
             // Below tripal function is used to get seqlen from featureloc relationship
             $obj_feature = chado_expand_var($subject, 'table', 'featureloc');
             //echo "<pre>"; print_r($subject);echo "</pre>";
             // Genomic sequence - nothing but co-ordinates sequence
             $genomic_link = "<a href='#' onclick=\"popup_message_display_popup(" . $subject->record->object_id->feature_id . ", '" . $subject->record->object_id->type_id->name . "', 680, 300, '0', '" . $subject->record->object_id->featureloc->feature_id->strand . "');\">Genomic Fasta</a>";
             // cDNA sequence
             $type_id_cdna = CDNA_TYPE_ID;
             //'585';
             $cdna_args = array(':feature_id' => $subject->record->subject_id->feature_id);
             $cdna_sql = "select * from chado.feature where uniquename=(select uniquename from chado.feature where feature_id=:feature_id) and type_id=" . $type_id_cdna;
             $cdna_sequence = chado_query($cdna_sql, $cdna_args)->fetchObject();
             $cDNA_link = "-";
             if (!empty($cdna_sequence->residues)) {
                 $cDNA_link = "<a href='#' onclick=\"popup_message_display_popup(" . $subject->record->subject_id->feature_id . ", '" . $subject->record->subject_id->type_id->name . "', 680, 300, '0', '" . $subject->record->subject_id->featureloc->feature_id->strand . "');\">cDNA Fasta</a>";
             }
             // CDS sequence
             $type_id_cds = CDS_TYPE_ID;