|
@@ -9,19 +9,8 @@
|
|
|
*/
|
|
|
class local__child_properties_formatter extends ChadoFieldFormatter {
|
|
|
|
|
|
- /**
|
|
|
- * The default label for this field.
|
|
|
- */
|
|
|
public static $default_label = 'Child Properties';
|
|
|
-
|
|
|
- /**
|
|
|
- * The list of field types for which this formatter is appropriate.
|
|
|
- */
|
|
|
public static $field_types = ['local__child_properties'];
|
|
|
-
|
|
|
- /**
|
|
|
- * The list of default settings for this formatter.
|
|
|
- */
|
|
|
public static $default_settings = [
|
|
|
'setting1' => 'default_value',
|
|
|
];
|
|
@@ -41,22 +30,16 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
|
|
|
// Get the settings.
|
|
|
$settings = $display['settings'];
|
|
|
|
|
|
- // For now, values come from the data__sequence_features field.
|
|
|
- // $data = $entity->{'data__sequence_features'}['und'];.
|
|
|
- // insert into chado.featureprop (feature_id, type_id, value, rank) VALUES (5505, 100, 'some madeup prop value on a protein', 0);.
|
|
|
+ // Get the data for this field.
|
|
|
$data = $entity->{'local__child_properties'}['und'];
|
|
|
|
|
|
if (!$data) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- $i = 0;
|
|
|
-
|
|
|
foreach ($data as $i => $value) {
|
|
|
|
|
|
$child = $value['value'];
|
|
|
-
|
|
|
- // TODO: this is an extra undefined! bad.
|
|
|
// Assumption: we're on the gene entity. We've got an array of mRNA feature ID's.
|
|
|
$header = [
|
|
|
'Feature Name',
|
|
@@ -67,7 +50,6 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
|
|
|
|
|
|
$info = $child['info'];
|
|
|
$name = $info->uniquename;
|
|
|
-
|
|
|
$element[0][$i] = [
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => $name,
|
|
@@ -77,7 +59,6 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
|
|
|
'collapsed',
|
|
|
],
|
|
|
],
|
|
|
- // see: https://www.drupal.org/forum/support/module-development-and-code-questions/2012-02-07/drupal-render-fieldset-element
|
|
|
'#attached' => ['js' => ['misc/collapse.js', 'misc/form.js']],
|
|
|
];
|
|
|
|
|
@@ -88,95 +69,27 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
|
|
|
'#markup' => $table,
|
|
|
'#title' => t("Child Properties for !root", ['!root' => $name]),
|
|
|
];
|
|
|
-
|
|
|
- $rows = $this->getAnnotationRows($child);
|
|
|
- $header = ['name', 'type', 'annotation'];
|
|
|
-
|
|
|
- $table = theme('table', ['rows' => $rows, 'header' => $header]);
|
|
|
- $element[0][$i]['annotation_table'] = [
|
|
|
- '#markup' => $table,
|
|
|
- '#title' => t("Annotations for !root", ['!root' => $name]),
|
|
|
- ];
|
|
|
-
|
|
|
- $i++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * This functionality should move to a separate field.
|
|
|
+ * Recursively goes through the child feature array for property listings.
|
|
|
*
|
|
|
- * @param $data
|
|
|
- */
|
|
|
- private function getAnnotationRows($data) {
|
|
|
-
|
|
|
- $rows = [];
|
|
|
-
|
|
|
- $info = $data['info'];
|
|
|
-
|
|
|
- $children = $data['children'] ?? NULL;
|
|
|
-
|
|
|
- $annotations = $info->feature_cvterm;
|
|
|
-
|
|
|
- if ($annotations) {
|
|
|
-
|
|
|
- if (is_array($annotations)) {
|
|
|
- foreach ($annotations as $ann) {
|
|
|
-
|
|
|
- $annotation_name = $ann->cvterm_id->name;
|
|
|
- if ($ann->is_not) {
|
|
|
- $annotation_name = "is not " . $annotation_name;
|
|
|
- }
|
|
|
-
|
|
|
- $rows[] = [
|
|
|
- $info->uniquename,
|
|
|
- $info->type_id->name,
|
|
|
- $annotation_name,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- $annotation_name = $annotations->cvterm_id->name;
|
|
|
- if ($annotations->is_not) {
|
|
|
- $annotation_name = "is not " . $annotation_name;
|
|
|
- }
|
|
|
-
|
|
|
- $rows[] = [
|
|
|
- $info->uniquename,
|
|
|
- $info->type_id->name,
|
|
|
- $annotation_name,
|
|
|
- ];
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if ($children && !empty($children)) {
|
|
|
-
|
|
|
- foreach ($children as $child) {
|
|
|
- $rows = array_merge($this->getAnnotationRows($child), $rows);
|
|
|
- }
|
|
|
- }
|
|
|
- return $rows;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Recursively goes through the child feature array and builds an array of.
|
|
|
+ * @param array $data
|
|
|
+ * Data formatted by the data__sequence_features field.
|
|
|
+ * Expects an info and a children key.
|
|
|
*
|
|
|
- * @param $data
|
|
|
+ * @return array
|
|
|
+ * Rows array suitable for table.
|
|
|
*/
|
|
|
private function getPropRows($data) {
|
|
|
|
|
|
$rows = [];
|
|
|
-
|
|
|
$info = $data['info'];
|
|
|
-
|
|
|
$children = $data['children'] ?? NULL;
|
|
|
-
|
|
|
$props = $info->featureprop;
|
|
|
|
|
|
if ($props) {
|
|
|
-
|
|
|
// If there is only one property, it will be an object not an array.
|
|
|
if (is_array($props)) {
|
|
|
foreach ($props as $prop) {
|
|
@@ -195,16 +108,12 @@ class local__child_properties_formatter extends ChadoFieldFormatter {
|
|
|
$props->type_id->name,
|
|
|
$props->value,
|
|
|
];
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
if ($children && !empty($children)) {
|
|
|
-
|
|
|
foreach ($children as $child) {
|
|
|
$result = array_merge($this->getPropRows($child), $rows);
|
|
|
-
|
|
|
$rows = $result;
|
|
|
}
|
|
|
}
|