|
@@ -150,29 +150,28 @@ class sbo__relationship extends ChadoField {
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
- /**
|
|
|
- *
|
|
|
- * @see TripalField::load()
|
|
|
- */
|
|
|
- public function load($entity) {
|
|
|
- $settings = $this->field['settings'];
|
|
|
|
|
|
- $record = $entity->chado_record;
|
|
|
- $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
|
|
|
+ private function loadRelationship($relationship, &$entity, $delta) {
|
|
|
|
|
|
$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'];
|
|
|
|
|
|
- // Get the PKey for this table
|
|
|
- $schema = chado_get_schema($field_table);
|
|
|
- $pkey = $schema['primary key'][0];
|
|
|
+ $rel_acc = $relationship->type_id->dbxref_id->db_id->name . ':' . $relationship->type_id->dbxref_id->accession;
|
|
|
+ $rel_type = $relationship->type_id->name;
|
|
|
+ $verb = $this->get_rel_verb($rel_type);
|
|
|
|
|
|
// Get the foreign keys for the subject and object tables
|
|
|
$subject_fkey_table = '';
|
|
|
$object_fkey_table = '';
|
|
|
+
|
|
|
+ $schema = chado_get_schema($field_table);
|
|
|
+ $pkey = $schema['primary key'][0];
|
|
|
+ $fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
|
|
|
+ $fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
|
|
|
+
|
|
|
+ // Not all tables have the columns named 'subject_id' and 'object_id'.
|
|
|
+ // some have variations on that name and we need to determine what they are.
|
|
|
$fkeys = $schema['foreign keys'];
|
|
|
$subject_id_key = 'subject_id';
|
|
|
$object_id_key = 'object_id';
|
|
@@ -188,37 +187,186 @@ class sbo__relationship extends ChadoField {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Get the schemas for the subject and object table. These should
|
|
|
+ // be the same as the base table but just to be safe we'll get them
|
|
|
+ // separately.
|
|
|
$subject_schema = chado_get_schema($subject_fkey_table);
|
|
|
- $object_schema = chado_get_schema($object_fkey_table);
|
|
|
$subject_pkey = $subject_schema['primary key'][0];
|
|
|
+ $object_schema = chado_get_schema($object_fkey_table);
|
|
|
$object_pkey = $object_schema['primary key'][0];
|
|
|
|
|
|
- // Get the FK that links to the base record.
|
|
|
+ // Not all realtionshp tables have a name field (e.g. organism_relationship)
|
|
|
+ // threfore in some cases we need to dig a bit deeper to get the entity
|
|
|
+ // name and the entity type name.
|
|
|
+ $subject_name = '';
|
|
|
+ $subject_type = '';
|
|
|
+ $object_name = '';
|
|
|
+ $object_type = '';
|
|
|
+
|
|
|
+ // The linked to table of a relationship linker table may not always
|
|
|
+ // have a type_id or name field. So we have to be a bit more
|
|
|
+ // specific about how we set some variables.
|
|
|
+ switch ($relationship->tablename) {
|
|
|
+ case 'acquisition_relationship':
|
|
|
+ $subject_type = 'acquisition';
|
|
|
+ $object_type = 'acquisition';
|
|
|
+ break;
|
|
|
+ case 'analysis_relationship':
|
|
|
+ $subject_type = 'analysis';
|
|
|
+ $object_type = 'analysis';
|
|
|
+ break;
|
|
|
+ case 'biomaterial_relationship':
|
|
|
+ $subject_type = 'biomaterial';
|
|
|
+ $object_type = 'biomaterial';
|
|
|
+ break;
|
|
|
+ case 'cell_line_relationship':
|
|
|
+ $subject_type = 'cell_line';
|
|
|
+ $object_type = 'cell_line';
|
|
|
+ break;
|
|
|
+ case 'element_relationship':
|
|
|
+ $subject_name = $relationship->$subject_id_key->feature_id->name;
|
|
|
+ $object_name = $relationship->$object_id_key->feature_id->name;
|
|
|
+ break;
|
|
|
+ case 'organism_relationship':
|
|
|
+ $subject_name = $relationship->$subject_id_key->genus . ' ' . $relationship->$subject_id_key->species;
|
|
|
+ $object_name = $relationship->$object_id_key->genus . ' ' . $relationship->$object_id_key->species;
|
|
|
+ $subject_type = 'organism';
|
|
|
+ $object_type = 'organism';
|
|
|
+ break;
|
|
|
+ case 'project_relationship':
|
|
|
+ $subject_type = 'project';
|
|
|
+ $object_type = 'project';
|
|
|
+ break;
|
|
|
+ case 'phylonode_relationship':
|
|
|
+ $subject_name = $relationship->$subject_id_key->label;
|
|
|
+ $object_name = $relationship->$object_id_key->label;
|
|
|
+ break;
|
|
|
+ case 'pub_relationship':
|
|
|
+ $subject_name = $relationship->$subject_id_key->uniquename;
|
|
|
+ $object_name = $relationship->$object_id_key->uniquename;
|
|
|
+ break;
|
|
|
+ case 'quantification_relationship':
|
|
|
+ $subject_type = 'quantification';
|
|
|
+ $object_type = 'quantification';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $subject_name = isset($relationship->$subject_id_key->name) ? $relationship->$subject_id_key->name : '';
|
|
|
+ $subject_type = isset($relationship->$subject_id_key->type_id) ? $relationship->$subject_id_key->type_id->name : '';
|
|
|
+ $object_name = isset($relationship->$object_id_key->name) ? $relationship->$object_id_key->name : '';
|
|
|
+ $object_type = isset($relationship->$object_id_key->type_id) ? $relationship->$object_id_key->type_id->name : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ $entity->{$field_name}['und'][$delta]['value'] = array(
|
|
|
+ 'local:relationship_subject' => array(
|
|
|
+ 'rdfs:type' => $subject_type,
|
|
|
+ 'schema:name' => $subject_name,
|
|
|
+ ),
|
|
|
+ 'local:relationship_type' => $relationship->type_id->name,
|
|
|
+ 'local:relationship_object' => array(
|
|
|
+ 'rdfs:type' => $object_type,
|
|
|
+ 'schema:name' => $object_name,
|
|
|
+ 'entity' => 'TripalEntity:' . $entity->id,
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ // Get the primary key for the subject and object.
|
|
|
+// $subject_id = $relationship->$subject_id_key->$subject_pkey;
|
|
|
+// $sentity_id = chado_get_record_entity_by_table($subject_fkey_table, $subject_id);
|
|
|
+// if ($sentity_id) {
|
|
|
+// $entity->{$field_name}['und'][$delta]['value']['local:relationship_subject']['entity'] = 'TripalEntity:' . $sentity_id;
|
|
|
+// }
|
|
|
+
|
|
|
+// // See if an entity exists for the object.
|
|
|
+// $object_id = $relationship->$object_id_key->$object_pkey;
|
|
|
+// $sentity_id = chado_get_record_entity_by_table($object_fkey_table, $object_id);
|
|
|
+// if ($sentity_id) {
|
|
|
+// $entity->{$field_name}['und'][$delta]['value']['local:relationship_object']['entity'] = 'TripalEntity:' . $sentity_id;
|
|
|
+// }
|
|
|
+
|
|
|
+ // If the subject or object have a unqiuename then add that in for refernce.
|
|
|
+ if (property_exists($relationship->$subject_id_key, 'uniquename')) {
|
|
|
+ $entity->{$field_name}['und'][$delta]['value']['local:relationship_subject']['data:0842'] = $relationship->$subject_id_key->uniquename;;
|
|
|
+ }
|
|
|
+ if (property_exists($relationship->$object_id_key, 'uniquename')) {
|
|
|
+ $entity->{$field_name}['und'][$delta]['value']['local:relationship_object']['data:0842'] = $relationship->$object_id_key->uniquename;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add in the TripalEntity ids if these base records in the relationship
|
|
|
+ // are published.
|
|
|
+ if (property_exists($relationship->$subject_id_key, 'entity_id')) {
|
|
|
+ $entity_id = $relationship->$subject_id_key->entity_id;
|
|
|
+ $entity->{$field_name}['und'][$delta]['value']['local:relationship_subject']['entity'] = 'TripalEntity:' . $entity_id;
|
|
|
+ }
|
|
|
+ if (property_exists($relationship->$object_id_key, 'entity_id')) {
|
|
|
+ $entity_id = $relationship->$object_id_key->entity_id;
|
|
|
+ $entity->{$field_name}['und'][$delta]['value']['local:relationship_object']['entity'] = 'TripalEntity:' . $entity_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add the clause to the values array. The clause is a written version
|
|
|
+ // of the relationships.
|
|
|
+ $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
|
|
|
+ $entity->{$field_name}['und'][$delta]['value']['SIO:000493'] = 'The ' . $subject_type . ', ' .
|
|
|
+ $subject_name . ', ' . $verb . ' ' . $rel_type_clean . ' this ' .
|
|
|
+ $object_type . '.';
|
|
|
+
|
|
|
+ $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
|
|
|
+ $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $subject_id_key] = $relationship->$subject_id_key->$subject_pkey;
|
|
|
+ $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
|
|
|
+ $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__' . $object_id_key] = $relationship->$object_id_key->$object_pkey;
|
|
|
+
|
|
|
+ // For the widget to work properly we will preform values.
|
|
|
+ $entity->{$field_name}['und'][$delta]['type_name'] = $relationship->type_id->name;
|
|
|
+ $entity->{$field_name}['und'][$delta]['subject_name'] = $subject_name . ' [id: ' . $relationship->$subject_id_key->$subject_pkey . ']';
|
|
|
+ $entity->{$field_name}['und'][$delta]['object_name'] = $object_name . ' [id: ' . $relationship->$object_id_key->$object_pkey . ']';
|
|
|
+ if (array_key_exists('value', $schema['fields'])) {
|
|
|
+ $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__value'] = $relationship->value;
|
|
|
+ }
|
|
|
+ if (array_key_exists('rank', $schema['fields'])) {
|
|
|
+ $entity->{$field_name}['und'][$delta]['chado-' . $field_table . '__rank'] = $relationship->rank;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @see TripalField::load()
|
|
|
+ */
|
|
|
+ public function load($entity) {
|
|
|
+ $settings = $this->field['settings'];
|
|
|
+
|
|
|
+ $record = $entity->chado_record;
|
|
|
+ $bundle = tripal_load_bundle_entity(array('name' => $entity->bundle));
|
|
|
+
|
|
|
+ $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'];
|
|
|
+
|
|
|
+ // Get the PKey for this table
|
|
|
$schema = chado_get_schema($field_table);
|
|
|
+ $pkey = $schema['primary key'][0];
|
|
|
$fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
|
|
|
$fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];
|
|
|
|
|
|
+ // Not all tables have the columns named 'subject_id' and 'object_id'.
|
|
|
+ // some have variations on that name and we need to determine what they are.
|
|
|
+ $fkeys = $schema['foreign keys'];
|
|
|
+ $subject_id_key = 'subject_id';
|
|
|
+ $object_id_key = 'object_id';
|
|
|
+ foreach ($fkeys as $fktable => $details) {
|
|
|
+ foreach ($details['columns'] as $fkey_lcolumn => $fkey_rcolumn) {
|
|
|
+ if (preg_match('/^subject_.*id/', $fkey_lcolumn)) {
|
|
|
+ $subject_id_key = $fkey_lcolumn;
|
|
|
+ }
|
|
|
+ if (preg_match('/^object_.*id/', $fkey_lcolumn)) {
|
|
|
+ $object_id_key = $fkey_lcolumn;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Set some defaults for the empty record.
|
|
|
$entity->{$field_name}['und'][0] = array(
|
|
|
- 'value' => array(
|
|
|
- /* The following shows what may be present in the value array
|
|
|
- // Clause
|
|
|
- 'SIO:000493' => '',
|
|
|
- 'local:relationship_subject' => array(
|
|
|
- // Identifier
|
|
|
- 'data:0842' => '',
|
|
|
- 'schema:name' => '',
|
|
|
- 'rdfs:type' => ''
|
|
|
- ),
|
|
|
- 'local:relationship_object' => array(
|
|
|
- // Identifier
|
|
|
- 'data:0842' => '',
|
|
|
- 'schema:name' => '',
|
|
|
- 'rdfs:type' => '',
|
|
|
- ),
|
|
|
- 'local:relationship_type' => '',
|
|
|
- */
|
|
|
- ),
|
|
|
+ 'value' => '',
|
|
|
'chado-' . $field_table . '__' . $pkey => '',
|
|
|
'chado-' . $field_table . '__' . $subject_id_key => '',
|
|
|
'chado-' . $field_table . '__' . $object_id_key => '',
|
|
@@ -269,244 +417,22 @@ class sbo__relationship extends ChadoField {
|
|
|
if (!$record->$rel_table) {
|
|
|
return;
|
|
|
}
|
|
|
- $srelationships = null;
|
|
|
- $orelationships = null;
|
|
|
|
|
|
+ // Load the subject relationships
|
|
|
+ $i = 0;
|
|
|
if (isset($record->$rel_table->$subject_id_key)) {
|
|
|
$srelationships = $record->$rel_table->$subject_id_key;
|
|
|
- }
|
|
|
- if (isset($record->$rel_table->$object_id_key)) {
|
|
|
- $orelationships = $record->$rel_table->$object_id_key;
|
|
|
- }
|
|
|
-
|
|
|
- $i = 0;
|
|
|
- if ($orelationships) {
|
|
|
- foreach ($orelationships as $relationship) {
|
|
|
- $rel_acc = $relationship->type_id->dbxref_id->db_id->name . ':' . $relationship->type_id->dbxref_id->accession;
|
|
|
- $rel_type = $relationship->type_id->name;
|
|
|
- $verb = $this->get_rel_verb($rel_type);
|
|
|
- $subject_id = $relationship->$subject_id_key->$subject_pkey;
|
|
|
-
|
|
|
- // The linked to table of a relationship linker table may not always
|
|
|
- // have a type_id or name field. So we have to be a bit more
|
|
|
- // specific about how we set some variables.
|
|
|
- switch ($relationship->tablename) {
|
|
|
- case 'acquisition_relationship':
|
|
|
- $subject_type = 'acquisition';
|
|
|
- $object_type = 'acquisition';
|
|
|
- break;
|
|
|
- case 'analysis_relationship':
|
|
|
- $subject_type = 'analysis';
|
|
|
- $object_type = 'analysis';
|
|
|
- break;
|
|
|
- case 'biomaterial_relationship':
|
|
|
- $subject_type = 'biomaterial';
|
|
|
- $object_type = 'biomaterial';
|
|
|
- break;
|
|
|
- case 'cell_line_relationship':
|
|
|
- $subject_type = 'cell_line';
|
|
|
- $object_type = 'cell_line';
|
|
|
- break;
|
|
|
- case 'element_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->feature_id->name;
|
|
|
- $object_name = $relationship->$object_id_key->feature_id->name;
|
|
|
- break;
|
|
|
- case 'organism_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->genus . ' ' . $relationship->$subject_id_key->species;
|
|
|
- $object_name = $relationship->$object_id_key->genus . ' ' . $relationship->$object_id_key->species;
|
|
|
- $subject_type = 'organism';
|
|
|
- $object_type = 'organism';
|
|
|
- break;
|
|
|
- case 'project_relationship':
|
|
|
- $subject_type = 'project';
|
|
|
- $object_type = 'project';
|
|
|
- break;
|
|
|
- case 'phylonode_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->label;
|
|
|
- $object_name = $relationship->$object_id_key->label;
|
|
|
- break;
|
|
|
- case 'pub_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->uniquename;
|
|
|
- $object_name = $relationship->$object_id_key->uniquename;
|
|
|
- break;
|
|
|
- case 'quantification_relationship':
|
|
|
- $subject_type = 'quantification';
|
|
|
- $object_type = 'quantification';
|
|
|
- break;
|
|
|
- default:
|
|
|
- $subject_name = isset($relationship->$subject_id_key->name) ? $relationship->$subject_id_key->name : '';
|
|
|
- $subject_type = isset($relationship->$subject_id_key->type_id) ? $relationship->$subject_id_key->type_id->name : '';
|
|
|
- $object_name = isset($relationship->$object_id_key->name) ? $relationship->$object_id_key->name : '';
|
|
|
- $object_type = isset($relationship->$object_id_key->type_id) ? $relationship->$object_id_key->type_id->name : '';
|
|
|
- }
|
|
|
-
|
|
|
- $entity->{$field_name}['und'][$i]['value'] = array(
|
|
|
- 'local:relationship_subject' => array(
|
|
|
- 'rdfs:type' => $subject_type,
|
|
|
- 'schema:name' => $subject_name,
|
|
|
- ),
|
|
|
- 'local:relationship_type' => $relationship->type_id->name,
|
|
|
- 'local:relationship_object' => array(
|
|
|
- 'rdfs:type' => $object_type,
|
|
|
- 'schema:name' => $object_name,
|
|
|
- 'entity' => 'TripalEntity:' . $entity->id,
|
|
|
- )
|
|
|
- );
|
|
|
-
|
|
|
- // See if an entity exists for the subject.
|
|
|
- $data_table = preg_replace('/_relationship/', '', $relationship->tablename);
|
|
|
- $sentity_id = chado_get_record_entity_by_table($data_table, $subject_id);
|
|
|
- if ($sentity_id) {
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['entity'] = 'TripalEntity:' . $sentity_id;
|
|
|
- }
|
|
|
-
|
|
|
- if (property_exists($relationship->$subject_id_key, 'uniquename')) {
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['data:0842'] = $relationship->$subject_id_key->uniquename;;
|
|
|
- }
|
|
|
- if (property_exists($relationship->$object_id_key, 'uniquename')) {
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['data:0842'] = $relationship->$object_id_key->uniquename;
|
|
|
- }
|
|
|
- if (property_exists($relationship->$subject_id_key, 'entity_id')) {
|
|
|
- $entity_id = $relationship->$subject_id_key->entity_id;
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['entity'] = 'TripalEntity:' . $entity_id;
|
|
|
- }
|
|
|
-
|
|
|
- // Add the clause to the values array.
|
|
|
- $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
|
|
|
- $entity->{$field_name}['und'][$i]['value']['SIO:000493'] = 'The ' . $subject_type . ', ' .
|
|
|
- $subject_name . ', ' . $verb . ' ' . $rel_type_clean . ' this ' .
|
|
|
- $object_type . '.';
|
|
|
-
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $subject_id_key] = $relationship->$subject_id_key->$subject_pkey;
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $object_id_key] = $relationship->$object_id_key->$object_pkey;
|
|
|
-
|
|
|
- $entity->{$field_name}['und'][$i]['type_name'] = $relationship->type_id->name;
|
|
|
- $entity->{$field_name}['und'][$i]['subject_name'] = $subject_name . ' [id: ' . $relationship->$subject_id_key->$fkey_rcolumn . ']';
|
|
|
- $entity->{$field_name}['und'][$i]['object_name'] = $object_name . ' [id: ' . $relationship->$object_id_key->$fkey_rcolumn . ']';
|
|
|
- if (array_key_exists('value', $schema['fields'])) {
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__value'] = $relationship->value;
|
|
|
- }
|
|
|
- if (array_key_exists('rank', $schema['fields'])) {
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $relationship->rank;
|
|
|
- }
|
|
|
+ foreach ($srelationships as $relationship) {
|
|
|
+ $this->loadRelationship($relationship, $entity, $i);
|
|
|
$i++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($srelationships) {
|
|
|
- foreach ($srelationships as $relationship) {
|
|
|
- $rel_acc = $relationship->type_id->dbxref_id->db_id->name . ':' . $relationship->type_id->dbxref_id->accession;
|
|
|
- $rel_type = $relationship->type_id->name;
|
|
|
- $verb = $this->get_rel_verb($rel_type);
|
|
|
- $object_id = $relationship->$object_id_key->$object_pkey;
|
|
|
-
|
|
|
- // The linked to table of a relationship linker table may not always
|
|
|
- // have a type_id or name field. So we have to be a bit more
|
|
|
- // specific about how we set some variables.
|
|
|
- switch ($relationship->tablename) {
|
|
|
- case 'acquisition_relationship':
|
|
|
- $subject_type = 'acquisition';
|
|
|
- $object_type = 'acquisition';
|
|
|
- break;
|
|
|
- case 'analysis_relationship':
|
|
|
- $subject_type = 'analysis';
|
|
|
- $object_type = 'analysis';
|
|
|
- break;
|
|
|
- case 'biomaterial_relationship':
|
|
|
- $subject_type = 'biomaterial';
|
|
|
- $object_type = 'biomaterial';
|
|
|
- break;
|
|
|
- case 'cell_line_relationship':
|
|
|
- $subject_type = 'cell_line';
|
|
|
- $object_type = 'cell_line';
|
|
|
- break;
|
|
|
- case 'element_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->feature_id->name;
|
|
|
- $object_name = $relationship->$object_id_key->feature_id->name;
|
|
|
- break;
|
|
|
- case 'organism_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->genus . ' ' . $relationship->$subject_id_key->species;
|
|
|
- $object_name = $relationship->$object_id_key->genus . ' ' . $relationship->$object_id_key->species;
|
|
|
- $subject_type = 'organism';
|
|
|
- $object_type = 'organism';
|
|
|
- break;
|
|
|
- case 'project_relationship':
|
|
|
- $subject_type = 'project';
|
|
|
- $object_type = 'project';
|
|
|
- break;
|
|
|
- case 'phylonode_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->label;
|
|
|
- $object_name = $relationship->$object_id_key->label;
|
|
|
- break;
|
|
|
- case 'pub_relationship':
|
|
|
- $subject_name = $relationship->$subject_id_key->uniquename;
|
|
|
- $object_name = $relationship->$object_id_key->uniquename;
|
|
|
- break;
|
|
|
- case 'quantification_relationship':
|
|
|
- $subject_type = 'quantification';
|
|
|
- $object_type = 'quantification';
|
|
|
- break;
|
|
|
- default:
|
|
|
- $subject_name = isset($relationship->$subject_id_key->name) ? $relationship->$subject_id_key->name : '';
|
|
|
- $subject_type = isset($relationship->$subject_id_key->type_id) ? $relationship->$subject_id_key->type_id->name : '';
|
|
|
- $object_name = isset($relationship->$object_id_key->name) ? $relationship->$object_id_key->name : '';
|
|
|
- $object_type = isset($relationship->$object_id_key->type_id) ? $relationship->$object_id_key->type_id->name : '';
|
|
|
- }
|
|
|
-
|
|
|
- $entity->{$field_name}['und'][$i]['value'] = array(
|
|
|
- 'local:relationship_subject' => array(
|
|
|
- 'rdfs:type' => $subject_type,
|
|
|
- 'schema:name' => $subject_name,
|
|
|
- 'entity' => 'TripalEntity:' . $entity->id,
|
|
|
- ),
|
|
|
- 'local:relationship_type' => $relationship->type_id->name,
|
|
|
- 'local:relationship_object' => array(
|
|
|
- 'rdfs:type' => $object_type,
|
|
|
- 'schema:name' => $object_name,
|
|
|
- )
|
|
|
- );
|
|
|
-
|
|
|
- // See if an entity exists for the object.
|
|
|
- $data_table = preg_replace('/_relationship/', '', $relationship->tablename);
|
|
|
- $oentity_id = chado_get_record_entity_by_table($data_table, $object_id);
|
|
|
- if ($oentity_id) {
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['entity'] = 'TripalEntity:' . $oentity_id;
|
|
|
- }
|
|
|
-
|
|
|
- if (property_exists($relationship->$subject_id_key, 'uniquename')) {
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_subject']['data:0842'] = $relationship->$subject_id_key->uniquename;
|
|
|
- }
|
|
|
- if (property_exists($relationship->$object_id_key, 'uniquename')) {
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['data:0842'] = $relationship->$object_id_key->uniquename;
|
|
|
- }
|
|
|
- if (property_exists($relationship->$object_id_key, 'entity_id')) {
|
|
|
- $entity_id = $relationship->$object_id_key->entity_id;
|
|
|
- $entity->{$field_name}['und'][$i]['value']['local:relationship_object']['entity'] = 'TripalEntity:' . $entity_id;
|
|
|
- }
|
|
|
-
|
|
|
- // Add the clause to the value array.
|
|
|
- $rel_type_clean = lcfirst(preg_replace('/_/', ' ', $rel_type));
|
|
|
- $entity->{$field_name}['und'][$i]['value']['SIO:000493'] = 'This ' .
|
|
|
- $subject_type . ' ' . $verb . ' ' . $rel_type_clean . ' the ' .
|
|
|
- $object_type . ' ' . $object_name . '.';
|
|
|
-
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $pkey] = $relationship->$pkey;
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $subject_id_key] = $relationship->$subject_id_key->$subject_pkey;
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__type_id'] = $relationship->type_id->cvterm_id;
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__' . $object_id_key] = $relationship->$object_id_key->$object_pkey;
|
|
|
-
|
|
|
- $entity->{$field_name}['und'][$i]['type_name'] = $relationship->type_id->name;
|
|
|
- $entity->{$field_name}['und'][$i]['subject_name'] = $subject_name . ' [id: ' . $relationship->$subject_id_key->$fkey_rcolumn . ']';
|
|
|
- $entity->{$field_name}['und'][$i]['object_name'] = $object_name . ' [id: ' . $relationship->$object_id_key->$fkey_rcolumn . ']';
|
|
|
-
|
|
|
- if (array_key_exists('value', $schema['fields'])) {
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__value'] = $relationship->value;
|
|
|
- }
|
|
|
- if (array_key_exists('rank', $schema['fields'])) {
|
|
|
- $entity->{$field_name}['und'][$i]['chado-' . $field_table . '__rank'] = $relationship->rank;
|
|
|
- }
|
|
|
+ // Load the object relationships
|
|
|
+ if (isset($record->$rel_table->$object_id_key)) {
|
|
|
+ $orelationships = $record->$rel_table->$object_id_key;
|
|
|
+ foreach ($orelationships as $relationship) {
|
|
|
+ $this->loadRelationship($relationship, $entity, $i);
|
|
|
$i++;
|
|
|
}
|
|
|
}
|