| 1 |
<?php |
<?php |
| 2 |
// $Id: handlers.inc,v 1.109.2.9 2009/09/15 19:29:09 merlinofchaos Exp $ |
// $Id: handlers.inc,v 1.109.2.10 2009/11/02 20:01:57 merlinofchaos Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file handlers.inc |
* @file handlers.inc |
| 5 |
* Defines the various handler objects to help build and display views. |
* Defines the various handler objects to help build and display views. |
| 14 |
return; |
return; |
| 15 |
} |
} |
| 16 |
|
|
| 17 |
if (!class_exists($definition['handler']) && !views_include_handler($definition, $type)) { |
if (!empty($definition['override handler']) && |
| 18 |
|
!class_exists($definition['override handler']) && |
| 19 |
|
!views_include_handler($definition['override handler'], $definition, $type)) { |
| 20 |
return; |
return; |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
$handler = new $definition['handler']; |
if (!class_exists($definition['handler']) && |
| 24 |
|
!views_include_handler($definition['handler'], $definition, $type)) { |
| 25 |
|
return; |
| 26 |
|
} |
| 27 |
|
|
| 28 |
|
if (!empty($definition['override handler'])) { |
| 29 |
|
$handler = new $definition['override handler']; |
| 30 |
|
} |
| 31 |
|
else { |
| 32 |
|
$handler = new $definition['handler']; |
| 33 |
|
} |
| 34 |
|
|
| 35 |
$handler->set_definition($definition); |
$handler->set_definition($definition); |
| 36 |
// let the handler have something like a constructor. |
// let the handler have something like a constructor. |
| 37 |
$handler->construct(); |
$handler->construct(); |
| 45 |
* This will also attempt to include all parents, though we're maxing the |
* This will also attempt to include all parents, though we're maxing the |
| 46 |
* parent chain to 10 to prevent infinite loops. |
* parent chain to 10 to prevent infinite loops. |
| 47 |
*/ |
*/ |
| 48 |
function views_include_handler($definition, $type, $count = 0) { |
function views_include_handler($handler, $definition, $type, $count = 0) { |
| 49 |
// Do not proceed if the class already exists. |
// Do not proceed if the class already exists. |
| 50 |
if (isset($definition['handler']) && class_exists($definition['handler'])) { |
if (isset($handler) && class_exists($handler)) { |
| 51 |
return TRUE; |
return TRUE; |
| 52 |
} |
} |
| 53 |
|
|
| 54 |
// simple infinite loop prevention. |
// simple infinite loop prevention. |
| 55 |
if ($count > 10) { |
if ($count > 10) { |
| 56 |
vpr(t('Handler @handler include tried to loop infinitely!', array('@handler' => $definition['handler']))); |
vpr(t('Handler @handler include tried to loop infinitely!', array('@handler' => $handler))); |
| 57 |
return FALSE; |
return FALSE; |
| 58 |
} |
} |
| 59 |
|
|
| 60 |
if (!isset($definition['path'])) { |
if (!isset($definition['path'])) { |
| 61 |
if ($type == 'handler') { |
if ($type == 'handler') { |
| 62 |
$definition += views_fetch_handler_data($definition['handler']); |
$definition += views_fetch_handler_data($handler); |
| 63 |
} |
} |
| 64 |
else { |
else { |
| 65 |
$definition += views_fetch_plugin_data($type, $definition['handler']); |
$definition += views_fetch_plugin_data($type, $handler); |
| 66 |
} |
} |
| 67 |
} |
} |
| 68 |
|
|
| 75 |
} |
} |
| 76 |
|
|
| 77 |
if ($parent) { |
if ($parent) { |
| 78 |
$rc = views_include_handler($parent, $type, $count + 1); |
$rc = views_include_handler($parent['handler'], $parent, $type, $count + 1); |
| 79 |
// If the parent chain cannot be included, don't try; this will |
// If the parent chain cannot be included, don't try; this will |
| 80 |
// help alleviate problems with modules with cross dependencies. |
// help alleviate problems with modules with cross dependencies. |
| 81 |
if (!$rc) { |
if (!$rc) { |
| 91 |
} |
} |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
return class_exists($definition['handler']); |
return class_exists($handler); |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
/** |
/** |
| 275 |
$this->query = &$view->query; |
$this->query = &$view->query; |
| 276 |
} |
} |
| 277 |
|
|
| 278 |
|
function option_definition() { |
| 279 |
|
$options = parent::option_definition(); |
| 280 |
|
|
| 281 |
|
$options['group_type'] = array('default' => 'group'); |
| 282 |
|
|
| 283 |
|
return $options; |
| 284 |
|
} |
| 285 |
|
|
| 286 |
/** |
/** |
| 287 |
* Return a string representing this handler's name in the UI. |
* Return a string representing this handler's name in the UI. |
| 288 |
*/ |
*/ |
| 292 |
} |
} |
| 293 |
|
|
| 294 |
/** |
/** |
| 295 |
* Provide a form for setting options. |
* Shortcut to get a handler's raw field value. |
| 296 |
*/ |
* |
| 297 |
function options_form(&$form, &$form_state) { } |
* This should be overridden for handlers with formulae or other |
| 298 |
|
* non-standard fields. Because this takes an argument, fields |
| 299 |
|
* overriding this can just call return parent::get_field($formula) |
| 300 |
|
*/ |
| 301 |
|
function get_field($field = NULL) { |
| 302 |
|
if (!isset($field)) { |
| 303 |
|
if (!empty($this->formula)) { |
| 304 |
|
$field = $this->get_formula(); |
| 305 |
|
} |
| 306 |
|
else { |
| 307 |
|
$field = $this->table_alias . '.' . $this->real_field; |
| 308 |
|
} |
| 309 |
|
} |
| 310 |
|
|
| 311 |
|
// If grouping, check to see if the aggregation method needs to modify the field. |
| 312 |
|
if ($this->view->display_handler->use_group_by()) { |
| 313 |
|
$info = $this->query->get_aggregation_info(); |
| 314 |
|
if (!empty($info[$this->options['group_type']]['method']) && function_exists($info[$this->options['group_type']]['method'])) { |
| 315 |
|
return $info[$this->options['group_type']]['method']($this->options['group_type'], $field); |
| 316 |
|
} |
| 317 |
|
} |
| 318 |
|
|
| 319 |
|
return $field; |
| 320 |
|
} |
| 321 |
|
|
| 322 |
/** |
/** |
| 323 |
* Validate the options form. |
* Validate the options form. |
| 324 |
*/ |
*/ |
| 325 |
function options_validate($form, &$form_state) { } |
function options_validate($form, &$form_state) { } |
| 326 |
|
|
| 327 |
|
function options_form(&$form, &$form_state) { } |
| 328 |
/** |
/** |
| 329 |
* Perform any necessary changes to the form values prior to storage. |
* Perform any necessary changes to the form values prior to storage. |
| 330 |
* There is no need for this function to actually store the data. |
* There is no need for this function to actually store the data. |
| 555 |
* |
* |
| 556 |
* If we were using PHP5, this would be abstract. |
* If we were using PHP5, this would be abstract. |
| 557 |
*/ |
*/ |
| 558 |
function query() { } |
function query($group_by = FALSE) { } |
| 559 |
|
|
| 560 |
/** |
/** |
| 561 |
* Ensure the main table for this handler is in the query. This is used |
* Ensure the main table for this handler is in the query. This is used |
| 1293 |
'views_handler_sort_random' => array( |
'views_handler_sort_random' => array( |
| 1294 |
'parent' => 'views_handler_sort', |
'parent' => 'views_handler_sort', |
| 1295 |
), |
), |
| 1296 |
|
|
| 1297 |
|
// group by handlers |
| 1298 |
|
'views_handler_argument_group_by_numeric' => array( |
| 1299 |
|
'parent' => 'views_handler_argument', |
| 1300 |
|
), |
| 1301 |
|
'views_handler_field_group_by_numeric' => array( |
| 1302 |
|
'parent' => 'views_handler_field', |
| 1303 |
|
), |
| 1304 |
|
'views_handler_filter_group_by_numeric' => array( |
| 1305 |
|
'parent' => 'views_handler_filter_numeric', |
| 1306 |
|
), |
| 1307 |
|
'views_handler_sort_group_by_numeric' => array( |
| 1308 |
|
'parent' => 'views_handler_sort', |
| 1309 |
|
), |
| 1310 |
), |
), |
| 1311 |
); |
); |
| 1312 |
} |
} |
| 1516 |
*/ |
*/ |
| 1517 |
function views_views_api() { |
function views_views_api() { |
| 1518 |
return array( |
return array( |
| 1519 |
'api' => 2, |
// in your modules do *not* use views_api_version()!!! |
| 1520 |
|
'api' => views_api_version(), |
| 1521 |
'path' => drupal_get_path('module', 'views') . '/modules', |
'path' => drupal_get_path('module', 'views') . '/modules', |
| 1522 |
); |
); |
| 1523 |
} |
} |