~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to sites/all/modules/views/includes/analyze.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: analyze.inc,v 1.1 2008/10/28 22:50:00 merlinofchaos Exp $
 
3
 
 
4
/**
 
5
 * @file
 
6
 * Contains the view analyze tool code.
 
7
 *
 
8
 * This tool is a small plugin manager to perform analysis on a view and
 
9
 * report results to the user. This tool is meant to let modules that
 
10
 * provide data to Views also help users properly use that data by
 
11
 * detecting invalid configurations. Views itself comes with only a
 
12
 * small amount of analysis tools, but more could easily be added either
 
13
 * by modules or as patches to Views itself.
 
14
 */
 
15
 
 
16
/**
 
17
 * Analyze a review and return the results.
 
18
 *
 
19
 * @return
 
20
 *   An array of analyze results organized into arrays keyed by 'ok',
 
21
 *   'warning' and 'error'.
 
22
 */
 
23
function views_analyze_view(&$view) {
 
24
  $view->init_display();
 
25
  $messages = module_invoke_all('views_analyze', $view);
 
26
 
 
27
  return $messages;
 
28
}
 
29
 
 
30
/**
 
31
 * Format the analyze result into a message string.
 
32
 *
 
33
 * This is based upon the format of drupal_set_message which uses separate
 
34
 * boxes for "ok", "warning" and "error".
 
35
 */
 
36
function views_analyze_format_result($view, $messages) {
 
37
  if (empty($messages)) {
 
38
    $messages = array(views_ui_analysis(t('View analysis can find nothing to report.'), 'ok'));
 
39
  }
 
40
 
 
41
  $types = array('ok' => array(), 'warning' => array(), 'error' => array());
 
42
  foreach ($messages as $message) {
 
43
    if (empty($types[$message['type']])) {
 
44
      $types[$message['type']] = array();
 
45
    }
 
46
    $types[$message['type']][] = $message['message'];
 
47
  }
 
48
 
 
49
  $output = '';
 
50
  foreach ($types as $type => $messages) {
 
51
    $message = '';
 
52
    if (count($messages) > 1) {
 
53
      $message = theme('item_list', $messages);
 
54
    }
 
55
    else if ($messages) {
 
56
      $message = array_shift($messages);
 
57
    }
 
58
 
 
59
    if ($message) {
 
60
      $output .= "<div class=\"$type\">$message</div>";
 
61
    }
 
62
  }
 
63
 
 
64
  return $output;
 
65
}
 
66
 
 
67
/**
 
68
 * Format an analysis message.
 
69
 *
 
70
 * This tool should be called by any module responding to the analyze hook
 
71
 * to properly format the message. It is usually used in the form:
 
72
 * @code
 
73
 *   $ret[] = views_ui_analysis(t('This is the message'), 'ok');
 
74
 * @endcode
 
75
 *
 
76
 * The 'ok' status should be used to provide information about things
 
77
 * that are acceptable. In general analysis isn't interested in 'ok'
 
78
 * messages, but instead the 'warning', which is a category for items
 
79
 * that may be broken unless the user knows what he or she is doing,
 
80
 * and 'error' for items that are definitely broken are much more useful.
 
81
 *
 
82
 * @param $messages
 
83
 *   The message to report.
 
84
 * @param $type
 
85
 *   The type of message. This should be "ok", "warning" or "error". Other
 
86
 *   values can be used but how they are treated by the output routine
 
87
 *   is undefined.
 
88
 */
 
89
function views_ui_analysis($message, $type = 'error') {
 
90
  return array('message' => $message, 'type' => $type);
 
91
}
 
92
 
 
93
/**
 
94
 * Implementation of hook_views_analyze().
 
95
 *
 
96
 * This is the basic views analysis that checks for very minimal problems.
 
97
 * There are other analysis tools in core specific sections, such as
 
98
 * node.views.inc as well.
 
99
 */
 
100
function views_ui_views_analyze($view) {
 
101
  $ret = array();
 
102
  // Check for something other than the default display:
 
103
  if (count($view->display) < 2) {
 
104
    $ret[] = views_ui_analysis(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning');
 
105
  }
 
106
 
 
107
  return $ret;
 
108
}
 
109