tripal_daemon.blocks.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions related to administrative blocks for daemon monitoring.
  5. */
  6. /**
  7. * Implements hook_block_info().
  8. */
  9. function tripal_daemon_block_info() {
  10. $blocks = array();
  11. $blocks['tripal_daemon_status'] = array(
  12. 'info' => t('Tripal Daemon Status'),
  13. );
  14. return $blocks;
  15. }
  16. /**
  17. * Implements hook_block_view().
  18. */
  19. function tripal_daemon_block_view($delta='') {
  20. $block = array();
  21. switch($delta) {
  22. case 'tripal_daemon_status':
  23. $is_running = drushd_is_daemon_running('tripal_daemon');
  24. $status_class = ($is_running) ? 'active' : 'inactive';
  25. $block['subject'] = t('Job Daemon Status');
  26. $block['content'] = theme_tripal_daemon_status_block_content();
  27. break;
  28. }
  29. return $block;
  30. }
  31. /**
  32. *
  33. */
  34. function theme_tripal_daemon_status_block_content() {
  35. $output = '';
  36. // Get information.
  37. $is_running = drushd_is_daemon_running('tripal_daemon');
  38. $status_file = drushd_get_daemon_status_file('tripal_daemon');
  39. $status = unserialize(file_get_contents($status_file));
  40. $status_class = ($is_running) ? 'active' : 'inactive';
  41. // Theme content.
  42. drupal_add_css(drupal_get_path('module','tripal_daemon') . '/theme/status_block.css');
  43. $output .= '<div class="daemon-status">';
  44. if ($is_running) {
  45. $output .= theme_image(array(
  46. 'path' => 'misc/message-24-ok.png',
  47. 'alt' => 'status-ok',
  48. ));
  49. $output .= 'Running';
  50. }
  51. else {
  52. $output .= theme_image(array(
  53. 'path' => 'misc/message-24-error.png',
  54. 'alt' => 'status-error',
  55. ));
  56. $output .= 'Stopped';
  57. }
  58. $output .= '</div>';
  59. $output .= '<ul>';
  60. foreach ($status as $k => $v) {
  61. if (is_bool($v)) {
  62. $v = ($v) ? 'True' : 'False';
  63. }
  64. $output .= '<li><strong>' . $k . '</strong>: ' . $v . '</li>';
  65. }
  66. $output .= '</ul>';
  67. return '<div class="inner '.$status_class.'">' . $output . '</div>';
  68. }