Projet

Général

Profil

Révision 7942932f

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

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/votingapi/votingapi.api.php
93 93
  );
94 94
}
95 95

  
96

  
97
/**
98
 * Return metadata used to build Views relationships on voting data.
99
 *
100
 * VotingAPI can store votes on any entity in the Drupal database: its content_type
101
 * and content_id columns can be used to store "node"/1, "comment"/2, and so
102
 * on. This hook is used to tell VotingAPI what Views base table the content_type
103
 * field corresponds to, and what field in that base table contains the value in
104
 * votingapi's content_id table.
105
 *
106
 * @return
107
 *   An array of records containing 'description', 'content_type', 'base_table',
108
 *   and 'content_id_column' entries.
109
 */
110
function hook_votingapi_relationships() {
111
  $relationships[] = array(
112
    // 'description' is used to construct the field description in the Views UI.
113
    'description' => t('users'),
114

  
115
    // 'content_type' contain the value that your module stores in the voting
116
    // api 'content_type' column. 'node', 'comment', etc.
117
    'content_type' => 'user',
118

  
119
    // 'base_table' contain the name of the Views base table that stores the
120
    // data your votes apply to.
121
    'base_table' => 'user',
122

  
123
    // 'content_id_column' contains the name of the views field that represents
124
    // your base_table's primary key. This column will be joined against the
125
    // voting api 'content_id' column.
126
    'content_id_column' => 'uid',
127

  
128
    // VotingAPI constructs pseudo-tables so that multiple relationships can
129
    // point to the same base table (normal and translation-based votes nodes
130
    // for example. These two columns allow you to override the names of the
131
    // pseudo-tables. You probably don't need to change this part unless you're
132
    // nedjo.
133
    'pseudo_vote' => 'votingapi_vote_special',
134
    'pseudo_cache' => 'votingapi_cache_special',
135
  );
136
}
137

  
138 96
/**
139 97
 * Returns callback functions and descriptions to format a VotingAPI Views field.
140 98
 *
......
189 147
/**
190 148
 * Select invidual votes from the database
191 149
 *
192
/**
193
 * Select individual votes from the database.
194
 *
195 150
 * @param $criteria
196 151
 *   A keyed array used to build the select query. Keys can contain
197 152
 *   a single value or an array of values to be matched.
......
229 184
  return $votes;
230 185
}
231 186

  
187
/**
188
 * Allows to act on votes before being inserted.
189
 *
190
 * @param $votes
191
 *  An array of votes, each with the following structure:
192
 *  $vote['entity_type']  (Optional, defaults to 'node')
193
 *  $vote['entity_id']    (Required)
194
 *  $vote['value_type']    (Optional, defaults to 'percent')
195
 *  $vote['value']         (Required)
196
 *  $vote['tag']           (Optional, defaults to 'vote')
197
 *  $vote['uid']           (Optional, defaults to current user)
198
 *  $vote['vote_source']   (Optional, defaults to current IP)
199
 *  $vote['timestamp']     (Optional, defaults to REQUEST_TIME)
200
 */
201
function hook_votingapi_preset_votes(&$votes) {
202
  foreach ($votes as $vote) {
203
    if ($vote['tag'] == 'recommend') {
204
      // Do something if the 'recommend' vote is being inserted.
205
    }
206
  }
207
}
208

  
232 209
/**
233 210
 * TODO
234 211
 *

Formats disponibles : Unified diff