Projet

Général

Profil

Paste
Télécharger (2,95 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / views / webform_plugin_row_submission_view.inc @ 01f36513

1
<?php
2

    
3
/**
4
 * Contains the submission view row style plugin.
5
 *
6
 * Plugin which performs a webform_submission_render on the resulting object.
7
 *
8
 * Most of the code on this object is in the theme function.
9
 *
10
 * @ingroup views_row_plugins
11
 */
12
class webform_views_plugin_row_submission_view extends views_plugin_row {
13

    
14
  /**
15
   * Basic properties that let the row style follow relationships.
16
   *
17
   * @var string
18
   */
19
  public $base_table = 'webform_submissions';
20
  public $base_field = 'sid';
21

    
22
  /**
23
   * Stores the nodes loaded with pre_render.
24
   *
25
   * @var array
26
   */
27
  private $submissions = array();
28
  private $nodes = array();
29

    
30
  /**
31
   *
32
   */
33
  public function option_definition() {
34
    $options = parent::option_definition();
35

    
36
    $options['format'] = array('default' => 'html');
37

    
38
    return $options;
39
  }
40

    
41
  /**
42
   *
43
   */
44
  public function options_form(&$form, &$form_state) {
45
    parent::options_form($form, $form_state);
46

    
47
    $options = $this->options_form_summary_options();
48
    $form['format'] = array(
49
      '#type' => 'radios',
50
      '#options' => $options,
51
      '#title' => t('Display mode'),
52
      '#default_value' => $this->options['format'],
53
    );
54
  }
55

    
56
  /**
57
   * Return the main options, which are shown in the summary title.
58
   */
59
  public function options_form_summary_options() {
60
    return array(
61
      'html' => t('HTML'),
62
      'text' => t('Plain text'),
63
    );
64
  }
65

    
66
  /**
67
   *
68
   */
69
  public function summary_title() {
70
    $options = $this->options_form_summary_options();
71
    return check_plain($options[$this->options['format']]);
72
  }
73

    
74
  /**
75
   *
76
   */
77
  public function pre_render($values) {
78
    $sids = array();
79
    foreach ($values as $row) {
80
      $sids[] = $row->{$this->field_alias};
81
    }
82
    module_load_include('inc', 'webform', 'includes/webform.submissions');
83
    $this->submissions = $sids ? webform_get_submissions(array('sid' => $sids)) : array();
84

    
85
    $nids = array();
86
    foreach ($this->submissions as $sid => $submission) {
87
      $nids[] = $submission->nid;
88
    }
89
    $nids = array_unique($nids);
90
    $this->nodes = $nids ? node_load_multiple($nids) : array();
91
  }
92

    
93
  /**
94
   *
95
   */
96
  public function render($row) {
97
    if (isset($this->submissions[$row->{$this->field_alias}])) {
98
      $submission = $this->submissions[$row->{$this->field_alias}];
99
      $node = $this->nodes[$submission->nid];
100
      $submission->view = $this->view;
101
      $format = $this->options['format'];
102
      $build = webform_submission_render($node, $submission, NULL, $format);
103

    
104
      // Add extra theme functions:
105
      $themes = array();
106
      foreach ($build['#theme'] as $hook) {
107
        $themes = array_merge($themes, _views_theme_functions($hook, $this->view, $this->view->display[$this->view->current_display]));
108
      }
109
      $build['#theme'] = $themes;
110

    
111
      // Render built submission, and if unsanitized plain text is used, make it safe for display.
112
      $render = drupal_render($build);
113
      return $format == 'html' ? $render : nl2br(check_plain($render));
114
    }
115
  }
116

    
117
}