accessibility_reporting.module

  1. cis7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  2. cle7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  3. ecd7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  4. elmsmedia7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  5. harmony7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  6. icor7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  7. meedjum_blog7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
  8. mooc7 sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module

Functions

File

sites/all/modules/ulmus/accessibility/modules/accessibility_reporting/accessibility_reporting.module
View source
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. function accessibility_reporting_menu() {
  6. $items = array();
  7. $items['accessibility/reporting/report'] = array(
  8. 'page callback' => 'accessibility_reporting_report',
  9. 'access arguments' => array('report acessibility results'),
  10. );
  11. return $items;
  12. }
  13. /**
  14. * Implements hook_permission().
  15. */
  16. function accessibility_reporting_permission() {
  17. return array('report acessibility results' => array(
  18. 'title' => t('User will report accessibility problems'),
  19. 'description' => t('When a user views a page, all accessibility problems are reported back.'),
  20. ),
  21. 'view acessibility reports' => array(
  22. 'title' => t('User can view accessibility reports'),
  23. 'description' => t('Users can read the results of accessibility reports.'),
  24. ),
  25. );
  26. }
  27. /**
  28. * Implements hook_form_FORM_ID_alter().
  29. */
  30. function accessibility_reporting_form_field_ui_field_edit_form_alter(&$form, $form_state) {
  31. if (in_array($form['#field']['type'], array('text_with_summary'))) {
  32. $form['instance']['accessibility_reporting'] = array(
  33. '#type' => 'checkbox',
  34. '#title' => t('Report on accessibility problems in this field.'),
  35. '#description' => t('When checked, every time this field is viewed accessibility problems are reported back.'),
  36. '#default_value' => (isset($form['#instance']['accessibility_reporting'])) ?
  37. $form['#instance']['accessibility_reporting'] :
  38. FALSE,
  39. );
  40. }
  41. }
  42. /**
  43. * Implements hook_field_attach_view_alter().
  44. */
  45. function accessibility_reporting_field_attach_view_alter(&$output, $context) {
  46. if (user_access('report accessibility results')) {
  47. $js_set = drupal_static(__FUNCTION__);
  48. foreach ($output as $field_key => $field) {
  49. if (is_array($field) && isset($field['#field_name'])) {
  50. $field = field_info_instance($field['#entity_type'], $field['#field_name'], $field['#bundle']);
  51. if (isset($field['accessibility_reporting']) && $field['accessibility_reporting']) {
  52. if(!$js_set) {
  53. drupal_add_js(drupal_get_path('module' , 'accessibility_reporting') . '/js/accessibility_reporting.js');
  54. accessibility_load();
  55. $js_set = TRUE;
  56. }
  57. $output[$field_key]['#pre_render'][] = '_accessibility_reporting_field_pre_render';
  58. }
  59. }
  60. }
  61. }
  62. }
  63. /**
  64. * Pre-render callback to wrap fields in a span.
  65. */
  66. function _accessibility_reporting_field_pre_render($element) {
  67. $element['#prefix'] = (isset($element['#prefix'])) ? $element['#prefix'] : '';
  68. $element['#suffix'] = (isset($element['#suffix'])) ? $element['#suffix'] : '';
  69. $info = entity_get_info($element['#entity_type']);
  70. $attributes = array('class' => array('accessibility-report-field'),
  71. 'data-field' => $element['#field_name'],
  72. 'data-entity-type' => $element['#entity_type'],
  73. 'data-bundle' => $element['#bundle'],
  74. 'data-entity-id' => $element['#object']->{$info['entity keys']['id']}
  75. );
  76. $element['#prefix'] = '<span ' . drupal_attributes($attributes) . '>' . $element['#prefix'];
  77. $element['#suffix'] .= '</span>';
  78. return $element;
  79. }
  80. /**
  81. * Report callback. Stores posted data to accessibility_reporting table.
  82. */
  83. function accessibility_reporting_report() {
  84. if(!isset($_POST['results'])) {
  85. return;
  86. }
  87. foreach($_POST['results'] as $result) {
  88. array_walk($result, 'check_plain');
  89. db_delete('accessibility_reporting')
  90. ->condition('entity_type', $result['entity_type'])
  91. ->condition('entity_id', $result['entity_id'])
  92. ->execute();
  93. if(isset($result['total']) && count($result['total'])) {
  94. foreach($result['total'] as $test_id => $total) {
  95. db_insert('accessibility_reporting')
  96. ->fields(array('test_id' => $test_id,
  97. 'entity_type' => $result['entity_type'],
  98. 'bundle' => $result['bundle'],
  99. 'entity_id' => $result['entity_id'],
  100. 'field' => $result['field'],
  101. 'total' => $total,
  102. ))
  103. ->execute();
  104. }
  105. }
  106. }
  107. }
  108. /**
  109. * Implements hook_views_api().
  110. */
  111. function accessibility_reporting_views_api() {
  112. return array(
  113. 'api' => 3,
  114. 'path' => drupal_get_path('module', 'accessibility_reporting') . '/views',
  115. );
  116. }