tripal_stock.admin.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @file
  4. * Administration of stocks
  5. */
  6. /**
  7. * Admin launchpad
  8. *
  9. * @ingroup tripal_legacy_stock
  10. */
  11. function tripal_stock_admin_stock_view() {
  12. $output = '';
  13. // set the breadcrumb
  14. $breadcrumb = [];
  15. $breadcrumb[] = l('Home', '<front>');
  16. $breadcrumb[] = l('Administration', 'admin');
  17. $breadcrumb[] = l('Tripal', 'admin/tripal');
  18. $breadcrumb[] = l('Chado', 'admin/tripal/legacy');
  19. $breadcrumb[] = l('Stocks', 'admin/tripal/legacy/tripal_stock');
  20. drupal_set_breadcrumb($breadcrumb);
  21. // Add the view
  22. $view = views_embed_view('tripal_stock_admin_stocks', 'default');
  23. if (isset($view)) {
  24. $output .= $view;
  25. }
  26. else {
  27. $output .= '<p>The Stock module uses primarily views to provide an '
  28. . 'administrative interface. Currently one or more views needed for this '
  29. . 'administrative interface are disabled. <strong>Click each of the following links to '
  30. . 'enable the pertinent views</strong>:</p>';
  31. $output .= '<ul>';
  32. $output .= '<li>' . l('Stocks View', 'admin/tripal/legacy/tripal_stock/views/stocks/enable') . '</li>';
  33. $output .= '</ul>';
  34. }
  35. return $output;
  36. }
  37. /**
  38. * Provide administration options for chado_stocks
  39. *
  40. * @return
  41. * Form array (as described by the drupal form api)
  42. *
  43. * @ingroup tripal_legacy_stock
  44. */
  45. function tripal_stock_admin() {
  46. $form = [];
  47. // STOCK PAGE TITLES CONFIGURATION
  48. $details = [
  49. 'module' => 'tripal_stock',
  50. 'content_type' => 'chado_stock',
  51. 'options' => [
  52. '[stock.name]' => 'Stock Name Only',
  53. '[stock.uniquename]' => 'Stock Unique Name Only',
  54. '[stock.name], [stock.uniquename] ([stock.type_id>cvterm.name]) [stock.organism_id>organism.genus] [stock.organism_id>organism.species]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name',
  55. ],
  56. 'unique_option' => '[stock.name], [stock.uniquename] ([stock.type_id>cvterm.name]) [stock.organism_id>organism.genus] [stock.organism_id>organism.species]',
  57. ];
  58. chado_add_admin_form_set_title($form, $form_state, $details);
  59. // URL ALIAS
  60. $details = [
  61. 'module' => 'tripal_stock',
  62. 'content_type' => 'chado_stock',
  63. 'options' => [
  64. '/stock/[stock.stock_id]' => 'Stock ID',
  65. '/stock/[stock.organism_id>organism.genus]/[stock.organism_id>organism.species]/[stock.type_id>cvterm.name]/[stock.uniquename]' => 'Unique Contraint: Includes the name, uniquename, type and scientific name',
  66. ],
  67. ];
  68. // This call adds the configuration form to your current form
  69. // This sub-form handles it's own validation & submit
  70. chado_add_admin_form_set_url($form, $form_state, $details);
  71. return system_settings_form($form);
  72. }
  73. /**
  74. * Implements hook_form_validate(): Validates user input
  75. *
  76. * @param $form
  77. * An array describing the form that was rendered
  78. * @param $form_state
  79. * An array describing the current state of the form including user input
  80. *
  81. * @ingroup tripal_legacy_stock
  82. */
  83. function tripal_stock_admin_validate($form, &$form_state) {
  84. global $user; // we need access to the user info
  85. $job_args = [];
  86. switch ($form_state['values']['op']) {
  87. case t('Set Controlled Vacabularies') :
  88. break;
  89. case t('Clean up orphaned stocks') :
  90. tripal_add_job('Cleanup orphaned stocks', 'tripal_stock',
  91. 'tripal_stock_cleanup', $job_args, $user->uid);
  92. break;
  93. }
  94. }