|
@@ -10,6 +10,7 @@
|
|
|
|
|
|
require('api/tripal_featuremap.api.inc');
|
|
|
require('includes/tripal_featuremap.admin.inc');
|
|
|
+require('includes/tripal_featuremap.form.inc');
|
|
|
|
|
|
/**
|
|
|
* Display help and module information
|
|
@@ -133,6 +134,24 @@ function tripal_featuremap_menu() {
|
|
|
'access arguments' => array('administer tripal featuremap'),
|
|
|
'type' => MENU_CALLBACK
|
|
|
);
|
|
|
+
|
|
|
+ // AJAX calls for adding/removing properties to a featuremap
|
|
|
+ $items['tripal_featuremap/properties/add'] = array(
|
|
|
+ 'page callback' => 'tripal_featuremap_property_add',
|
|
|
+ 'access arguments' => array('edit chado_featuremap content'),
|
|
|
+ 'type ' => MENU_CALLBACK,
|
|
|
+ );
|
|
|
+ $items['tripal_featuremap/properties/description'] = array(
|
|
|
+ 'page callback' => 'tripal_featuremap_property_get_description',
|
|
|
+ 'access arguments' => array('edit chado_featuremap content'),
|
|
|
+ 'type ' => MENU_CALLBACK,
|
|
|
+ );
|
|
|
+ $items['tripal_featuremap/properties/minus/%/%'] = array(
|
|
|
+ 'page callback' => 'tripal_featuremap_property_delete',
|
|
|
+ 'page arguments' => array(3, 4),
|
|
|
+ 'access arguments' => array('edit chado_featuremap content'),
|
|
|
+ 'type ' => MENU_CALLBACK,
|
|
|
+ );
|
|
|
|
|
|
return $items;
|
|
|
}
|
|
@@ -207,11 +226,20 @@ function tripal_featuremap_theme() {
|
|
|
'arguments' => array('node' => NULL),
|
|
|
'template' => 'tripal_featuremap_publication',
|
|
|
),
|
|
|
+ 'tripal_featuremap_references' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
+ 'template' => 'tripal_featuremap_references',
|
|
|
+ ),
|
|
|
'tripal_featuremap_admin' => array(
|
|
|
'template' => 'tripal_featuremap_admin',
|
|
|
'arguments' => array(NULL),
|
|
|
'path' => drupal_get_path('module', 'tripal_featuremap') . '/theme'
|
|
|
),
|
|
|
+
|
|
|
+ // Themed Forms
|
|
|
+ 'chado_featuremap_node_form' => array(
|
|
|
+ 'arguments' => array('form'),
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -269,96 +297,7 @@ function tripal_featuremap_map_access($op, $node, $account) {
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * When editing or creating a new node of type 'chado_featuremap' we need
|
|
|
- * a form. This function creates the form that will be used for this.
|
|
|
- *
|
|
|
- * @ingroup tripal_featuremap
|
|
|
- */
|
|
|
-function chado_featuremap_form($node) {
|
|
|
- $type = node_get_types('type', $node);
|
|
|
- $form = array();
|
|
|
-
|
|
|
- $featuremap = $node->featuremap;
|
|
|
-
|
|
|
- // keep track of the map id if we have. If we do have one then
|
|
|
- // this is an update as opposed to an insert.
|
|
|
- $form['featuremap_id'] = array(
|
|
|
- '#type' => 'value',
|
|
|
- '#value' => $featuremap->featuremap_id,
|
|
|
- );
|
|
|
-
|
|
|
- $form['title']= array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Map Name'),
|
|
|
- '#description' => t('Please enter a name for this map'),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $featuremap->name,
|
|
|
- );
|
|
|
-
|
|
|
- $form['description']= array(
|
|
|
- '#type' => 'textarea',
|
|
|
- '#title' => t('Map Description'),
|
|
|
- '#description' => t('A description of the map.'),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $featuremap->description,
|
|
|
- );
|
|
|
-
|
|
|
- // get the list of unit types
|
|
|
- $values = array(
|
|
|
- 'cv_id' => array(
|
|
|
- 'name' => 'tripal_featuremap',
|
|
|
- )
|
|
|
- );
|
|
|
- $columns = array('cvterm_id','name');
|
|
|
- $options = array('order_by' => array('name' => 'ASC'));
|
|
|
- $featuremap_units = tripal_core_chado_select('cvterm', $columns, $values, $options);
|
|
|
- $units = array();
|
|
|
- $units[''] = '';
|
|
|
- foreach($featuremap_units as $unit) {
|
|
|
- $units[$unit->cvterm_id] = $unit->name;
|
|
|
- }
|
|
|
-
|
|
|
- $form['unittype_id'] = array(
|
|
|
- '#title' => t('Map Units'),
|
|
|
- '#type' => t('select'),
|
|
|
- '#description' => t("Chose the units for this map"),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $featuremap->unittype_id->cvterm_id,
|
|
|
- '#options' => $units,
|
|
|
- );
|
|
|
|
|
|
- return $form;
|
|
|
-}
|
|
|
-/**
|
|
|
- * validates submission of form when adding or updating a map node
|
|
|
- *
|
|
|
- * @ingroup tripal_featuremap
|
|
|
- */
|
|
|
-function chado_featuremap_validate($node) {
|
|
|
- $map = 0;
|
|
|
- // check to make sure the unique name on the map is unique
|
|
|
- // before we try to insert into chado. If this is an update then we will
|
|
|
- // have a featuremap_id, therefore we want to look for another map with this
|
|
|
- // name but with a different featuremap_id. If this is an insert, just look
|
|
|
- // for a case where the name already exists.
|
|
|
- if ($node->featuremap_id) {
|
|
|
- $sql = "SELECT * FROM ".
|
|
|
- "{featuremap} WHERE ".
|
|
|
- "name = '%s' ".
|
|
|
- "AND NOT featuremap_id = %d";
|
|
|
- $map = db_fetch_object(chado_query($sql, $node->title, $node->featuremap_id));
|
|
|
- }
|
|
|
- else {
|
|
|
- $sql = "SELECT * FROM ".
|
|
|
- "{featuremap} ".
|
|
|
- "WHERE name = '%s'";
|
|
|
- $map = db_fetch_object(chado_query($sql, $node->title));
|
|
|
- }
|
|
|
- if ($map) {
|
|
|
- form_set_error('name', t('The unique map name already exists. Please choose another'));
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
/**
|
|
|
* When a new chado_featuremap node is created we also need to add information
|
|
@@ -369,6 +308,8 @@ function chado_featuremap_validate($node) {
|
|
|
*/
|
|
|
function chado_featuremap_insert($node) {
|
|
|
|
|
|
+ // if the featuremap_id already exists then we got to the insert via
|
|
|
+ // a syncing operation. We do not need to add the feature map
|
|
|
if ($node->featuremap_id) {
|
|
|
$featuremap['featuremap_id'] = $node->featuremap_id;
|
|
|
}
|
|
@@ -379,27 +320,103 @@ function chado_featuremap_insert($node) {
|
|
|
'unittype_id' => $node->unittype_id
|
|
|
);
|
|
|
$featuremap = tripal_core_chado_insert('featuremap', $values);
|
|
|
+ if(!$featuremap) {
|
|
|
+ drupal_set_message(t('Unable to add featuremap.', 'warning'));
|
|
|
+ watchdog('tripal_featuremap', 'Unable to create feature map where values: %values',
|
|
|
+ array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // now add the properties
|
|
|
+ $properties = array(); // stores all of the properties we need to add
|
|
|
+ $cross_refs = array(); // stores any cross references for this featuremap
|
|
|
+
|
|
|
+ // get the list of properties for easy lookup (without doing lots of database queries
|
|
|
+ $properties_list = array();
|
|
|
+ $sql = "
|
|
|
+ SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
|
|
|
+ FROM {cvterm} CVT
|
|
|
+ INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
|
|
|
+ WHERE
|
|
|
+ CV.name = 'featuremap_property' AND
|
|
|
+ NOT CVT.is_obsolete = 1
|
|
|
+ ORDER BY CVT.name ASC
|
|
|
+ ";
|
|
|
+ $prop_types = chado_query($sql);
|
|
|
+ while ($prop = db_fetch_object($prop_types)) {
|
|
|
+ $properties_list[$prop->cvterm_id] = $prop->name;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get the properties that should be added. Properties are in one of two forms:
|
|
|
+ // 1) prop_value-[type id]-[index]
|
|
|
+ // 2) new_value-[type id]-[index]
|
|
|
+ // 3) new_id, new_value
|
|
|
+ foreach ($node as $name => $value) {
|
|
|
+ if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
|
|
|
+ $type_id = $matches[1];
|
|
|
+ $index = $matches[2];
|
|
|
+ $name = $properties_list[$type_id];
|
|
|
+ $properties[$name][$index] = trim($value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($node->new_id and $node->new_value) {
|
|
|
+ $type_id = $node->new_id;
|
|
|
+ $index = count($properties[$name]);
|
|
|
+ $name = $properties_list[$type_id];
|
|
|
+ $properties[$name][$index] = trim($node->new_value);
|
|
|
+ }
|
|
|
+
|
|
|
+ // iterate through all of the properties to see if the Map dbxref is set,
|
|
|
+ // if so, add it to the $cross_refs array
|
|
|
+ foreach ($properties as $name => $element) {
|
|
|
+ foreach ($element as $index => $value) {
|
|
|
+ if ($name == "Map Dbxref") {
|
|
|
+ // we will add the cross-references to the featuremap_dbxref table
|
|
|
+ // but we also want to keep the property in the featuremapprop table so don't unset it
|
|
|
+ $cross_refs[] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // now add in the properties
|
|
|
+ foreach ($properties as $property => $elements) {
|
|
|
+ foreach ($elements as $rank => $value) {
|
|
|
+
|
|
|
+ $status = tripal_featuremap_insert_property($featuremap['featuremap_id'], $property, $value, FALSE);
|
|
|
+ if (!$status) {
|
|
|
+ drupal_set_message("Error cannot add property: $property", "error");
|
|
|
+ watchdog('t_featuremap', "Error cannot add property: %prop",
|
|
|
+ array('%property' => $property), WATCHDOG_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // add in any database cross-references
|
|
|
+ foreach ($cross_refs as $index => $ref) {
|
|
|
+ $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap['featuremap_id'], trim($ref));
|
|
|
+ if (!$featuremap_dbxref) {
|
|
|
+ drupal_set_message("Error cannot add map cross reference: $ref", "error");
|
|
|
+ watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
|
|
|
+ array('%ref' => $ref), WATCHDOG_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ // add the record to the chado_featuremap table in Drupal
|
|
|
if ($featuremap) {
|
|
|
// make sure the entry for this feature doesn't already exist in the chado_featuremap table
|
|
|
// if it doesn't exist then we want to add it.
|
|
|
$featuremap_id = chado_get_id_for_node('featuremap', $node) ;
|
|
|
if (!$featuremap_id) {
|
|
|
// next add the item to the drupal table
|
|
|
- $sql = "INSERT INTO {chado_featuremap} (nid, vid, featuremap_id) ".
|
|
|
- "VALUES (%d, %d, %d)";
|
|
|
+ $sql = "INSERT INTO {chado_featuremap} (nid, vid, featuremap_id) VALUES (%d, %d, %d)";
|
|
|
db_query($sql, $node->nid, $node->vid, $featuremap['featuremap_id']);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- drupal_set_message(t('Unable to add featuremap.', 'warning'));
|
|
|
- watchdog('tripal_featuremap',
|
|
|
- 'Insert feature: Unable to create featuremap where values: %values',
|
|
|
- array('%values' => print_r($values, TRUE)),
|
|
|
- WATCHDOG_WARNING
|
|
|
- );
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
* Update nodes
|
|
@@ -423,6 +440,94 @@ function chado_featuremap_update($node) {
|
|
|
'unittype_id' => $node->unittype_id
|
|
|
);
|
|
|
$status = tripal_core_chado_update('featuremap', $match, $values);
|
|
|
+ if (!$status) {
|
|
|
+ drupal_set_message("Error updating map", "error");
|
|
|
+ watchdog('t_featuremap', "Error updating map", array(), WATCHDOG_ERROR);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // now update the properties
|
|
|
+ $properties = array(); // stores all of the properties we need to add
|
|
|
+ $cross_refs = array(); // stores any cross references for this map
|
|
|
+
|
|
|
+ // get the list of properties for easy lookup (without doing lots of database queries
|
|
|
+ $properties_list = array();
|
|
|
+ $sql = "
|
|
|
+ SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
|
|
|
+ FROM {cvterm} CVT
|
|
|
+ INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
|
|
|
+ WHERE
|
|
|
+ CV.name = 'featuremap_property' AND
|
|
|
+ NOT CVT.is_obsolete = 1
|
|
|
+ ORDER BY CVT.name ASC
|
|
|
+ ";
|
|
|
+ $prop_types = chado_query($sql);
|
|
|
+ while ($prop = db_fetch_object($prop_types)) {
|
|
|
+ $properties_list[$prop->cvterm_id] = $prop->name;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get the properties that should be added. Properties are in one of three forms:
|
|
|
+ // 1) prop_value-[type id]-[index]
|
|
|
+ // 2) new_value-[type id]-[index]
|
|
|
+ // 3) new_id, new_value
|
|
|
+ // dpm($node);
|
|
|
+ foreach ($node as $key => $value) {
|
|
|
+ if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
|
|
|
+ $type_id = $matches[1];
|
|
|
+ $index = $matches[2];
|
|
|
+ $name = $properties_list[$type_id];
|
|
|
+ $properties[$name][$index] = trim($value);
|
|
|
+ }
|
|
|
+ if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
|
|
|
+ $type_id = $matches[1];
|
|
|
+ $index = $matches[2];
|
|
|
+ $name = $properties_list[$type_id];
|
|
|
+ $properties[$name][$index] = trim($value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($node->new_id and $node->new_value) {
|
|
|
+ $type_id = $node->new_id;
|
|
|
+ $name = $properties_list[$type_id];
|
|
|
+ $index = count($properties[$name]);
|
|
|
+ $properties[$name][$index] = trim($node->new_value);
|
|
|
+ }
|
|
|
+
|
|
|
+ // iterate through all of the properties to see if the Map dbxref is set,
|
|
|
+ // if so, add it to the $cross_refs array
|
|
|
+ foreach ($properties as $name => $element) {
|
|
|
+ foreach ($element as $index => $value) {
|
|
|
+ if ($name == "Map Dbxref") {
|
|
|
+ // we will add the cross-references to the featuremap_dbxref table
|
|
|
+ // but we also want to keep the property in the featuremapprop table so don't unset it
|
|
|
+ $cross_refs[] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // now add in the properties by first removing any the featuremap
|
|
|
+ // already has and adding the ones we have
|
|
|
+ tripal_core_chado_delete('featuremapprop', array('featuremap_id' => $featuremap_id));
|
|
|
+ foreach ($properties as $property => $elements) {
|
|
|
+ foreach ($elements as $rank => $value) {
|
|
|
+ $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE);
|
|
|
+ if (!$status) {
|
|
|
+ drupal_set_message("Error cannot add property: '$property'", "error");
|
|
|
+ watchdog('t_featuremap', "Error cannot add property: '%prop'",
|
|
|
+ array('%prop' => $property), WATCHDOG_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // add in any database cross-references after first removing
|
|
|
+ tripal_core_chado_delete('featuremap_dbxref', array('featuremap_id' => $featuremap_id));
|
|
|
+ foreach ($cross_refs as $index => $ref) {
|
|
|
+ $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, trim($ref));
|
|
|
+ if (!$featuremap_dbxref) {
|
|
|
+ drupal_set_message("Error cannot add map cross reference: $ref", "error");
|
|
|
+ watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
|
|
|
+ array('%ref' => $ref), WATCHDOG_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
/**
|
|
|
* When a node is requested by the user this function is called to allow us
|
|
@@ -501,3 +606,7 @@ function theme_tripal_featuremap_search_result($node) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+function tripal_featuremap_form_alter(&$form, &$form_state, $form_id) {
|
|
|
+ if ($form_id == "chado_featuremap_node_form") {
|
|
|
+ }
|
|
|
+}
|