123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <?php
- /**
- * Administrative settings form
- *
- * @ingroup tripal_featuremap
- */
- function tripal_featuremap_admin() {
- $form = array();
- // before proceeding check to see if we have any
- // currently processing jobs. If so, we don't want
- // to give the opportunity to sync maps
- $active_jobs = FALSE;
- if (tripal_get_module_active_jobs('tripal_featuremap')) {
- $active_jobs = TRUE;
- }
- // add the field set for syncing maps
- if (!$active_jobs) {
- get_tripal_featuremap_admin_form_sync_set($form);
- get_tripal_featuremap_admin_form_cleanup_set($form);
- // TODO: complete coding of indexing and taxonomy assignment to features.
- // get_tripal_featuremap_admin_form_reindex_set($form);
- // get_tripal_featuremap_admin_form_taxonomy_set($form);
- }
- else {
- $form['notice'] = array(
- '#type' => 'fieldset',
- '#title' => t('Feature Map Management Temporarily Unavailable')
- );
- $form['notice']['message'] = array(
- '#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.'),
- );
- }
- return system_settings_form($form);
- }
- /**
- *
- *
- * @ingroup tripal_featuremap
- */
- function get_tripal_featuremap_admin_form_cleanup_set(&$form) {
- $form['cleanup'] = array(
- '#type' => 'fieldset',
- '#title' => t('Clean Up')
- );
- $form['cleanup']['description'] = array(
- '#type' => 'item',
- '#value' => t("With Drupal and chado residing in different databases ".
- "it is possible that nodes in Drupal and maps in Chado become ".
- "\"orphaned\". This can occur if an map node in Drupal is ".
- "deleted but the corresponding chado map is not and/or vice ".
- "versa. Click the button below to resolve these discrepancies."),
- '#weight' => 1,
- );
- $form['cleanup']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Clean up orphaned maps'),
- '#weight' => 2,
- );
- }
- /**
- *
- *
- * @ingroup tripal_featuremap
- */
- function get_tripal_featuremap_admin_form_taxonomy_set(&$form) {
- $form['taxonify'] = array(
- '#type' => 'fieldset',
- '#title' => t('Assign Drupal Taxonomy to Map Features')
- );
- // get the list of maps
- $sql = "SELECT * FROM {featuremap} ORDER BY name";
- $lib_rset = chado_query($sql);
- // iterate through all of the maps
- $lib_boxes = array();
- while ($featuremap = db_fetch_object($lib_rset)) {
- $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name";
- }
- $form['taxonify']['description'] = array(
- '#type' => 'item',
- '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
- "nodes. These terms allow for advanced filtering during searching. This option allows ".
- "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."),
- '#weight' => 1,
- );
- $form['taxonify']['tx-maps'] = array(
- '#title' => t('Maps'),
- '#type' => t('checkboxes'),
- '#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."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2
- );
- $form['taxonify']['tx-button'] = array(
- '#type' => 'submit',
- '#value' => t('Set Feature Taxonomy'),
- '#weight' => 3
- );
- }
- /**
- *
- * @ingroup tripal_featuremap
- */
- function get_tripal_featuremap_admin_form_reindex_set(&$form) {
- // define the fieldsets
- $form['reindex'] = array(
- '#type' => 'fieldset',
- '#title' => t('Reindex Map Features')
- );
- // get the list of maps
- $sql = "SELECT * FROM {featuremap} ORDER BY name";
- $lib_rset = chado_query($sql);
- // iterate through all of the maps
- $lib_boxes = array();
- while ($featuremap = db_fetch_object($lib_rset)) {
- $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name";
- }
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#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."),
- '#weight' => 1,
- );
- $form['reindex']['re-maps'] = array(
- '#title' => t('Maps'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2,
- );
- $form['reindex']['re-button'] = array(
- '#type' => 'submit',
- '#value' => t('Reindex Features'),
- '#weight' => 3,
- );
- }
- /**
- *
- * @ingroup tripal_featuremap
- */
- function get_tripal_featuremap_admin_form_sync_set(&$form) {
- // define the fieldsets
- $form['sync'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sync Maps')
- );
- // get the list of maps
- $sql = "SELECT * FROM {featuremap} ORDER BY name";
- $lib_rset = chado_query($sql);
- // if we've added any maps to the list that can be synced
- // then we want to build the form components to allow the user
- // to select one or all of them. Otherwise, just present
- // a message stating that all maps are currently synced.
- $lib_boxes = array();
- $added = 0;
- while ($featuremap = db_fetch_object($lib_rset)) {
- // check to see if the map is already present as a node in drupal.
- // if so, then skip it.
- $sql = "SELECT * FROM {chado_featuremap} WHERE featuremap_id = %d";
- if (!db_fetch_object(db_query($sql, $featuremap->featuremap_id))) {
- $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name";
- $added++;
- }
- }
- // if we have maps we need to add to the checkbox then
- // build that form element
- if ($added > 0) {
- $lib_boxes['all'] = "All Maps";
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for the creation of Drupal content for maps in chado. Only the selected maps will be synced."),
- '#weight' => 1,
- );
- $form['sync']['featuremaps'] = array(
- '#title' => t('Available Maps'),
- '#type' => t('checkboxes'),
- '#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."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $lib_boxes,
- '#weight' => 2,
- );
- $form['sync']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Sync Maps'),
- '#weight' => 3,
- );
- }
- // we don't have any maps to select from
- else {
- $form['sync']['value'] = array(
- '#value' => t('All maps in Chado are currently synced with Drupal.')
- );
- }
- }
- /**
- *
- * @ingroup tripal_featuremap
- */
- function tripal_featuremap_admin_validate($form, &$form_state) {
- global $user; // we need access to the user info
- $job_args = array();
- // Submit the Sync Job if selected
- if ($form_state['values']['op'] == t('Sync Maps')) {
- // check to see if the user wants to sync chado and drupal. If
- // so then we need to register a job to do so with tripal
- $featuremaps = $form_state['values']['featuremaps'];
- $do_all = FALSE;
- $to_sync = array();
- foreach ($featuremaps as $featuremap_id) {
- if (preg_match("/^all$/i", $featuremap_id)) {
- $do_all = TRUE;
- }
- if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
- // get the map info
- $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d";
- $featuremap = db_fetch_object(chado_query($sql, $featuremap_id));
- $to_sync[$featuremap_id] = $featuremap->name;
- }
- }
- // submit the job to the tripal job manager
- if ($do_all) {
- tripal_add_job('Sync all maps', 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid);
- }
- else{
- foreach ($to_sync as $featuremap_id => $name) {
- $job_args[0] = $featuremap_id;
- tripal_add_job("Sync map: $name", 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid);
- }
- }
- }
- // -------------------------------------
- // Submit the Reindex Job if selected
- if ($form_state['values']['op'] == t('Reindex Features')) {
- $featuremaps = $form_state['values']['re-maps'];
- foreach ($featuremaps as $featuremap_id) {
- if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
- // get the map info
- $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d";
- $featuremap = db_fetch_object(chado_query($sql, $featuremap_id));
- $job_args[0] = $featuremap_id;
- tripal_add_job("Reindex features for map: $featuremap->name", 'tripal_featuremap',
- 'tripal_featuremap_reindex_features', $job_args, $user->uid);
- }
- }
- }
- // -------------------------------------
- // Submit the Taxonomy Job if selected
- if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
- $featuremaps = $form_state['values']['tx-maps'];
- foreach ($featuremaps as $featuremap_id) {
- if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
- // get the map info
- $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = %d";
- $featuremap = db_fetch_object(chado_query($sql, $featuremap_id));
- $job_args[0] = $featuremap_id;
- tripal_add_job("Set taxonomy for features in map: $featuremap->name", 'tripal_featuremap',
- 'tripal_featuremap_taxonify_features', $job_args, $user->uid);
- }
- }
- }
- // -------------------------------------
- // Submit the Cleanup Job if selected
- if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
- tripal_add_job('Cleanup orphaned maps', 'tripal_featuremap',
- 'tripal_featuremap_cleanup', $job_args, $user->uid);
- }
- }
- /**
- *
- *
- * @ingroup tripal_featuremap
- */
- function tripal_featuremap_sync_featuremaps($featuremap_id = NULL, $job_id = NULL) {
- global $user;
- $page_content = '';
- // get the list of featuremaps and create new nodes
- if (!$featuremap_id) {
- $sql = "SELECT * FROM {featuremap} L";
- $results = chado_query($sql);
- }
- else {
- $sql = "SELECT * FROM {featuremap} L WHERE featuremap_id = %d";
- $results = chado_query($sql, $featuremap_id);
- }
- // We'll use the following SQL statement for checking if the map
- // already exists as a drupal node.
- $sql = "SELECT * FROM {chado_featuremap} ".
- "WHERE featuremap_id = %d";
- while ($featuremap = db_fetch_object($results)) {
- // check if this map already exists in the drupal database. if it
- // does then skip this map and go to the next one.
- if (!db_fetch_object(db_query($sql, $featuremap->featuremap_id))) {
- $new_node = new stdClass();
- $new_node->type = 'chado_featuremap';
- $new_node->uid = $user->uid;
- $new_node->title = "$featuremap->name";
- $new_node->featuremap_id = $featuremap->featuremap_id;
- node_validate($new_node);
- $errors = form_get_errors();
- if (!$errors) {
- $node = node_submit($new_node);
- node_save($node);
- if ($node->nid) {
- print "Added " . $featuremap->name . "\n";
- }
- else {
- print "ERROR: Unable to create " . $featuremap->name . "\n";
- }
- }
- else {
- print "ERROR: Unable to create " . $featuremap->name . "\n" . print_r($errors, TRUE) . "\n";
- }
- }
- else {
- print "Skipped " . $featuremap->name . "\n";
- }
- }
- return $page_content;
- }
- /**
- * Remove orphaned drupal nodes
- *
- * @param $dummy
- * Not Used -kept for backwards compatibility
- * @param $job_id
- * The id of the tripal job executing this function
- *
- * @ingroup tripal_featuremap
- */
- function tripal_featuremap_cleanup($dummy = NULL, $job_id = NULL) {
- return tripal_core_clean_orphaned_nodes('featuremap', $job_id);
-
- }
- /**
- * Add the map as a taxonomy term for associating with map_features
- *
- * @ingroup tripal_featuremap
- */
- function tripal_featuremap_add_taxonomy($node, $featuremap_id) {
- }
|