Tripal v1.0 (6.x-1.0)
|
00001 <?php 00007 function tripal_featuremap_admin() { 00008 $form = array(); 00009 00010 // before proceeding check to see if we have any 00011 // currently processing jobs. If so, we don't want 00012 // to give the opportunity to sync maps 00013 $active_jobs = FALSE; 00014 if (tripal_get_module_active_jobs('tripal_featuremap')) { 00015 $active_jobs = TRUE; 00016 } 00017 00018 // add the field set for syncing maps 00019 if (!$active_jobs) { 00020 get_tripal_featuremap_admin_form_sync_set($form); 00021 get_tripal_featuremap_admin_form_cleanup_set($form); 00022 // TODO: complete coding of indexing and taxonomy assignment to features. 00023 // get_tripal_featuremap_admin_form_reindex_set($form); 00024 // get_tripal_featuremap_admin_form_taxonomy_set($form); 00025 } 00026 else { 00027 $form['notice'] = array( 00028 '#type' => 'fieldset', 00029 '#title' => t('Feature Map Management Temporarily Unavailable') 00030 ); 00031 $form['notice']['message'] = array( 00032 '#value' => t('Currently, feature map management jobs are waiting or are running. Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'), 00033 ); 00034 } 00035 00036 return system_settings_form($form); 00037 } 00043 function get_tripal_featuremap_admin_form_cleanup_set(&$form) { 00044 $form['cleanup'] = array( 00045 '#type' => 'fieldset', 00046 '#title' => t('Clean Up') 00047 ); 00048 $form['cleanup']['description'] = array( 00049 '#type' => 'item', 00050 '#value' => t("With Drupal and chado residing in different databases ". 00051 "it is possible that nodes in Drupal and maps in Chado become ". 00052 "\"orphaned\". This can occur if an map node in Drupal is ". 00053 "deleted but the corresponding chado map is not and/or vice ". 00054 "versa. Click the button below to resolve these discrepancies."), 00055 '#weight' => 1, 00056 ); 00057 $form['cleanup']['button'] = array( 00058 '#type' => 'submit', 00059 '#value' => t('Clean up orphaned maps'), 00060 '#weight' => 2, 00061 ); 00062 } 00063 00069 function get_tripal_featuremap_admin_form_taxonomy_set(&$form) { 00070 $form['taxonify'] = array( 00071 '#type' => 'fieldset', 00072 '#title' => t('Assign Drupal Taxonomy to Map Features') 00073 ); 00074 00075 // get the list of maps 00076 $sql = "SELECT * FROM {featuremap} ORDER BY name"; 00077 $lib_rset = chado_query($sql); 00078 00079 // iterate through all of the maps 00080 $lib_boxes = array(); 00081 while ($featuremap = db_fetch_object($lib_rset)) { 00082 $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name"; 00083 } 00084 00085 $form['taxonify']['description'] = array( 00086 '#type' => 'item', 00087 '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " . 00088 "nodes. These terms allow for advanced filtering during searching. This option allows ". 00089 "for setting taxonomy only for features that belong to the selected maps below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."), 00090 '#weight' => 1, 00091 ); 00092 00093 $form['taxonify']['tx-maps'] = array( 00094 '#title' => t('Maps'), 00095 '#type' => t('checkboxes'), 00096 '#description' => t("Check the maps whose features you want to reset taxonomy. Note: this list contains all maps, even those that may not be synced."), 00097 '#required' => FALSE, 00098 '#prefix' => '<div id="lib_boxes">', 00099 '#suffix' => '</div>', 00100 '#options' => $lib_boxes, 00101 '#weight' => 2 00102 ); 00103 $form['taxonify']['tx-button'] = array( 00104 '#type' => 'submit', 00105 '#value' => t('Set Feature Taxonomy'), 00106 '#weight' => 3 00107 ); 00108 } 00113 function get_tripal_featuremap_admin_form_reindex_set(&$form) { 00114 // define the fieldsets 00115 $form['reindex'] = array( 00116 '#type' => 'fieldset', 00117 '#title' => t('Reindex Map Features') 00118 ); 00119 00120 // get the list of maps 00121 $sql = "SELECT * FROM {featuremap} ORDER BY name"; 00122 $lib_rset = chado_query($sql); 00123 00124 // iterate through all of the maps 00125 $lib_boxes = array(); 00126 while ($featuremap = db_fetch_object($lib_rset)) { 00127 $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name"; 00128 } 00129 $form['reindex']['description'] = array( 00130 '#type' => 'item', 00131 '#value' => t("This option allows for reindexing of only those features that belong to the selected maps below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."), 00132 '#weight' => 1, 00133 ); 00134 00135 $form['reindex']['re-maps'] = array( 00136 '#title' => t('Maps'), 00137 '#type' => t('checkboxes'), 00138 '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."), 00139 '#required' => FALSE, 00140 '#prefix' => '<div id="lib_boxes">', 00141 '#suffix' => '</div>', 00142 '#options' => $lib_boxes, 00143 '#weight' => 2, 00144 ); 00145 $form['reindex']['re-button'] = array( 00146 '#type' => 'submit', 00147 '#value' => t('Reindex Features'), 00148 '#weight' => 3, 00149 ); 00150 } 00155 function get_tripal_featuremap_admin_form_sync_set(&$form) { 00156 // define the fieldsets 00157 $form['sync'] = array( 00158 '#type' => 'fieldset', 00159 '#title' => t('Sync Maps') 00160 ); 00161 00162 00163 // get the list of maps 00164 $sql = "SELECT * FROM {featuremap} ORDER BY name"; 00165 $lib_rset = chado_query($sql); 00166 00167 // if we've added any maps to the list that can be synced 00168 // then we want to build the form components to allow the user 00169 // to select one or all of them. Otherwise, just present 00170 // a message stating that all maps are currently synced. 00171 $lib_boxes = array(); 00172 $added = 0; 00173 while ($featuremap = db_fetch_object($lib_rset)) { 00174 // check to see if the map is already present as a node in drupal. 00175 // if so, then skip it. 00176 $sql = "SELECT * FROM {chado_featuremap} WHERE featuremap_id = %d"; 00177 if (!db_fetch_object(db_query($sql, $featuremap->featuremap_id))) { 00178 $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name"; 00179 $added++; 00180 } 00181 } 00182 00183 // if we have maps we need to add to the checkbox then 00184 // build that form element 00185 if ($added > 0) { 00186 $lib_boxes['all'] = "All Maps"; 00187 00188 $form['reindex']['description'] = array( 00189 '#type' => 'item', 00190 '#value' => t("This option allows for the creation of Drupal content for maps in chado. Only the selected maps will be synced."), 00191 '#weight' => 1, 00192 ); 00193 00194 00195 $form['sync']['featuremaps'] = array( 00196 '#title' => t('Available Maps'), 00197 '#type' => t('checkboxes'), 00198 '#description' => t("Check the maps you want to sync. Drupal content will be created for each of the maps listed above. Select 'All Maps' to sync all of them."), 00199 '#required' => FALSE, 00200 '#prefix' => '<div id="lib_boxes">', 00201 '#suffix' => '</div>', 00202 '#options' => $lib_boxes, 00203 '#weight' => 2, 00204 ); 00205 $form['sync']['button'] = array( 00206 '#type' => 'submit', 00207 '#value' => t('Sync Maps'), 00208 '#weight' => 3, 00209 ); 00210 } 00211 // we don't have any maps to select from 00212 else { 00213 $form['sync']['value'] = array( 00214 '#value' => t('All maps in Chado are currently synced with Drupal.') 00215 ); 00216 } 00217 } 00222 function tripal_featuremap_admin_validate($form, &$form_state) { 00223 global $user; // we need access to the user info 00224 $job_args = array(); 00225 00226 // Submit the Sync Job if selected 00227 if ($form_state['values']['op'] == t('Sync Maps')) { 00228 00229 // check to see if the user wants to sync chado and drupal. If 00230 // so then we need to register a job to do so with tripal 00231 $featuremaps = $form_state['values']['featuremaps']; 00232 $do_all = FALSE; 00233 $to_sync = array(); 00234 00235 foreach ($featuremaps as $featuremap_id) { 00236 if (preg_match("/^all$/i", $featuremap_id)) { 00237 $do_all = TRUE; 00238 } 00239 if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) { 00240 // get the map info 00241 $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d"; 00242 $featuremap = db_fetch_object(chado_query($sql, $featuremap_id)); 00243 $to_sync[$featuremap_id] = $featuremap->name; 00244 } 00245 } 00246 00247 // submit the job to the tripal job manager 00248 if ($do_all) { 00249 tripal_add_job('Sync all maps', 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid); 00250 } 00251 else{ 00252 foreach ($to_sync as $featuremap_id => $name) { 00253 $job_args[0] = $featuremap_id; 00254 tripal_add_job("Sync map: $name", 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid); 00255 } 00256 } 00257 } 00258 00259 // ------------------------------------- 00260 // Submit the Reindex Job if selected 00261 if ($form_state['values']['op'] == t('Reindex Features')) { 00262 $featuremaps = $form_state['values']['re-maps']; 00263 foreach ($featuremaps as $featuremap_id) { 00264 if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) { 00265 // get the map info 00266 $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d"; 00267 $featuremap = db_fetch_object(chado_query($sql, $featuremap_id)); 00268 $job_args[0] = $featuremap_id; 00269 tripal_add_job("Reindex features for map: $featuremap->name", 'tripal_featuremap', 00270 'tripal_featuremap_reindex_features', $job_args, $user->uid); 00271 } 00272 } 00273 } 00274 00275 // ------------------------------------- 00276 // Submit the Taxonomy Job if selected 00277 if ($form_state['values']['op'] == t('Set Feature Taxonomy')) { 00278 $featuremaps = $form_state['values']['tx-maps']; 00279 foreach ($featuremaps as $featuremap_id) { 00280 if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) { 00281 // get the map info 00282 $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d"; 00283 $featuremap = db_fetch_object(chado_query($sql, $featuremap_id)); 00284 $job_args[0] = $featuremap_id; 00285 tripal_add_job("Set taxonomy for features in map: $featuremap->name", 'tripal_featuremap', 00286 'tripal_featuremap_taxonify_features', $job_args, $user->uid); 00287 } 00288 } 00289 } 00290 // ------------------------------------- 00291 // Submit the Cleanup Job if selected 00292 if ($form_state['values']['op'] == t('Clean up orphaned maps')) { 00293 tripal_add_job('Cleanup orphaned maps', 'tripal_featuremap', 00294 'tripal_featuremap_cleanup', $job_args, $user->uid); 00295 } 00296 } 00297 00303 function tripal_featuremap_sync_featuremaps($featuremap_id = NULL, $job_id = NULL) { 00304 00305 global $user; 00306 $page_content = ''; 00307 00308 // get the list of featuremaps and create new nodes 00309 if (!$featuremap_id) { 00310 $sql = "SELECT * FROM {featuremap} L"; 00311 $results = chado_query($sql); 00312 } 00313 else { 00314 $sql = "SELECT * FROM {featuremap} L WHERE featuremap_id = %d"; 00315 $results = chado_query($sql, $featuremap_id); 00316 } 00317 00318 // We'll use the following SQL statement for checking if the map 00319 // already exists as a drupal node. 00320 $sql = "SELECT * FROM {chado_featuremap} ". 00321 "WHERE featuremap_id = %d"; 00322 00323 while ($featuremap = db_fetch_object($results)) { 00324 00325 // check if this map already exists in the drupal database. if it 00326 // does then skip this map and go to the next one. 00327 if (!db_fetch_object(db_query($sql, $featuremap->featuremap_id))) { 00328 00329 $new_node = new stdClass(); 00330 $new_node->type = 'chado_featuremap'; 00331 $new_node->uid = $user->uid; 00332 $new_node->title = "$featuremap->name"; 00333 $new_node->featuremap_id = $featuremap->featuremap_id; 00334 00335 node_validate($new_node); 00336 $errors = form_get_errors(); 00337 if (!$errors) { 00338 $node = node_submit($new_node); 00339 node_save($node); 00340 if ($node->nid) { 00341 print "Added " . $featuremap->name . "\n"; 00342 } 00343 else { 00344 print "ERROR: Unable to create " . $featuremap->name . "\n"; 00345 } 00346 } 00347 else { 00348 print "ERROR: Unable to create " . $featuremap->name . "\n" . print_r($errors, TRUE) . "\n"; 00349 } 00350 } 00351 else { 00352 print "Skipped " . $featuremap->name . "\n"; 00353 } 00354 } 00355 return $page_content; 00356 } 00357 00368 function tripal_featuremap_cleanup($dummy = NULL, $job_id = NULL) { 00369 00370 return tripal_core_clean_orphaned_nodes('featuremap', $job_id); 00371 00372 } 00378 function tripal_featuremap_add_taxonomy($node, $featuremap_id) { 00379 00380 }