| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_views_default_views().
|
| 6 |
*
|
| 7 |
* Create default views used by this module.
|
| 8 |
*/
|
| 9 |
|
| 10 |
function democracy_forum_views_default_views() {
|
| 11 |
//------ Proposals view ------------------------------------------------------
|
| 12 |
$view = new stdClass();
|
| 13 |
$view->name = 'proposals';
|
| 14 |
$view->description = t('Lists proposals');
|
| 15 |
$view->access = array(
|
| 16 |
);
|
| 17 |
$view->view_args_php = '';
|
| 18 |
$view->page = TRUE;
|
| 19 |
$view->page_title = t('Proposals');
|
| 20 |
$view->page_header = '';
|
| 21 |
$view->page_footer = '';
|
| 22 |
$view->page_empty = t('No proposals have been made.');
|
| 23 |
$view->page_type = 'table';
|
| 24 |
$view->url = 'proposals';
|
| 25 |
$view->use_pager = FALSE;
|
| 26 |
$view->nodes_per_page = '25';
|
| 27 |
$view->sort = array(
|
| 28 |
array(
|
| 29 |
'tablename' => 'term_data',
|
| 30 |
'field' => 'weight',
|
| 31 |
'sortorder' => 'ASC',
|
| 32 |
'options' => '',
|
| 33 |
),
|
| 34 |
array(
|
| 35 |
'tablename' => 'node',
|
| 36 |
'field' => 'changed',
|
| 37 |
'sortorder' => 'ASC',
|
| 38 |
'options' => 'normal',
|
| 39 |
),
|
| 40 |
);
|
| 41 |
$view->argument = array(
|
| 42 |
array(
|
| 43 |
'type' => 'taxid',
|
| 44 |
'argdefault' => '2',
|
| 45 |
'title' => '',
|
| 46 |
'options' => '',
|
| 47 |
'wildcard' => '',
|
| 48 |
'wildcard_substitution' => '',
|
| 49 |
),
|
| 50 |
);
|
| 51 |
$view->field = array(
|
| 52 |
array(
|
| 53 |
'tablename' => 'node',
|
| 54 |
'field' => 'title',
|
| 55 |
'label' => t('Title'),
|
| 56 |
'handler' => 'views_handler_field_nodelink',
|
| 57 |
'options' => 'link',
|
| 58 |
),
|
| 59 |
array(
|
| 60 |
'tablename' => 'users',
|
| 61 |
'field' => 'name',
|
| 62 |
'label' => t('Proposed by'),
|
| 63 |
),
|
| 64 |
array(
|
| 65 |
'tablename' => 'term_node_'. variable_get('democracy_forum_proposal_vocabulary', ''),
|
| 66 |
'field' => 'name',
|
| 67 |
'label' => t('Status'),
|
| 68 |
'options' => 'nolink',
|
| 69 |
),
|
| 70 |
);
|
| 71 |
$view->filter = array(
|
| 72 |
array(
|
| 73 |
'tablename' => 'node',
|
| 74 |
'field' => 'status',
|
| 75 |
'operator' => '=',
|
| 76 |
'options' => '',
|
| 77 |
'value' => '1',
|
| 78 |
),
|
| 79 |
array(
|
| 80 |
'tablename' => 'node',
|
| 81 |
'field' => 'type',
|
| 82 |
'operator' => 'OR',
|
| 83 |
'options' => '',
|
| 84 |
'value' => array(
|
| 85 |
0 => 'proposal',
|
| 86 |
),
|
| 87 |
),
|
| 88 |
);
|
| 89 |
$view->exposed_filter = array(
|
| 90 |
);
|
| 91 |
$view->requires = array(term_data, node, users, term_node_ . variable_get('democracy_forum_proposal_vocabulary', ''));
|
| 92 |
$views[$view->name] = $view;
|
| 93 |
|
| 94 |
//------ Recent arguments list view ------------------------------------------
|
| 95 |
$view = new stdClass();
|
| 96 |
$view->name = 'arguments_recent';
|
| 97 |
$view->description = t('Display recent arguments');
|
| 98 |
$view->access = array();
|
| 99 |
$view->view_args_php = '';
|
| 100 |
$view->page = TRUE;
|
| 101 |
$view->page_title = t('New arguments');
|
| 102 |
$view->page_header = '';
|
| 103 |
$view->page_footer = '';
|
| 104 |
$view->page_empty = t('No arguments have been added.');;
|
| 105 |
$view->page_type = 'table';
|
| 106 |
$view->url = 'view_arguments_recent';
|
| 107 |
$view->use_pager = FALSE;
|
| 108 |
$view->nodes_per_page = '25';
|
| 109 |
$view->sort = array(
|
| 110 |
array(
|
| 111 |
'tablename' => 'node_comment_statistics',
|
| 112 |
'field' => 'last_comment_timestamp',
|
| 113 |
'sortorder' => 'DESC',
|
| 114 |
'options' => 'normal',
|
| 115 |
),
|
| 116 |
);
|
| 117 |
$view->argument = array(
|
| 118 |
);
|
| 119 |
$view->field = array(
|
| 120 |
array(
|
| 121 |
'tablename' => 'node',
|
| 122 |
'field' => 'title',
|
| 123 |
'label' => '',
|
| 124 |
'handler' => 'views_handler_field_nodelink',
|
| 125 |
'options' => 'link',
|
| 126 |
),
|
| 127 |
array(
|
| 128 |
'tablename' => 'users',
|
| 129 |
'field' => 'name',
|
| 130 |
'label' => t('By'),
|
| 131 |
),
|
| 132 |
array(
|
| 133 |
'tablename' => 'node_comment_statistics',
|
| 134 |
'field' => 'comment_count',
|
| 135 |
'label' => t('Replies'),
|
| 136 |
'handler' => 'views_handler_field_int',
|
| 137 |
),
|
| 138 |
);
|
| 139 |
$view->filter = array(
|
| 140 |
array(
|
| 141 |
'tablename' => 'node',
|
| 142 |
'field' => 'type',
|
| 143 |
'operator' => 'OR',
|
| 144 |
'options' => '',
|
| 145 |
'value' => array(
|
| 146 |
0 => 'procon_argument',
|
| 147 |
),
|
| 148 |
),
|
| 149 |
array(
|
| 150 |
'tablename' => 'node',
|
| 151 |
'field' => 'status',
|
| 152 |
'operator' => '=',
|
| 153 |
'options' => '',
|
| 154 |
'value' => '1',
|
| 155 |
),
|
| 156 |
);
|
| 157 |
$view->exposed_filter = array();
|
| 158 |
$view->requires = array(node_comment_statistics, node, users);
|
| 159 |
$views[$view->name] = $view;
|
| 160 |
|
| 161 |
// ---------- Related council isses view -------------------------------------
|
| 162 |
$view = new stdClass();
|
| 163 |
$view->name = 'council_related';
|
| 164 |
$view->description = '';
|
| 165 |
$view->access = array(
|
| 166 |
);
|
| 167 |
$view->view_args_php = '';
|
| 168 |
$view->page = TRUE;
|
| 169 |
$view->page_title = '';
|
| 170 |
$view->page_header = '';
|
| 171 |
$view->page_footer = '';
|
| 172 |
$view->page_empty = '';
|
| 173 |
$view->page_type = 'list';
|
| 174 |
$view->url = 'view_council_related';
|
| 175 |
$view->use_pager = FALSE;
|
| 176 |
$view->nodes_per_page = '4';
|
| 177 |
$view->sort = array(
|
| 178 |
array(
|
| 179 |
'tablename' => 'node',
|
| 180 |
'field' => 'created',
|
| 181 |
'sortorder' => 'ASC',
|
| 182 |
'options' => 'normal',
|
| 183 |
),
|
| 184 |
);
|
| 185 |
$view->argument = array(
|
| 186 |
array(
|
| 187 |
'type' => 'taxid',
|
| 188 |
'argdefault' => '1',
|
| 189 |
'title' => '',
|
| 190 |
'options' => '',
|
| 191 |
'wildcard' => '',
|
| 192 |
'wildcard_substitution' => '',
|
| 193 |
),
|
| 194 |
array(
|
| 195 |
'type' => 'nid',
|
| 196 |
'argdefault' => '2',
|
| 197 |
'title' => '',
|
| 198 |
'options' => '1',
|
| 199 |
'wildcard' => '',
|
| 200 |
'wildcard_substitution' => '',
|
| 201 |
),
|
| 202 |
);
|
| 203 |
$view->field = array(
|
| 204 |
array(
|
| 205 |
'tablename' => 'node',
|
| 206 |
'field' => 'title',
|
| 207 |
'label' => '',
|
| 208 |
'handler' => 'views_handler_field_nodelink',
|
| 209 |
'options' => 'link',
|
| 210 |
),
|
| 211 |
);
|
| 212 |
$view->filter = array(
|
| 213 |
array(
|
| 214 |
'tablename' => 'node',
|
| 215 |
'field' => 'status',
|
| 216 |
'operator' => '=',
|
| 217 |
'options' => '',
|
| 218 |
'value' => '1',
|
| 219 |
),
|
| 220 |
);
|
| 221 |
$view->exposed_filter = array(
|
| 222 |
);
|
| 223 |
$view->requires = array(node);
|
| 224 |
$views[$view->name] = $view;
|
| 225 |
|
| 226 |
//-------- Council view, summary of council meetings and list of issues ------
|
| 227 |
$view = new stdClass();
|
| 228 |
$view->name = 'council';
|
| 229 |
$view->description = t('List council issues');
|
| 230 |
$view->access = array();
|
| 231 |
$view->view_args_php = '';
|
| 232 |
$view->page = TRUE;
|
| 233 |
$view->page_title = t('Council');
|
| 234 |
$view->page_header = '';
|
| 235 |
$view->page_footer = '';
|
| 236 |
$view->page_empty = t('There are no issues for this council meeting yet.');
|
| 237 |
$view->page_type = 'table';
|
| 238 |
$view->url = 'democracyforum/council';
|
| 239 |
$view->use_pager = TRUE;
|
| 240 |
$view->nodes_per_page = '30';
|
| 241 |
$view->sort = array(
|
| 242 |
array(
|
| 243 |
'tablename' => 'node',
|
| 244 |
'field' => 'created',
|
| 245 |
'sortorder' => 'ASC',
|
| 246 |
'options' => 'normal',
|
| 247 |
),
|
| 248 |
);
|
| 249 |
$view->argument = array(
|
| 250 |
array(
|
| 251 |
'type' => 'taxid',
|
| 252 |
'argdefault' => '5',
|
| 253 |
'title' => t('Council meeting %1'),
|
| 254 |
'options' => '',
|
| 255 |
'wildcard' => '',
|
| 256 |
'wildcard_substitution' => '',
|
| 257 |
),
|
| 258 |
);
|
| 259 |
$view->field = array(
|
| 260 |
array(
|
| 261 |
'tablename' => 'node',
|
| 262 |
'field' => 'title',
|
| 263 |
'label' => t('Issue'),
|
| 264 |
'handler' => 'views_handler_field_nodelink',
|
| 265 |
'options' => 'link',
|
| 266 |
),
|
| 267 |
);
|
| 268 |
$view->filter = array(
|
| 269 |
array(
|
| 270 |
'tablename' => 'node',
|
| 271 |
'field' => 'status',
|
| 272 |
'operator' => '=',
|
| 273 |
'options' => '',
|
| 274 |
'value' => '1',
|
| 275 |
),
|
| 276 |
array(
|
| 277 |
'tablename' => 'term_data',
|
| 278 |
'field' => 'vid',
|
| 279 |
'operator' => 'AND',
|
| 280 |
'options' => '',
|
| 281 |
'value' => array(
|
| 282 |
0 => variable_get('democracy_forum_council_vocabulary', ''),
|
| 283 |
),
|
| 284 |
),
|
| 285 |
);
|
| 286 |
$view->exposed_filter = array(
|
| 287 |
);
|
| 288 |
$view->requires = array(node, term_data);
|
| 289 |
$views[$view->name] = $view;
|
| 290 |
|
| 291 |
return $views;
|
| 292 |
}
|
| 293 |
|
| 294 |
/**
|
| 295 |
* Theme council_related view.
|
| 296 |
* Lists the issues for a specific council and makes it possible to style the
|
| 297 |
* item differently depending on the user has voted or not on the issue.
|
| 298 |
*/
|
| 299 |
function theme_views_view_list_council_related($view, $nodes, $type) {
|
| 300 |
$fields = _views_get_fields();
|
| 301 |
|
| 302 |
foreach ($nodes as $node) {
|
| 303 |
$item = '';
|
| 304 |
foreach ($view->field as $field) {
|
| 305 |
$item .= views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
|
| 306 |
}
|
| 307 |
$voted = _advpoll_user_voted($node->nid);
|
| 308 |
$voted_class = ($voted[0] ? ' voted' : '');
|
| 309 |
// TODO: don't return any class at all instead of empty class
|
| 310 |
$items[] = array($item, 'class' => $voted_class);
|
| 311 |
}
|
| 312 |
if ($items) {
|
| 313 |
return theme('item_list', $items);
|
| 314 |
}
|
| 315 |
}
|
| 316 |
|
| 317 |
/**
|
| 318 |
* Theme summary of councils.
|
| 319 |
*/
|
| 320 |
function theme_views_summary_council($view, $type, $level, $nodes, $args) {
|
| 321 |
foreach ($nodes as $node) {
|
| 322 |
$items[] = views_get_summary_link($view->argument[$level]['type'], $node, $view->real_url) .' - '. $node->num_nodes .' '. format_plural($node->num_nodes, 'issue', 'issues');
|
| 323 |
}
|
| 324 |
if ($items) {
|
| 325 |
$output .= theme('item_list', $items);
|
| 326 |
}
|
| 327 |
|
| 328 |
return $output;
|
| 329 |
}
|
| 330 |
|
| 331 |
/**
|
| 332 |
* Theme coucil table view
|
| 333 |
* Lists the council issues with results and link to decision if provided.
|
| 334 |
*
|
| 335 |
* TODO: too much logic in this theme function, it's sort of a hack. Result and
|
| 336 |
* link should be made into view fields among many things.
|
| 337 |
*/
|
| 338 |
function theme_views_view_table_council($view, $nodes, $type) {
|
| 339 |
$fields = _views_get_fields();
|
| 340 |
$tid = $view->args[0];
|
| 341 |
$term = taxonomy_get_term($tid);
|
| 342 |
$council_status = democracy_forum_council_status($term, 'short');
|
| 343 |
$status = $council_status['status'];
|
| 344 |
// Add the default stylesheet
|
| 345 |
drupal_add_css(drupal_get_path('module', 'democracy_forum') .'/democracy_forum.css');
|
| 346 |
|
| 347 |
// Standard table provided by this view
|
| 348 |
foreach ($nodes as $node) {
|
| 349 |
$row = array();
|
| 350 |
foreach ($view->field as $field) {
|
| 351 |
$cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
|
| 352 |
$cell['class'] = "view-field view-field-$field[queryname]";
|
| 353 |
$row[] = $cell;
|
| 354 |
}
|
| 355 |
// Note that this doesn't use the actual 'close' status of a poll, instead
|
| 356 |
// it's calculated from the defined council date.
|
| 357 |
if ($status == 'passed') {
|
| 358 |
// TODO: Here the whole noad object is loaded, which could be really
|
| 359 |
// expensive if listing many issues. It would be better to only get the
|
| 360 |
// relevant data and even cache the winning result.
|
| 361 |
$node_loaded = node_load($node->nid);
|
| 362 |
// Display winner result
|
| 363 |
$row[] = array('data' => democracy_forum_advpoll_winner_binary($node_loaded));
|
| 364 |
// Display result from the council meeting
|
| 365 |
$result = check_plain($node_loaded->democracy_forum_council_result);
|
| 366 |
$link = check_plain($node_loaded->democracy_forum_council_link);
|
| 367 |
|
| 368 |
$row[] = array('data' => theme('democracy_forum_council_result', $result, $link));
|
| 369 |
}
|
| 370 |
$rows[] = $row;
|
| 371 |
}
|
| 372 |
|
| 373 |
if ($status == 'passed') {
|
| 374 |
// Headers
|
| 375 |
$view->table_header[] = array('data' => t('How @site-name voted', array('@site-name' => variable_get('site_name', 'Drupal'))));
|
| 376 |
$view->table_header[] = array('data' => t('How the council voted'));
|
| 377 |
}
|
| 378 |
$output = '<p ="council-status">'. $council_status['output'] .'</p>';
|
| 379 |
$output .= theme('table', $view->table_header, $rows);
|
| 380 |
|
| 381 |
return $output;
|
| 382 |
}
|