tripal_cv.admin.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * @file
  4. * Provides administration of controlled vocabularies & their terms.
  5. */
  6. /**
  7. * Provide landing page to the new admin pages
  8. *
  9. * @ingroup tripal_cv
  10. */
  11. function tripal_cv_admin_cv_listing() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = array();
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado Modules', 'admin/tripal/chado');
  19. $breadcrumb[] = l('Vocabularies', 'admin/tripal/chado/tripal_cv');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $cvs_view = views_embed_view('tripal_cv_admin_cvs','default');
  23. $cvterms_view = views_embed_view('tripal_cv_admin_cvterms','default');
  24. if (isset($cvs_view) && isset($cvterms_view)) {
  25. $output .= $cvs_view;
  26. }
  27. else {
  28. $output .= '<p>The Tripal Controlled Vocabulary module uses primarily views to provide an '
  29. . 'administrative interface. Currently one or more views needed for this '
  30. . 'administrative interface are disabled. <strong>Click each of the following links to '
  31. . 'enable the pertinent views</strong>:</p>';
  32. $output .= '<ul>';
  33. if (!isset($cvs_view)) {
  34. $output .= '<li>'.l('Tripal Vocabularies', 'admin/tripal/chado/tripal_cv/views/cvs/enable').'</li>';
  35. }
  36. if (!isset($cvterm_view)) {
  37. $output .= '<li>'.l('Tripal Vocabulary Terms', 'admin/tripal/chado/tripal_cv/views/cvterms/enable').'</li>';
  38. }
  39. $output .= '</ul>';
  40. }
  41. return $output;
  42. }
  43. /**
  44. *
  45. */
  46. function tripal_cv_admin_set_defaults_form() {
  47. $form = array();
  48. $form['instructions'] = array(
  49. '#markup' => t('Much of the data housed in Chado is typed, meaning that a ' .
  50. 'controlled vocabulary describes what type of data the record is. For example, '.
  51. 'a feature must have a "type" which is typically a term from ' .
  52. 'the Sequence Ontology. Record properties typically have a type as well. '.
  53. 'Tripal allows the administrator to set a default type for each table in '.
  54. 'Chado that requires a type from a vocabulary. By default, autocomplete fields, '.
  55. 'type select boxes and type validation occur using the default vocabularies set below. '),
  56. );
  57. // get the list of all tables that use the cvterm table as an FK
  58. $cvterm_schema = chado_get_schema('cvterm');
  59. $referring_tables = $cvterm_schema['referring_tables'];
  60. // get the list of tables that already have default set
  61. $cv_defaults = db_select('tripal_cv_defaults', 'TCD')
  62. ->fields('TCD', array('cv_default_id', 'table_name', 'field_name', 'cv_id'))
  63. ->orderBy('table_name', 'ASC')
  64. ->execute();
  65. // get the list of vocabularies
  66. $cvs = tripal_get_cv_select_options();
  67. $form['settings'] = array(
  68. '#type' => 'fieldset',
  69. '#title' => t('Configured Defaults'),
  70. '#description' => t('The following tables have a default vocabulary'),
  71. '#tree' => TRUE,
  72. );
  73. foreach ($cv_defaults as $cv_default) {
  74. $cv_default_id = $cv_default->cv_default_id;
  75. $cv = tripal_get_cv(array('cv_id' => $cv_default->cv_id));
  76. $form['settings']['existing'][$cv_default_id]["id"] = array(
  77. '#type' => 'hidden',
  78. '#value' => $cv_default_id,
  79. );
  80. $form['settings']['existing'][$cv_default_id]["table_name"] = array(
  81. '#type' => 'markup',
  82. '#markup' => $cv_default->table_name
  83. );
  84. $form['settings']['existing'][$cv_default_id]["field_name"] = array(
  85. '#type' => 'markup',
  86. '#markup' => $cv_default->field_name
  87. );
  88. $form['settings']['existing'][$cv_default_id]["vocabulary"] = array(
  89. '#type' => 'select',
  90. '#options' => $cvs,
  91. '#default_value' => $cv_default->cv_id,
  92. '#suffix' => '<a target="_blank" href="'. url('admin/tripal/chado/tripal_cv/cvterms') . '?cv=' . $cv->name . '">View terms</a>'
  93. );
  94. // remove button
  95. $form['settings']['existing'][$cv_default_id]['remove'] = array(
  96. '#type' => 'submit',
  97. '#value' => t('Remove'),
  98. '#name' => "cv_remove-$cv_default_id",
  99. '#ajax' => array(
  100. 'callback' => "tripal_cv_admin_set_defaults_ajax_update",
  101. 'wrapper' => 'tripal-generic-edit-properties-table',
  102. 'effect' => 'fade',
  103. 'method' => 'replace',
  104. 'prevent' => 'click'
  105. ),
  106. // When this button is clicked, the form will be validated and submitted.
  107. // Therefore, we set custom submit and validate functions to override the
  108. // default node form submit. In the validate function we validate only the
  109. // property fields and in the submit we remove the indicated property
  110. // from the chado_properties array. In order to keep validate errors
  111. // from the node form validate and Drupal required errors for non-property fields
  112. // preventing the user from removing properties we set the #limit_validation_errors below
  113. '#validate' => array('chado_add_node_form_properties_remove_button_validate'),
  114. '#submit' => array('chado_add_node_form_properties_remove_button_submit'),
  115. // Limit the validation of the form upon clicking this button to the property_table tree
  116. // No other fields will be validated (ie: no fields from the main form or any other api
  117. // added form).
  118. '#limit_validation_errors' => array(
  119. array('property_table') // Validate all fields within $form_state['values']['property_table']
  120. )
  121. );
  122. }
  123. return $form;
  124. }
  125. /**
  126. *
  127. * @param unknown $variables
  128. */
  129. function theme_tripal_cv_admin_set_defaults_form($variables) {
  130. $element = $variables['element'];
  131. $header = array(
  132. 'table_name' => array('data' => t('Table Name'), 'width' => '20%'),
  133. 'field_name' => array('data' => t('Field Name'), 'width' => '20%'),
  134. 'vocabulary' => array('data' => t('Default Vocabulary'), 'width' => '40%'),
  135. 'property_action' => array('data' => t('Actions'), 'width' => '20%'),
  136. );
  137. $rows = array();
  138. foreach ($element['settings']['existing'] as $key => $value) {
  139. if (is_numeric($key)) {
  140. $rows[] = array(
  141. drupal_render($value['table_name']),
  142. drupal_render($value['field_name']),
  143. drupal_render($value['vocabulary']),
  144. drupal_render($value['remove']),
  145. );
  146. }
  147. }
  148. $settings_table = theme('table', array(
  149. 'header' => $header,
  150. 'rows' => $rows
  151. ));
  152. $element['settings']['existing'] = array(
  153. '#type' => 'markup',
  154. '#markup' => $settings_table,
  155. );
  156. return drupal_render_children($element);
  157. }