tripal.collections.inc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. *
  4. */
  5. function tripal_user_collections_page() {
  6. global $user;
  7. $headers = array('Name', 'Description', 'Create Date', 'Downloads Formats', 'Actions');
  8. $rows = array();
  9. $collections = db_select('tripal_collection', 'tc')
  10. ->fields('tc', array('collection_id'))
  11. ->condition('uid', $user->uid)
  12. ->orderBy('tc.collection_name')
  13. ->execute();
  14. while ($collection_id = $collections->fetchField()) {
  15. $collection = new TripalEntityCollection();
  16. $collection->load($collection_id);
  17. $downloads = array();
  18. $formatters = $collection->getDownloadFormatters();
  19. foreach ($formatters as $class_name => $label) {
  20. $outfile = $collection->getOutfilePath($class_name);
  21. $outfileURL = file_create_url($outfile);
  22. if (file_exists($outfile)) {
  23. $downloads[] = l($label, $outfileURL);
  24. }
  25. else {
  26. $downloads[] = 'Waiting on ' . $label . '...';
  27. }
  28. }
  29. $download_list = theme_item_list(array(
  30. 'items' => $downloads,
  31. 'title' => '',
  32. 'type' => 'ul',
  33. 'attributes' => array(),
  34. ));
  35. $rows[] = array(
  36. 'data' => array(
  37. $collection->getName(),
  38. $collection->getDescription(),
  39. $collection->getCreateDate(),
  40. $download_list,
  41. l('Delete', 'user/' . $user->uid . '/data-collections/' . $collection_id . '/delete'),
  42. ),
  43. );
  44. }
  45. $content['instructions'] = array(
  46. '#type' => 'markup',
  47. '#markup' => '<p>' . t('Data collections allow you to store sets of data
  48. for download or later use by other tools on this site. Typically data
  49. collections are created using search tools. The following data
  50. collections are available to you. Some files take time to generate
  51. before they can be downloaded.') . '</p>',
  52. );
  53. $content['files_table'] = array(
  54. '#type' => 'item',
  55. '#title' => 'Data Collections',
  56. '#markup' => theme_table(array(
  57. 'header' => $headers,
  58. 'rows' => $rows,
  59. 'attributes' => array(),
  60. 'caption' => '',
  61. 'colgroups' => array(),
  62. 'sticky' => TRUE,
  63. 'empty' => t('You currently have no data collections.')
  64. )),
  65. );
  66. return $content;
  67. }
  68. function tripal_user_collections_delete_form($form, &$form_state, $uid, $collection_id) {
  69. $form_state['collection_id'] = $collection_id;
  70. $form['#submit'][] = 'tripal_user_collections_delete_form_submit';
  71. $collection = new TripalEntityCollection();
  72. $collection->load($collection_id);
  73. $form = confirm_form($form,
  74. t('Click the delete button below to confirm deletion of the collection titled: %title',
  75. array('%title' => $collection->getName())), 'user/' . $uid . '/data-collections',
  76. '<p>' .t('This action cannot be undone.') .'</p>', t('Delete'), t('Cancel'), 'confirm');
  77. return $form;
  78. }
  79. /**
  80. * Deletes a user's collection.
  81. *
  82. * @param $collection_id
  83. * The ID of the collection to delete.
  84. */
  85. function tripal_user_collections_delete_form_submit($form, &$form_state) {
  86. global $user;
  87. $collection_id = $form_state['collection_id'];
  88. $collection = new TripalEntityCollection();
  89. $collection->load($collection_id);
  90. if ($collection->getUserID() == $user->uid) {
  91. try {
  92. $collection->delete();
  93. drupal_set_message('The data collection has been deleted.');
  94. }
  95. catch (Exception $e) {
  96. drupal_set_message('There was a problem deleting the data collection please contact the site to report the error.', 'error');
  97. }
  98. }
  99. drupal_goto('user/' . $user->uid . '/data-collections');
  100. }