Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00011 require('api/tripal_featuremap.api.inc'); 00012 require('includes/tripal_featuremap.admin.inc'); 00013 00023 function tripal_featuremap_help($path, $arg) { 00024 $output = ''; 00025 switch ($path) { 00026 case "admin/help#tripal_featuremap": 00027 $output = '<p>'. 00028 t("Displays links to nodes created on this date") . 00029 '</p>'; 00030 break; 00031 } 00032 return $output; 00033 } 00034 00041 function tripal_featuremap_node_info() { 00042 $nodes = array(); 00043 $nodes['chado_featuremap'] = array( 00044 'name' => t('Map'), 00045 'module' => 'chado_featuremap', 00046 'description' => t('A feature map from the chado database (e.g. genetic map)'), 00047 'has_title' => FALSE, 00048 'title_label' => t('Feature Map'), 00049 'has_body' => FALSE, 00050 'body_label' => t('Feature Map Description'), 00051 'locked' => TRUE 00052 ); 00053 return $nodes; 00054 } 00055 00063 function tripal_featuremap_perm() { 00064 return array( 00065 'access chado_featuremap content', 00066 'create chado_featuremap content', 00067 'delete chado_featuremap content', 00068 'edit chado_featuremap content', 00069 'administer tripal featuremap', 00070 ); 00071 } 00077 function chado_featuremap_access($op, $node, $account) { 00078 if ($op == 'create') { 00079 if (!user_access('create chado_featuremap content', $account)) { 00080 return FALSE; 00081 } 00082 } 00083 if ($op == 'update') { 00084 if (!user_access('edit chado_featuremap content', $account)) { 00085 return FALSE; 00086 } 00087 } 00088 if ($op == 'delete') { 00089 if (!user_access('delete chado_featuremap content', $account)) { 00090 return FALSE; 00091 } 00092 } 00093 if ($op == 'view') { 00094 if (!user_access('access chado_featuremap content', $account)) { 00095 return FALSE; 00096 } 00097 } 00098 return NULL; 00099 } 00107 function tripal_featuremap_menu() { 00108 $items = array(); 00109 00110 // The administative settings menu 00111 $items['admin/tripal/tripal_featuremap'] = array( 00112 'title' => 'Maps', 00113 'description' => 'Basic Description of Tripal Map Module Functionality', 00114 'page callback' => 'theme', 00115 'page arguments' => array('tripal_featuremap_admin'), 00116 'access arguments' => array('administer tripal featuremap'), 00117 'type' => MENU_NORMAL_ITEM, 00118 ); 00119 00120 $items['admin/tripal/tripal_featuremap/configuration'] = array( 00121 'title' => 'Configuration', 00122 'description' => 'Manage integration of Chado maps including associated features.', 00123 'page callback' => 'drupal_get_form', 00124 'page arguments' => array('tripal_featuremap_admin'), 00125 'access arguments' => array('administer tripal featuremap'), 00126 'type' => MENU_NORMAL_ITEM, 00127 ); 00128 00129 // Synchronizing maps from Chado to Drupal 00130 $items['chado_sync_featuremaps'] = array( 00131 'title' => 'Sync Data', 00132 'page callback' => 'tripal_featuremap_sync_featuremaps', 00133 'access arguments' => array('administer tripal featuremap'), 00134 'type' => MENU_CALLBACK 00135 ); 00136 00137 return $items; 00138 } 00139 00148 function tripal_featuremap_views_api() { 00149 return array( 00150 'api' => 2.0, 00151 ); 00152 } 00153 00154 00155 00163 function tripal_featuremap_nodeapi(&$node, $op, $teaser, $page) { 00164 00165 switch ($op) { 00166 // Note that this function only adds map view to an organism/feature 00167 // node. 00168 case 'view': 00169 // add the map to the organism/feature search indexing 00170 if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) { 00171 $node->content['tripal_featuremap_index_version'] = array( 00172 '#value' => theme('tripal_featuremap_search_index', $node), 00173 ); 00174 } 00175 elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) { 00176 $node->content['tripal_featuremap_index_version'] = array( 00177 '#value' => theme('tripal_featuremap_search_result', $node), 00178 ); 00179 } 00180 } 00181 } 00182 00190 function tripal_featuremap_theme() { 00191 return array( 00192 'tripal_featuremap_search_index' => array( 00193 'arguments' => array('node'), 00194 ), 00195 'tripal_featuremap_search_result' => array( 00196 'arguments' => array('node'), 00197 ), 00198 'tripal_featuremap_base' => array( 00199 'arguments' => array('node' => NULL), 00200 'template' => 'tripal_featuremap_base', 00201 ), 00202 'tripal_featuremap_properties' => array( 00203 'arguments' => array('node' => NULL), 00204 'template' => 'tripal_featuremap_properties', 00205 ), 00206 'tripal_featuremap_publication' => array( 00207 'arguments' => array('node' => NULL), 00208 'template' => 'tripal_featuremap_publication', 00209 ), 00210 'tripal_featuremap_admin' => array( 00211 'template' => 'tripal_featuremap_admin', 00212 'arguments' => array(NULL), 00213 'path' => drupal_get_path('module', 'tripal_featuremap') . '/theme' 00214 ), 00215 ); 00216 } 00217 00225 function theme_tripal_featuremap_search_index($node) { 00226 } 00227 00232 function tripal_featuremap_cron() { 00233 00234 } 00241 function tripal_featuremap_map_access($op, $node, $account) { 00242 if ($op == 'create') { 00243 if (!user_access('create chado_featuremap content', $account)) { 00244 return FALSE; 00245 } 00246 } 00247 00248 if ($op == 'update') { 00249 if (!user_access('edit any chado_featuremap content', $account) && 00250 !user_access('edit own chado_featuremap content', $account)) { 00251 return FALSE; 00252 } 00253 if (user_access('edit own chado_featuremap content', $account) && 00254 $account->uid != $node->uid) { 00255 return FALSE; 00256 } 00257 } 00258 00259 if ($op == 'delete') { 00260 if (!user_access('delete any chado_featuremap content', $account) && 00261 !user_access('delete own chado_featuremap content', $account)) { 00262 return FALSE; 00263 } 00264 if (user_access('delete own chado_featuremap content', $account) && 00265 $account->uid != $node->uid) { 00266 return FALSE; 00267 } 00268 } 00269 return NULL; 00270 } 00271 00278 function chado_featuremap_form($node) { 00279 $type = node_get_types('type', $node); 00280 $form = array(); 00281 00282 $featuremap = $node->featuremap; 00283 00284 // keep track of the map id if we have. If we do have one then 00285 // this is an update as opposed to an insert. 00286 $form['featuremap_id'] = array( 00287 '#type' => 'value', 00288 '#value' => $featuremap->featuremap_id, 00289 ); 00290 00291 $form['title']= array( 00292 '#type' => 'textfield', 00293 '#title' => t('Map Name'), 00294 '#description' => t('Please enter a name for this map'), 00295 '#required' => TRUE, 00296 '#default_value' => $featuremap->name, 00297 ); 00298 00299 $form['description']= array( 00300 '#type' => 'textarea', 00301 '#title' => t('Map Description'), 00302 '#description' => t('A description of the map.'), 00303 '#required' => TRUE, 00304 '#default_value' => $featuremap->description, 00305 ); 00306 00307 // get the list of unit types 00308 $values = array( 00309 'cv_id' => array( 00310 'name' => 'tripal_featuremap', 00311 ) 00312 ); 00313 $columns = array('cvterm_id','name'); 00314 $options = array('order_by' => array('name' => 'ASC')); 00315 $featuremap_units = tripal_core_chado_select('cvterm', $columns, $values, $options); 00316 $units = array(); 00317 $units[''] = ''; 00318 foreach($featuremap_units as $unit) { 00319 $units[$unit->cvterm_id] = $unit->name; 00320 } 00321 00322 $form['unittype_id'] = array( 00323 '#title' => t('Map Units'), 00324 '#type' => t('select'), 00325 '#description' => t("Chose the units for this map"), 00326 '#required' => TRUE, 00327 '#default_value' => $featuremap->unittype_id->cvterm_id, 00328 '#options' => $units, 00329 ); 00330 00331 return $form; 00332 } 00338 function chado_featuremap_validate($node) { 00339 $map = 0; 00340 // check to make sure the unique name on the map is unique 00341 // before we try to insert into chado. If this is an update then we will 00342 // have a featuremap_id, therefore we want to look for another map with this 00343 // name but with a different featuremap_id. If this is an insert, just look 00344 // for a case where the name already exists. 00345 if ($node->featuremap_id) { 00346 $sql = "SELECT * FROM ". 00347 "{featuremap} WHERE ". 00348 "name = '%s' ". 00349 "AND NOT featuremap_id = %d"; 00350 $map = db_fetch_object(chado_query($sql, $node->title, $node->featuremap_id)); 00351 } 00352 else { 00353 $sql = "SELECT * FROM ". 00354 "{featuremap} ". 00355 "WHERE name = '%s'"; 00356 $map = db_fetch_object(chado_query($sql, $node->title)); 00357 } 00358 if ($map) { 00359 form_set_error('name', t('The unique map name already exists. Please choose another')); 00360 } 00361 } 00362 00370 function chado_featuremap_insert($node) { 00371 00372 if ($node->featuremap_id) { 00373 $featuremap['featuremap_id'] = $node->featuremap_id; 00374 } 00375 else { 00376 $values = array( 00377 'name' => $node->title, 00378 'description' => $node->description, 00379 'unittype_id' => $node->unittype_id 00380 ); 00381 $featuremap = tripal_core_chado_insert('featuremap', $values); 00382 } 00383 00384 if ($featuremap) { 00385 // make sure the entry for this feature doesn't already exist in the chado_featuremap table 00386 // if it doesn't exist then we want to add it. 00387 $featuremap_id = chado_get_id_for_node('featuremap', $node) ; 00388 if (!$featuremap_id) { 00389 // next add the item to the drupal table 00390 $sql = "INSERT INTO {chado_featuremap} (nid, vid, featuremap_id) ". 00391 "VALUES (%d, %d, %d)"; 00392 db_query($sql, $node->nid, $node->vid, $featuremap['featuremap_id']); 00393 } 00394 } 00395 else { 00396 drupal_set_message(t('Unable to add featuremap.', 'warning')); 00397 watchdog('tripal_featuremap', 00398 'Insert feature: Unable to create featuremap where values: %values', 00399 array('%values' => print_r($values, TRUE)), 00400 WATCHDOG_WARNING 00401 ); 00402 } 00403 } 00409 function chado_featuremap_update($node) { 00410 if ($node->revision) { 00411 // there is no way to handle revisions in Chado but leave 00412 // this here just to make not we've addressed it. 00413 } 00414 $featuremap_id = chado_get_id_for_node('featuremap', $node) ; 00415 00416 // update the map record 00417 $match = array( 00418 'featuremap_id' => $featuremap_id, 00419 ); 00420 $values = array( 00421 'name' => $node->title, 00422 'unittype_id' => $node->unittype_id 00423 ); 00424 $status = tripal_core_chado_update('featuremap', $match, $values); 00425 } 00432 function chado_featuremap_load($node) { 00433 // get the feature details from chado 00434 $featuremap_id = chado_get_id_for_node('featuremap', $node); 00435 00436 $values = array('featuremap_id' => $featuremap_id); 00437 $featuremap = tripal_core_generate_chado_var('featuremap', $values); 00438 00439 $additions = new stdClass(); 00440 $additions->featuremap = $featuremap; 00441 return $additions; 00442 00443 } 00450 function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) { 00451 // use drupal's default node view: 00452 if (!$teaser) { 00453 00454 $node = node_prepare($node, $teaser); 00455 } 00456 return $node; 00457 } 00458 00463 function chado_featuremap_delete(&$node) { 00464 00465 $featuremap_id = chado_get_id_for_node('featuremap', $node); 00466 00467 // if we don't have a map id for this node then this isn't a node of 00468 // type chado_featuremap or the entry in the chado_featuremap table was lost. 00469 if (!$featuremap_id) { 00470 return; 00471 } 00472 00473 // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of 00474 // drupal database 00475 $sql_del = "DELETE FROM {chado_featuremap} ". 00476 "WHERE nid = %d ". 00477 "AND vid = %d"; 00478 db_query($sql_del, $node->nid, $node->vid); 00479 $sql_del = "DELETE FROM {node} ". 00480 "WHERE nid = %d ". 00481 "AND vid = %d"; 00482 db_query($sql_del, $node->nid, $node->vid); 00483 $sql_del = "DELETE FROM {node_revisions} ". 00484 "WHERE nid = %d ". 00485 "AND vid = %d"; 00486 db_query($sql_del, $node->nid, $node->vid); 00487 00488 // Remove data from map and mapprop tables of chado database as well 00489 chado_query("DELETE FROM {featuremap} WHERE featuremap_id = %d", $featuremap_id); 00490 chado_query("DELETE FROM {featuremapprop} WHERE featuremap_id = %d", $featuremap_id); 00491 } 00492 00493 /* 00494 * 00495 */ 00496 function theme_tripal_featuremap_search_result($node) { 00497 00498 } 00499