Projet

Général

Profil

Révision c5920ca5

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/webform/views/webform_handler_relationship_submission_data.inc
12 12
    $options = parent::option_definition();
13 13
    $options['webform_nid'] = array('default' => NULL);
14 14
    $options['webform_cid'] = array('default' => NULL);
15
    $options['webform_form_key'] = array('default' => NULL);
16
    $options['webform_join_by'] = array('default' => 'nid_cid');
15 17
    return $options;
16 18
  }
17 19

  
......
27 29

  
28 30
    // Helper function provides webform_nid and webform_cid options.
29 31
    _webform_views_options_form($form, $form_state, $nid, $cid);
32

  
33
    $form['webform_join_by'] = array(
34
      '#type' => 'select',
35
      '#title' => t('Relate using'),
36
      '#default_value' => $this->options['webform_join_by'],
37
      '#options' => array(
38
        'nid_cid' => t('Node and Component ID'),
39
        'cid' => t('Component ID'),
40
        'form_key' => t('Component Form Key'),
41
      ),
42
      '#description' => t('Choose <em>Node and Component ID</em> when this view will display data from only this webform.</br>Choose <em>Component ID</em> when this view will display data from other webforms and where the Component ID is identical.</br>Choose <em>Component Form Key</em> when this view will display data from other webforms with varying Component IDs.'),
43
    );
44

  
30 45
  }
31 46

  
32 47
  /**
......
43 58
  public function options_submit(&$form, &$form_state) {
44 59
    parent::options_submit($form, $form_state);
45 60
    _webform_views_options_submit($form, $form_state);
61
    $options =& $form_state['values']['options'];
62
    $options['webform_form_key'] = $options['webform_join_by_form_key'] == 'form_key' && ($node = node_load($options['webform_nid']))
63
                                        ? $node->webform['components'][$options['webform_cid']]['form_key']
64
                                        : NULL;
65
    // Drop PHP reference.
66
    unset($options);
46 67
  }
47 68

  
48 69
  /**
......
51 72
   * It respects the given component ids, provided via options form.
52 73
   */
53 74
  public function query() {
54
    $this->definition['extra'][] = array(
55
      'table' => NULL,
56
      'field' => "%alias.nid",
57
      'value' => $this->options['webform_nid'],
58
    );
59
    $this->definition['extra'][] = array(
60
      'table' => NULL,
61
      'field' => "%alias.cid",
62
      'value' => $this->options['webform_cid'],
63
    );
75
    // When defining extra clauses, the 'table' key can be used to specify the
76
    // alias of another table. If NULL is specified, then the field is not
77
    // qualified with a table. Therefore, do NOT specify "'table' => NULL".
78
    switch ($this->options['webform_join_by']) {
79
      case 'form_key':
80
        $form_key = $this->options['webform_form_key'];
81
        $join_type = $this->options['required'] ? 'INNER' : 'LEFT';
82

  
83
        $this->ensure_my_table();
84
        $join = new views_join();
85

  
86
        $join->construct(
87
          // The table to be joined.
88
          'webform_component',
89
          // The left table (i.e. this table, webform_submission).
90
          $this->table,
91
          // The left field (i.e. the webform node id).
92
          'nid',
93
          // The field (i.e. webform_components.nid).
94
          'nid',
95
          // Extra array of additional conditions.
96
          array(
97
            array(
98
              // Extra join of form_key.
99
              'field' => 'form_key',
100
              // ...    = $form_key (operator '=' is default)
101
              'value' => $form_key,
102
            ),
103
          ),
104
          // Join type is the same as this relationship's join type.
105
          $join_type);
106

  
107
        $alias = $this->query->add_relationship(
108
          // Requested alias for new reliationship.
109
          'webform_component_' . $form_key,
110
          // Addition join to be added to this relatinship.
111
          $join,
112
          // Base table (i.e. drivingevals_submission)
113
          $this->table_alias,
114
          // Add the view to this relationship.
115
          $this->relationship);
116

  
117
        // The actual alias for this relationship's join is not known yet. Becasue
118
        // of name conflicts, it may have a number appended to the end. %alias is
119
        // substitued when the query is build with the actual alias name.
120
        $this->definition['extra'][] = "%alias.cid = {$alias}.cid";
121
        break;
122

  
123
      case 'nid_cid':
124
        $this->definition['extra'][] = array(
125
          'field' => "nid",
126
          'value' => $this->options['webform_nid'],
127
        );
128
        // FALL THROUGH.
129
      case 'cid':
130
        $this->definition['extra'][] = array(
131
          'field' => "cid",
132
          'value' => $this->options['webform_cid'],
133
        );
134
        break;
135
    }
64 136

  
65 137
    // The rest of building the join is performed by the parent.
66 138
    parent::query();

Formats disponibles : Unified diff