| 1 |
<?php
|
| 2 |
// $Id: biblio.views.inc,v 1.17 2009/06/25 18:23:09 rjerome Exp $
|
| 3 |
function biblio_views_plugins() {
|
| 4 |
return array(
|
| 5 |
'display' => array(
|
| 6 |
'biblio' => array(
|
| 7 |
'title' => t('Biblio Page'),
|
| 8 |
'help' => t(''),
|
| 9 |
'handler' => 'views_plugin_display_page_biblio',
|
| 10 |
'path' => drupal_get_path('module', 'biblio') . '/views', // not necessary for most modules
|
| 11 |
// 'theme' => 'views_view_row_node',
|
| 12 |
'base' => array('node'), // only works with 'node' as base.
|
| 13 |
'uses options' => TRUE,
|
| 14 |
'type' => 'normal',
|
| 15 |
),
|
| 16 |
),
|
| 17 |
'style' => array(
|
| 18 |
// ... list of style plugins,
|
| 19 |
),
|
| 20 |
'row' => array(
|
| 21 |
// ... list of row style plugins,
|
| 22 |
),
|
| 23 |
'argument default' => array(
|
| 24 |
// ... list of argument default plugins,
|
| 25 |
),
|
| 26 |
'argument validator' => array(
|
| 27 |
// ... list of argument validator plugins,
|
| 28 |
),
|
| 29 |
'access' => array(
|
| 30 |
// ... list of access plugins,
|
| 31 |
),
|
| 32 |
);
|
| 33 |
}
|
| 34 |
/**
|
| 35 |
* Implementation of hook_views_handlers().
|
| 36 |
*/
|
| 37 |
function biblio_views_handlers() {
|
| 38 |
return array(
|
| 39 |
'info' => array(
|
| 40 |
'path' => drupal_get_path('module', 'biblio') . '/views',
|
| 41 |
),
|
| 42 |
'handlers' => array(
|
| 43 |
/*
|
| 44 |
* Fields
|
| 45 |
*/
|
| 46 |
'biblio_handler_field' => array(
|
| 47 |
'parent' => 'views_handler_field',
|
| 48 |
),
|
| 49 |
'biblio_handler_citation' => array(
|
| 50 |
'parent' => 'views_handler_field',
|
| 51 |
),
|
| 52 |
'biblio_handler_field_contributor' => array(
|
| 53 |
'parent' => 'biblio_handler_field',
|
| 54 |
),
|
| 55 |
'biblio_handler_field_biblio_type' => array(
|
| 56 |
'parent' => 'biblio_handler_field',
|
| 57 |
),
|
| 58 |
'biblio_handler_field_biblio_keyword_kid' => array(
|
| 59 |
'parent' => 'views_handler_field_prerender_list',
|
| 60 |
),
|
| 61 |
'biblio_handler_field_biblio_keyword_data_word' => array(
|
| 62 |
'parent' => 'biblio_handler_field',
|
| 63 |
),
|
| 64 |
/*
|
| 65 |
* Filters
|
| 66 |
*/
|
| 67 |
'biblio_handler_filter_contributor' => array(
|
| 68 |
'parent' => 'views_handler_filter_many_to_one',
|
| 69 |
),
|
| 70 |
'biblio_handler_filter_biblio_type' => array(
|
| 71 |
'parent' => 'views_handler_filter_in_operator',
|
| 72 |
),
|
| 73 |
'biblio_handler_filter_biblio_contributor_auth_type' => array(
|
| 74 |
'parent' => 'views_handler_filter_in_operator',
|
| 75 |
),
|
| 76 |
'biblio_handler_filter_biblio_keyword_kid' => array(
|
| 77 |
'parent' => 'views_handler_filter_many_to_one',
|
| 78 |
),
|
| 79 |
)
|
| 80 |
);
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Implementation of hook_views_data().
|
| 85 |
*
|
| 86 |
* Exposes all fields to the views system.
|
| 87 |
*/
|
| 88 |
function biblio_views_data() {
|
| 89 |
$viewsdata = array();
|
| 90 |
|
| 91 |
/**************** biblio table **************/
|
| 92 |
$data = array();
|
| 93 |
// everything belongs to the Biblio group
|
| 94 |
$data['table']['group'] = t('Biblio');
|
| 95 |
|
| 96 |
$data['citation'] = array(
|
| 97 |
'title' => t('Biblio Citation'),
|
| 98 |
'help' => t("Display the complete citation for a given node"),
|
| 99 |
'field' => array(
|
| 100 |
'handler' => 'biblio_handler_citation',
|
| 101 |
),
|
| 102 |
);
|
| 103 |
$result = db_query('SELECT f.name,f.type,ftd.title,ft.ftdid FROM {biblio_fields} f
|
| 104 |
INNER JOIN {biblio_field_type} AS ft ON ft.fid = f.fid
|
| 105 |
INNER JOIN {biblio_field_type_data} ftd ON ft.ftdid = ftd.ftdid
|
| 106 |
WHERE ft.tid=0');
|
| 107 |
|
| 108 |
while ($field = db_fetch_array($result)){
|
| 109 |
$data[$field['name']] = array(
|
| 110 |
'title' => $field['title'],
|
| 111 |
'help' => "Display the " . $field['title'],
|
| 112 |
'field' => array('handler' => 'biblio_handler_field'),
|
| 113 |
'sort' => array('handler' => 'views_handler_sort'),
|
| 114 |
'filter' => array('handler' => 'views_handler_filter_string'),
|
| 115 |
'argument' => array('handler' => 'views_handler_argument_string')
|
| 116 |
);
|
| 117 |
|
| 118 |
// for contrib_widgets we use a special handler:
|
| 119 |
if ($field['type'] == 'contrib_widget') {
|
| 120 |
$data[$field['name']]['field'] = array(
|
| 121 |
'handler' => 'biblio_handler_field_contributor',
|
| 122 |
'auth_category' => $field['ftdid'],
|
| 123 |
);
|
| 124 |
unset($data[$field['name']]['sort']);
|
| 125 |
unset($data[$field['name']]['filter']);
|
| 126 |
unset($data[$field['name']]['argument']);
|
| 127 |
}
|
| 128 |
}
|
| 129 |
$data['biblio_year']['argument'] = array('handler' => 'views_handler_argument_numeric'); // biblio_year is an int
|
| 130 |
$data['biblio_year']['filter'] = array('handler' => 'views_handler_filter_numeric'); // biblio_year is an int
|
| 131 |
unset($data['biblio_keywords']); // keywords are in a separate table which has it's own handlers
|
| 132 |
|
| 133 |
$data['table']['join'] = array(
|
| 134 |
'node' => array(
|
| 135 |
// links directly to node via vid
|
| 136 |
'left_field' => 'vid',
|
| 137 |
'field' => 'vid',
|
| 138 |
'type' => 'inner',
|
| 139 |
),
|
| 140 |
'node_revisions' => array(
|
| 141 |
'left_field' => 'vid',
|
| 142 |
'field' => 'vid',
|
| 143 |
'type' => 'inner',
|
| 144 |
),
|
| 145 |
);
|
| 146 |
|
| 147 |
$viewsdata['biblio'] = $data;
|
| 148 |
|
| 149 |
/**************** biblio_types table *********************/
|
| 150 |
|
| 151 |
$data = array();
|
| 152 |
$data['table']['group'] = t('Biblio');
|
| 153 |
$data['table']['join'] = array(
|
| 154 |
'node' => array(
|
| 155 |
'left_table' => 'biblio',
|
| 156 |
'left_field' => 'biblio_type',
|
| 157 |
'field' => 'tid',
|
| 158 |
),
|
| 159 |
'node_revision' => array(
|
| 160 |
'left_table' => 'biblio',
|
| 161 |
'left_field' => 'biblio_type',
|
| 162 |
'field' => 'tid',
|
| 163 |
),
|
| 164 |
);
|
| 165 |
$data['name'] = array(
|
| 166 |
'field' => array('handler' => 'views_handler_field'),
|
| 167 |
'sort' => array('handler' => 'views_handler_sort'),
|
| 168 |
'title' => t('Type of Publication'),
|
| 169 |
'help' => t('The type of publication: Journal, Book, Conference Paper, etc.')
|
| 170 |
);
|
| 171 |
$data['tid'] = array(
|
| 172 |
'filter' => array('handler' => 'biblio_handler_filter_biblio_type'),
|
| 173 |
'title' => t('Type of Publication'),
|
| 174 |
'help' => t('The type of publication: Journal, Book, Conference Paper, etc.')
|
| 175 |
);
|
| 176 |
|
| 177 |
$viewsdata['biblio_types'] = $data;
|
| 178 |
|
| 179 |
/**************** biblio contributors table **************/
|
| 180 |
|
| 181 |
$data = array();
|
| 182 |
$data['table']['group'] = t('Biblio');
|
| 183 |
$data['table']['join'] = array(
|
| 184 |
'node' => array(
|
| 185 |
'left_field' => 'vid',
|
| 186 |
'field' => 'vid',
|
| 187 |
),
|
| 188 |
'node_revision' => array(
|
| 189 |
'left_field' => 'vid',
|
| 190 |
'field' => 'vid',
|
| 191 |
),
|
| 192 |
// This is provided for many_to_one argument
|
| 193 |
'biblio' => array(
|
| 194 |
'field' => 'vid',
|
| 195 |
'left_field' => 'vid',
|
| 196 |
),
|
| 197 |
);
|
| 198 |
$data['cid'] = array(
|
| 199 |
'title' => t('Author ID'),
|
| 200 |
'help' => t('Filter by author id.'),
|
| 201 |
'argument' => array(
|
| 202 |
'handler' => 'views_handler_argument_many_to_one',
|
| 203 |
'name table' => 'biblio_contributor_data',
|
| 204 |
'name field' => 'lastname',
|
| 205 |
'empty name field' => t('No Author'),
|
| 206 |
'numeric' => TRUE,
|
| 207 |
),
|
| 208 |
'filter' => array(
|
| 209 |
'handler' => 'biblio_handler_filter_contributor',
|
| 210 |
)
|
| 211 |
);
|
| 212 |
$data['rank'] = array(
|
| 213 |
'title' => t('Author Rank'),
|
| 214 |
'help' => t('Rank defines the author order "0" being the first author, "1" the second and so on.'),
|
| 215 |
'filter' => array(
|
| 216 |
'handler' => 'views_handler_filter_numeric',
|
| 217 |
)
|
| 218 |
);
|
| 219 |
$data['auth_type'] = array(
|
| 220 |
'title' => t('Author Type'),
|
| 221 |
'help' => t('Rank defines the type of author Author, Editor, Translator and so on.'),
|
| 222 |
'filter' => array(
|
| 223 |
'handler' => 'biblio_handler_filter_biblio_contributor_auth_type',
|
| 224 |
)
|
| 225 |
);
|
| 226 |
|
| 227 |
$viewsdata['biblio_contributor'] = $data;
|
| 228 |
|
| 229 |
/**************** biblio_contributor_data table ***********/
|
| 230 |
$data = array();
|
| 231 |
$data['table']['group'] = t('Biblio');
|
| 232 |
$data['table']['join'] = array(
|
| 233 |
'biblio_contributor' => array(
|
| 234 |
'left_field' => 'cid',
|
| 235 |
'field' => 'cid',
|
| 236 |
),
|
| 237 |
'node' => array(
|
| 238 |
'left_table' => 'biblio_contributor',
|
| 239 |
'left_field' => 'cid',
|
| 240 |
'field' => 'cid',
|
| 241 |
),
|
| 242 |
);
|
| 243 |
$data['drupal_uid'] = array(
|
| 244 |
'field' => array('handler' => 'views_handler_field'),
|
| 245 |
'filter' => array('handler' => 'views_handler_filter'),
|
| 246 |
'argument' => array('handler' => 'views_handler_argument_numeric'),
|
| 247 |
'title' => t('Drupal UserID'),
|
| 248 |
'help' => t('This is the Drupal user associated with the Biblio Author.')
|
| 249 |
);
|
| 250 |
$data['lastname'] = array(
|
| 251 |
'sort' => array('handler' => 'views_handler_sort'),
|
| 252 |
'filter' => array('handler' => 'views_handler_filter'),
|
| 253 |
'argument' => array('handler' => 'views_handler_argument_string'),
|
| 254 |
'title' => t('Author Lastname'),
|
| 255 |
'help' => t('')
|
| 256 |
);
|
| 257 |
|
| 258 |
$viewsdata['biblio_contributor_data'] = $data;
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
/***************** Describe the keyword table *************/
|
| 263 |
|
| 264 |
$data = array();
|
| 265 |
$data['table']['group'] = t('Biblio');
|
| 266 |
$data['table']['join'] = array(
|
| 267 |
'node' => array(
|
| 268 |
'left_field' => 'vid',
|
| 269 |
'field' => 'vid',
|
| 270 |
),
|
| 271 |
'node_revision' => array(
|
| 272 |
'left_field' => 'vid',
|
| 273 |
'field' => 'vid',
|
| 274 |
),
|
| 275 |
// This is provided for many_to_one argument
|
| 276 |
'biblio' => array(
|
| 277 |
'field' => 'vid',
|
| 278 |
'left_field' => 'vid',
|
| 279 |
),
|
| 280 |
);
|
| 281 |
$data['kid'] = array(
|
| 282 |
'title' => t('Keyword ID'),
|
| 283 |
'help' => t('The Biblio keyword ID'),
|
| 284 |
'field' => array(
|
| 285 |
'title' => t('All keywords'),
|
| 286 |
'help' => t('Display all keywords associated with a node.'),
|
| 287 |
'handler' => 'biblio_handler_field_biblio_keyword_kid',
|
| 288 |
),
|
| 289 |
'argument' => array(
|
| 290 |
'handler' => 'views_handler_argument_many_to_one',
|
| 291 |
'name table' => 'biblio_keyword_data',
|
| 292 |
'name field' => 'word',
|
| 293 |
'empty name field' => t('No Keyword'),
|
| 294 |
'numeric' => TRUE,
|
| 295 |
),
|
| 296 |
'filter' => array(
|
| 297 |
'title' => t('Keyword'),
|
| 298 |
'handler' => 'biblio_handler_filter_biblio_keyword_kid',
|
| 299 |
'numeric' => TRUE,
|
| 300 |
),
|
| 301 |
);
|
| 302 |
|
| 303 |
$viewsdata['biblio_keyword'] = $data;
|
| 304 |
|
| 305 |
/***************** Describe the keyword_data table ***********/
|
| 306 |
|
| 307 |
$data = array();
|
| 308 |
$data['table']['group'] = t('Biblio');
|
| 309 |
$data['table']['base'] = array(
|
| 310 |
'field' => 'kid',
|
| 311 |
'title' => t('Biblio Keywords'),
|
| 312 |
);
|
| 313 |
|
| 314 |
$data['table']['join'] = array(
|
| 315 |
'biblio_keyword' => array(
|
| 316 |
'left_field' => 'kid',
|
| 317 |
'field' => 'kid',
|
| 318 |
),
|
| 319 |
'node' => array(
|
| 320 |
'left_table' => 'biblio_keyword',
|
| 321 |
'left_field' => 'kid',
|
| 322 |
'field' => 'kid',
|
| 323 |
),
|
| 324 |
'biblio' => array(
|
| 325 |
'left_table' => 'biblio_keyword',
|
| 326 |
'left_field' => 'kid',
|
| 327 |
'field' => 'kid',
|
| 328 |
),
|
| 329 |
);
|
| 330 |
$data['word'] = array(
|
| 331 |
'field' => array('handler' => 'biblio_handler_field_biblio_keyword_data_word'),
|
| 332 |
'filter' => array('handler' => 'views_handler_filter'),
|
| 333 |
'argument' => array('handler' => 'views_handler_argument'),
|
| 334 |
'sort' => array('handler' => 'views_handler_sort'),
|
| 335 |
'title' => t('Keyword'),
|
| 336 |
'skip base' => array('node', 'node_revision'),
|
| 337 |
);
|
| 338 |
$data['kid'] = array(
|
| 339 |
'field' => array('handler' => 'views_handler_field_numeric'),
|
| 340 |
// 'filter' => array('handler' => 'views_handler_filter'),
|
| 341 |
// 'argument' => array('handler' => 'views_handler_argument'),
|
| 342 |
'title' => t('Keyword ID'),
|
| 343 |
'skip base' => array('node', 'node_revision'),
|
| 344 |
);
|
| 345 |
|
| 346 |
|
| 347 |
$viewsdata['biblio_keyword_data'] = $data;
|
| 348 |
|
| 349 |
return $viewsdata;
|
| 350 |
}
|
| 351 |
|
| 352 |
function template_preprocess_views_view_unformatted__biblio_year(&$vars) {
|
| 353 |
$view = $vars['view'];
|
| 354 |
$rows = $vars['rows'];
|
| 355 |
|
| 356 |
$vars['classes'] = array();
|
| 357 |
// Set up striping values.
|
| 358 |
foreach ($rows as $id => $row) {
|
| 359 |
$vars['classes'][$id] = 'views-row';
|
| 360 |
$vars['classes'][$id] .= ' views-row-' . ($id + 1);
|
| 361 |
$vars['classes'][$id] .= ' views-row-' . ($id % 2 ? 'even' : 'odd');
|
| 362 |
if ($id == 0) {
|
| 363 |
$vars['classes'][$id] .= ' views-row-first';
|
| 364 |
}
|
| 365 |
}
|
| 366 |
$vars['classes'][$id] .= ' views-row-last';
|
| 367 |
}
|