| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: calendar_plugin_display_attachment.inc,v 1.1.2.22 2011/01/03 02:39:05 karens Exp $ 3 /** 4 * The plugin that handles calendar attachment displays. 5 * 6 * Adding year/month/day/week pages as attachments makes it 7 * possible to use any style type, so they could be tables, 8 * lists, teasers, or nodes as well as traditional calendar 9 * pages. 10 * 11 * Force 'inherit_arguments' and 'inherit_filters' to TRUE, 12 * and 'attachment_position' to 'after', and don't display 13 * those options in the UI. 14 * 15 * Allows paging (regular attachments do not), and adds an option 16 * to choose what calendar period this display represents. 17 */ 18 class calendar_plugin_display_attachment extends views_plugin_display_attachment { 19 20 /** 21 * Instead of going through the standard views_view.tpl.php, delegate this 22 * to the style handler. 23 */ 24 function render() { 25 if (!empty($this->view->date_info->forbid)) { 26 return ''; 27 } 28 return $this->view->style_plugin->render($this->view->result); 29 } 30 31 /** 32 * Create an array of possible display periods. 33 */ 34 function display_types($type = 'month') { 35 $types = calendar_display_types(); 36 return $types[$type]; 37 } 38 39 /** 40 * Identify the period of this display. 41 */ 42 function calendar_type() { 43 $types = calendar_display_types(); 44 $default = $this->get_option('calendar_type'); 45 if (!array_key_exists($default, $types)) $default = 'month'; 46 return $default; 47 } 48 49 50 /** 51 * Inspect argument and view information to see which calendar 52 * period we should show. The argument tells us what to use 53 * if there is no value, the view args tell us what to use 54 * if there are values. 55 */ 56 function display_granularity($display_id) { 57 58 $arguments = $this->view->get_items('argument', $display_id); 59 $wildcard = ''; 60 $argument = ''; 61 $default_granularity = ''; 62 $i = 0; 63 foreach ($arguments as $argument) { 64 if ($argument['id'] == 'date_argument') { 65 $pos = $i; 66 $default_granularity = $argument['granularity']; 67 $wildcard = $argument['wildcard']; 68 $argument = !empty($this->view->args) && !empty($this->view->args[$pos]) ? $this->view->args[$pos] : ''; 69 break; 70 } 71 $i++; 72 } 73 // TODO Anything else we need to do for 'all' arguments? 74 if ($argument == $wildcard) { 75 $view_granularity = $default_granularity; 76 } 77 elseif (!empty($argument)) { 78 require_once('./'. drupal_get_path('module', 'date_api') .'/date_api_sql.inc'); 79 $date_handler = new date_sql_handler(); 80 $view_granularity = $date_handler->arg_granularity($argument); 81 } 82 else { 83 $view_granularity = $default_granularity; 84 } 85 return $view_granularity; 86 } 87 88 /** 89 * Display validation. 90 */ 91 function validate() { 92 $errors = parent::validate(); 93 94 $arguments = $this->display->handler->get_option('arguments'); 95 if (!in_array('date_argument', array_keys($arguments))) { 96 if (empty($this->view->date_info->arg_missing)) { 97 $errors[] = t("A Calendar period display will not work without a Date argument."); 98 } 99 $this->view->date_info->arg_missing = TRUE; 100 } 101 elseif ($arguments['date_argument']['default_action'] != 'default' || $arguments['date_argument']['default_argument_type'] != 'date') { 102 if (empty($this->view->date_info->arg_missing_default)) { 103 $errors[] = calendar_errors('missing_argument_default'); 104 } 105 $this->view->date_info->arg_missing_default = TRUE; 106 } 107 108 return $errors; 109 } 110 111 /** 112 * Attach only the appropriate displays for the current argument. 113 */ 114 function attach_to($display_id) { 115 $display_granularity = $this->calendar_type(); 116 $view_granularity = $this->display_granularity($display_id); 117 118 // If this is not the right display to show, 119 // don't attach it, just exit. 120 if ($view_granularity != $display_granularity) { 121 unset($this->display); 122 return; 123 } 124 125 $this->view->date_info->parent_id = $display_id; 126 127 // See if we're attaching to a block rather than a page. 128 if (substr($display_id, 0, 14) == 'calendar_block') { 129 $this->view->date_info->mini = TRUE; 130 $this->view->date_info->block = TRUE; 131 $this->view->date_info->calendar_popup = FALSE; 132 if (!isset($this->view->date_info->block_identifier)) { 133 $this->view->date_info->block_identifier = 'mini'; 134 } 135 } 136 elseif (substr($display_id, 0, 9) == 'calendar_') { 137 $this->view->date_info->calendar_colors = $this->view->display[$display_id]->handler->options['calendar_colors']; 138 $this->view->date_info->calendar_colors_taxonomy = $this->view->display[$display_id]->handler->options['calendar_colors_taxonomy']; 139 $this->view->date_info->calendar_colors_group = $this->view->display[$display_id]->handler->options['calendar_colors_group']; 140 $this->view->date_info->calendar_popup = $this->view->display[$display_id]->handler->options['calendar_popup']; 141 $this->view->date_info->calendar_date_link = $this->view->display[$display_id]->handler->options['calendar_date_link']; 142 } 143 parent::attach_to($display_id); 144 } 145 146 function pre_execute() { 147 // Make sure parent function is called so things like items per page get set. 148 parent::pre_execute(); 149 $this->view->date_info->display_granularity = $this->calendar_type(); 150 $this->view->date_info->calendar_type = $this->calendar_type(); 151 } 152 153 function query() { 154 // If we are using legend colors based on taxonomy, make sure the 155 // node vid field is added to the query so the theme can use it. 156 if (!empty($this->view->date_info->calendar_colors_taxonomy)) { 157 if (empty($this->additional_fields)) $this->additional_fields = array(); 158 $this->view->query->add_field('node', 'vid'); 159 } 160 parent::query(); 161 } 162 163 /** 164 * Override some of the parent options. 165 */ 166 function options(&$display) { 167 parent::options($display); 168 $display['inherit_argments'] = TRUE; 169 $display['inherit_filters'] = TRUE; 170 $display['attachment_position'] = 'after'; 171 } 172 173 /** 174 * Add custom option definitions. 175 */ 176 function option_definition() { 177 $options = parent::option_definition(); 178 $options['calendar_type'] = array('default' => $this->calendar_type()); 179 return $options; 180 } 181 182 function options_form(&$form, &$form_state) { 183 // It is very important to call the parent function here: 184 parent::options_form($form, $form_state); 185 186 switch ($form_state['section']) { 187 case 'calendar_type': 188 $form['#title'] .= t('Calendar period'); 189 $form['calendar_type'] = array( 190 '#type' => 'select', 191 '#description' => t('Select the calendar time period for this display.'), 192 '#default_value' => $this->calendar_type(), 193 '#options' => calendar_display_types(), 194 ); 195 break; 196 } 197 } 198 199 /** 200 * Perform any necessary changes to the form values prior to storage. 201 * There is no need for this function to actually store the data. 202 */ 203 function options_submit($form, &$form_state) { 204 // It is very important to call the parent function here: 205 parent::options_submit($form, $form_state); 206 switch ($form_state['section']) { 207 case 'calendar_type': 208 $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]); 209 break; 210 } 211 } 212 213 /** 214 * Provide the summary for attachment options in the views UI. 215 * 216 * This output is returned as an array. 217 */ 218 function options_summary(&$categories, &$options) { 219 parent::options_summary($categories, $options); 220 $types = calendar_display_types(); 221 $categories['calendar_settings'] = array( 222 'title' => t('Calendar settings'), 223 ); 224 225 $options['calendar_type'] = array( 226 'category' => 'calendar_settings', 227 'title' => t('Calendar period'), 228 'value' => $types[$this->calendar_type()], 229 ); 230 } 231 232 /** 233 * Take away the option to change these values. 234 */ 235 function defaultable_sections($section = NULL) { 236 if (in_array($section, array('inherit_argments', 'inherit_filters', 'attachment_position',))) { 237 return FALSE; 238 } 239 return parent::defaultable_sections($section); 240 } 241 242 }
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 |