| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 //$Id: calendar.views_default.inc,v 1.1.2.23 2010/11/28 23:31:28 karens Exp $ 3 /** 4 * Set up so it can be used as an API to create default calendars for 5 * specific date fields. 6 * 7 * Use variable_set() to establish criteria for default calendars. 8 * Set the variable in custom modules or in settings. 9 * 10 * Example: Add a new default calendar to custom 11 * calendars that are already configured: 12 * 13 * $options = variable_get('calendar_default_view_options', array()); 14 * $option = array( 15 * 'name' => 'example_event', 16 * 'description' => 'An example event calendar for the date field.', 17 * 'path' => 'example_event', 18 * 'types' => array('example_content_type'), 19 * 'date_fields' => array('field_example_date'), 20 * ); 21 * $options[] = $option; 22 * variable_set('calendar_default_view_options', $options); 23 * 24 */ 25 function calendar_views_default_views() { 26 $views = array(); 27 28 // Construct the default view with default options. 29 $view = calendar_views_construct(); 30 $views[$view->name] = $view; 31 32 // Then see if there are any custom calendars to be created 33 // using variable_get(). 34 $calendar_options = variable_get('calendar_default_view_options', array()); 35 36 foreach ((array) $calendar_options as $calendar_option) { 37 $view = calendar_views_construct($calendar_option); 38 $views[$view->name] = $view; 39 } 40 return $views; 41 } 42 43 /** 44 * 45 * Construct a default calendar to match specified options. 46 * Views calls it without options, so the basic 47 * default view will use the default values. 48 * 49 * @param $options: an optional array of options to 50 * create default calendars. 51 * 52 * Possible options include: 53 * @param string $name: 54 * The view name, if empty, defaults to 'calendar'. 55 * @param string $description: 56 * The view description, if empty, defaults to generic description. 57 * @param string $path: 58 * The view url, if empty, defaults to 'calendar'. 59 * @param array $types: 60 * Array of content types to limit the calendar to those types. 61 * If empty, defaults to no type filter. 62 * @param array $date_fields: 63 * Date fields used to filter the calendar. 64 * If empty, defaults to array('changed') for node.changed. 65 * @param array $display_fields: 66 * Fields to display in the calendar. 67 * If empty, defaults to title and date fields. 68 * 69 * @return the default calendar array. 70 */ 71 function calendar_views_construct($options = NULL) { 72 73 $name = NULL; 74 $description = NULL; 75 $path = NULL; 76 $types = NULL; 77 $date_fields = NULL; 78 $display_fields = NULL; 79 80 if (empty($options)) { 81 $disabled = TRUE; 82 } 83 else { 84 $disabled = FALSE; 85 extract($options); 86 } 87 if (empty($name)) { 88 $name = 'calendar'; 89 } 90 if (empty($description)) { 91 $description = 'A multi-dimensional calendar view with back/next navigation.'; 92 } 93 if (empty($path)) { 94 $path = 'calendar'; 95 } 96 if (empty($types)) { 97 $types = array(); 98 } 99 if (empty($date_fields)) { 100 $date_fields = array('changed'); 101 } 102 $colors = array(); 103 $date_link_type = ''; 104 foreach ($types as $type => $label) { 105 $colors[0][$type] = '#ffffff'; 106 $date_link_type = $type; 107 } 108 // Can handle core node date fields or CCK date fields. 109 110 $fields = array(); 111 $alias_fields = $date_fields; 112 $sort_fields = array(); 113 $upcoming_fields = array(); 114 115 foreach ($date_fields as $key => $field_name) { 116 if (substr($field_name, 0, 6) == 'field_') { 117 $table = 'node_data_'. $field_name; 118 $alias_fields[$key] = $field_name .'_value'; 119 $alias = $table .'.'. $field_name .'_value'; 120 $cck_field = TRUE; 121 } 122 else { 123 $table = 'node'; 124 $alias_fields[$key] = $field_name; 125 $alias = $table .'.'. $field_name; 126 $cck_field = FALSE; 127 } 128 $fields[$alias] = $alias; 129 130 // Add a sort for each date field: 131 $sort_fields[$field_name] = array( 132 'order' => 'ASC', 133 'delta' => '-1', 134 'id' => $field_name . ($cck_field ? '_value' : ''), 135 'table' => $table, 136 'field' => $field_name . ($cck_field ? '_value' : ''), 137 'relationship' => 'none', 138 ); 139 } 140 141 // Set up fields section with some of the basic options. 142 // Won't handle all possible options, but should cover 143 // the main ones needed for Drupal core and CCK fields. 144 145 if (empty($display_fields)) { 146 $display_fields = array('title' => array()); 147 foreach ($date_fields as $field) { 148 $display_fields[$field] = array(); 149 } 150 } 151 152 foreach ($display_fields as $key => $value) { 153 $cck_field = substr($key, 0, 6) == 'field_' ? TRUE : FALSE; 154 $date_field = $cck_field && in_array($key, $date_fields) ? TRUE : FALSE; 155 $display_fields[$key]['label'] = ''; 156 $display_fields[$key]['link_to_node'] = $key == 'title' ? 1 : 0; 157 $display_fields[$key]['exclude'] = 0; 158 $display_fields[$key]['id'] = $date_field ? $key .'_value' : $key; 159 $display_fields[$key]['field'] = $date_field ? $key .'_value' : $key; 160 $display_fields[$key]['table'] = $cck_field ? 'node_data_'. $key : 'node'; 161 $display_fields[$key]['relationship'] = 'none'; 162 if (in_array($key, array('changed'))) { 163 $display_fields[$key]['date_format'] = 'small'; 164 } 165 elseif ($cck_field) { 166 $display_fields[$key]['label_type'] = 'none'; 167 $display_fields[$key]['format'] = 'time'; 168 $display_fields[$key]['multiple'] = array( 169 'group' => 0, 170 'multiple_number' => '', 171 'multiple_from' => '', 172 'multiple_reversed' => 0, 173 ); 174 } 175 // Upcoming and iCal fields should display the whole date, not just time. 176 $upcoming_fields[$key] = $display_fields[$key]; 177 $upcoming_fields[$key]['format'] = 'default'; 178 } 179 180 $filters = array( 181 'status' => array( 182 'operator' => '=', 183 'value' => 1, 184 'group' => '0', 185 'exposed' => FALSE, 186 'expose' => array( 187 'operator' => FALSE, 188 'label' => '', 189 ), 190 'id' => 'status', 191 'table' => 'node', 192 'field' => 'status', 193 'relationship' => 'none', 194 ), 195 ); 196 // Limit to types provided: 197 if (!empty($types)) { 198 $filters += array( 199 'type' => array( 200 'operator' => 'in', 201 'value' => drupal_map_assoc(array_keys($types)), 202 'group' => '0', 203 'exposed' => FALSE, 204 'expose' => array( 205 'operator' => FALSE, 206 'label' => '', 207 ), 208 'id' => 'type', 209 'table' => 'node', 210 'field' => 'type', 211 'relationship' => 'none', 212 ), 213 ); 214 } 215 // Filters for Upcoming and iCal views: 216 $upcoming_filters = $filters + array( 217 'date_filter' => array( 218 'operator' => '>=', 219 'value' => array( 220 'value' => NULL, 221 'min' => NULL, 222 'max' => NULL, 223 'default_date' => 'now', 224 'default_to_date' => '', 225 ), 226 'group' => '0', 227 'exposed' => FALSE, 228 'expose' => array( 229 'operator' => FALSE, 230 'label' => '', 231 ), 232 'date_fields' => $fields, 233 'granularity' => 'day', 234 'form_type' => 'date_select', 235 'default_date' => 'now', 236 'default_to_date' => '', 237 'id' => 'date_filter', 238 'table' => 'node', 239 'field' => 'date_filter', 240 'override' => array( 241 'button' => 'Use default', 242 ), 243 'relationship' => 'none', 244 ), 245 ); 246 247 $view = new view; 248 $view->name = $name; 249 $view->description = $description; 250 $view->tag = 'Calendar'; 251 $view->view_php = ''; 252 $view->base_table = 'node'; 253 $view->is_cacheable = FALSE; 254 $view->api_version = 2; 255 $view->disabled = $disabled; /* Edit this to true to make a default view disabled initially */ 256 257 // Defaults. 258 $handler = $view->new_display('default', 'Defaults', 'default'); 259 $handler->override_option('fields', $display_fields); 260 $handler->override_option('sorts', $sort_fields); 261 262 $handler->override_option('arguments', array( 263 'date_argument' => array( 264 'default_action' => 'default', 265 'style_plugin' => 'default_summary', 266 'style_options' => array(), 267 'wildcard' => 'all', 268 'wildcard_substitution' => 'All', 269 'title' => '', 270 'default_argument_type' => 'date', 271 'default_argument' => '', 272 'validate_type' => 'none', 273 'validate_fail' => 'not found', 274 'date_fields' => $fields, 275 'year_range' => '-3:+3', 276 'date_method' => 'OR', 277 'granularity' => 'month', 278 'id' => 'date_argument', 279 'table' => 'node', 280 'field' => 'date_argument', 281 'relationship' => 'none', 282 'default_argument_user' => 0, 283 'default_argument_fixed' => '', 284 'default_argument_php' => '', 285 'validate_argument_node_type' => array(), 286 'validate_argument_node_access' => 0, 287 'validate_argument_nid_type' => 'nid', 288 'validate_argument_vocabulary' => array( 289 ), 290 'validate_argument_type' => 'tid', 291 'validate_argument_php' => '', 292 'override' => array( 293 'button' => 'Override', 294 ), 295 'default_options_div_prefix' => '', 296 ), 297 )); 298 $handler->override_option('filters', $filters); 299 $handler->override_option('access', array( 300 'type' => 'none', 301 'role' => array(), 302 'perm' => '', 303 )); 304 $handler->override_option('title', 'Calendar'); 305 if (!empty($header)) { 306 $handler->override_option('header', $header); 307 // The only format we can be sure of is filtered. 308 $handler->override_option('header_format', '1'); 309 } 310 $handler->override_option('header_empty', 1); 311 $handler->override_option('items_per_page', 0); 312 $handler->override_option('use_more', 0); 313 $handler->override_option('style_plugin', 'calendar_nav'); 314 $handler->override_option('style_options', array( 315 )); 316 317 // Calendar page. 318 $handler = $view->new_display('calendar', 'Calendar page', 'calendar_1'); 319 $handler->override_option('style_options', array()); 320 $handler->override_option('path', $path); 321 $handler->override_option('menu', array( 322 'type' => 'none', 323 'title' => '', 324 'weight' => 0, 325 'name' => 'navigation', 326 )); 327 $handler->override_option('tab_options', array( 328 'type' => 'none', 329 'title' => '', 330 'weight' => 0, 331 )); 332 $handler->override_option('calendar_colors', array($colors)); 333 $handler->override_option('calendar_colors_vocabulary', array()); 334 $handler->override_option('calendar_colors_taxonomy', array()); 335 $handler->override_option('calendar_colors_group', array()); 336 $handler->override_option('calendar_popup', 0); 337 $handler->override_option('calendar_date_link', $date_link_type); 338 // Calendar block. 339 $handler = $view->new_display('calendar_block', 'Calendar block', 'calendar_block_1'); 340 $handler->override_option('style_options', array()); 341 $handler->override_option('block_description', 'Calendar'); 342 $handler->override_option('block_caching', -1); 343 344 // Year view. 345 $handler = $view->new_display('calendar_period', 'Year view', 'calendar_period_1'); 346 $handler->override_option('style_plugin', 'calendar_style'); 347 $handler->override_option('style_options', array( 348 'display_type' => 'year', 349 'name_size' => 1, 350 'max_items' => 0, 351 )); 352 $handler->override_option('attachment_position', 'after'); 353 $handler->override_option('inherit_arguments', TRUE); 354 $handler->override_option('inherit_exposed_filters', TRUE); 355 $handler->override_option('displays', array( 356 'calendar_1' => 'calendar_1', 357 'default' => 0, 358 'calendar_block_1' => 0, 359 )); 360 $handler->override_option('calendar_type', 'year'); 361 362 // Month view. 363 $handler = $view->new_display('calendar_period', 'Month view', 'calendar_period_2'); 364 $handler->override_option('style_plugin', 'calendar_style'); 365 $handler->override_option('style_options', array( 366 'display_type' => 'month', 367 'name_size' => '99', 368 'with_weekno' => '1', 369 'date_fields' => NULL, 370 'max_items' => 0, 371 )); 372 373 if (module_exists('calendar_multiday')) { 374 $handler->override_option['style_options']['multiday_theme'] = 1; 375 } 376 377 $handler->override_option('attachment_position', 'after'); 378 $handler->override_option('inherit_arguments', TRUE); 379 $handler->override_option('inherit_exposed_filters', TRUE); 380 $handler->override_option('displays', array( 381 'calendar_1' => 'calendar_1', 382 'default' => 0, 383 'calendar_block_1' => 0, 384 )); 385 $handler->override_option('calendar_type', 'month'); 386 387 // Day view. 388 $handler = $view->new_display('calendar_period', 'Day view', 'calendar_period_3'); 389 $handler->override_option('style_plugin', 'calendar_style'); 390 $handler->override_option('style_options', array( 391 'name_size' => '99', 392 'with_weekno' => 0, 393 'max_items' => 0, 394 'max_items_behavior' => 'more', 395 'groupby_times' => 'hour', 396 'groupby_times_custom' => '', 397 'groupby_field' => '', 398 )); 399 400 if (module_exists('calendar_multiday')) { 401 $handler->override_option['style_options']['theme_style'] = 1; 402 } 403 404 $handler->override_option('attachment_position', 'after'); 405 $handler->override_option('inherit_arguments', TRUE); 406 $handler->override_option('inherit_exposed_filters', TRUE); 407 $handler->override_option('displays', array( 408 'calendar_1' => 'calendar_1', 409 'default' => 0, 410 'calendar_block_1' => 0, 411 )); 412 $handler->override_option('calendar_type', 'day'); 413 414 // Week view. 415 $handler = $view->new_display('calendar_period', 'Week view', 'calendar_period_4'); 416 $handler->override_option('style_plugin', 'calendar_style'); 417 $handler->override_option('style_options', array( 418 'name_size' => '99', 419 'with_weekno' => 0, 420 'max_items' => 0, 421 'max_items_behavior' => 'more', 422 'groupby_times' => 'hour', 423 'groupby_times_custom' => '', 424 'groupby_field' => '', 425 )); 426 427 if (module_exists('calendar_multiday')) { 428 $handler->override_option['style_options']['theme_style'] = 1; 429 } 430 431 $handler->override_option('attachment_position', 'after'); 432 $handler->override_option('inherit_arguments', TRUE); 433 $handler->override_option('inherit_exposed_filters', TRUE); 434 $handler->override_option('displays', array( 435 'calendar_1' => 'calendar_1', 436 'default' => 0, 437 'calendar_block_1' => 0, 438 )); 439 $handler->override_option('calendar_type', 'week'); 440 441 // Block view. 442 $handler = $view->new_display('calendar_period', 'Block view', 'calendar_period_5'); 443 $handler->override_option('style_plugin', 'calendar_style'); 444 $handler->override_option('style_options', array( 445 'display_type' => 'month', 446 'name_size' => '1', 447 )); 448 $handler->override_option('attachment_position', 'after'); 449 $handler->override_option('inherit_arguments', TRUE); 450 $handler->override_option('inherit_exposed_filters', TRUE); 451 $handler->override_option('displays', array( 452 'calendar_1' => 0, 453 'default' => 0, 454 'calendar_block_1' => 'calendar_block_1', 455 )); 456 $handler->override_option('calendar_type', 'month'); 457 458 459 // iCal feed. 460 if (module_exists('calendar_ical')) { 461 $handler = $view->new_display('calendar_ical', 'iCal feed', 'calendar_ical_1'); 462 $handler->override_option('arguments', array()); 463 $handler->override_option('filters', $upcoming_filters); 464 $handler->override_option('style_plugin', 'ical'); 465 $handler->override_option('style_options', array( 466 'mission_description' => FALSE, 467 'description' => '', 468 'summary_field' => 'node_title', 469 'description_field' => '', 470 'location_field' => '', 471 )); 472 $handler->override_option('row_plugin', ''); 473 $handler->override_option('path', $path .'/ical'); 474 $handler->override_option('menu', array( 475 'type' => 'none', 476 'title' => '', 477 'weight' => 0, 478 'name' => 'navigation', 479 )); 480 $handler->override_option('tab_options', array( 481 'type' => 'none', 482 'title' => '', 483 'weight' => 0, 484 )); 485 $handler->override_option('displays', array( 486 'calendar_1' => 'calendar_1', 487 'default' => 0, 488 'calendar_block_1' => 'calendar_block_1', 489 )); 490 $handler->override_option('sitename_title', FALSE); 491 } 492 493 // Upcoming events block. 494 $handler = $view->new_display('block', 'Upcoming', 'block_1'); 495 $handler->override_option('fields', $upcoming_fields); 496 $handler->override_option('arguments', array()); 497 $handler->override_option('filters', $upcoming_filters); 498 $handler->override_option('use_more', 1); 499 $handler->override_option('items_per_page', 5); 500 $handler->override_option('style_plugin', 'list'); 501 $handler->override_option('style_options', array( 502 'grouping' => '', 503 'type' => 'ul', 504 )); 505 $handler->override_option('title', 'Upcoming'); 506 $handler->override_option('block_description', 'Upcoming'); 507 $handler->override_option('block_caching', -1); 508 509 return $view; 510 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |