updated contrib modules
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views area handlers.
|
||||
* Definition of views_handler_area and views_handler_area_broken.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -20,29 +20,31 @@
|
||||
class views_handler_area extends views_handler {
|
||||
|
||||
/**
|
||||
* Overrides views_handler::init().
|
||||
*
|
||||
* Make sure that no result area handlers are set to be shown when the result
|
||||
* is empty.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function init(&$view, &$options) {
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
// Make sure that no result area handlers are set to be shown when the
|
||||
// result is empty.
|
||||
if ($this->handler_type == 'empty') {
|
||||
$this->options['empty'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this field's label.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function label() {
|
||||
public function label() {
|
||||
if (!isset($this->options['label'])) {
|
||||
return $this->ui_name();
|
||||
}
|
||||
return $this->options['label'];
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
|
||||
@@ -54,17 +56,17 @@ class views_handler_area extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide extra data to the administration form
|
||||
* Provide extra data to the administration form.
|
||||
*/
|
||||
function admin_summary() {
|
||||
public function admin_summary() {
|
||||
return $this->label();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options form that provides the label widget that all fields
|
||||
* should have.
|
||||
* Default options form that provides the label widget that all fields should
|
||||
* have.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
@@ -83,23 +85,25 @@ class views_handler_area extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't run a query
|
||||
* Don't run a query.
|
||||
*/
|
||||
function query() { }
|
||||
public function query() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the area
|
||||
* Render the area.
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
public function render($empty = FALSE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Area handlers shouldn't have groupby.
|
||||
*/
|
||||
function use_group_by() {
|
||||
public function use_group_by() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,14 +112,39 @@ class views_handler_area extends views_handler {
|
||||
* @ingroup views_area_handlers
|
||||
*/
|
||||
class views_handler_area_broken extends views_handler_area {
|
||||
function ui_name($short = FALSE) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return t('Broken/missing handler');
|
||||
}
|
||||
|
||||
function ensure_my_table() { /* No table to ensure! */ }
|
||||
function query($group_by = FALSE) { /* No query to run */ }
|
||||
function render($empty = FALSE) { return ''; }
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ensure_my_table() {
|
||||
// No table to ensure!
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
// No query to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($empty = FALSE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#prefix' => '<div class="form-item description">',
|
||||
'#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'),
|
||||
@@ -123,9 +152,12 @@ class views_handler_area_broken extends views_handler_area {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is considered 'broken'
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function broken() { return TRUE; }
|
||||
public function broken() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains views_handler_area_messages.
|
||||
* Definition of views_handler_area_messages.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@@ -12,7 +12,10 @@
|
||||
*/
|
||||
class views_handler_area_result extends views_handler_area {
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['content'] = array(
|
||||
@@ -23,7 +26,10 @@ class views_handler_area_result extends views_handler_area {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$variables = array(
|
||||
'items' => array(
|
||||
@@ -47,11 +53,10 @@ class views_handler_area_result extends views_handler_area {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find out the information to render.
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
public function render($empty = FALSE) {
|
||||
// Must have options and does not work on summaries.
|
||||
if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
|
||||
return;
|
||||
@@ -61,7 +66,7 @@ class views_handler_area_result extends views_handler_area {
|
||||
// Calculate the page totals.
|
||||
$current_page = (int) $this->view->get_current_page() + 1;
|
||||
$per_page = (int) $this->view->get_items_per_page();
|
||||
// @TODO: Maybe use a possible is views empty functionality.
|
||||
// @todo Maybe use a possible is views empty functionality.
|
||||
// Not every view has total_rows set, use view->result instead.
|
||||
$total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
|
||||
$name = check_plain($this->view->human_name);
|
||||
@@ -81,15 +86,25 @@ class views_handler_area_result extends views_handler_area {
|
||||
}
|
||||
$current_record_count = ($end - $start) + 1;
|
||||
// Get the search information.
|
||||
$items = array('start', 'end', 'total', 'name', 'per_page', 'current_page', 'current_record_count', 'page_count');
|
||||
$items = array(
|
||||
'start',
|
||||
'end',
|
||||
'total',
|
||||
'name',
|
||||
'per_page',
|
||||
'current_page',
|
||||
'current_record_count',
|
||||
'page_count',
|
||||
);
|
||||
$replacements = array();
|
||||
foreach ($items as $item) {
|
||||
$replacements["@$item"] = ${$item};
|
||||
}
|
||||
// Send the output.
|
||||
if (!empty($total)) {
|
||||
if (!empty($total) || !empty($this->options['empty'])) {
|
||||
$output .= filter_xss_admin(str_replace(array_keys($replacements), array_values($replacements), $format));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,15 +12,30 @@
|
||||
*/
|
||||
class views_handler_area_text extends views_handler_area {
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['content'] = array('default' => '', 'translatable' => TRUE, 'format_key' => 'format');
|
||||
$options['format'] = array('default' => NULL);
|
||||
$options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
$options['content'] = array(
|
||||
'default' => '',
|
||||
'translatable' => TRUE,
|
||||
'format_key' => 'format',
|
||||
);
|
||||
$options['format'] = array(
|
||||
'default' => NULL,
|
||||
);
|
||||
$options['tokenize'] = array(
|
||||
'default' => FALSE,
|
||||
'bool' => TRUE,
|
||||
);
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['content'] = array(
|
||||
@@ -31,7 +46,7 @@ class views_handler_area_text extends views_handler_area {
|
||||
'#wysiwyg' => FALSE,
|
||||
);
|
||||
|
||||
// @TODO: Refactor token handling into a base class.
|
||||
// @todo Refactor token handling into a base class.
|
||||
$form['tokenize'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use replacement tokens from the first row'),
|
||||
@@ -44,14 +59,17 @@ class views_handler_area_text extends views_handler_area {
|
||||
$options[t('Fields')]["[$field]"] = $handler->ui_name();
|
||||
}
|
||||
|
||||
$count = 0; // This lets us prepare the key as we want it printed.
|
||||
$count = 0;
|
||||
// This lets us prepare the key as we want it printed.
|
||||
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
|
||||
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
|
||||
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
|
||||
}
|
||||
|
||||
if (!empty($options)) {
|
||||
$output = '<p>' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.' . '</p>');
|
||||
$output = '<p>'
|
||||
. t("The following tokens are available. If you would like to have the characters '[' and ']' please use the html entity codes '%5B' or '%5D' or they will get replaced with empty space.")
|
||||
. '</p>';
|
||||
foreach (array_keys($options) as $type) {
|
||||
if (!empty($options[$type])) {
|
||||
$items = array();
|
||||
@@ -61,7 +79,7 @@ class views_handler_area_text extends views_handler_area {
|
||||
$output .= theme('item_list',
|
||||
array(
|
||||
'items' => $items,
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -82,13 +100,19 @@ class views_handler_area_text extends views_handler_area {
|
||||
}
|
||||
}
|
||||
|
||||
function options_submit(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
$form_state['values']['options']['format'] = $form_state['values']['options']['content']['format'];
|
||||
$form_state['values']['options']['content'] = $form_state['values']['options']['content']['value'];
|
||||
parent::options_submit($form, $form_state);
|
||||
}
|
||||
|
||||
function render($empty = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($empty = FALSE) {
|
||||
$format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
return $this->render_textarea($this->options['content'], $format);
|
||||
@@ -99,7 +123,7 @@ class views_handler_area_text extends views_handler_area {
|
||||
/**
|
||||
* Render a text area, using the proper format.
|
||||
*/
|
||||
function render_textarea($value, $format) {
|
||||
public function render_textarea($value, $format) {
|
||||
if ($value) {
|
||||
if ($this->options['tokenize']) {
|
||||
$value = $this->view->style_plugin->tokenize_value($value, 0);
|
||||
@@ -107,4 +131,5 @@ class views_handler_area_text extends views_handler_area {
|
||||
return check_markup($value, $format, '', FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,13 +12,19 @@
|
||||
*/
|
||||
class views_handler_area_text_custom extends views_handler_area_text {
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
unset($options['format']);
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// Alter the form element, to be a regular text area.
|
||||
@@ -26,14 +32,20 @@ class views_handler_area_text_custom extends views_handler_area_text {
|
||||
unset($form['content']['#format']);
|
||||
unset($form['content']['#wysiwyg']);
|
||||
|
||||
// @TODO: Use the token refactored base class.
|
||||
// @todo Use the token refactored base class.
|
||||
}
|
||||
|
||||
// Empty, so we don't inherit options_submit from the parent.
|
||||
function options_submit(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
// Empty, so we don't inherit options_submit from the parent.
|
||||
}
|
||||
|
||||
function render($empty = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($empty = FALSE) {
|
||||
if (!$empty || !empty($this->options['empty'])) {
|
||||
return $this->render_textarea_custom($this->options['content']);
|
||||
}
|
||||
@@ -43,8 +55,14 @@ class views_handler_area_text_custom extends views_handler_area_text {
|
||||
|
||||
/**
|
||||
* Render a text area with filter_xss_admin.
|
||||
*
|
||||
* @param string $value
|
||||
* The text area string to process.
|
||||
*
|
||||
* @return string
|
||||
* The string after it has been sanitized, optionally tokenized too.
|
||||
*/
|
||||
function render_textarea_custom($value) {
|
||||
public function render_textarea_custom($value) {
|
||||
if ($value) {
|
||||
if ($this->options['tokenize']) {
|
||||
$value = $this->view->style_plugin->tokenize_value($value, 0);
|
||||
|
@@ -12,7 +12,10 @@
|
||||
*/
|
||||
class views_handler_area_view extends views_handler_area {
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['view_to_insert'] = array('default' => '');
|
||||
@@ -21,10 +24,9 @@ class views_handler_area_view extends views_handler_area {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options form that provides the label widget that all fields
|
||||
* should have.
|
||||
* Default options form; provides the label widget all fields should have.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$view_display = $this->view->name . ':' . $this->view->current_display;
|
||||
@@ -48,9 +50,9 @@ class views_handler_area_view extends views_handler_area {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the area
|
||||
* Render the area.
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
public function render($empty = FALSE) {
|
||||
if ($view = $this->loadView()) {
|
||||
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
|
||||
return $view->preview(NULL, $this->view->args);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @todo.
|
||||
* Definition of views_handler_argument.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -14,50 +14,63 @@
|
||||
/**
|
||||
* Base class for arguments.
|
||||
*
|
||||
* The basic argument works for very simple arguments such as nid and uid
|
||||
* The basic argument works for very simple arguments such as nid and uid.
|
||||
*
|
||||
* Definition terms for this handler:
|
||||
* - name field: The field to use for the name to use in the summary, which is
|
||||
* the displayed output. For example, for the node: nid argument,
|
||||
* the argument itself is the nid, but node.title is displayed.
|
||||
* the displayed output. For example, for the node: nid argument, the argument
|
||||
* itself is the nid, but node.title is displayed.
|
||||
* - name table: The table to use for the name, should it not be in the same
|
||||
* table as the argument.
|
||||
* table as the argument.
|
||||
* - empty field name: For arguments that can have no value, such as taxonomy
|
||||
* which can have "no term", this is the string which
|
||||
* will be displayed for this lack of value. Be sure to use
|
||||
* t().
|
||||
* which can have "no term", this is the string which will be displayed for
|
||||
* this lack of value. Be sure to use t().
|
||||
* - validate type: A little used string to allow an argument to restrict
|
||||
* which validator is available to just one. Use the
|
||||
* validator ID. This probably should not be used at all,
|
||||
* and may disappear or change.
|
||||
* which validator is available to just one. Use the validator ID. This
|
||||
* probably should not be used at all, and may disappear or change.
|
||||
* - numeric: If set to TRUE this field is numeric and will use %d instead of
|
||||
* %s in queries.
|
||||
* %s in queries.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument extends views_handler {
|
||||
var $validator = NULL;
|
||||
var $argument = NULL;
|
||||
var $value = NULL;
|
||||
|
||||
/**
|
||||
* The table to use for the name, should it not be in the same table as the argument.
|
||||
* @var object
|
||||
*/
|
||||
public $validator = NULL;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $argument = NULL;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
public $value = NULL;
|
||||
|
||||
/**
|
||||
* The table to use for the name, if not the same table as the argument.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $name_table;
|
||||
public $name_table;
|
||||
|
||||
/**
|
||||
* The field to use for the name to use in the summary, which is
|
||||
* the displayed output. For example, for the node: nid argument,
|
||||
* the argument itself is the nid, but node.title is displayed.
|
||||
* The field to use for the name to use in the summary.
|
||||
*
|
||||
* Used as the displayed output. For example, for the node: nid argument, the
|
||||
* argument itself is the nid, but node.title is displayed.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $name_field;
|
||||
public $name_field;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function construct() {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
|
||||
if (!empty($this->definition['name field'])) {
|
||||
@@ -68,7 +81,10 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
}
|
||||
|
||||
function init(&$view, &$options) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
|
||||
// Compatibility: The new UI changed several settings.
|
||||
@@ -132,31 +148,43 @@ class views_handler_argument extends views_handler {
|
||||
|
||||
/**
|
||||
* Give an argument the opportunity to modify the breadcrumb, if it wants.
|
||||
* This only gets called on displays where a breadcrumb is actually used.
|
||||
*
|
||||
* Only gets called on displays where a breadcrumb is actually used.
|
||||
*
|
||||
* The breadcrumb will be in the form of an array, with the keys being
|
||||
* the path and the value being the already sanitized title of the path.
|
||||
*/
|
||||
function set_breadcrumb(&$breadcrumb) { }
|
||||
public function set_breadcrumb(&$breadcrumb) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the argument can generate a breadcrumb
|
||||
* Determine if the argument can generate a breadcrumb.
|
||||
*
|
||||
* @return TRUE/FALSE
|
||||
* @return bool
|
||||
* Indicates whether the argument can generate a breadcrumb.
|
||||
*/
|
||||
function uses_breadcrumb() {
|
||||
public function uses_breadcrumb() {
|
||||
$info = $this->default_actions($this->options['default_action']);
|
||||
return !empty($info['breadcrumb']);
|
||||
}
|
||||
|
||||
function is_exception($arg = NULL) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function is_exception($arg = NULL) {
|
||||
if (!isset($arg)) {
|
||||
$arg = isset($this->argument) ? $this->argument : NULL;
|
||||
}
|
||||
return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg;
|
||||
return !empty($this->options['exception']['value']) && ($this->options['exception']['value'] === $arg);
|
||||
}
|
||||
|
||||
function exception_title() {
|
||||
/**
|
||||
* Work out which title to use.
|
||||
*
|
||||
* @return string
|
||||
* The title string to use.
|
||||
*/
|
||||
public function exception_title() {
|
||||
// If title overriding is off for the exception, return the normal title.
|
||||
if (empty($this->options['exception']['title_enable'])) {
|
||||
return $this->get_title();
|
||||
@@ -167,15 +195,19 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Determine if the argument needs a style plugin.
|
||||
*
|
||||
* @return TRUE/FALSE
|
||||
* @return bool
|
||||
* the argument needs a plugin style.
|
||||
*/
|
||||
function needs_style_plugin() {
|
||||
public function needs_style_plugin() {
|
||||
$info = $this->default_actions($this->options['default_action']);
|
||||
$validate_info = $this->default_actions($this->options['validate']['fail']);
|
||||
return !empty($info['style plugin']) || !empty($validate_info['style plugin']);
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['default_action'] = array('default' => 'ignore');
|
||||
@@ -213,7 +245,10 @@ class views_handler_argument extends views_handler {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$argument_text = $this->view->display_handler->get_argument_text();
|
||||
@@ -380,8 +415,9 @@ class views_handler_argument extends views_handler {
|
||||
'#prefix' => '<div id="edit-options-validate-options-' . $id . '-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
'#type' => 'item',
|
||||
// Even if the plugin has no options add the key to the form_state.
|
||||
'#input' => TRUE, // trick it into checking input to make #process run
|
||||
// Even if the plugin has no options, add the key to the
|
||||
// form_state. Trick it into checking input to make #process run.
|
||||
'#input' => TRUE,
|
||||
'#dependency' => array(
|
||||
'edit-options-specify-validation' => array('1'),
|
||||
'edit-options-validate-type' => array($id),
|
||||
@@ -411,7 +447,10 @@ class views_handler_argument extends views_handler {
|
||||
);
|
||||
}
|
||||
|
||||
function options_validate(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_validate(&$form, &$form_state) {
|
||||
if (empty($form_state['values']['options'])) {
|
||||
return;
|
||||
}
|
||||
@@ -440,7 +479,10 @@ class views_handler_argument extends views_handler {
|
||||
|
||||
}
|
||||
|
||||
function options_submit(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
if (empty($form_state['values']['options'])) {
|
||||
return;
|
||||
}
|
||||
@@ -451,7 +493,8 @@ class views_handler_argument extends views_handler {
|
||||
if ($plugin) {
|
||||
$options = &$form_state['values']['options']['argument_default'][$default_id];
|
||||
$plugin->options_submit($form['argument_default'][$default_id], $form_state, $options);
|
||||
// Copy the now submitted options to their final resting place so they get saved.
|
||||
// Copy the now submitted options to their final resting place so they
|
||||
// get saved.
|
||||
$form_state['values']['options']['default_argument_options'] = $options;
|
||||
}
|
||||
|
||||
@@ -462,7 +505,8 @@ class views_handler_argument extends views_handler {
|
||||
if ($plugin) {
|
||||
$options = &$form_state['values']['options']['summary']['options'][$summary_id];
|
||||
$plugin->options_submit($form['summary']['options'][$summary_id], $form_state, $options);
|
||||
// Copy the now submitted options to their final resting place so they get saved.
|
||||
// Copy the now submitted options to their final resting place so they
|
||||
// get saved.
|
||||
$form_state['values']['options']['summary_options'] = $options;
|
||||
}
|
||||
}
|
||||
@@ -472,7 +516,8 @@ class views_handler_argument extends views_handler {
|
||||
if ($plugin) {
|
||||
$options = &$form_state['values']['options']['validate']['options'][$validate_id];
|
||||
$plugin->options_submit($form['validate']['options'][$validate_id], $form_state, $options);
|
||||
// Copy the now submitted options to their final resting place so they get saved.
|
||||
// Copy the now submitted options to their final resting place so they
|
||||
// get saved.
|
||||
$form_state['values']['options']['validate_options'] = $options;
|
||||
}
|
||||
|
||||
@@ -484,47 +529,53 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a list of default behaviors for this argument if the argument
|
||||
* is not present.
|
||||
* List of default behaviors for this argument if the argument is not present.
|
||||
*
|
||||
* Override this method to provide additional (or fewer) default behaviors.
|
||||
*/
|
||||
function default_actions($which = NULL) {
|
||||
public function default_actions($which = NULL) {
|
||||
$defaults = array(
|
||||
'ignore' => array(
|
||||
'title' => t('Display all results for the specified field'),
|
||||
'method' => 'default_ignore',
|
||||
'breadcrumb' => TRUE, // generate a breadcrumb to here
|
||||
// Generate a breadcrumb to here.
|
||||
'breadcrumb' => TRUE,
|
||||
),
|
||||
'default' => array(
|
||||
'title' => t('Provide default value'),
|
||||
'method' => 'default_default',
|
||||
'form method' => 'default_argument_form',
|
||||
'has default argument' => TRUE,
|
||||
'default only' => TRUE, // this can only be used for missing argument, not validation failure
|
||||
'breadcrumb' => TRUE, // generate a breadcrumb to here
|
||||
// This can only be used for missing argument, not validation failure.
|
||||
'default only' => TRUE,
|
||||
// Generate a breadcrumb to here.
|
||||
'breadcrumb' => TRUE,
|
||||
),
|
||||
'not found' => array(
|
||||
'title' => t('Hide view'),
|
||||
'method' => 'default_not_found',
|
||||
'hard fail' => TRUE, // This is a hard fail condition
|
||||
// This is a hard fail condition.
|
||||
'hard fail' => TRUE,
|
||||
),
|
||||
'summary' => array(
|
||||
'title' => t('Display a summary'),
|
||||
'method' => 'default_summary',
|
||||
'form method' => 'default_summary_form',
|
||||
'style plugin' => TRUE,
|
||||
'breadcrumb' => TRUE, // generate a breadcrumb to here
|
||||
// Generate a breadcrumb to here.
|
||||
'breadcrumb' => TRUE,
|
||||
),
|
||||
'empty' => array(
|
||||
'title' => t('Display contents of "No results found"'),
|
||||
'method' => 'default_empty',
|
||||
'breadcrumb' => TRUE, // generate a breadcrumb to here
|
||||
// Generate a breadcrumb to here.
|
||||
'breadcrumb' => TRUE,
|
||||
),
|
||||
'access denied' => array(
|
||||
'title' => t('Display "Access Denied"'),
|
||||
'method' => 'default_access_denied',
|
||||
'breadcrumb' => FALSE, // generate a breadcrumb to here
|
||||
// Generate a breadcrumb to here.
|
||||
'breadcrumb' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -543,10 +594,11 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a form for selecting the default argument when the
|
||||
* default action is set to provide default argument.
|
||||
* Provide a form for selecting the default argument.
|
||||
*
|
||||
* Used when the default action is set to provide default argument.
|
||||
*/
|
||||
function default_argument_form(&$form, &$form_state) {
|
||||
public function default_argument_form(&$form, &$form_state) {
|
||||
$plugins = views_fetch_plugin_data('argument default');
|
||||
$options = array();
|
||||
|
||||
@@ -554,7 +606,7 @@ class views_handler_argument extends views_handler {
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Skip default argument for view URL'),
|
||||
'#default_value' => $this->options['default_argument_skip_url'],
|
||||
'#description' => t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.')
|
||||
'#description' => t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.'),
|
||||
);
|
||||
|
||||
$form['default_argument_type'] = array(
|
||||
@@ -564,8 +616,11 @@ class views_handler_argument extends views_handler {
|
||||
'#id' => 'edit-options-default-argument-type',
|
||||
'#title' => t('Type'),
|
||||
'#default_value' => $this->options['default_argument_type'],
|
||||
|
||||
'#dependency' => array('radio:options[default_action]' => array('default')),
|
||||
'#dependency' => array(
|
||||
'radio:options[default_action]' => array(
|
||||
'default',
|
||||
),
|
||||
),
|
||||
// Views custom key, moves this element to the appropriate container
|
||||
// under the radio button.
|
||||
'#argument_option' => 'default',
|
||||
@@ -588,7 +643,7 @@ class views_handler_argument extends views_handler {
|
||||
'#input' => TRUE,
|
||||
'#dependency' => array(
|
||||
'radio:options[default_action]' => array('default'),
|
||||
'edit-options-default-argument-type' => array($id)
|
||||
'edit-options-default-argument-type' => array($id),
|
||||
),
|
||||
'#dependency_count' => 2,
|
||||
);
|
||||
@@ -603,10 +658,11 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a form for selecting further summary options when the
|
||||
* default action is set to display one.
|
||||
* Form for selecting further summary options.
|
||||
*
|
||||
* Only used when the default action is set to display one.
|
||||
*/
|
||||
function default_summary_form(&$form, &$form_state) {
|
||||
public function default_summary_form(&$form, &$form_state) {
|
||||
$style_plugins = views_fetch_plugin_data('style');
|
||||
$summary_plugins = array();
|
||||
$format_options = array();
|
||||
@@ -635,7 +691,7 @@ class views_handler_argument extends views_handler {
|
||||
'#default_value' => $this->options['summary']['number_of_records'],
|
||||
'#options' => array(
|
||||
0 => $this->get_sort_name(),
|
||||
1 => t('Number of records')
|
||||
1 => t('Number of records'),
|
||||
),
|
||||
'#dependency' => array('radio:options[default_action]' => array('summary')),
|
||||
);
|
||||
@@ -659,7 +715,8 @@ class views_handler_argument extends views_handler {
|
||||
'#suffix' => '</div>',
|
||||
'#id' => 'edit-options-summary-options-' . $id,
|
||||
'#type' => 'item',
|
||||
'#input' => TRUE, // trick it into checking input to make #process run
|
||||
// Trick it into checking input to make #process run.
|
||||
'#input' => TRUE,
|
||||
'#dependency' => array(
|
||||
'radio:options[default_action]' => array('summary'),
|
||||
'radio:options[summary][format]' => array($id),
|
||||
@@ -677,11 +734,11 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* Override this method only with extreme care.
|
||||
*
|
||||
* @return
|
||||
* @return bool
|
||||
* A boolean value; if TRUE, continue building this view. If FALSE,
|
||||
* building the view will be aborted here.
|
||||
*/
|
||||
function default_action($info = NULL) {
|
||||
public function default_action($info = NULL) {
|
||||
if (!isset($info)) {
|
||||
$info = $this->default_actions($this->options['default_action']);
|
||||
}
|
||||
@@ -699,29 +756,30 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* How to act if validation failes
|
||||
* How to act if validation fails.
|
||||
*/
|
||||
function validate_fail() {
|
||||
public function validate_fail() {
|
||||
$info = $this->default_actions($this->options['validate']['fail']);
|
||||
return $this->default_action($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default action: ignore.
|
||||
*
|
||||
* If an argument was expected and was not given, in this case, simply
|
||||
* ignore the argument entirely.
|
||||
* If an argument was expected and was not given, in this case, simply ignore
|
||||
* the argument entirely.
|
||||
*/
|
||||
function default_ignore() {
|
||||
public function default_ignore() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default action: not found.
|
||||
*
|
||||
* If an argument was expected and was not given, in this case, report
|
||||
* the view as 'not found' or hide it.
|
||||
* If an argument was expected and was not given, in this case, report the
|
||||
* view as 'not found' or hide it.
|
||||
*/
|
||||
function default_not_found() {
|
||||
public function default_not_found() {
|
||||
// Set a failure condition and let the display manager handle it.
|
||||
$this->view->build_info['fail'] = TRUE;
|
||||
return FALSE;
|
||||
@@ -730,21 +788,21 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Default action: access denied.
|
||||
*
|
||||
* If an argument was expected and was not given, in this case, report
|
||||
* the view as 'access denied'.
|
||||
* If an argument was expected and was not given, in this case, report the
|
||||
* view as 'access denied'.
|
||||
*/
|
||||
function default_access_denied() {
|
||||
public function default_access_denied() {
|
||||
$this->view->build_info['denied'] = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default action: empty
|
||||
* Default action: empty.
|
||||
*
|
||||
* If an argument was expected and was not given, in this case, display
|
||||
* the view's empty text
|
||||
* If an argument was expected and was not given, in this case, display the
|
||||
* view's empty text.
|
||||
*/
|
||||
function default_empty() {
|
||||
public function default_empty() {
|
||||
// We return with no query; this will force the empty text.
|
||||
$this->view->built = TRUE;
|
||||
$this->view->executed = TRUE;
|
||||
@@ -753,17 +811,20 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* This just returns true. The view argument builder will know where
|
||||
* to find the argument from.
|
||||
* This just returns true.
|
||||
*
|
||||
* The view argument builder will know where to find the argument from.
|
||||
*
|
||||
* @todo Why is this needed?
|
||||
*/
|
||||
function default_default() {
|
||||
public function default_default() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the argument is set to provide a default argument.
|
||||
*/
|
||||
function has_default_argument() {
|
||||
public function has_default_argument() {
|
||||
$info = $this->default_actions($this->options['default_action']);
|
||||
return !empty($info['has default argument']);
|
||||
}
|
||||
@@ -771,7 +832,7 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Get a default argument, if available.
|
||||
*/
|
||||
function get_default_argument() {
|
||||
public function get_default_argument() {
|
||||
$plugin = $this->get_plugin('argument default');
|
||||
if ($plugin) {
|
||||
return $plugin->get_argument();
|
||||
@@ -784,7 +845,7 @@ class views_handler_argument extends views_handler {
|
||||
* For example, the validation plugin may want to alter an argument for use in
|
||||
* the URL.
|
||||
*/
|
||||
function process_summary_arguments(&$args) {
|
||||
public function process_summary_arguments(&$args) {
|
||||
if ($this->options['validate']['type'] != 'none') {
|
||||
if (isset($this->validator) || $this->validator = $this->get_plugin('argument validator')) {
|
||||
$this->validator->process_summary_arguments($args);
|
||||
@@ -795,20 +856,19 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Default action: summary.
|
||||
*
|
||||
* If an argument was expected and was not given, in this case, display
|
||||
* a summary query.
|
||||
* If an argument was expected and was not given, in this case, display a
|
||||
* summary query.
|
||||
*/
|
||||
function default_summary() {
|
||||
public function default_summary() {
|
||||
$this->view->build_info['summary'] = TRUE;
|
||||
$this->view->build_info['summary_level'] = $this->options['id'];
|
||||
|
||||
// Change the display style to the summary style for this
|
||||
// argument.
|
||||
// Change the display style to the summary style for this argument.
|
||||
$this->view->plugin_name = $this->options['summary']['format'];
|
||||
$this->view->style_options = $this->options['summary_options'];
|
||||
|
||||
// Clear out the normal primary field and whatever else may have
|
||||
// been added and let the summary do the work.
|
||||
// Clear out the normal primary field and whatever else may have been added
|
||||
// and let the summary do the work.
|
||||
$this->query->clear_fields();
|
||||
$this->summary_query();
|
||||
|
||||
@@ -826,14 +886,14 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* This must:
|
||||
* - add_groupby: group on this field in order to create summaries.
|
||||
* - add_field: add a 'num_nodes' field for the count. Usually it will
|
||||
* be a count on $view->base_field
|
||||
* - add_field: add a 'num_nodes' field for the count. Usually it will be a
|
||||
* count on $view->base_field
|
||||
* - set_count_field: Reset the count field so we get the right paging.
|
||||
*
|
||||
* @return
|
||||
* @return string
|
||||
* The alias used to get the number of records (count) for this entry.
|
||||
*/
|
||||
function summary_query() {
|
||||
public function summary_query() {
|
||||
$this->ensure_my_table();
|
||||
// Add the field.
|
||||
$this->base_alias = $this->query->add_field($this->table_alias, $this->real_field);
|
||||
@@ -844,15 +904,15 @@ class views_handler_argument extends views_handler {
|
||||
|
||||
/**
|
||||
* Add the name field, which is the field displayed in summary queries.
|
||||
*
|
||||
* This is often used when the argument is numeric.
|
||||
*/
|
||||
function summary_name_field() {
|
||||
// Add the 'name' field. For example, if this is a uid argument, the
|
||||
// name field would be 'name' (i.e, the username).
|
||||
|
||||
public function summary_name_field() {
|
||||
// Add the 'name' field. For example, if this is a uid argument, the name
|
||||
// field would be 'name' (i.e, the username).
|
||||
if (isset($this->name_table)) {
|
||||
// if the alias is different then we're probably added, not ensured,
|
||||
// so look up the join and add it instead.
|
||||
// If the alias is different then we're probably added, not ensured, so
|
||||
// look up the join and add it instead.
|
||||
if ($this->table_alias != $this->name_table) {
|
||||
$j = views_get_table_join($this->name_table, $this->table);
|
||||
if ($j) {
|
||||
@@ -878,15 +938,21 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Some basic summary behavior that doesn't need to be repeated as much as
|
||||
* code that goes into summary_query()
|
||||
* Some basic summary behavior.
|
||||
*
|
||||
* This doesn't need to be repeated as much as code that goes into
|
||||
* summary_query().
|
||||
*/
|
||||
function summary_basics($count_field = TRUE) {
|
||||
// Add the number of nodes counter
|
||||
public function summary_basics($count_field = TRUE) {
|
||||
// Add the number of nodes counter.
|
||||
$distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct));
|
||||
|
||||
$count_alias = $this->query->add_field($this->query->base_table, $this->query->base_field, 'num_records',
|
||||
array('count' => TRUE, 'distinct' => $distinct));
|
||||
$count_alias = $this->query->add_field($this->query->base_table,
|
||||
$this->query->base_field, 'num_records',
|
||||
array(
|
||||
'count' => TRUE,
|
||||
'distinct' => $distinct,
|
||||
));
|
||||
$this->query->add_groupby($this->name_alias);
|
||||
|
||||
if ($count_field) {
|
||||
@@ -897,36 +963,44 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the summary based upon the user's selection. The base variant of
|
||||
* this is usually adequte.
|
||||
* Sorts the summary based upon the user's selection.
|
||||
*
|
||||
* @param $order
|
||||
* The base variant of this is usually adequte.
|
||||
*
|
||||
* @param string $order
|
||||
* The order selected in the UI.
|
||||
* @param string $by
|
||||
* Optional alias for this field.
|
||||
*/
|
||||
function summary_sort($order, $by = NULL) {
|
||||
public function summary_sort($order, $by = NULL) {
|
||||
$this->query->add_orderby(NULL, NULL, $order, (!empty($by) ? $by : $this->name_alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the argument to use to link from the summary to the next level;
|
||||
* this will be called once per row of a summary, and used as part of
|
||||
* Provide the argument to use to link from the summary to the next level.
|
||||
*
|
||||
* This will be called once per row of a summary, and used as part of
|
||||
* $view->get_url().
|
||||
*
|
||||
* @param $data
|
||||
* @param object $data
|
||||
* The query results for the row.
|
||||
*/
|
||||
function summary_argument($data) {
|
||||
public function summary_argument($data) {
|
||||
return $data->{$this->base_alias};
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the name to use for the summary. By default this is just
|
||||
* the name field.
|
||||
* Provides the name to use for the summary.
|
||||
*
|
||||
* @param $data
|
||||
* By default this is just the name field.
|
||||
*
|
||||
* @param object $data
|
||||
* The query results for the row.
|
||||
*
|
||||
* @return string
|
||||
* The summary.
|
||||
*/
|
||||
function summary_name($data) {
|
||||
public function summary_name($data) {
|
||||
$value = $data->{$this->name_alias};
|
||||
if (empty($value) && !empty($this->definition['empty field name'])) {
|
||||
$value = $this->definition['empty field name'];
|
||||
@@ -938,8 +1012,11 @@ class views_handler_argument extends views_handler {
|
||||
* Set up the query for this argument.
|
||||
*
|
||||
* The argument sent may be found at $this->argument.
|
||||
*
|
||||
* @param bool $group_by
|
||||
* Whether the query uses a group-by.
|
||||
*/
|
||||
function query($group_by = FALSE) {
|
||||
public function query($group_by = FALSE) {
|
||||
$this->ensure_my_table();
|
||||
$this->query->add_where(0, "$this->table_alias.$this->real_field", $this->argument);
|
||||
}
|
||||
@@ -949,15 +1026,17 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* This usually needs to be overridden to provide a proper title.
|
||||
*/
|
||||
function title() {
|
||||
public function title() {
|
||||
return check_plain($this->argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the view object to get the title. This may be set by a
|
||||
* validator so we don't necessarily call through to title().
|
||||
* Called by the view object to get the title.
|
||||
*
|
||||
* This may be set by a validator so we don't necessarily call through to
|
||||
* title().
|
||||
*/
|
||||
function get_title() {
|
||||
public function get_title() {
|
||||
if (isset($this->validated_title)) {
|
||||
return $this->validated_title;
|
||||
}
|
||||
@@ -969,7 +1048,7 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Validate that this argument works. By default, all arguments are valid.
|
||||
*/
|
||||
function validate_arg($arg) {
|
||||
public function validate_arg($arg) {
|
||||
// By using % in URLs, arguments could be validated twice; this eases
|
||||
// that pain.
|
||||
if (isset($this->argument_validated)) {
|
||||
@@ -989,7 +1068,7 @@ class views_handler_argument extends views_handler {
|
||||
return $this->argument_validated = $plugin->validate_argument($arg);
|
||||
}
|
||||
|
||||
// If the plugin isn't found, fall back to the basic validation path:
|
||||
// If the plugin isn't found, fall back to the basic validation path.
|
||||
return $this->argument_validated = $this->validate_argument_basic($arg);
|
||||
}
|
||||
|
||||
@@ -997,10 +1076,10 @@ class views_handler_argument extends views_handler {
|
||||
* Called by the menu system to validate an argument.
|
||||
*
|
||||
* This checks to see if this is a 'soft fail', which means that if the
|
||||
* argument fails to validate, but there is an action to take anyway,
|
||||
* then validation cannot actually fail.
|
||||
* argument fails to validate, but there is an action to take anyway, then
|
||||
* validation cannot actually fail.
|
||||
*/
|
||||
function validate_argument($arg) {
|
||||
public function validate_argument($arg) {
|
||||
$validate_info = $this->default_actions($this->options['validate']['fail']);
|
||||
if (empty($validate_info['hard fail'])) {
|
||||
return TRUE;
|
||||
@@ -1008,8 +1087,8 @@ class views_handler_argument extends views_handler {
|
||||
|
||||
$rc = $this->validate_arg($arg);
|
||||
|
||||
// If the validator has changed the validate fail condition to a
|
||||
// soft fail, deal with that:
|
||||
// If the validator has changed the validate fail condition to a soft fail,
|
||||
// deal with that.
|
||||
$validate_info = $this->default_actions($this->options['validate']['fail']);
|
||||
if (empty($validate_info['hard fail'])) {
|
||||
return TRUE;
|
||||
@@ -1021,11 +1100,14 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Provide a basic argument validation.
|
||||
*
|
||||
* This can be overridden for more complex types; the basic
|
||||
* validator only checks to see if the argument is not NULL
|
||||
* or is numeric if the definition says it's numeric.
|
||||
* This can be overridden for more complex types; the basic validator only
|
||||
* checks to see if the argument is not NULL or is numeric if the definition
|
||||
* says it's numeric.
|
||||
*
|
||||
* @return bool
|
||||
* Whether or not the argument validates.
|
||||
*/
|
||||
function validate_argument_basic($arg) {
|
||||
public function validate_argument_basic($arg) {
|
||||
if (!isset($arg) || $arg === '') {
|
||||
return FALSE;
|
||||
}
|
||||
@@ -1038,19 +1120,23 @@ class views_handler_argument extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the input for this argument
|
||||
* Set the input for this argument.
|
||||
*
|
||||
* @return TRUE if it successfully validates; FALSE if it does not.
|
||||
* @return bool
|
||||
* TRUE if it successfully validates; FALSE if it does not.
|
||||
*/
|
||||
function set_argument($arg) {
|
||||
public function set_argument($arg) {
|
||||
$this->argument = $arg;
|
||||
return $this->validate_arg($arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of this argument.
|
||||
*
|
||||
* @return string
|
||||
* The value.
|
||||
*/
|
||||
function get_value() {
|
||||
public function get_value() {
|
||||
// If we already processed this argument, we're done.
|
||||
if (isset($this->argument)) {
|
||||
return $this->argument;
|
||||
@@ -1089,8 +1175,11 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* Arguments can have styles for the summary view. This special export
|
||||
* handler makes sure this works properly.
|
||||
*
|
||||
* @return string
|
||||
* The export summary.
|
||||
*/
|
||||
function export_summary($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
public function export_summary($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
$output = '';
|
||||
$name = $this->options['summary'][$option];
|
||||
$options = $this->options['summary_options'];
|
||||
@@ -1113,8 +1202,11 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* Arguments use validation plugins. This special export handler makes sure
|
||||
* this works properly.
|
||||
*
|
||||
* @return string
|
||||
* The validation response.
|
||||
*/
|
||||
function export_validation($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
public function export_validation($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
$output = '';
|
||||
$name = $this->options['validate'][$option];
|
||||
$options = $this->options['validate_options'];
|
||||
@@ -1137,8 +1229,11 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* Since style and validation plugins have their own export handlers, this
|
||||
* one is currently only used for default argument plugins.
|
||||
*
|
||||
* @return string
|
||||
* Export string.
|
||||
*/
|
||||
function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
public function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
$output = '';
|
||||
if ($option == 'default_argument_type') {
|
||||
$type = 'argument default';
|
||||
@@ -1162,28 +1257,30 @@ class views_handler_argument extends views_handler {
|
||||
/**
|
||||
* Get the display or row plugin, if it exists.
|
||||
*/
|
||||
function get_plugin($type = 'argument default', $name = NULL) {
|
||||
public function get_plugin($type = 'argument default', $name = NULL) {
|
||||
$options = array();
|
||||
switch ($type) {
|
||||
case 'argument default':
|
||||
$plugin_name = $this->options['default_argument_type'];
|
||||
$options_name = 'default_argument_options';
|
||||
break;
|
||||
|
||||
case 'argument validator':
|
||||
$plugin_name = $this->options['validate']['type'];
|
||||
$options_name = 'validate_options';
|
||||
break;
|
||||
|
||||
case 'style':
|
||||
$plugin_name = $this->options['summary']['format'];
|
||||
$options_name = 'summary_options';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$name) {
|
||||
$name = $plugin_name;
|
||||
}
|
||||
|
||||
// we only fetch the options if we're fetching the plugin actually
|
||||
// in use.
|
||||
// We only fetch the options if we're fetching the plugin actually in use.
|
||||
if ($name == $plugin_name) {
|
||||
$options = $this->options[$options_name];
|
||||
}
|
||||
@@ -1206,10 +1303,14 @@ class views_handler_argument extends views_handler {
|
||||
*
|
||||
* Subclasses should override this to specify what the default sort order of
|
||||
* their argument is (e.g. alphabetical, numeric, date).
|
||||
*
|
||||
* @return string
|
||||
* The label for the sorter.
|
||||
*/
|
||||
function get_sort_name() {
|
||||
public function get_sort_name() {
|
||||
return t('Default sort', array(), array('context' => 'Sort order'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1218,22 +1319,44 @@ class views_handler_argument extends views_handler {
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_broken extends views_handler_argument {
|
||||
function ui_name($short = FALSE) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return t('Broken/missing handler');
|
||||
}
|
||||
|
||||
function ensure_my_table() { /* No table to ensure! */ }
|
||||
function query($group_by = FALSE) { /* No query to run */ }
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ensure_my_table() {
|
||||
// No table to ensure!
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
// No query to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is considered 'broken'
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function broken() { return TRUE; }
|
||||
public function broken() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -10,41 +10,54 @@
|
||||
*
|
||||
* Adds an option to set a default argument based on the current date.
|
||||
*
|
||||
* @param $arg_format
|
||||
* The format string to use on the current time when
|
||||
* creating a default date argument.
|
||||
* @param string $arg_format
|
||||
* The format string to use on the current time when creating a default date
|
||||
* argument.
|
||||
*
|
||||
* Definitions terms:
|
||||
* - many to one: If true, the "many to one" helper will be used.
|
||||
* - invalid input: A string to give to the user for obviously invalid input.
|
||||
* This is deprecated in favor of argument validators.
|
||||
* This is deprecated in favor of argument validators.
|
||||
*
|
||||
* @see views_many_to_one_helper()
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_date extends views_handler_argument_formula {
|
||||
var $option_name = 'default_argument_date';
|
||||
var $arg_format = 'Y-m-d';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $option_name = 'default_argument_date';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $arg_format = 'Y-m-d';
|
||||
|
||||
/**
|
||||
* Add an option to set the default value to the current date.
|
||||
*/
|
||||
function default_argument_form(&$form, &$form_state) {
|
||||
public function default_argument_form(&$form, &$form_state) {
|
||||
parent::default_argument_form($form, $form_state);
|
||||
$form['default_argument_type']['#options'] += array('date' => t('Current date'));
|
||||
$form['default_argument_type']['#options'] += array('node_created' => t("Current node's creation time"));
|
||||
$form['default_argument_type']['#options'] += array('node_changed' => t("Current node's update time")); }
|
||||
$form['default_argument_type']['#options'] += array('node_changed' => t("Current node's update time"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the empty argument value to the current date,
|
||||
* formatted appropriately for this argument.
|
||||
* Set the empty argument value to the current date.
|
||||
*
|
||||
* Formatted appropriately for this argument.
|
||||
*
|
||||
* @return string
|
||||
* The default argument.
|
||||
*/
|
||||
function get_default_argument($raw = FALSE) {
|
||||
public function get_default_argument($raw = FALSE) {
|
||||
if (!$raw && $this->options['default_argument_type'] == 'date') {
|
||||
return date($this->arg_format, REQUEST_TIME);
|
||||
}
|
||||
else if (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
|
||||
elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
|
||||
foreach (range(1, 3) as $i) {
|
||||
$node = menu_get_object('node', $i);
|
||||
if (!empty($node)) {
|
||||
@@ -71,11 +84,12 @@ class views_handler_argument_date extends views_handler_argument_formula {
|
||||
}
|
||||
|
||||
/**
|
||||
* The date handler provides some default argument types, which aren't argument default plugins,
|
||||
* so addapt the export mechanism.
|
||||
* Adapt the export mechanism.
|
||||
*
|
||||
* The date handler provides some default argument types, which aren't
|
||||
* argument default plugins.
|
||||
*/
|
||||
function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
|
||||
public function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
|
||||
// Only use a special behaviour for the special argument types, else just
|
||||
// use the default behaviour.
|
||||
if ($option == 'default_argument_type') {
|
||||
@@ -94,8 +108,11 @@ class views_handler_argument_date extends views_handler_argument_formula {
|
||||
return parent::export_plugin($indent, $prefix, $storage, $option, $definition, $parents);
|
||||
}
|
||||
|
||||
|
||||
function get_sort_name() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_sort_name() {
|
||||
return t('Date', array(), array('context' => 'Sort order'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,11 +16,16 @@
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_formula extends views_handler_argument {
|
||||
var $formula = NULL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
function construct() {
|
||||
public $formula = NULL;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
|
||||
if (!empty($this->definition['formula'])) {
|
||||
@@ -28,14 +33,17 @@ class views_handler_argument_formula extends views_handler_argument {
|
||||
}
|
||||
}
|
||||
|
||||
function get_formula() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_formula() {
|
||||
return str_replace('***table***', $this->table_alias, $this->formula);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the summary query based on a formula
|
||||
*/
|
||||
function summary_query() {
|
||||
public function summary_query() {
|
||||
$this->ensure_my_table();
|
||||
// Now that our table is secure, get our formula.
|
||||
$formula = $this->get_formula();
|
||||
@@ -50,14 +58,15 @@ class views_handler_argument_formula extends views_handler_argument {
|
||||
/**
|
||||
* Build the query based upon the formula
|
||||
*/
|
||||
function query($group_by = FALSE) {
|
||||
public function query($group_by = FALSE) {
|
||||
$this->ensure_my_table();
|
||||
// Now that our table is secure, get our formula.
|
||||
$placeholder = $this->placeholder();
|
||||
$formula = $this->get_formula() .' = ' . $placeholder;
|
||||
$formula = $this->get_formula() . ' = ' . $placeholder;
|
||||
$placeholders = array(
|
||||
$placeholder => $this->argument,
|
||||
);
|
||||
$this->query->add_where(0, $formula, $placeholders, 'formula');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,8 +10,12 @@
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_group_by_numeric extends views_handler_argument {
|
||||
function query($group_by = FALSE) {
|
||||
class views_handler_argument_group_by_numeric extends views_handler_argument {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
$this->ensure_my_table();
|
||||
$field = $this->get_field();
|
||||
$placeholder = $this->placeholder();
|
||||
@@ -19,11 +23,18 @@ class views_handler_argument_group_by_numeric extends views_handler_argument {
|
||||
$this->query->add_having_expression(0, "$field = $placeholder", array($placeholder => $this->argument));
|
||||
}
|
||||
|
||||
function ui_name($short = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return $this->get_field(parent::ui_name($short));
|
||||
}
|
||||
|
||||
function get_sort_name() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_sort_name() {
|
||||
return t('Numerical', array(), array('context' => 'Sort order'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,29 +6,39 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* An argument handler for use in fields that have a many to one relationship
|
||||
* with the table(s) to the left. This adds a bunch of options that are
|
||||
* reasonably common with this type of relationship.
|
||||
* Argument handler for fields that have many-to-one table relationships.
|
||||
*
|
||||
* (i.e. with the table(s) to the left.)
|
||||
* This adds a bunch of options that are reasonably common with this type of
|
||||
* relationship.
|
||||
*
|
||||
* Definition terms:
|
||||
* - numeric: If true, the field will be considered numeric. Probably should
|
||||
* always be set TRUE as views_handler_argument_string has many to one
|
||||
* capabilities.
|
||||
* - zero is null: If true, a 0 will be handled as empty, so for example
|
||||
* a default argument can be provided or a summary can be shown.
|
||||
* - zero is null: If true, a 0 will be handled as empty, so for example a
|
||||
* default argument can be provided or a summary can be shown.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
function init(&$view, &$options) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
$this->helper = new views_many_to_one_helper($this);
|
||||
|
||||
// Ensure defaults for these, during summaries and stuff:
|
||||
// Ensure defaults for these, during summaries and stuff.
|
||||
$this->operator = 'or';
|
||||
$this->value = array();
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
if (!empty($this->definition['numeric'])) {
|
||||
@@ -49,7 +59,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// allow + for or, , for and
|
||||
@@ -85,11 +98,14 @@ class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
* Override ensure_my_table so we can control how this joins in.
|
||||
* The operator actually has influence over joining.
|
||||
*/
|
||||
function ensure_my_table() {
|
||||
public function ensure_my_table() {
|
||||
$this->helper->ensure_my_table();
|
||||
}
|
||||
|
||||
function query($group_by = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
$empty = FALSE;
|
||||
if (isset($this->definition['zero is null']) && $this->definition['zero is null']) {
|
||||
if (empty($this->argument)) {
|
||||
@@ -118,7 +134,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
$this->helper->add_filter();
|
||||
}
|
||||
|
||||
function title() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function title() {
|
||||
if (!$this->argument) {
|
||||
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
|
||||
}
|
||||
@@ -144,7 +163,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query());
|
||||
}
|
||||
|
||||
function summary_query() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function summary_query() {
|
||||
$field = $this->table . '.' . $this->field;
|
||||
$join = $this->get_join();
|
||||
|
||||
@@ -167,7 +189,10 @@ class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
return $this->summary_basics();
|
||||
}
|
||||
|
||||
function summary_argument($data) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function summary_argument($data) {
|
||||
$value = $data->{$this->base_alias};
|
||||
if (empty($value)) {
|
||||
$value = 0;
|
||||
@@ -179,7 +204,8 @@ class views_handler_argument_many_to_one extends views_handler_argument {
|
||||
/**
|
||||
* Override for specific title lookups.
|
||||
*/
|
||||
function title_query() {
|
||||
public function title_query() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,11 @@
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_null extends views_handler_argument {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['must_not_be'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
return $options;
|
||||
@@ -21,7 +25,7 @@ class views_handler_argument_null extends views_handler_argument {
|
||||
* Override options_form() so that only the relevant options
|
||||
* are displayed to the user.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['must_not_be'] = array(
|
||||
'#type' => 'checkbox',
|
||||
@@ -38,9 +42,9 @@ class views_handler_argument_null extends views_handler_argument {
|
||||
* Override default_actions() to remove actions that don't
|
||||
* make sense for a null argument.
|
||||
*/
|
||||
function default_actions($which = NULL) {
|
||||
public function default_actions($which = NULL) {
|
||||
if ($which) {
|
||||
if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) {
|
||||
if (in_array($which, array('ignore', 'not found', 'empty', 'default', 'access denied'))) {
|
||||
return parent::default_actions($which);
|
||||
}
|
||||
return;
|
||||
@@ -51,7 +55,10 @@ class views_handler_argument_null extends views_handler_argument {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
function validate_argument_basic($arg) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate_argument_basic($arg) {
|
||||
if (!empty($this->options['must_not_be'])) {
|
||||
return !isset($arg);
|
||||
}
|
||||
@@ -63,5 +70,7 @@ class views_handler_argument_null extends views_handler_argument {
|
||||
* Override the behavior of query() to prevent the query
|
||||
* from being changed in any way.
|
||||
*/
|
||||
function query($group_by = FALSE) {}
|
||||
public function query($group_by = FALSE) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,25 +6,30 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Basic argument handler for arguments that are numeric. Incorporates
|
||||
* break_phrase.
|
||||
* Basic argument handler for arguments that are numeric.
|
||||
*
|
||||
* Incorporates break_phrase.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_numeric extends views_handler_argument {
|
||||
|
||||
/**
|
||||
* The operator used for the query: or|and.
|
||||
* @var string
|
||||
*/
|
||||
var $operator;
|
||||
public $operator;
|
||||
|
||||
/**
|
||||
* The actual value which is used for querying.
|
||||
* @var array
|
||||
*/
|
||||
var $value;
|
||||
public $value;
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
@@ -33,7 +38,10 @@ class views_handler_argument_numeric extends views_handler_argument {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// allow + for or, , for and
|
||||
@@ -54,7 +62,10 @@ class views_handler_argument_numeric extends views_handler_argument {
|
||||
);
|
||||
}
|
||||
|
||||
function title() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function title() {
|
||||
if (!$this->argument) {
|
||||
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized');
|
||||
}
|
||||
@@ -80,14 +91,18 @@ class views_handler_argument_numeric extends views_handler_argument {
|
||||
|
||||
/**
|
||||
* Override for specific title lookups.
|
||||
*
|
||||
* @return array
|
||||
* Returns all titles, if it's just one title it's an array with one entry.
|
||||
*/
|
||||
function title_query() {
|
||||
public function title_query() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function query($group_by = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
$this->ensure_my_table();
|
||||
|
||||
if (!empty($this->options['break_phrase'])) {
|
||||
@@ -110,7 +125,11 @@ class views_handler_argument_numeric extends views_handler_argument {
|
||||
}
|
||||
}
|
||||
|
||||
function get_sort_name() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_sort_name() {
|
||||
return t('Numerical', array(), array('context' => 'Sort order'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,24 +6,30 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Basic argument handler to implement string arguments that may have length
|
||||
* limits.
|
||||
* Argument handler to implement string arguments that may have length limits.
|
||||
*
|
||||
* @ingroup views_argument_handlers
|
||||
*/
|
||||
class views_handler_argument_string extends views_handler_argument {
|
||||
function init(&$view, &$options) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
if (!empty($this->definition['many to one'])) {
|
||||
$this->helper = new views_many_to_one_helper($this);
|
||||
|
||||
// Ensure defaults for these, during summaries and stuff:
|
||||
// Ensure defaults for these, during summaries and stuff.
|
||||
$this->operator = 'or';
|
||||
$this->value = array();
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['glossary'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
@@ -32,6 +38,7 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
$options['path_case'] = array('default' => 'none');
|
||||
$options['transform_dash'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
$options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
$options['not'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
|
||||
if (!empty($this->definition['many to one'])) {
|
||||
$options['add_table'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
@@ -41,7 +48,10 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['glossary'] = array(
|
||||
@@ -123,12 +133,19 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
'#default_value' => !empty($this->options['break_phrase']),
|
||||
'#fieldset' => 'more',
|
||||
);
|
||||
$form['not'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Exclude'),
|
||||
'#description' => t('If selected, the numbers entered for the filter will be excluded rather than limiting the view.'),
|
||||
'#default_value' => !empty($this->options['not']),
|
||||
'#fieldset' => 'more',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the summary query based on a string
|
||||
* Build the summary query based on a string.
|
||||
*/
|
||||
function summary_query() {
|
||||
public function summary_query() {
|
||||
if (empty($this->definition['many to one'])) {
|
||||
$this->ensure_my_table();
|
||||
}
|
||||
@@ -157,14 +174,14 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
*
|
||||
* $this->ensure_my_table() MUST have been called prior to this.
|
||||
*/
|
||||
function get_formula() {
|
||||
public function get_formula() {
|
||||
return "SUBSTRING($this->table_alias.$this->real_field, 1, " . intval($this->options['limit']) . ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the query based upon the formula
|
||||
*/
|
||||
function query($group_by = FALSE) {
|
||||
public function query($group_by = FALSE) {
|
||||
$argument = $this->argument;
|
||||
if (!empty($this->options['transform_dash'])) {
|
||||
$argument = strtr($argument, '-', ' ');
|
||||
@@ -198,21 +215,19 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
}
|
||||
|
||||
if (count($this->value) > 1) {
|
||||
$operator = 'IN';
|
||||
$operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
|
||||
$argument = $this->value;
|
||||
}
|
||||
else {
|
||||
$operator = '=';
|
||||
$operator = empty($this->options['not']) ? '=' : '!=';
|
||||
}
|
||||
|
||||
if ($formula) {
|
||||
$placeholder = $this->placeholder();
|
||||
if ($operator == 'IN') {
|
||||
$field .= " IN($placeholder)";
|
||||
}
|
||||
else {
|
||||
$field .= ' = ' . $placeholder;
|
||||
if (count($this->value) > 1) {
|
||||
$placeholder = "($placeholder)";
|
||||
}
|
||||
$field .= " $operator $placeholder";
|
||||
$placeholders = array(
|
||||
$placeholder => $argument,
|
||||
);
|
||||
@@ -223,7 +238,10 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
}
|
||||
}
|
||||
|
||||
function summary_argument($data) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function summary_argument($data) {
|
||||
$value = $this->case_transform($data->{$this->base_alias}, $this->options['path_case']);
|
||||
if (!empty($this->options['transform_dash'])) {
|
||||
$value = strtr($value, ' ', '-');
|
||||
@@ -231,11 +249,17 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
return $value;
|
||||
}
|
||||
|
||||
function get_sort_name() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_sort_name() {
|
||||
return t('Alphabetical', array(), array('context' => 'Sort order'));
|
||||
}
|
||||
|
||||
function title() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function title() {
|
||||
$this->argument = $this->case_transform($this->argument, $this->options['case']);
|
||||
if (!empty($this->options['transform_dash'])) {
|
||||
$this->argument = strtr($this->argument, '-', ' ');
|
||||
@@ -263,11 +287,14 @@ class views_handler_argument_string extends views_handler_argument {
|
||||
/**
|
||||
* Override for specific title lookups.
|
||||
*/
|
||||
function title_query() {
|
||||
public function title_query() {
|
||||
return drupal_map_assoc($this->value, 'check_plain');
|
||||
}
|
||||
|
||||
function summary_name($data) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function summary_name($data) {
|
||||
return $this->case_transform(parent::summary_name($data), $this->options['case']);
|
||||
}
|
||||
|
||||
|
@@ -2,25 +2,26 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @todo.
|
||||
* Definition of views_handler_field.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup views_field_handlers Views field handlers
|
||||
* @{
|
||||
* Handlers to tell Views how to build and display fields.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Indicator of the render_text() method for rendering a single item.
|
||||
* (If no render_item() is present).
|
||||
*
|
||||
* If no render_item() is present.
|
||||
*/
|
||||
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_SINGLE_ITEM', 0);
|
||||
|
||||
/**
|
||||
* Indicator of the render_text() method for rendering the whole element.
|
||||
* (if no render_item() method is available).
|
||||
*
|
||||
* if no render_item() method is available.
|
||||
*/
|
||||
define('VIEWS_HANDLER_RENDER_TEXT_PHASE_COMPLETELY', 1);
|
||||
|
||||
@@ -34,17 +35,29 @@ define('VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY', 2);
|
||||
*
|
||||
* Definition terms:
|
||||
* - additional fields: An array of fields that should be added to the query
|
||||
* for some purpose. The array is in the form of:
|
||||
* array('identifier' => array('table' => tablename,
|
||||
* 'field' => fieldname); as many fields as are necessary
|
||||
* may be in this array.
|
||||
* for some purpose. The array is in the form of:
|
||||
* array(
|
||||
* 'identifier' => array(
|
||||
* 'table' => tablename,
|
||||
* 'field' => fieldname,
|
||||
* )
|
||||
* );
|
||||
* with as many fields as are necessary may be in this array.
|
||||
* - click sortable: If TRUE, this field may be click sorted.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field extends views_handler {
|
||||
var $field_alias = 'unknown';
|
||||
var $aliases = array();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public $field_alias = 'unknown';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public $aliases = array();
|
||||
|
||||
/**
|
||||
* The field value prior to any rewriting.
|
||||
@@ -55,15 +68,15 @@ class views_handler_field extends views_handler {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* Stores additional fields which get's added to the query.
|
||||
* Stores additional fields which get added to the query.
|
||||
* The generated aliases are stored in $aliases.
|
||||
*/
|
||||
var $additional_fields = array();
|
||||
public $additional_fields = array();
|
||||
|
||||
/**
|
||||
* Construct a new field handler.
|
||||
*/
|
||||
function construct() {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
|
||||
$this->additional_fields = array();
|
||||
@@ -79,21 +92,24 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Determine if this field can allow advanced rendering.
|
||||
*
|
||||
* Fields can set this to FALSE if they do not wish to allow
|
||||
* token based rewriting or link-making.
|
||||
* Fields can set this to FALSE if they do not wish to allow token based
|
||||
* rewriting or link-making.
|
||||
*/
|
||||
function allow_advanced_render() {
|
||||
public function allow_advanced_render() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function init(&$view, &$options) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to add the field to a query.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
// Add the field.
|
||||
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
|
||||
@@ -105,16 +121,15 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Add 'additional' fields to the query.
|
||||
*
|
||||
* @param $fields
|
||||
* An array of fields. The key is an identifier used to later find the
|
||||
* field alias used. The value is either a string in which case it's
|
||||
* assumed to be a field on this handler's table; or it's an array in the
|
||||
* form of
|
||||
* @code array('table' => $tablename, 'field' => $fieldname) @endcode
|
||||
* @param array $fields
|
||||
* An array of fields. The key is an identifier used to later find the field
|
||||
* alias used. The value is either a string in which case it's assumed to be
|
||||
* a field on this handler's table; or it's an array in the form of
|
||||
* @code array('table' => $tablename, 'field' => $fieldname) @endcode
|
||||
*/
|
||||
function add_additional_fields($fields = NULL) {
|
||||
public function add_additional_fields($fields = NULL) {
|
||||
if (!isset($fields)) {
|
||||
// notice check
|
||||
// Notice check.
|
||||
if (empty($this->additional_fields)) {
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +154,12 @@ class views_handler_field extends views_handler {
|
||||
}
|
||||
|
||||
if (empty($table_alias)) {
|
||||
debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array('@handler' => $this->definition['handler'], '@identifier' => $identifier, '@table' => $info['table'])));
|
||||
$t_args = array(
|
||||
'@handler' => $this->definition['handler'],
|
||||
'@identifier' => $identifier,
|
||||
'@table' => $info['table'],
|
||||
);
|
||||
debug(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', $t_args));
|
||||
$this->aliases[$identifier] = 'broken';
|
||||
continue;
|
||||
}
|
||||
@@ -162,7 +182,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Called to determine what to tell the clicksorter.
|
||||
*/
|
||||
function click_sort($order) {
|
||||
public function click_sort($order) {
|
||||
if (isset($this->field_alias)) {
|
||||
// Since fields should always have themselves already added, just
|
||||
// add a sort on the field.
|
||||
@@ -174,14 +194,14 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Determine if this field is click sortable.
|
||||
*/
|
||||
function click_sortable() {
|
||||
public function click_sortable() {
|
||||
return !empty($this->definition['click sortable']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this field's label.
|
||||
*/
|
||||
function label() {
|
||||
public function label() {
|
||||
if (!isset($this->options['label'])) {
|
||||
return '';
|
||||
}
|
||||
@@ -191,7 +211,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return an HTML element based upon the field's element type.
|
||||
*/
|
||||
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_type'] === '0') {
|
||||
return '';
|
||||
@@ -219,7 +239,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return an HTML element for the label based upon the field's element type.
|
||||
*/
|
||||
function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
public function element_label_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_label_type'] === '0') {
|
||||
return '';
|
||||
@@ -239,7 +259,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return an HTML element for the wrapper based upon the field's element type.
|
||||
*/
|
||||
function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
public function element_wrapper_type($none_supported = FALSE, $default_empty = FALSE) {
|
||||
if ($none_supported) {
|
||||
if ($this->options['element_wrapper_type'] === '0') {
|
||||
return 0;
|
||||
@@ -259,11 +279,10 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Provide a list of elements valid for field HTML.
|
||||
*
|
||||
* This function can be overridden by fields that want more or fewer
|
||||
* elements available, though this seems like it would be an incredibly
|
||||
* rare occurence.
|
||||
* This function can be overridden by fields that want more or fewer elements
|
||||
* available, though this seems like it would be an incredibly rare occurence.
|
||||
*/
|
||||
function get_elements() {
|
||||
public function get_elements() {
|
||||
static $elements = NULL;
|
||||
if (!isset($elements)) {
|
||||
$elements = variable_get('views_field_rewrite_elements', array(
|
||||
@@ -289,7 +308,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return the class of the field.
|
||||
*/
|
||||
function element_classes($row_index = NULL) {
|
||||
public function element_classes($row_index = NULL) {
|
||||
$classes = explode(' ', $this->options['element_class']);
|
||||
foreach ($classes as &$class) {
|
||||
$class = $this->tokenize_value($class, $row_index);
|
||||
@@ -304,15 +323,14 @@ class views_handler_field extends views_handler {
|
||||
* This function actually figures out which field was last and uses its
|
||||
* tokens so they will all be available.
|
||||
*/
|
||||
function tokenize_value($value, $row_index = NULL) {
|
||||
public function tokenize_value($value, $row_index = NULL) {
|
||||
if (strpos($value, '[') !== FALSE || strpos($value, '!') !== FALSE || strpos($value, '%') !== FALSE) {
|
||||
$fake_item = array(
|
||||
'alter_text' => TRUE,
|
||||
'text' => $value,
|
||||
);
|
||||
|
||||
// Use isset() because empty() will trigger on 0 and 0 is
|
||||
// the first row.
|
||||
// Use isset() because empty() will trigger on 0 and 0 is the first row.
|
||||
if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
|
||||
$tokens = $this->view->style_plugin->render_tokens[$row_index];
|
||||
}
|
||||
@@ -339,7 +357,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return the class of the field's label.
|
||||
*/
|
||||
function element_label_classes($row_index = NULL) {
|
||||
public function element_label_classes($row_index = NULL) {
|
||||
$classes = explode(' ', $this->options['element_label_class']);
|
||||
foreach ($classes as &$class) {
|
||||
$class = $this->tokenize_value($class, $row_index);
|
||||
@@ -351,7 +369,7 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Return the class of the field's wrapper.
|
||||
*/
|
||||
function element_wrapper_classes($row_index = NULL) {
|
||||
public function element_wrapper_classes($row_index = NULL) {
|
||||
$classes = explode(' ', $this->options['element_wrapper_class']);
|
||||
foreach ($classes as &$class) {
|
||||
$class = $this->tokenize_value($class, $row_index);
|
||||
@@ -366,12 +384,12 @@ class views_handler_field extends views_handler {
|
||||
* This api exists so that other modules can easy set the values of the field
|
||||
* without having the need to change the render method as well.
|
||||
*
|
||||
* @param $values
|
||||
* @param object $values
|
||||
* An object containing all retrieved values.
|
||||
* @param $field
|
||||
* @param string $field
|
||||
* Optional name of the field where the value is stored.
|
||||
*/
|
||||
function get_value($values, $field = NULL) {
|
||||
public function get_value($values, $field = NULL) {
|
||||
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
|
||||
if (isset($values->{$alias})) {
|
||||
return $values->{$alias};
|
||||
@@ -383,13 +401,16 @@ class views_handler_field extends views_handler {
|
||||
* by in the style settings.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if this field handler is groupable, otherwise FALSE.
|
||||
* TRUE if this field handler is groupable, otherwise FALSE.
|
||||
*/
|
||||
function use_string_group_by() {
|
||||
public function use_string_group_by() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE);
|
||||
@@ -403,6 +424,7 @@ class views_handler_field extends views_handler {
|
||||
'absolute' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'external' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'replace_spaces' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'unwanted_characters' => array('default' => ''),
|
||||
'path_case' => array('default' => 'none', 'translatable' => FALSE),
|
||||
'trim_whitespace' => array('default' => FALSE, 'bool' => TRUE),
|
||||
'alt' => array('default' => '', 'translatable' => TRUE),
|
||||
@@ -447,10 +469,19 @@ class views_handler_field extends views_handler {
|
||||
/**
|
||||
* Performs some cleanup tasks on the options array before saving it.
|
||||
*/
|
||||
function options_submit(&$form, &$form_state) {
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
$options = &$form_state['values']['options'];
|
||||
$types = array('element_type', 'element_label_type', 'element_wrapper_type');
|
||||
$classes = array_combine(array('element_class', 'element_label_class', 'element_wrapper_class'), $types);
|
||||
$types = array(
|
||||
'element_type',
|
||||
'element_label_type',
|
||||
'element_wrapper_type',
|
||||
);
|
||||
$base_types = array(
|
||||
'element_class',
|
||||
'element_label_class',
|
||||
'element_wrapper_class',
|
||||
);
|
||||
$classes = array_combine($base_types, $types);
|
||||
|
||||
foreach ($types as $type) {
|
||||
if (!$options[$type . '_enable']) {
|
||||
@@ -471,10 +502,9 @@ class views_handler_field extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options form that provides the label widget that all fields
|
||||
* should have.
|
||||
* Default options form provides the label widget that all fields should have.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$label = $this->label();
|
||||
@@ -581,7 +611,7 @@ class views_handler_field extends views_handler {
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create a CSS class'),
|
||||
'#dependency' => array(
|
||||
'edit-options-element-label-type-enable' => array(1)
|
||||
'edit-options-element-label-type-enable' => array(1),
|
||||
),
|
||||
'#default_value' => !empty($this->options['element_label_class']) || (string) $this->options['element_label_class'] == '0',
|
||||
'#fieldset' => 'style_settings',
|
||||
@@ -703,7 +733,7 @@ class views_handler_field extends views_handler {
|
||||
'#title' => t('Replace spaces with dashes'),
|
||||
'#default_value' => $this->options['alter']['replace_spaces'],
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1)
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
);
|
||||
$form['alter']['external'] = array(
|
||||
@@ -715,6 +745,16 @@ class views_handler_field extends views_handler {
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
);
|
||||
$form['alter']['unwanted_characters'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Remove unwanted characters'),
|
||||
'#description' => t('Space-separated list of characters to remove from the URL path'),
|
||||
'#default_value' => $this->options['alter']['unwanted_characters'],
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1)
|
||||
),
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
$form['alter']['path_case'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Transform the case'),
|
||||
@@ -722,7 +762,7 @@ class views_handler_field extends views_handler {
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
'#options' => array(
|
||||
'#options' => array(
|
||||
'none' => t('No transform'),
|
||||
'upper' => t('Upper case'),
|
||||
'lower' => t('Lower case'),
|
||||
@@ -753,7 +793,7 @@ class views_handler_field extends views_handler {
|
||||
'#title' => t('Rel Text'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $this->options['alter']['rel'],
|
||||
'#description' => t('Include Rel attribute for use in lightbox2 or other javascript utility.'),
|
||||
'#description' => t('Include Rel attribute for use in lightbox2 or other JavaScript utility.'),
|
||||
'#dependency' => array(
|
||||
'edit-options-alter-make-link' => array(1),
|
||||
),
|
||||
@@ -796,7 +836,8 @@ class views_handler_field extends views_handler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$count = 0; // This lets us prepare the key as we want it printed.
|
||||
// This lets us prepare the key as we want it printed.
|
||||
$count = 0;
|
||||
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
|
||||
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
|
||||
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
|
||||
@@ -819,15 +860,15 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$output .= theme('item_list',
|
||||
array(
|
||||
'items' => $items,
|
||||
'type' => $type
|
||||
'type' => $type,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
// This construct uses 'hidden' and not markup because process doesn't
|
||||
// run. It also has an extra div because the dependency wants to hide
|
||||
// the parent in situations like this, so we need a second div to
|
||||
// make this work.
|
||||
// run. It also has an extra div because the dependency wants to hide the
|
||||
// parent in situations like this, so we need a second div to make this
|
||||
// work.
|
||||
$form['alter']['help'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Replacement patterns'),
|
||||
@@ -997,28 +1038,29 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Provide extra data to the administration form
|
||||
*/
|
||||
function admin_summary() {
|
||||
public function admin_summary() {
|
||||
return $this->label();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run before any fields are rendered.
|
||||
*
|
||||
* This gives the handlers some time to set up before any handler has
|
||||
* been rendered.
|
||||
* This gives the handlers some time to set up before any handler has been
|
||||
* rendered.
|
||||
*
|
||||
* @param $values
|
||||
* @param array $values
|
||||
* An array of all objects returned from the query.
|
||||
*/
|
||||
function pre_render(&$values) { }
|
||||
public function pre_render(&$values) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the field.
|
||||
*
|
||||
* @param $values
|
||||
* @param array $values
|
||||
* The values retrieved from the database.
|
||||
*/
|
||||
function render($values) {
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->sanitize_value($value);
|
||||
}
|
||||
@@ -1029,7 +1071,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* This renders a field normally, then decides if render-as-link and
|
||||
* text-replacement rendering is necessary.
|
||||
*/
|
||||
function advanced_render($values) {
|
||||
public function advanced_render($values) {
|
||||
if ($this->allow_advanced_render() && method_exists($this, 'render_item')) {
|
||||
$raw_items = $this->get_items($values);
|
||||
// If there are no items, set the original value to NULL.
|
||||
@@ -1094,7 +1136,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Checks if a field value is empty.
|
||||
*
|
||||
* @param $value
|
||||
* @param mixed $value
|
||||
* The field value.
|
||||
* @param bool $empty_zero
|
||||
* Whether or not this field is configured to consider 0 as empty.
|
||||
@@ -1102,9 +1144,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* Whether or not to use empty() to check the value.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the value is considered empty, FALSE otherwise.
|
||||
* TRUE if the value is considered empty, FALSE otherwise.
|
||||
*/
|
||||
function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
|
||||
public function is_value_empty($value, $empty_zero, $no_skip_empty = TRUE) {
|
||||
if (!isset($value)) {
|
||||
$empty = TRUE;
|
||||
}
|
||||
@@ -1124,7 +1166,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* This is separated out as some fields may render lists, and this allows
|
||||
* each item to be handled individually.
|
||||
*/
|
||||
function render_text($alter) {
|
||||
public function render_text($alter) {
|
||||
$value = $this->last_render;
|
||||
|
||||
if (!empty($alter['alter_text']) && $alter['text'] !== '') {
|
||||
@@ -1139,9 +1181,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
// Check if there should be no further rewrite for empty values.
|
||||
$no_rewrite_for_empty = $this->options['hide_alter_empty'] && $this->is_value_empty($this->original_value, $this->options['empty_zero']);
|
||||
|
||||
// Check whether the value is empty and return nothing, so the field isn't rendered.
|
||||
// First check whether the field should be hidden if the value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty = FALSE).
|
||||
// For numeric values you can specify whether "0"/0 should be empty.
|
||||
// Check whether the value is empty and return nothing, so the field isn't
|
||||
// rendered. First check whether the field should be hidden if the
|
||||
// value(hide_alter_empty = TRUE) /the rewrite is empty (hide_alter_empty =
|
||||
// FALSE). For numeric values you can specify whether "0"/0 should be empty.
|
||||
if ((($this->options['hide_empty'] && empty($value))
|
||||
|| ($alter['phase'] != VIEWS_HANDLER_RENDER_TEXT_PHASE_EMPTY && $no_rewrite_for_empty))
|
||||
&& $this->is_value_empty($value, $this->options['empty_zero'], FALSE)) {
|
||||
@@ -1169,7 +1212,8 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$more_link_path = $this->options['alter']['more_link_path'];
|
||||
$more_link_path = strip_tags(decode_entities(strtr($more_link_path, $tokens)));
|
||||
|
||||
// Take sure that paths which was runned through url() does work as well.
|
||||
// Take sure that paths which was runned through url() does work as
|
||||
// well.
|
||||
$base_path = base_path();
|
||||
// Checks whether the path starts with the base_path.
|
||||
if (strpos($more_link_path, $base_path) === 0) {
|
||||
@@ -1189,7 +1233,7 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
|
||||
if (!empty($alter['make_link']) && !empty($alter['path'])) {
|
||||
if (!isset($tokens)) {
|
||||
$tokens = $this->get_render_tokens($alter);
|
||||
$tokens = $this->get_render_tokens($alter);
|
||||
}
|
||||
$value = $this->render_as_link($alter, $value, $tokens);
|
||||
}
|
||||
@@ -1200,9 +1244,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Render this field as altered text, from a fieldset set by the user.
|
||||
*/
|
||||
function render_altered($alter, $tokens) {
|
||||
// Filter this right away as our substitutions are already sanitized.
|
||||
$value = filter_xss_admin($alter['text']);
|
||||
public function render_altered($alter, $tokens) {
|
||||
// We trust admins so we allow any tag content. This is important for
|
||||
// displays such as XML where we should not mess with tags.
|
||||
$value = $alter['text'];
|
||||
$value = strtr($value, $tokens);
|
||||
|
||||
return $value;
|
||||
@@ -1211,21 +1256,20 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Trim the field down to the specified length.
|
||||
*/
|
||||
function render_trim_text($alter, $value) {
|
||||
public function render_trim_text($alter, $value) {
|
||||
if (!empty($alter['strip_tags'])) {
|
||||
// NOTE: It's possible that some external fields might override the
|
||||
// element type so if someone from, say, CCK runs into a bug here,
|
||||
// this may be why =)
|
||||
// element type so if someone from, say, CCK runs into a bug here, this
|
||||
// may be why =)
|
||||
$this->definition['element type'] = 'span';
|
||||
}
|
||||
return views_trim_text($alter, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render this field as a link, with the info from a fieldset set by
|
||||
* the user.
|
||||
* Render this field as a link, with info from a fieldset set by the user.
|
||||
*/
|
||||
function render_as_link($alter, $text, $tokens) {
|
||||
public function render_as_link($alter, $text, $tokens) {
|
||||
$value = '';
|
||||
|
||||
if (!empty($alter['prefix'])) {
|
||||
@@ -1243,9 +1287,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
|
||||
// strip_tags() removes <front>, so check whether its different to front.
|
||||
if ($path != '<front>') {
|
||||
// Use strip tags as there should never be HTML in the path.
|
||||
// However, we need to preserve special characters like " that
|
||||
// were removed by check_plain().
|
||||
// Use strip tags as there should never be HTML in the path. However, we
|
||||
// need to preserve special characters like " that were removed by
|
||||
// check_plain().
|
||||
$path = strip_tags(decode_entities(strtr($path, $tokens)));
|
||||
|
||||
if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
|
||||
@@ -1255,6 +1299,12 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
if (!empty($alter['replace_spaces'])) {
|
||||
$path = str_replace(' ', '-', $path);
|
||||
}
|
||||
|
||||
if (!empty($alter['unwanted_characters'])) {
|
||||
foreach (explode(' ', $alter['unwanted_characters']) as $unwanted) {
|
||||
$path = str_replace($unwanted, '', $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the URL and move any query and fragment parameters out of the path.
|
||||
@@ -1266,16 +1316,16 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
}
|
||||
|
||||
// If the path is empty do not build a link around the given text and return
|
||||
// it as is.
|
||||
// http://www.example.com URLs will not have a $url['path'], so check host as well.
|
||||
// it as is. http://www.example.com URLs will not have a $url['path'], so
|
||||
// check host as well.
|
||||
if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
// If no scheme is provided in the $path, assign the default 'http://'.
|
||||
// This allows a url of 'www.example.com' to be converted to 'http://www.example.com'.
|
||||
// Only do this on for external URLs.
|
||||
if ($alter['external']){
|
||||
// This allows a url of 'www.example.com' to be converted to
|
||||
// 'http://www.example.com'. Only do this on for external URLs.
|
||||
if ($alter['external']) {
|
||||
if (!isset($url['scheme'])) {
|
||||
// There is no scheme, add the default 'http://' to the $path.
|
||||
$path = "http://$path";
|
||||
@@ -1320,13 +1370,14 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$options['attributes']['rel'] = $rel;
|
||||
}
|
||||
|
||||
$target = check_plain(trim(strtr($alter['target'],$tokens)));
|
||||
$target = check_plain(trim(strtr($alter['target'], $tokens)));
|
||||
if (!empty($target)) {
|
||||
$options['attributes']['target'] = $target;
|
||||
}
|
||||
|
||||
// Allow the addition of arbitrary attributes to links. Additional attributes
|
||||
// currently can only be altered in preprocessors and not within the UI.
|
||||
// Allow the addition of arbitrary attributes to links. Additional
|
||||
// attributes currently can only be altered in preprocessors and not within
|
||||
// the UI.
|
||||
if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) {
|
||||
foreach ($alter['link_attributes'] as $key => $attribute) {
|
||||
if (!isset($options['attributes'][$key])) {
|
||||
@@ -1375,11 +1426,10 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Get the 'render' tokens to use for advanced rendering.
|
||||
*
|
||||
* This runs through all of the fields and arguments that
|
||||
* are available and gets their values. This will then be
|
||||
* used in one giant str_replace().
|
||||
* This runs through all of the fields and arguments that are available and
|
||||
* gets their values. This will then be used in one giant str_replace().
|
||||
*/
|
||||
function get_render_tokens($item) {
|
||||
public function get_render_tokens($item) {
|
||||
$tokens = array();
|
||||
if (!empty($this->view->build_info['substitutions'])) {
|
||||
$tokens = $this->view->build_info['substitutions'];
|
||||
@@ -1391,9 +1441,9 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
$tokens[$token] = '';
|
||||
}
|
||||
|
||||
// Use strip tags as there should never be HTML in the path.
|
||||
// However, we need to preserve special characters like " that
|
||||
// were removed by check_plain().
|
||||
// Use strip tags as there should never be HTML in the path. However, we
|
||||
// need to preserve special characters like " that were removed by
|
||||
// check_plain().
|
||||
$tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
|
||||
}
|
||||
|
||||
@@ -1450,27 +1500,28 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* '%bar_b_c' => 'value'
|
||||
* );
|
||||
*
|
||||
* @param $array
|
||||
* @param array $array
|
||||
* An array of values.
|
||||
*
|
||||
* @param $parent_keys
|
||||
* @param array $parent_keys
|
||||
* An array of parent keys. This will represent the array depth.
|
||||
*
|
||||
* @return
|
||||
* An array of available tokens, with nested keys representative of the array structure.
|
||||
* @return array
|
||||
* An array of available tokens, with nested keys representative of the
|
||||
* array structure.
|
||||
*/
|
||||
function get_token_values_recursive(array $array, array $parent_keys = array()) {
|
||||
public function get_token_values_recursive(array $array, array $parent_keys = array()) {
|
||||
$tokens = array();
|
||||
|
||||
foreach ($array as $param => $val) {
|
||||
if (is_array($val)) {
|
||||
// Copy parent_keys array, so we don't afect other elements of this iteration.
|
||||
$child_parent_keys = $parent_keys;
|
||||
$child_parent_keys[] = $param;
|
||||
// Get the child tokens.
|
||||
$child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
|
||||
// Add them to the current tokens array.
|
||||
$tokens += $child_tokens;
|
||||
// Copy parent_keys array, so we don't afect other elements of this
|
||||
// iteration.
|
||||
$child_parent_keys = $parent_keys;
|
||||
$child_parent_keys[] = $param;
|
||||
// Get the child tokens.
|
||||
$child_tokens = $this->get_token_values_recursive($val, $child_parent_keys);
|
||||
// Add them to the current tokens array.
|
||||
$tokens += $child_tokens;
|
||||
}
|
||||
else {
|
||||
// Create a token key based on array element structure.
|
||||
@@ -1485,50 +1536,57 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
/**
|
||||
* Add any special tokens this field might use for itself.
|
||||
*
|
||||
* This method is intended to be overridden by items that generate
|
||||
* fields as a list. For example, the field that displays all terms
|
||||
* on a node might have tokens for the tid and the term.
|
||||
* This method is intended to be overridden by items that generate fields as a
|
||||
* list. For example, the field that displays all terms on a node might have
|
||||
* tokens for the tid and the term.
|
||||
*
|
||||
* By convention, tokens should follow the format of [token-subtoken]
|
||||
* where token is the field ID and subtoken is the field. If the
|
||||
* field ID is terms, then the tokens might be [terms-tid] and [terms-name].
|
||||
* By convention, tokens should follow the format of [token-subtoken] where
|
||||
* token is the field ID and subtoken is the field. If the field ID is terms,
|
||||
* then the tokens might be [terms-tid] and [terms-name].
|
||||
*/
|
||||
function add_self_tokens(&$tokens, $item) { }
|
||||
public function add_self_tokens(&$tokens, $item) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Document any special tokens this field might use for itself.
|
||||
*
|
||||
* @see add_self_tokens()
|
||||
*/
|
||||
function document_self_tokens(&$tokens) { }
|
||||
public function document_self_tokens(&$tokens) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call out to the theme() function, which probably just calls render() but
|
||||
* allows sites to override output fairly easily.
|
||||
* Call out to the theme() function.
|
||||
*
|
||||
* It probably just calls render() but allows sites to override output fairly
|
||||
* easily.
|
||||
*/
|
||||
function theme($values) {
|
||||
public function theme($values) {
|
||||
return theme($this->theme_functions(),
|
||||
array(
|
||||
'view' => $this->view,
|
||||
'field' => $this,
|
||||
'row' => $values
|
||||
'row' => $values,
|
||||
));
|
||||
}
|
||||
|
||||
function theme_functions() {
|
||||
/**
|
||||
* Build a list of suitable theme functions for this view.
|
||||
*/
|
||||
public function theme_functions() {
|
||||
$themes = array();
|
||||
$hook = 'views_view_field';
|
||||
|
||||
$display = $this->view->display[$this->view->current_display];
|
||||
|
||||
if (!empty($display)) {
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id;
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->id;
|
||||
$themes[] = $hook . '__' . $display->id . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $display->id;
|
||||
if ($display->id != $display->display_plugin) {
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin;
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin;
|
||||
$themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id'];
|
||||
$themes[] = $hook . '__' . $display->display_plugin;
|
||||
}
|
||||
@@ -1541,9 +1599,13 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
return $themes;
|
||||
}
|
||||
|
||||
function ui_name($short = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return $this->get_field(parent::ui_name($short));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1552,22 +1614,44 @@ If you would like to have the characters \'[\' and \']\' please use the html ent
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_broken extends views_handler_field {
|
||||
function ui_name($short = FALSE) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return t('Broken/missing handler');
|
||||
}
|
||||
|
||||
function ensure_my_table() { /* No table to ensure! */ }
|
||||
function query($group_by = FALSE) { /* No query to run */ }
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ensure_my_table() {
|
||||
// No table to ensure!
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
// No query to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is considered 'broken'
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function broken() { return TRUE; }
|
||||
public function broken() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1576,7 +1660,11 @@ class views_handler_field_broken extends views_handler_field {
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_file_size extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['file_size_display'] = array('default' => 'formatted');
|
||||
@@ -1584,7 +1672,10 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['file_size_display'] = array(
|
||||
'#title' => t('File size display'),
|
||||
@@ -1596,7 +1687,10 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
if ($value) {
|
||||
switch ($this->options['file_size_display']) {
|
||||
@@ -1611,6 +1705,7 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1619,10 +1714,15 @@ class views_handler_field_file_size extends views_handler_field {
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_xss extends views_handler_field {
|
||||
function render($values) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
return $this->sanitize_value($value, 'xss');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -11,18 +11,22 @@
|
||||
* Allows for display of true/false, yes/no, on/off, enabled/disabled.
|
||||
*
|
||||
* Definition terms:
|
||||
* - output formats: An array where the first entry is displayed on boolean true
|
||||
* and the second is displayed on boolean false. An example for sticky is:
|
||||
* @code
|
||||
* 'output formats' => array(
|
||||
* 'sticky' => array(t('Sticky'), ''),
|
||||
* ),
|
||||
* @endcode
|
||||
* - output formats: An array where the first entry is displayed on boolean true
|
||||
* and the second is displayed on boolean false. An example for sticky is:
|
||||
* @code
|
||||
* 'output formats' => array(
|
||||
* 'sticky' => array(t('Sticky'), ''),
|
||||
* ),
|
||||
* @endcode
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_boolean extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['type'] = array('default' => 'yes-no');
|
||||
$options['type_custom_true'] = array('default' => '', 'translatable' => TRUE);
|
||||
@@ -32,7 +36,10 @@ class views_handler_field_boolean extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function init(&$view, &$options) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
|
||||
$default_formats = array(
|
||||
@@ -48,7 +55,10 @@ class views_handler_field_boolean extends views_handler_field {
|
||||
$this->formats = array_merge($default_formats, $output_formats, $custom_format);
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
foreach ($this->formats as $key => $item) {
|
||||
$options[$key] = implode('/', $item);
|
||||
}
|
||||
@@ -91,7 +101,10 @@ class views_handler_field_boolean extends views_handler_field {
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
if (!empty($this->options['not'])) {
|
||||
$value = !$value;
|
||||
@@ -100,11 +113,12 @@ class views_handler_field_boolean extends views_handler_field {
|
||||
if ($this->options['type'] == 'custom') {
|
||||
return $value ? filter_xss_admin($this->options['type_custom_true']) : filter_xss_admin($this->options['type_custom_false']);
|
||||
}
|
||||
else if (isset($this->formats[$this->options['type']])) {
|
||||
elseif (isset($this->formats[$this->options['type']])) {
|
||||
return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1];
|
||||
}
|
||||
else {
|
||||
return $value ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,11 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_contextual_links extends views_handler_field_links {
|
||||
function pre_render(&$values) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function pre_render(&$values) {
|
||||
// Add a row plugin css class for the contextual link.
|
||||
$class = 'contextual-links-region';
|
||||
if (!empty($this->view->style_plugin->options['row_class'])) {
|
||||
@@ -22,7 +26,10 @@ class views_handler_field_contextual_links extends views_handler_field_links {
|
||||
}
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['fields']['#description'] = t('Fields to be included as contextual links.');
|
||||
@@ -32,7 +39,7 @@ class views_handler_field_contextual_links extends views_handler_field_links {
|
||||
/**
|
||||
* Render the contextual fields.
|
||||
*/
|
||||
function render($values) {
|
||||
public function render($values) {
|
||||
$links = $this->get_links();
|
||||
if (!empty($links)) {
|
||||
$build = array(
|
||||
@@ -52,4 +59,5 @@ class views_handler_field_contextual_links extends views_handler_field_links {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,14 +11,21 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_counter extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['counter_start'] = array('default' => 1);
|
||||
$options['reverse'] = array('default' => FALSE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['counter_start'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Starting value'),
|
||||
@@ -37,24 +44,31 @@ class views_handler_field_counter extends views_handler_field {
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function query() {
|
||||
// do nothing -- to override the parent query.
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// Do nothing -- to override the parent query.
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$reverse = empty($this->options['reverse']) ? 1 : -1;
|
||||
|
||||
// Note: 1 is subtracted from the counter start value below because the
|
||||
// Note: 1 is subtracted from the counter start value below because the
|
||||
// counter value is incremented by 1 at the end of this function.
|
||||
$counter_start = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] : 0;
|
||||
$count = ($reverse == -1) ? count($this->view->result) + $counter_start : $counter_start -1;
|
||||
$count = ($reverse == -1) ? count($this->view->result) + $counter_start : $counter_start - 1;
|
||||
$pager = $this->view->query->pager;
|
||||
|
||||
// Get the base count of the pager.
|
||||
if ($pager->use_pager()) {
|
||||
if ($reverse == -1) {
|
||||
$count = ($pager->total_items + $counter_start - ($pager->get_current_page() * $pager->get_items_per_page()) + $pager->get_offset());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$count += (($pager->get_items_per_page() * $pager->get_current_page() + $pager->get_offset())) * $reverse;
|
||||
}
|
||||
}
|
||||
@@ -63,4 +77,5 @@ class views_handler_field_counter extends views_handler_field {
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,11 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_ctools_dropdown extends views_handler_field_links {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['views_admin_css'] = array('default' => TRUE, 'bool' => TRUE);
|
||||
@@ -19,7 +23,10 @@ class views_handler_field_ctools_dropdown extends views_handler_field_links {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['fields']['#description'] = t('Fields to be included as ctools dropdown button.');
|
||||
$form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing a link action.');
|
||||
@@ -35,7 +42,7 @@ class views_handler_field_ctools_dropdown extends views_handler_field_links {
|
||||
/**
|
||||
* Render the dropdown button.
|
||||
*/
|
||||
function render($values) {
|
||||
public function render($values) {
|
||||
static $added_admin_css;
|
||||
$links = $this->get_links();
|
||||
|
||||
@@ -46,10 +53,20 @@ class views_handler_field_ctools_dropdown extends views_handler_field_links {
|
||||
$added_admin_css = TRUE;
|
||||
}
|
||||
|
||||
return theme('links__ctools_dropbutton', array('links' => $links, 'attributes' => array('class' => array('links', 'inline'))));
|
||||
$vars = array(
|
||||
'links' => $links,
|
||||
'attributes' => array(
|
||||
'class' => array(
|
||||
'links',
|
||||
'inline',
|
||||
),
|
||||
),
|
||||
);
|
||||
return theme('links__ctools_dropbutton', $vars);
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,11 +11,18 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_custom extends views_handler_field {
|
||||
function query() {
|
||||
// do nothing -- to override the parent query.
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// Do nothing -- to override the parent query.
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
// Override the alter text option to always alter the text.
|
||||
@@ -24,10 +31,13 @@ class views_handler_field_custom extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// Remove the checkbox
|
||||
// Remove the checkbox.
|
||||
unset($form['alter']['alter_text']);
|
||||
unset($form['alter']['text']['#dependency']);
|
||||
unset($form['alter']['text']['#process']);
|
||||
@@ -36,10 +46,14 @@ class views_handler_field_custom extends views_handler_field {
|
||||
$form['#pre_render'][] = 'views_handler_field_custom_pre_render_move_text';
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
// Return the text, so the code never thinks the value is empty.
|
||||
return $this->options['alter']['text'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -8,10 +8,17 @@
|
||||
/**
|
||||
* A handler to provide proper displays for dates.
|
||||
*
|
||||
* This may be used on table fields that hold either UNIX timestamps or SQL
|
||||
* datetime strings.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_date extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['date_format'] = array('default' => 'small');
|
||||
@@ -23,8 +30,10 @@ class views_handler_field_date extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$date_formats = array();
|
||||
$date_types = system_get_date_types();
|
||||
foreach ($date_types as $key => $value) {
|
||||
@@ -52,66 +61,112 @@ class views_handler_field_date extends views_handler_field {
|
||||
'#title' => t('Custom date format'),
|
||||
'#description' => t('If "Custom", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')),
|
||||
'#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '',
|
||||
'#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'today time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span')),
|
||||
'#dependency' => array(
|
||||
'edit-options-date-format' => $this->supported_date_types(),
|
||||
),
|
||||
);
|
||||
$form['second_date_format'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Second date format'),
|
||||
'#options' => $date_formats + array(
|
||||
'custom' => t('Custom'),
|
||||
),
|
||||
'#description' => t('The date format which will be used for rendering dates other than today.'),
|
||||
'#default_value' => isset($this->options['second_date_format']) ? $this->options['second_date_format'] : 'small',
|
||||
'#dependency' => array('edit-options-date-format' => array('today time ago')),
|
||||
);
|
||||
$form['second_date_format_custom'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom date format of second date'),
|
||||
'#description' => t('If "Custom" is selected in "Second date format", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')),
|
||||
'#default_value' => isset($this->options['second_date_format_custom']) ? $this->options['second_date_format_custom'] : '',
|
||||
// We have to use states instead of ctools dependency because dependency
|
||||
// doesn't handle multiple conditions.
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'#edit-options-date-format' => array('value' => 'today time ago'),
|
||||
'#edit-options-second-date-format' => array('value' => 'custom'),
|
||||
),
|
||||
),
|
||||
// We have to use ctools dependency too because states doesn't add the
|
||||
// correct left margin to the element's wrapper.
|
||||
'#dependency' => array(
|
||||
// This condition is handled by form API's states.
|
||||
// 'edit-options-date-format' => array('today time ago'),
|
||||
'edit-options-second-date-format' => array('custom'),
|
||||
),
|
||||
);
|
||||
'#type' => 'select',
|
||||
'#title' => t('Second date format'),
|
||||
'#options' => $date_formats + array(
|
||||
'custom' => t('Custom'),
|
||||
),
|
||||
'#description' => t('The date format which will be used for rendering dates other than today.'),
|
||||
'#default_value' => isset($this->options['second_date_format']) ? $this->options['second_date_format'] : 'small',
|
||||
'#dependency' => array(
|
||||
'edit-options-date-format' => array('today time ago'),
|
||||
),
|
||||
);
|
||||
$form['second_date_format_custom'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Custom date format of second date'),
|
||||
'#description' => t('If "Custom" is selected in "Second date format", see the <a href="@url" target="_blank">PHP manual</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.', array('@url' => 'http://php.net/manual/function.date.php')),
|
||||
'#default_value' => isset($this->options['second_date_format_custom']) ? $this->options['second_date_format_custom'] : '',
|
||||
// We have to use states instead of ctools dependency because dependency
|
||||
// doesn't handle multiple conditions.
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'#edit-options-date-format' => array('value' => 'today time ago'),
|
||||
'#edit-options-second-date-format' => array('value' => 'custom'),
|
||||
),
|
||||
),
|
||||
// We have to use ctools dependency too because states doesn't add the
|
||||
// correct left margin to the element's wrapper.
|
||||
'#dependency' => array(
|
||||
// This condition is handled by form API's states.
|
||||
// 'edit-options-date-format' => array('today time ago'),
|
||||
'edit-options-second-date-format' => array('custom'),
|
||||
),
|
||||
);
|
||||
$form['timezone'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Timezone'),
|
||||
'#description' => t('Timezone to be used for date output.'),
|
||||
'#options' => array('' => t('- Default site/user timezone -')) + system_time_zones(FALSE),
|
||||
'#options' => array(
|
||||
'' => t('- Default site/user timezone -'),
|
||||
) + system_time_zones(FALSE),
|
||||
'#default_value' => $this->options['timezone'],
|
||||
'#dependency' => array('edit-options-date-format' => array_merge(array('custom'), array_keys($date_formats))),
|
||||
'#dependency' => array(
|
||||
'edit-options-date-format' => array_merge(array('custom'), array_keys($date_formats)),
|
||||
),
|
||||
);
|
||||
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* Provide a list of all of the supported standard date types.
|
||||
*
|
||||
* @return array
|
||||
* The list of supported formats.
|
||||
*/
|
||||
private function supported_date_types() {
|
||||
return array(
|
||||
'custom',
|
||||
'raw time ago',
|
||||
'time ago',
|
||||
'today time ago',
|
||||
'raw time hence',
|
||||
'time hence',
|
||||
'raw time span',
|
||||
'time span',
|
||||
'raw time span',
|
||||
'inverse time span',
|
||||
'time span',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
|
||||
if (!is_numeric($value)) {
|
||||
// If the value isn't numeric, assume it's an SQL DATETIME.
|
||||
$value = strtotime($value);
|
||||
}
|
||||
|
||||
$format = $this->options['date_format'];
|
||||
if (in_array($format, array('custom', 'raw time ago', 'time ago', 'today time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) {
|
||||
if (in_array($format, $this->supported_date_types())) {
|
||||
$custom_format = $this->options['custom_date_format'];
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
$timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
|
||||
$time_diff = REQUEST_TIME - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
|
||||
// Will be positive for a datetime in the past (ago), and negative for a
|
||||
// datetime in the future (hence).
|
||||
$time_diff = REQUEST_TIME - $value;
|
||||
switch ($format) {
|
||||
case 'raw time ago':
|
||||
return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2);
|
||||
|
||||
case 'time ago':
|
||||
return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2)));
|
||||
$t_args = array(
|
||||
'%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2),
|
||||
);
|
||||
return t('%time ago', $t_args);
|
||||
|
||||
case 'today time ago':
|
||||
$second_format = $this->options['second_date_format'];
|
||||
$second_custom_format = $this->options['second_date_format_custom'];
|
||||
@@ -127,24 +182,32 @@ class views_handler_field_date extends views_handler_field {
|
||||
else {
|
||||
return format_date($value, $this->options['second_date_format'], '', $timezone);
|
||||
}
|
||||
|
||||
case 'raw time hence':
|
||||
return format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2);
|
||||
|
||||
case 'time hence':
|
||||
return t('%time hence', array('%time' => format_interval(-$time_diff, is_numeric($custom_format) ? $custom_format : 2)));
|
||||
|
||||
case 'raw time span':
|
||||
return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
|
||||
|
||||
case 'inverse time span':
|
||||
return ($time_diff > 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2);
|
||||
|
||||
case 'time span':
|
||||
return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2)));
|
||||
|
||||
case 'custom':
|
||||
if ($custom_format == 'r') {
|
||||
return format_date($value, $format, $custom_format, $timezone, 'en');
|
||||
}
|
||||
return format_date($value, $format, $custom_format, $timezone);
|
||||
|
||||
default:
|
||||
return format_date($value, $format, '', $timezone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
* Fields based upon this handler work with all query-backends if the tables
|
||||
* used by the query backend have an 'entity type' specified. In order to
|
||||
* make fields based upon this handler automatically available to all compatible
|
||||
* query backends, the views field can be defined in the table
|
||||
* query backends, the views field can be defined in the table.
|
||||
* @code views_entity_{ENTITY_TYPE} @endcode.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
@@ -41,13 +41,15 @@ class views_handler_field_entity extends views_handler_field {
|
||||
|
||||
// Initialize the entity-type used.
|
||||
$table_data = views_fetch_data($this->table);
|
||||
$this->entity_type = $table_data['table']['entity type'];
|
||||
if (isset($table_data['table']['entity type'])) {
|
||||
$this->entity_type = $table_data['table']['entity type'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to add the field for the entity id.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->table_alias = $base_table = $this->view->base_table;
|
||||
$this->base_field = $this->view->base_field;
|
||||
|
||||
@@ -75,16 +77,16 @@ class views_handler_field_entity extends views_handler_field {
|
||||
/**
|
||||
* Load the entities for all rows that are about to be displayed.
|
||||
*/
|
||||
function pre_render(&$values) {
|
||||
public function pre_render(&$values) {
|
||||
if (!empty($values)) {
|
||||
list($this->entity_type, $this->entities) = $this->query->get_result_entities($values, !empty($this->relationship) ? $this->relationship : NULL, $this->field_alias);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden to return the entity object, or a certain property of the entity.
|
||||
* Return the entity object or a certain property of the entity.
|
||||
*/
|
||||
function get_value($values, $field = NULL) {
|
||||
public function get_value($values, $field = NULL) {
|
||||
if (isset($this->entities[$this->view->row_index])) {
|
||||
$entity = $this->entities[$this->view->row_index];
|
||||
// Support to get a certain part of the entity.
|
||||
@@ -101,4 +103,5 @@ class views_handler_field_entity extends views_handler_field {
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,9 +13,9 @@
|
||||
class views_handler_field_links extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Overrides views_handler_field::option_definition().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function option_definition() {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['fields'] = array('default' => array());
|
||||
@@ -26,9 +26,9 @@ class views_handler_field_links extends views_handler_field {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_field::options_form().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$all_fields = $this->view->display_handler->get_field_labels();
|
||||
@@ -59,11 +59,12 @@ class views_handler_field_links extends views_handler_field {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_field::options_form().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function options_submit(&$form, &$form_state) {
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
// Remove unselected options.
|
||||
$form_state['values']['options']['fields'] = array_filter($form_state['values']['options']['fields']);
|
||||
parent::options_submit($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +73,7 @@ class views_handler_field_links extends views_handler_field {
|
||||
* @return array
|
||||
* The links which are used by the render function.
|
||||
*/
|
||||
function get_links() {
|
||||
public function get_links() {
|
||||
$links = array();
|
||||
foreach ($this->options['fields'] as $field) {
|
||||
if (empty($this->view->field[$field]->last_render_text)) {
|
||||
@@ -121,7 +122,6 @@ class views_handler_field_links extends views_handler_field {
|
||||
}
|
||||
|
||||
// Omit tweaks of query, fragment, and link_class.
|
||||
|
||||
$alt = strtr($alter['alt'], $tokens);
|
||||
if ($alt && $alt != $title) {
|
||||
// Set the title attribute only if it improves accessibility.
|
||||
@@ -148,8 +148,9 @@ class views_handler_field_links extends views_handler_field {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_field::query().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function query() { }
|
||||
public function query() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,16 +10,21 @@
|
||||
* @ingroup views_field_handlers
|
||||
*
|
||||
* Definition items:
|
||||
* - options callback: The function to call in order to generate the value options. If omitted, the options 'Yes' and 'No' will be used.
|
||||
* - options callback: The function to call in order to generate the value
|
||||
* options. If omitted, the options 'Yes' and 'No' will be used.
|
||||
* - options arguments: An array of arguments to pass to the options callback.
|
||||
*/
|
||||
class views_handler_field_machine_name extends views_handler_field {
|
||||
|
||||
/**
|
||||
* @var array Stores the available options.
|
||||
*/
|
||||
var $value_options;
|
||||
public $value_options;
|
||||
|
||||
function get_value_options() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_value_options() {
|
||||
if (isset($this->value_options)) {
|
||||
return;
|
||||
}
|
||||
@@ -37,14 +42,20 @@ class views_handler_field_machine_name extends views_handler_field {
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['machine_name'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['machine_name'] = array(
|
||||
@@ -55,11 +66,17 @@ class views_handler_field_machine_name extends views_handler_field {
|
||||
);
|
||||
}
|
||||
|
||||
function pre_render(&$values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function pre_render(&$values) {
|
||||
$this->get_value_options();
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
if (!empty($this->options['machine_name']) || !isset($this->value_options[$value])) {
|
||||
$result = check_plain($value);
|
||||
@@ -70,4 +87,5 @@ class views_handler_field_machine_name extends views_handler_field {
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,17 +10,18 @@
|
||||
* format field.
|
||||
*
|
||||
* - format: (REQUIRED) Either a string format id to use for this field or an
|
||||
* array('field' => {$field}) where $field is the field in this table
|
||||
* used to control the format such as the 'format' field in the node,
|
||||
* which goes with the 'body' field.
|
||||
* array('field' => {$field}) where $field is the field in this table used to
|
||||
* control the format such as the 'format' field in the node, which goes with
|
||||
* the 'body' field.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_markup extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Constructor; calls to base object constructor.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function construct() {
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
|
||||
$this->format = $this->definition['format'];
|
||||
@@ -31,7 +32,10 @@ class views_handler_field_markup extends views_handler_field {
|
||||
}
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
if (is_array($this->format)) {
|
||||
$format = $this->get_value($values, 'format');
|
||||
@@ -45,7 +49,10 @@ class views_handler_field_markup extends views_handler_field {
|
||||
}
|
||||
}
|
||||
|
||||
function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
|
||||
if ($inline) {
|
||||
return 'span';
|
||||
}
|
||||
@@ -56,4 +63,5 @@ class views_handler_field_markup extends views_handler_field {
|
||||
|
||||
return 'div';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,14 +15,21 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_math extends views_handler_field_numeric {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['expression'] = array('default' => '');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['expression'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Expression'),
|
||||
@@ -30,17 +37,20 @@ class views_handler_field_math extends views_handler_field_numeric {
|
||||
'#default_value' => $this->options['expression'],
|
||||
);
|
||||
|
||||
// Create a place for the help
|
||||
// Create a place for the help.
|
||||
$form['expression_help'] = array();
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// Then move the existing help:
|
||||
// Then move the existing help.
|
||||
$form['expression_help'] = $form['alter']['help'];
|
||||
unset($form['expression_help']['#dependency']);
|
||||
unset($form['alter']['help']);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
ctools_include('math-expr');
|
||||
$tokens = array_map('floatval', $this->get_render_tokens(array()));
|
||||
$value = strtr($this->options['expression'], $tokens);
|
||||
@@ -80,5 +90,10 @@ class views_handler_field_math extends views_handler_field_numeric {
|
||||
return $this->sanitize_value($this->options['prefix'] . $value . $this->options['suffix']);
|
||||
}
|
||||
|
||||
function query() { }
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,16 +6,20 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Render a field as a numeric value
|
||||
* Render a field as a numeric value.
|
||||
*
|
||||
* Definition terms:
|
||||
* - float: If true this field contains a decimal value. If unset this field
|
||||
* will be assumed to be integer.
|
||||
* will be assumed to be integer.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_numeric extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['set_precision'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
@@ -31,7 +35,10 @@ class views_handler_field_numeric extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
if (!empty($this->definition['float'])) {
|
||||
$form['set_precision'] = array(
|
||||
'#type' => 'checkbox',
|
||||
@@ -105,9 +112,17 @@ class views_handler_field_numeric extends views_handler_field {
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
|
||||
// Output nothing if the value is null.
|
||||
if (is_null($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Hiding should happen before rounding or adding prefix/suffix.
|
||||
if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) {
|
||||
return '';
|
||||
@@ -117,12 +132,13 @@ class views_handler_field_numeric extends views_handler_field {
|
||||
$value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']);
|
||||
}
|
||||
else {
|
||||
$remainder = abs($value) - intval(abs($value));
|
||||
$point_position = strpos($value, '.');
|
||||
$remainder = ($point_position === FALSE) ? '' : substr($value, $point_position + 1);
|
||||
$value = $value > 0 ? floor($value) : ceil($value);
|
||||
$value = number_format($value, 0, '', $this->options['separator']);
|
||||
if ($remainder) {
|
||||
// The substr may not be locale safe.
|
||||
$value .= $this->options['decimal'] . substr($remainder, 2);
|
||||
$value .= $this->options['decimal'] . $remainder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,4 +151,5 @@ class views_handler_field_numeric extends views_handler_field {
|
||||
. $this->sanitize_value($value)
|
||||
. $this->sanitize_value($this->options['suffix'], 'xss');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,17 +16,22 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_prerender_list extends views_handler_field {
|
||||
|
||||
/**
|
||||
* Stores all items which are used to render the items.
|
||||
*
|
||||
* It should be keyed first by the id of the base table, for example nid.
|
||||
* The second key is the id of the thing which is displayed multiple times
|
||||
* per row, for example the tid.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $items = array();
|
||||
public $items = array();
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['type'] = array('default' => 'separator');
|
||||
@@ -35,7 +40,10 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Display type'),
|
||||
@@ -63,7 +71,7 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
* yet or won't update their prerender list fields. If a render_item method
|
||||
* exists, this will not get used by advanced_render.
|
||||
*/
|
||||
function render($values) {
|
||||
public function render($values) {
|
||||
$field = $this->get_value($values);
|
||||
if (!empty($this->items[$field])) {
|
||||
if ($this->options['type'] == 'separator') {
|
||||
@@ -74,7 +82,7 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
array(
|
||||
'items' => $this->items[$field],
|
||||
'title' => NULL,
|
||||
'type' => $this->options['type']
|
||||
'type' => $this->options['type'],
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -86,7 +94,7 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
* When using advanced render, each possible item in the list is rendered
|
||||
* individually. Then the items are all pasted together.
|
||||
*/
|
||||
function render_items($items) {
|
||||
public function render_items($items) {
|
||||
if (!empty($items)) {
|
||||
if ($this->options['type'] == 'separator') {
|
||||
return implode($this->sanitize_value($this->options['separator'], 'xss_admin'), $items);
|
||||
@@ -96,7 +104,7 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
array(
|
||||
'items' => $items,
|
||||
'title' => NULL,
|
||||
'type' => $this->options['type']
|
||||
'type' => $this->options['type'],
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -105,14 +113,18 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
/**
|
||||
* Return an array of items for the field.
|
||||
*
|
||||
* Items should be stored in the result array, if possible, as an array
|
||||
* with 'value' as the actual displayable value of the item, plus
|
||||
* any items that might be found in the 'alter' options array for
|
||||
* creating links, such as 'path', 'fragment', 'query' etc, such a thing
|
||||
* is to be made. Additionally, items that might be turned into tokens
|
||||
* should also be in this array.
|
||||
* Items should be stored in the result array, if possible, as an array with
|
||||
* 'value' as the actual displayable value of the item, plus any items that
|
||||
* might be found in the 'alter' options array for creating links, such as
|
||||
* 'path', 'fragment', 'query' etc, such a thing is to be made. Additionally,
|
||||
* items that might be turned into tokens should also be in this array.
|
||||
*
|
||||
* @param mixed $values
|
||||
*
|
||||
* @return array
|
||||
* The items.
|
||||
*/
|
||||
function get_items($values) {
|
||||
public function get_items($values) {
|
||||
// Only the parent get_value returns a single field.
|
||||
$field = parent::get_value($values);
|
||||
if (!empty($this->items[$field])) {
|
||||
@@ -125,14 +137,14 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
/**
|
||||
* Get the value that's supposed to be rendered.
|
||||
*
|
||||
* @param $values
|
||||
* @param object $values
|
||||
* An object containing all retrieved values.
|
||||
* @param $field
|
||||
* @param string $field
|
||||
* Optional name of the field where the value is stored.
|
||||
* @param $raw
|
||||
* @param bool $raw
|
||||
* Use the raw data and not the data defined in pre_render
|
||||
*/
|
||||
function get_value($values, $field = NULL, $raw = FALSE) {
|
||||
public function get_value($values, $field = NULL, $raw = FALSE) {
|
||||
if ($raw) {
|
||||
return parent::get_value($values, $field);
|
||||
}
|
||||
@@ -149,10 +161,14 @@ class views_handler_field_prerender_list extends views_handler_field {
|
||||
*
|
||||
* By default, advanced rendering will NOT be allowed if the class
|
||||
* inheriting from this does not implement a 'render_items' method.
|
||||
*
|
||||
* @return bool
|
||||
* Whether or not the the render method exists.
|
||||
*/
|
||||
function allow_advanced_render() {
|
||||
public function allow_advanced_render() {
|
||||
// Note that the advanced render bits also use the presence of
|
||||
// this method to determine if it needs to render items as a list.
|
||||
return method_exists($this, 'render_item');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,15 +12,20 @@
|
||||
*/
|
||||
class views_handler_field_serialized extends views_handler_field {
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['format'] = array('default' => 'unserialized');
|
||||
$options['key'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['format'] = array(
|
||||
@@ -42,14 +47,20 @@ class views_handler_field_serialized extends views_handler_field {
|
||||
);
|
||||
}
|
||||
|
||||
function options_validate(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_validate(&$form, &$form_state) {
|
||||
// Require a key if the format is key.
|
||||
if ($form_state['values']['options']['format'] == 'key' && $form_state['values']['options']['key'] == '') {
|
||||
form_error($form['key'], t('You have to enter a key if you want to display a key of the data.'));
|
||||
}
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
|
||||
if ($this->options['format'] == 'unserialized') {
|
||||
@@ -60,6 +71,7 @@ class views_handler_field_serialized extends views_handler_field {
|
||||
return check_plain($value[$this->options['key']]);
|
||||
}
|
||||
|
||||
return $value;
|
||||
return check_plain($value);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,11 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_time_interval extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['granularity'] = array('default' => 2);
|
||||
@@ -19,7 +23,10 @@ class views_handler_field_time_interval extends views_handler_field {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['granularity'] = array(
|
||||
@@ -30,8 +37,12 @@ class views_handler_field_time_interval extends views_handler_field {
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $values->{$this->field_alias};
|
||||
return format_interval($value, isset($this->options['granularity']) ? $this->options['granularity'] : 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,12 +6,16 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that turns a URL into a clickable link.
|
||||
* Field handler that turns a URL into a clickable link.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_field_url extends views_handler_field {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['display_as_link'] = array('default' => TRUE, 'bool' => TRUE);
|
||||
@@ -22,7 +26,7 @@ class views_handler_field_url extends views_handler_field {
|
||||
/**
|
||||
* Provide link to the page being visited.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['display_as_link'] = array(
|
||||
'#title' => t('Display as link'),
|
||||
'#type' => 'checkbox',
|
||||
@@ -31,7 +35,10 @@ class views_handler_field_url extends views_handler_field {
|
||||
parent::options_form($form, $form_state);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function render($values) {
|
||||
$value = $this->get_value($values);
|
||||
if (!empty($this->options['display_as_link'])) {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
@@ -43,4 +50,5 @@ class views_handler_field_url extends views_handler_field {
|
||||
return $this->sanitize_value($value, 'url');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -22,14 +22,26 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
// exposed filter options
|
||||
var $always_multiple = TRUE;
|
||||
// Don't display empty space where the operator would be.
|
||||
var $no_operator = TRUE;
|
||||
// Whether to accept NULL as a false value or not
|
||||
var $accept_null = FALSE;
|
||||
|
||||
function construct() {
|
||||
/**
|
||||
* Exposed filter options.
|
||||
*/
|
||||
public $always_multiple = TRUE;
|
||||
|
||||
/**
|
||||
* Don't display empty space where the operator would be.
|
||||
*/
|
||||
public $no_operator = TRUE;
|
||||
|
||||
/**
|
||||
* Whether to accept NULL as a false value or not.
|
||||
*/
|
||||
public $accept_null = FALSE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function construct() {
|
||||
$this->value_value = t('True');
|
||||
if (isset($this->definition['label'])) {
|
||||
$this->value_value = $this->definition['label'];
|
||||
@@ -37,7 +49,7 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
if (isset($this->definition['accept null'])) {
|
||||
$this->accept_null = (bool) $this->definition['accept null'];
|
||||
}
|
||||
else if (isset($this->definition['accept_null'])) {
|
||||
elseif (isset($this->definition['accept_null'])) {
|
||||
$this->accept_null = (bool) $this->definition['accept_null'];
|
||||
}
|
||||
$this->value_options = NULL;
|
||||
@@ -56,7 +68,7 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
* dynamic for some reason, child classes should use a guard to reduce
|
||||
* database hits as much as possible.
|
||||
*/
|
||||
function get_value_options() {
|
||||
public function get_value_options() {
|
||||
if (isset($this->definition['type'])) {
|
||||
if ($this->definition['type'] == 'yes-no') {
|
||||
$this->value_options = array(1 => t('Yes'), 0 => t('No'));
|
||||
@@ -75,7 +87,10 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['value']['default'] = FALSE;
|
||||
@@ -83,11 +98,17 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function operator_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operator_form(&$form, &$form_state) {
|
||||
$form['operator'] = array();
|
||||
}
|
||||
|
||||
function value_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function value_form(&$form, &$form_state) {
|
||||
if (empty($this->value_options)) {
|
||||
// Initialize the array of possible values for this filter.
|
||||
$this->get_value_options();
|
||||
@@ -122,13 +143,19 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function value_validate($form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function value_validate($form, &$form_state) {
|
||||
if ($form_state['values']['options']['value'] == 'All' && !empty($form_state['values']['options']['expose']['required'])) {
|
||||
form_set_error('value', t('You must select a value unless this is an non-required exposed filter.'));
|
||||
}
|
||||
}
|
||||
|
||||
function admin_summary() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function admin_summary() {
|
||||
if ($this->is_a_group()) {
|
||||
return t('grouped');
|
||||
}
|
||||
@@ -145,14 +172,20 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
return $this->value_options[!empty($this->value)];
|
||||
}
|
||||
|
||||
function expose_options() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function expose_options() {
|
||||
parent::expose_options();
|
||||
$this->options['expose']['operator_id'] = '';
|
||||
$this->options['expose']['label'] = $this->value_value;
|
||||
$this->options['expose']['required'] = TRUE;
|
||||
}
|
||||
|
||||
function query() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$field = "$this->table_alias.$this->real_field";
|
||||
|
||||
@@ -176,4 +209,5 @@ class views_handler_filter_boolean_operator extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,7 +17,11 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_boolean_operator_string extends views_handler_filter_boolean_operator {
|
||||
function query() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$where = "$this->table_alias.$this->real_field ";
|
||||
|
||||
@@ -32,4 +36,5 @@ class views_handler_filter_boolean_operator_string extends views_handler_filter_
|
||||
}
|
||||
$this->query->add_where_expression($this->options['group'], $where);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,19 +11,26 @@
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_handler_filter_combine extends views_handler_filter_string {
|
||||
|
||||
/**
|
||||
* @var views_plugin_query_default
|
||||
*/
|
||||
public $query;
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['fields'] = array('default' => array());
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$this->view->init_style();
|
||||
|
||||
@@ -49,7 +56,10 @@ class views_handler_filter_combine extends views_handler_filter_string {
|
||||
}
|
||||
}
|
||||
|
||||
function query() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->view->_build('field');
|
||||
$fields = array();
|
||||
// Only add the fields if they have a proper field and table alias.
|
||||
@@ -63,7 +73,7 @@ class views_handler_filter_combine extends views_handler_filter_string {
|
||||
// Always add the table of the selected fields to be sure a table alias
|
||||
// exists.
|
||||
$field->ensure_my_table();
|
||||
if (!empty($field->field_alias) && !empty($field->field_alias)) {
|
||||
if (!empty($field->table_alias) && !empty($field->real_field)) {
|
||||
$fields[] = "$field->table_alias.$field->real_field";
|
||||
}
|
||||
}
|
||||
@@ -86,20 +96,28 @@ class views_handler_filter_combine extends views_handler_filter_string {
|
||||
}
|
||||
}
|
||||
|
||||
// By default things like op_equal uses add_where, that doesn't support
|
||||
// complex expressions, so override all operators.
|
||||
function op_equal($field) {
|
||||
/**
|
||||
* By default things like op_equal uses add_where, that doesn't support
|
||||
* complex expressions, so override all operators.
|
||||
*/
|
||||
public function op_equal($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$operator = $this->operator();
|
||||
$this->query->add_where_expression($this->options['group'], "$field $operator $placeholder", array($placeholder => $this->value));
|
||||
}
|
||||
|
||||
function op_contains($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_contains($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%'));
|
||||
}
|
||||
|
||||
function op_word($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_word($field) {
|
||||
$where = $this->operator == 'word' ? db_or() : db_and();
|
||||
|
||||
// Don't filter on empty strings.
|
||||
@@ -132,37 +150,66 @@ class views_handler_filter_combine extends views_handler_filter_string {
|
||||
$this->query->add_where($this->options['group'], $where);
|
||||
}
|
||||
|
||||
function op_starts($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_starts($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => db_like($this->value) . '%'));
|
||||
}
|
||||
|
||||
function op_not_starts($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_not_starts($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => db_like($this->value) . '%'));
|
||||
}
|
||||
|
||||
function op_ends($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_ends($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field LIKE $placeholder", array($placeholder => '%' . db_like($this->value)));
|
||||
}
|
||||
|
||||
function op_not_ends($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_not_ends($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => '%' . db_like($this->value)));
|
||||
}
|
||||
|
||||
function op_not($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_not($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field NOT LIKE $placeholder", array($placeholder => '%' . db_like($this->value) . '%'));
|
||||
}
|
||||
|
||||
function op_regex($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_regex($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field RLIKE $placeholder", array($placeholder => $this->value));
|
||||
}
|
||||
|
||||
function op_empty($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_not_regex($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "$field NOT RLIKE $placeholder", array($placeholder => $this->value));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_empty($field) {
|
||||
if ($this->operator == 'empty') {
|
||||
$operator = "IS NULL";
|
||||
}
|
||||
@@ -172,4 +219,5 @@ class views_handler_filter_combine extends views_handler_filter_string {
|
||||
|
||||
$this->query->add_where_expression($this->options['group'], "$field $operator");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,19 +11,23 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
// value is already set up properly, we're just adding our new field to it.
|
||||
// Value is already set up properly, we're just adding our new field to it.
|
||||
$options['value']['contains']['type']['default'] = 'date';
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a type selector to the value form
|
||||
* Add a type selector to the value form.
|
||||
*/
|
||||
function value_form(&$form, &$form_state) {
|
||||
public function value_form(&$form, &$form_state) {
|
||||
if (empty($form_state['exposed'])) {
|
||||
$form['value']['type'] = array(
|
||||
'#type' => 'radios',
|
||||
@@ -38,7 +42,10 @@ class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
parent::value_form($form, $form_state);
|
||||
}
|
||||
|
||||
function options_validate(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_validate(&$form, &$form_state) {
|
||||
parent::options_validate($form, $form_state);
|
||||
|
||||
if (!empty($this->options['exposed']) && empty($form_state['values']['options']['expose']['required'])) {
|
||||
@@ -49,7 +56,10 @@ class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
$this->validate_valid_time($form['value'], $form_state['values']['options']['operator'], $form_state['values']['options']['value']);
|
||||
}
|
||||
|
||||
function exposed_validate(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exposed_validate(&$form, &$form_state) {
|
||||
if (empty($this->options['exposed'])) {
|
||||
return;
|
||||
}
|
||||
@@ -74,7 +84,7 @@ class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
/**
|
||||
* Validate that the time values convert to something usable.
|
||||
*/
|
||||
function validate_valid_time(&$form, $operator, $value) {
|
||||
public function validate_valid_time(&$form, $operator, $value) {
|
||||
$operators = $this->operators();
|
||||
|
||||
if ($operators[$operator]['values'] == 1) {
|
||||
@@ -98,7 +108,7 @@ class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
/**
|
||||
* Validate the build group options form.
|
||||
*/
|
||||
function build_group_validate($form, &$form_state) {
|
||||
public function build_group_validate($form, &$form_state) {
|
||||
// Special case to validate grouped date filters, this is because the
|
||||
// $group['value'] array contains the type of filter (date or offset)
|
||||
// and therefore the number of items the comparission has to be done
|
||||
@@ -122,8 +132,10 @@ class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function accept_exposed_input($input) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function accept_exposed_input($input) {
|
||||
if (empty($this->options['exposed'])) {
|
||||
return TRUE;
|
||||
}
|
||||
@@ -146,36 +158,45 @@ class views_handler_filter_date extends views_handler_filter_numeric {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
elseif ($operators[$operator]['values'] == 2) {
|
||||
if ($this->value['min'] == '' || $this->value['max'] == '') {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// restore what got overwritten by the parent.
|
||||
// Restore what got overwritten by the parent.
|
||||
$this->value['type'] = $type;
|
||||
return $rc;
|
||||
}
|
||||
|
||||
function op_between($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_between($field) {
|
||||
// Use the substitutions to ensure a consistent timestamp.
|
||||
$query_substitutions = views_views_query_substitutions($this->view);
|
||||
$a = intval(strtotime($this->value['min'], $query_substitutions['***CURRENT_TIME***']));
|
||||
$b = intval(strtotime($this->value['max'], $query_substitutions['***CURRENT_TIME***']));
|
||||
|
||||
// This is safe because we are manually scrubbing the values.
|
||||
// It is necessary to do it this way because $a and $b are formulas when using an offset.
|
||||
// This is safe because we are manually scrubbing the values. It is
|
||||
// necessary to do it this way because $a and $b are formulas when using an
|
||||
// offset.
|
||||
$operator = strtoupper($this->operator);
|
||||
$this->query->add_where_expression($this->options['group'], "$field $operator $a AND $b");
|
||||
}
|
||||
|
||||
function op_simple($field) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function op_simple($field) {
|
||||
// Use the substitutions to ensure a consistent timestamp.
|
||||
$query_substitutions = views_views_query_substitutions($this->view);
|
||||
$value = intval(strtotime($this->value['value'], $query_substitutions['***CURRENT_TIME***']));
|
||||
|
||||
// This is safe because we are manually scrubbing the value.
|
||||
// It is necessary to do it this way because $value is a formula when using an offset.
|
||||
// This is safe because we are manually scrubbing the value. It is
|
||||
// necessary to do it this way because $value is a formula when using an
|
||||
// offset.
|
||||
$this->query->add_where_expression($this->options['group'], "$field $this->operator $value");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Definition of views_handler_filter_entity_bundle
|
||||
* Definition of views_handler_filter_entity_bundle.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -13,6 +13,7 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_entity_bundle extends views_handler_filter_in_operator {
|
||||
|
||||
/**
|
||||
* Stores the entity type on which the filter filters.
|
||||
*
|
||||
@@ -20,7 +21,10 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
|
||||
*/
|
||||
public $entity_type;
|
||||
|
||||
function init(&$view, &$options) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
|
||||
$this->get_entity_type();
|
||||
@@ -32,16 +36,17 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
|
||||
* @return string
|
||||
* The entity type on the filter.
|
||||
*/
|
||||
function get_entity_type() {
|
||||
public function get_entity_type() {
|
||||
if (!isset($this->entity_type)) {
|
||||
$data = views_fetch_data($this->table);
|
||||
if (isset($data['table']['entity type'])) {
|
||||
$this->entity_type = $data['table']['entity type'];
|
||||
}
|
||||
|
||||
// If the current filter is under a relationship you can't be sure that the
|
||||
// entity type of the view is the entity type of the current filter
|
||||
// For example a filter from a node author on a node view does have users as entity type.
|
||||
// If the current filter is under a relationship you can't be sure that
|
||||
// the entity type of the view is the entity type of the current filter
|
||||
// For example a filter from a node author on a node view does have users
|
||||
// as entity type.
|
||||
if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
|
||||
$relationships = $this->view->display_handler->get_option('relationships');
|
||||
if (!empty($relationships[$this->options['relationship']])) {
|
||||
@@ -55,8 +60,10 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
|
||||
return $this->entity_type;
|
||||
}
|
||||
|
||||
|
||||
function get_value_options() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_value_options() {
|
||||
if (!isset($this->value_options)) {
|
||||
$info = entity_get_info($this->entity_type);
|
||||
$types = $info['bundles'];
|
||||
@@ -76,7 +83,7 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
|
||||
* bundle, though these two need an additional join to node/vocab table
|
||||
* to work as required.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
|
||||
// Adjust the join for the comment case.
|
||||
@@ -119,4 +126,5 @@ class views_handler_filter_entity_bundle extends views_handler_filter_in_operato
|
||||
}
|
||||
parent::query();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,18 +6,21 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple filter to handle equal to / not equal to filters
|
||||
* Simple filter to handle equal to / not equal to filters.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_equality extends views_handler_filter {
|
||||
// exposed filter options
|
||||
var $always_multiple = TRUE;
|
||||
|
||||
/**
|
||||
* Provide simple equality operator
|
||||
* Exposed filter options.
|
||||
*/
|
||||
function operator_options() {
|
||||
public $always_multiple = TRUE;
|
||||
|
||||
/**
|
||||
* Provide simple equality operator.
|
||||
*/
|
||||
public function operator_options() {
|
||||
return array(
|
||||
'=' => t('Is equal to'),
|
||||
'!=' => t('Is not equal to'),
|
||||
@@ -25,9 +28,9 @@ class views_handler_filter_equality extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a simple textfield for equality
|
||||
* Provide a simple textfield for equality.
|
||||
*/
|
||||
function value_form(&$form, &$form_state) {
|
||||
public function value_form(&$form, &$form_state) {
|
||||
$form['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Value'),
|
||||
@@ -42,4 +45,5 @@ class views_handler_filter_equality extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,17 +10,19 @@
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
|
||||
class views_handler_filter_fields_compare extends views_handler_filter {
|
||||
|
||||
function can_expose() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function can_expose() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_filter#option_definition().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function option_definition() {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['left_field'] = $options['right_field'] = array('default' => '');
|
||||
@@ -31,21 +33,21 @@ class views_handler_filter_fields_compare extends views_handler_filter {
|
||||
/**
|
||||
* Provide a list of all operators.
|
||||
*/
|
||||
function fields_operator_options() {
|
||||
public function fields_operator_options() {
|
||||
return array(
|
||||
'<' => t('Is less than'),
|
||||
'<=' => t('Is less than or equal to'),
|
||||
'=' => t('Is equal to'),
|
||||
'<>' => t('Is not equal to'),
|
||||
'<>' => t('Is not equal to'),
|
||||
'>=' => t('Is greater than or equal to'),
|
||||
'>' => t('Is greater than')
|
||||
'>' => t('Is greater than'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a list of available fields.
|
||||
*/
|
||||
function field_options() {
|
||||
public function field_options() {
|
||||
$options = array();
|
||||
|
||||
$field_handlers = $this->view->display_handler->get_handlers('field');
|
||||
@@ -59,9 +61,9 @@ class views_handler_filter_fields_compare extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_filter#options_form().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$field_options = $this->field_options();
|
||||
@@ -93,11 +95,10 @@ class views_handler_filter_fields_compare extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_filter#query().
|
||||
*
|
||||
* Build extra condition from existing fields (from existing joins).
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
// Build extra condition from existing fields (from existing joins).
|
||||
$left = $this->options['left_field'];
|
||||
$right = $this->options['right_field'];
|
||||
|
||||
@@ -120,22 +121,21 @@ class views_handler_filter_fields_compare extends views_handler_filter {
|
||||
$right_table_alias = $this->query->ensure_table($right_handler->table, $right_handler->relationship);
|
||||
|
||||
// Build piece of SQL.
|
||||
$snippet =
|
||||
$left_table_alias . '.' . $left_handler->real_field .
|
||||
' ' . $this->options['operator'] . ' ' .
|
||||
$right_table_alias . '.' . $right_handler->real_field;
|
||||
$snippet = $left_table_alias . '.' . $left_handler->real_field
|
||||
. ' ' . $this->options['operator'] . ' '
|
||||
. $right_table_alias . '.' . $right_handler->real_field;
|
||||
|
||||
$this->query->add_where_expression($this->options['group'], $snippet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides views_handler_filter#admin_summary().
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function admin_summary() {
|
||||
public function admin_summary() {
|
||||
return check_plain(
|
||||
$this->options['left_field'] . ' ' .
|
||||
$this->options['operator'] . ' ' .
|
||||
$this->options['right_field']
|
||||
$this->options['left_field'] . ' '
|
||||
. $this->options['operator'] . ' '
|
||||
. $this->options['right_field']
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,11 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_group_by_numeric extends views_handler_filter_numeric {
|
||||
function query() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$field = $this->get_field();
|
||||
|
||||
@@ -20,7 +24,11 @@ class views_handler_filter_group_by_numeric extends views_handler_filter_numeric
|
||||
$this->{$info[$this->operator]['method']}($field);
|
||||
}
|
||||
}
|
||||
function op_between($field) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_between($field) {
|
||||
$placeholder_min = $this->placeholder();
|
||||
$placeholder_max = $this->placeholder();
|
||||
if ($this->operator == 'between') {
|
||||
@@ -32,12 +40,18 @@ class views_handler_filter_group_by_numeric extends views_handler_filter_numeric
|
||||
}
|
||||
}
|
||||
|
||||
function op_simple($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_simple($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_having_expression($this->options['group'], "$field $this->operator $placeholder", array($placeholder => $this->value['value']));
|
||||
}
|
||||
|
||||
function op_empty($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_empty($field) {
|
||||
if ($this->operator == 'empty') {
|
||||
$operator = "IS NULL";
|
||||
}
|
||||
@@ -48,9 +62,18 @@ class views_handler_filter_group_by_numeric extends views_handler_filter_numeric
|
||||
$this->query->add_having_expression($this->options['group'], "$field $operator");
|
||||
}
|
||||
|
||||
function ui_name($short = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return $this->get_field(parent::ui_name($short));
|
||||
}
|
||||
|
||||
function can_group() { return FALSE; }
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function can_group() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,24 +6,32 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple filter to handle matching of multiple options selectable via checkboxes
|
||||
* Simple filter to handle matching of multiple options using checkboxes.
|
||||
*
|
||||
* Definition items:
|
||||
* - options callback: The function to call in order to generate the value options. If omitted, the options 'Yes' and 'No' will be used.
|
||||
* - options callback: The function to call in order to generate the value
|
||||
* options. If omitted, the options 'Yes' and 'No' will be used.
|
||||
* - options arguments: An array of arguments to pass to the options callback.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_in_operator extends views_handler_filter {
|
||||
var $value_form_type = 'checkboxes';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public $value_form_type = 'checkboxes';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* Stores all operations which are available on the form.
|
||||
*/
|
||||
var $value_options = NULL;
|
||||
public $value_options = NULL;
|
||||
|
||||
function construct() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function construct() {
|
||||
parent::construct();
|
||||
$this->value_title = t('Options');
|
||||
$this->value_options = NULL;
|
||||
@@ -40,7 +48,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
* @return
|
||||
* Return the stored values in $this->value_options if someone expects it.
|
||||
*/
|
||||
function get_value_options() {
|
||||
public function get_value_options() {
|
||||
if (isset($this->value_options)) {
|
||||
return;
|
||||
}
|
||||
@@ -60,22 +68,32 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
return $this->value_options;
|
||||
}
|
||||
|
||||
function expose_options() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function expose_options() {
|
||||
parent::expose_options();
|
||||
$this->options['expose']['reduce'] = FALSE;
|
||||
}
|
||||
|
||||
function expose_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function expose_form(&$form, &$form_state) {
|
||||
parent::expose_form($form, $form_state);
|
||||
$form['expose']['reduce'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Limit list to selected items'),
|
||||
'#description' => t('If checked, the only items presented to the user will be the ones selected here.'),
|
||||
'#default_value' => !empty($this->options['expose']['reduce']), // safety
|
||||
// Safety.
|
||||
'#default_value' => !empty($this->options['expose']['reduce']),
|
||||
);
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['operator']['default'] = 'in';
|
||||
@@ -86,11 +104,11 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* This kind of construct makes it relatively easy for a child class
|
||||
* to add or remove functionality by overriding this function and
|
||||
* adding/removing items from this array.
|
||||
* This kind of construct makes it relatively easy for a child class to add or
|
||||
* remove functionality by overriding this function and adding/removing items
|
||||
* from this array.
|
||||
*/
|
||||
function operators() {
|
||||
public function operators() {
|
||||
$operators = array(
|
||||
'in' => array(
|
||||
'title' => t('Is one of'),
|
||||
@@ -129,9 +147,9 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build strings from the operators() for 'select' options
|
||||
* Build strings from the operators() for 'select' options.
|
||||
*/
|
||||
function operator_options($which = 'title') {
|
||||
public function operator_options($which = 'title') {
|
||||
$options = array();
|
||||
foreach ($this->operators() as $id => $info) {
|
||||
$options[$id] = $info[$which];
|
||||
@@ -140,7 +158,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function operator_values($values = 1) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operator_values($values = 1) {
|
||||
$options = array();
|
||||
foreach ($this->operators() as $id => $info) {
|
||||
if (isset($info['values']) && $info['values'] == $values) {
|
||||
@@ -151,7 +172,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function value_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function value_form(&$form, &$form_state) {
|
||||
$form['value'] = array();
|
||||
$options = array();
|
||||
|
||||
@@ -172,7 +196,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
|
||||
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
|
||||
// exposed and locked.
|
||||
// Exposed and locked.
|
||||
$which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
|
||||
}
|
||||
else {
|
||||
@@ -229,7 +253,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
/**
|
||||
* When using exposed filters, we may be required to reduce the set.
|
||||
*/
|
||||
function reduce_value_options($input = NULL) {
|
||||
public function reduce_value_options($input = NULL) {
|
||||
if (!isset($input)) {
|
||||
$input = $this->value_options;
|
||||
}
|
||||
@@ -257,9 +281,12 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function accept_exposed_input($input) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function accept_exposed_input($input) {
|
||||
// A very special override because the All state for this type of
|
||||
// filter could have a default:
|
||||
// filter could have a default.
|
||||
if (empty($this->options['exposed'])) {
|
||||
return TRUE;
|
||||
}
|
||||
@@ -276,7 +303,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
return parent::accept_exposed_input($input);
|
||||
}
|
||||
|
||||
function value_submit($form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function value_submit($form, &$form_state) {
|
||||
// Drupal's FAPI system automatically puts '0' in for any checkbox that
|
||||
// was not set, and the key to the checkbox if it is set.
|
||||
// Unfortunately, this means that if the key to that checkbox is 0,
|
||||
@@ -289,7 +319,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
$form_state['values']['options']['value'] = $form['value']['#value'];
|
||||
}
|
||||
|
||||
function admin_summary() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function admin_summary() {
|
||||
if ($this->is_a_group()) {
|
||||
return t('grouped');
|
||||
}
|
||||
@@ -317,7 +350,7 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
if (count($this->value) == 0) {
|
||||
$values = t('Unknown');
|
||||
}
|
||||
else if (count($this->value) == 1) {
|
||||
elseif (count($this->value) == 1) {
|
||||
// If any, use the 'single' short name of the operator instead.
|
||||
if (isset($info[$this->operator]['short_single'])) {
|
||||
$operator = check_plain($info[$this->operator]['short_single']);
|
||||
@@ -351,14 +384,20 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
return $operator . (($values !== '') ? ' ' . $values : '');
|
||||
}
|
||||
|
||||
function query() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$info = $this->operators();
|
||||
if (!empty($info[$this->operator]['method'])) {
|
||||
$this->{$info[$this->operator]['method']}();
|
||||
}
|
||||
}
|
||||
|
||||
function op_simple() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_simple() {
|
||||
if (empty($this->value)) {
|
||||
return;
|
||||
}
|
||||
@@ -369,7 +408,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", array_values($this->value), $this->operator);
|
||||
}
|
||||
|
||||
function op_empty() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_empty() {
|
||||
$this->ensure_my_table();
|
||||
if ($this->operator == 'empty') {
|
||||
$operator = "IS NULL";
|
||||
@@ -381,7 +423,10 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
$this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field", NULL, $operator);
|
||||
}
|
||||
|
||||
function validate() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate() {
|
||||
$this->get_value_options();
|
||||
$errors = array();
|
||||
|
||||
@@ -396,11 +441,13 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
}
|
||||
if (is_array($this->value)) {
|
||||
if (!isset($this->value_options)) {
|
||||
// Don't validate if there are none value options provided, for example for special handlers.
|
||||
// Don't validate if there are none value options provided, for example
|
||||
// for special handlers.
|
||||
return $errors;
|
||||
}
|
||||
if ($this->options['exposed'] && !$this->options['expose']['required'] && empty($this->value)) {
|
||||
// Don't validate if the field is exposed and no default value is provided.
|
||||
// Don't validate if the field is exposed and no default value is
|
||||
// provided.
|
||||
return $errors;
|
||||
}
|
||||
|
||||
@@ -423,4 +470,5 @@ class views_handler_filter_in_operator extends views_handler_filter {
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,8 +6,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Complex filter to handle filtering for many to one relationships,
|
||||
* such as terms (many terms per node) or roles (many roles per user).
|
||||
* Complex filter to handle filtering for many to one relationships.
|
||||
*
|
||||
* Examples: terms (many terms per node), roles (many roles per user).
|
||||
*
|
||||
* The construct method needs to be overridden to provide a list of options;
|
||||
* alternately, the value_form and admin_summary methods need to be overriden
|
||||
@@ -16,19 +17,31 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_many_to_one extends views_handler_filter_in_operator {
|
||||
|
||||
/**
|
||||
* @var views_many_to_one_helper
|
||||
*
|
||||
* Stores the Helper object which handles the many_to_one complexity.
|
||||
*/
|
||||
var $helper = NULL;
|
||||
public $helper = NULL;
|
||||
|
||||
function init(&$view, &$options) {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public $value_form_type = 'select';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
$this->helper = new views_many_to_one_helper($this);
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['operator']['default'] = 'or';
|
||||
@@ -45,7 +58,10 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
|
||||
return $options;
|
||||
}
|
||||
|
||||
function operators() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operators() {
|
||||
$operators = array(
|
||||
'or' => array(
|
||||
'title' => t('Is one of'),
|
||||
@@ -93,8 +109,10 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
|
||||
return $operators;
|
||||
}
|
||||
|
||||
var $value_form_type = 'select';
|
||||
function value_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function value_form(&$form, &$form_state) {
|
||||
parent::value_form($form, $form_state);
|
||||
|
||||
if (empty($form_state['exposed'])) {
|
||||
@@ -106,7 +124,7 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
|
||||
* Override ensure_my_table so we can control how this joins in.
|
||||
* The operator actually has influence over joining.
|
||||
*/
|
||||
function ensure_my_table() {
|
||||
public function ensure_my_table() {
|
||||
// Defer to helper if the operator specifies it.
|
||||
$info = $this->operators();
|
||||
if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') {
|
||||
@@ -116,10 +134,14 @@ class views_handler_filter_many_to_one extends views_handler_filter_in_operator
|
||||
return parent::ensure_my_table();
|
||||
}
|
||||
|
||||
function op_helper() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_helper() {
|
||||
if (empty($this->value)) {
|
||||
return;
|
||||
}
|
||||
$this->helper->add_filter();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,8 +11,16 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_numeric extends views_handler_filter {
|
||||
var $always_multiple = TRUE;
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* Exposed filter options.
|
||||
*/
|
||||
public $always_multiple = TRUE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['value'] = array(
|
||||
@@ -26,7 +34,10 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function operators() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operators() {
|
||||
$operators = array(
|
||||
'<' => array(
|
||||
'title' => t('Is less than'),
|
||||
@@ -105,6 +116,12 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
'method' => 'op_regex',
|
||||
'values' => 1,
|
||||
),
|
||||
'not_regular_expression' => array(
|
||||
'title' => t('Not regular expression'),
|
||||
'short' => t('not regex'),
|
||||
'method' => 'op_not_regex',
|
||||
'values' => 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -114,7 +131,7 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
/**
|
||||
* Provide a list of all the numeric operators
|
||||
*/
|
||||
function operator_options($which = 'title') {
|
||||
public function operator_options($which = 'title') {
|
||||
$options = array();
|
||||
foreach ($this->operators() as $id => $info) {
|
||||
$options[$id] = $info[$which];
|
||||
@@ -123,7 +140,10 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function operator_values($values = 1) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operator_values($values = 1) {
|
||||
$options = array();
|
||||
foreach ($this->operators() as $id => $info) {
|
||||
if ($info['values'] == $values) {
|
||||
@@ -133,10 +153,11 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a simple textfield for equality
|
||||
*/
|
||||
function value_form(&$form, &$form_state) {
|
||||
public function value_form(&$form, &$form_state) {
|
||||
$form['value']['#tree'] = TRUE;
|
||||
|
||||
// We have to make some choices when creating this as an exposed
|
||||
@@ -144,72 +165,108 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
// not rendered, we can't render dependencies; instead we only
|
||||
// render the form items we need.
|
||||
$which = 'all';
|
||||
$limit_operators = !empty($this->options['expose']['limit_operators']) && (count($this->options['expose']['available_operators']) > 0);
|
||||
$use_value = FALSE;
|
||||
$use_minmax = FALSE;
|
||||
|
||||
if (!empty($form['operator'])) {
|
||||
$source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator';
|
||||
}
|
||||
|
||||
if (!empty($form_state['exposed'])) {
|
||||
$operator_values_with_1_values = $this->operator_values(1);
|
||||
$operator_values_with_2_values = $this->operator_values(2);
|
||||
if ($limit_operators) {
|
||||
// If limit operators is enabled, check that at least one operator
|
||||
// with two values is enabled to display the min max widgets
|
||||
foreach ($operator_values_with_2_values as $operator) {
|
||||
if (isset($this->options['expose']['available_operators'][$operator])) {
|
||||
$use_minmax = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// the same for operators with one value
|
||||
foreach ($operator_values_with_1_values as $operator) {
|
||||
if (isset($this->options['expose']['available_operators'][$operator])) {
|
||||
$use_value = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$use_minmax = $use_value = TRUE;
|
||||
}
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
|
||||
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator_id'])) {
|
||||
// exposed and locked.
|
||||
$which = in_array($this->operator, $this->operator_values(2)) ? 'minmax' : 'value';
|
||||
$which = in_array($this->operator, $operator_values_with_2_values) ? 'minmax' : 'value';
|
||||
}
|
||||
else {
|
||||
$source = 'edit-' . drupal_html_id($this->options['expose']['operator_id']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($which == 'all') {
|
||||
$form['value']['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('Value') : '',
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['value'],
|
||||
'#dependency' => array($source => $this->operator_values(1)),
|
||||
);
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['value'])) {
|
||||
$form_state['input'][$identifier]['value'] = $this->value['value'];
|
||||
}
|
||||
else {
|
||||
$use_minmax = $use_value = TRUE;
|
||||
}
|
||||
elseif ($which == 'value') {
|
||||
// When exposed we drop the value-value and just do value if
|
||||
// the operator is locked.
|
||||
$form['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('Value') : '',
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['value'],
|
||||
);
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
|
||||
$form_state['input'][$identifier] = $this->value['value'];
|
||||
|
||||
if ($use_value) {
|
||||
if ($which == 'all') {
|
||||
$form['value']['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('Value') : '',
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['value'],
|
||||
'#dependency' => array($source => $this->operator_values(1)),
|
||||
);
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['value'])) {
|
||||
$form_state['input'][$identifier]['value'] = $this->value['value'];
|
||||
}
|
||||
}
|
||||
elseif ($which == 'value') {
|
||||
// When exposed we drop the value-value and just do value if
|
||||
// the operator is locked.
|
||||
$form['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('Value') : '',
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['value'],
|
||||
);
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) {
|
||||
$form_state['input'][$identifier] = $this->value['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($which == 'all' || $which == 'minmax') {
|
||||
$form['value']['min'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('Min') : '',
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['min'],
|
||||
);
|
||||
$form['value']['max'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('And max') : t('And'),
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['max'],
|
||||
);
|
||||
if ($which == 'all') {
|
||||
$dependency = array(
|
||||
'#dependency' => array($source => $this->operator_values(2)),
|
||||
if ($use_minmax) {
|
||||
$form['value']['min'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('Min') : '',
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['min'],
|
||||
);
|
||||
$form['value']['min'] += $dependency;
|
||||
$form['value']['max'] += $dependency;
|
||||
$form['value']['max'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => empty($form_state['exposed']) ? t('And max') : t('And'),
|
||||
'#size' => 30,
|
||||
'#default_value' => $this->value['max'],
|
||||
);
|
||||
|
||||
if ($which == 'all') {
|
||||
$dependency = array(
|
||||
'#dependency' => array($source => $this->operator_values(2)),
|
||||
);
|
||||
|
||||
$form['value']['min'] += $dependency;
|
||||
$form['value']['max'] += $dependency;
|
||||
}
|
||||
}
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['min'])) {
|
||||
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['min']) && $use_minmax) {
|
||||
$form_state['input'][$identifier]['min'] = $this->value['min'];
|
||||
}
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['max'])) {
|
||||
if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['max']) && $use_minmax) {
|
||||
$form_state['input'][$identifier]['max'] = $this->value['max'];
|
||||
}
|
||||
|
||||
@@ -223,7 +280,10 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function query() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$field = "$this->table_alias.$this->real_field";
|
||||
|
||||
@@ -233,7 +293,10 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function op_between($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_between($field) {
|
||||
if ($this->operator == 'between') {
|
||||
$this->query->add_where($this->options['group'], $field, array($this->value['min'], $this->value['max']), 'BETWEEN');
|
||||
}
|
||||
@@ -242,11 +305,17 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function op_simple($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_simple($field) {
|
||||
$this->query->add_where($this->options['group'], $field, $this->value['value'], $this->operator);
|
||||
}
|
||||
|
||||
function op_empty($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_empty($field) {
|
||||
if ($this->operator == 'empty') {
|
||||
$operator = "IS NULL";
|
||||
}
|
||||
@@ -257,11 +326,24 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
$this->query->add_where($this->options['group'], $field, NULL, $operator);
|
||||
}
|
||||
|
||||
function op_regex($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_regex($field) {
|
||||
$this->query->add_where($this->options['group'], $field, $this->value['value'], 'RLIKE');
|
||||
}
|
||||
|
||||
function admin_summary() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_not_regex($field) {
|
||||
$this->query->add_where($this->options['group'], $field, $this->value['value'], 'NOT RLIKE');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function admin_summary() {
|
||||
if ($this->is_a_group()) {
|
||||
return t('grouped');
|
||||
}
|
||||
@@ -281,15 +363,15 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some minor translation of the exposed input
|
||||
* Do some minor translation of the exposed input.
|
||||
*/
|
||||
function accept_exposed_input($input) {
|
||||
public function accept_exposed_input($input) {
|
||||
if (empty($this->options['exposed'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// rewrite the input value so that it's in the correct format so that
|
||||
// the parent gets the right data.
|
||||
// Rewrite the input value so that it's in the correct format so that the
|
||||
// parent gets the right data.
|
||||
if (!empty($this->options['expose']['identifier'])) {
|
||||
$value = &$input[$this->options['expose']['identifier']];
|
||||
if (!is_array($value)) {
|
||||
@@ -311,6 +393,7 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if ($value['min'] === '' && $value['max'] === '') {
|
||||
return FALSE;
|
||||
@@ -322,4 +405,5 @@ class views_handler_filter_numeric extends views_handler_filter {
|
||||
|
||||
return $rc;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,10 +12,16 @@
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_handler_filter_string extends views_handler_filter {
|
||||
// exposed filter options
|
||||
var $always_multiple = TRUE;
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* Exposed filter options.
|
||||
*/
|
||||
public $always_multiple = TRUE;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['expose']['contains']['required'] = array('default' => FALSE, 'bool' => TRUE);
|
||||
@@ -24,11 +30,11 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* This kind of construct makes it relatively easy for a child class
|
||||
* to add or remove functionality by overriding this function and
|
||||
* adding/removing items from this array.
|
||||
* This kind of construct makes it relatively easy for a child class to add or
|
||||
* remove functionality by overriding this function and adding/removing items
|
||||
* from this array.
|
||||
*/
|
||||
function operators() {
|
||||
public function operators() {
|
||||
$operators = array(
|
||||
'=' => array(
|
||||
'title' => t('Is equal to'),
|
||||
@@ -103,7 +109,7 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
'values' => 1,
|
||||
),
|
||||
);
|
||||
// if the definition allows for the empty operator, add it.
|
||||
// If the definition allows for the empty operator, add it.
|
||||
if (!empty($this->definition['allow empty'])) {
|
||||
$operators += array(
|
||||
'empty' => array(
|
||||
@@ -129,6 +135,12 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
'method' => 'op_regex',
|
||||
'values' => 1,
|
||||
),
|
||||
'not_regular_expression' => array(
|
||||
'title' => t('Not regular expression'),
|
||||
'short' => t('not regex'),
|
||||
'method' => 'op_not_regex',
|
||||
'values' => 1,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -136,9 +148,9 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build strings from the operators() for 'select' options
|
||||
* Build strings from the operators() for 'select' options.
|
||||
*/
|
||||
function operator_options($which = 'title') {
|
||||
public function operator_options($which = 'title') {
|
||||
$options = array();
|
||||
foreach ($this->operators() as $id => $info) {
|
||||
$options[$id] = $info[$which];
|
||||
@@ -147,7 +159,10 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function admin_summary() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function admin_summary() {
|
||||
if ($this->is_a_group()) {
|
||||
return t('grouped');
|
||||
}
|
||||
@@ -157,7 +172,7 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
|
||||
$options = $this->operator_options('short');
|
||||
$output = '';
|
||||
if(!empty($options[$this->operator])) {
|
||||
if (!empty($options[$this->operator])) {
|
||||
$output = check_plain($options[$this->operator]);
|
||||
}
|
||||
if (in_array($this->operator, $this->operator_values(1))) {
|
||||
@@ -166,7 +181,10 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
return $output;
|
||||
}
|
||||
|
||||
function operator_values($values = 1) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operator_values($values = 1) {
|
||||
$options = array();
|
||||
foreach ($this->operators() as $id => $info) {
|
||||
if (isset($info['values']) && $info['values'] == $values) {
|
||||
@@ -178,13 +196,12 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a simple textfield for equality
|
||||
* Provide a simple textfield for equality.
|
||||
*/
|
||||
function value_form(&$form, &$form_state) {
|
||||
// We have to make some choices when creating this as an exposed
|
||||
// filter form. For example, if the operator is locked and thus
|
||||
// not rendered, we can't render dependencies; instead we only
|
||||
// render the form items we need.
|
||||
public function value_form(&$form, &$form_state) {
|
||||
// We have to make some choices when creating this as an exposed filter
|
||||
// form. For example, if the operator is locked and thus not rendered, we
|
||||
// can't render dependencies; instead we only render the form items we need.
|
||||
$which = 'all';
|
||||
if (!empty($form['operator'])) {
|
||||
$source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator';
|
||||
@@ -223,23 +240,26 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
// Ensure there is something in the 'value'.
|
||||
$form['value'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => NULL
|
||||
'#value' => NULL,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function operator() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function operator() {
|
||||
return $this->operator == '=' ? 'LIKE' : 'NOT LIKE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this filter to the query.
|
||||
*
|
||||
* Due to the nature of fapi, the value and the operator have an unintended
|
||||
* level of indirection. You will find them in $this->operator
|
||||
* and $this->value respectively.
|
||||
* Due to the nature of FAPI, the value and the operator have an unintended
|
||||
* level of indirection. You will find them in $this->operator and
|
||||
* $this->value respectively.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$field = "$this->table_alias.$this->real_field";
|
||||
|
||||
@@ -249,15 +269,26 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
}
|
||||
}
|
||||
|
||||
function op_equal($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_equal($field) {
|
||||
$this->query->add_where($this->options['group'], $field, $this->value, $this->operator());
|
||||
}
|
||||
|
||||
function op_contains($field) {
|
||||
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_contains($field) {
|
||||
if (!empty($this->value)) {
|
||||
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'LIKE');
|
||||
}
|
||||
}
|
||||
|
||||
function op_word($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_word($field) {
|
||||
$where = $this->operator == 'word' ? db_or() : db_and();
|
||||
|
||||
// Don't filter on empty strings.
|
||||
@@ -267,11 +298,11 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
|
||||
preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$phrase = false;
|
||||
$phrase = FALSE;
|
||||
// Strip off phrase quotes
|
||||
if ($match[2]{0} == '"') {
|
||||
$match[2] = substr($match[2], 1, -1);
|
||||
$phrase = true;
|
||||
$phrase = TRUE;
|
||||
}
|
||||
$words = trim($match[2], ',?!();:-');
|
||||
$words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
|
||||
@@ -285,46 +316,80 @@ class views_handler_filter_string extends views_handler_filter {
|
||||
return;
|
||||
}
|
||||
|
||||
// previously this was a call_user_func_array but that's unnecessary
|
||||
// as views will unpack an array that is a single arg.
|
||||
// Previously this was a call_user_func_array but that's unnecessary as
|
||||
// Views will unpack an array that is a single arg.
|
||||
$this->query->add_where($this->options['group'], $where);
|
||||
}
|
||||
|
||||
function op_starts($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_starts($field) {
|
||||
$this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'LIKE');
|
||||
}
|
||||
|
||||
function op_not_starts($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_not_starts($field) {
|
||||
$this->query->add_where($this->options['group'], $field, db_like($this->value) . '%', 'NOT LIKE');
|
||||
}
|
||||
|
||||
function op_ends($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_ends($field) {
|
||||
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'LIKE');
|
||||
}
|
||||
|
||||
function op_not_ends($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_not_ends($field) {
|
||||
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value), 'NOT LIKE');
|
||||
}
|
||||
|
||||
function op_not($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_not($field) {
|
||||
$this->query->add_where($this->options['group'], $field, '%' . db_like($this->value) . '%', 'NOT LIKE');
|
||||
}
|
||||
|
||||
function op_shorter($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_shorter($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "LENGTH($field) < $placeholder", array($placeholder => $this->value));
|
||||
}
|
||||
|
||||
function op_longer($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_longer($field) {
|
||||
$placeholder = $this->placeholder();
|
||||
$this->query->add_where_expression($this->options['group'], "LENGTH($field) > $placeholder", array($placeholder => $this->value));
|
||||
}
|
||||
|
||||
function op_regex($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_regex($field) {
|
||||
$this->query->add_where($this->options['group'], $field, $this->value, 'RLIKE');
|
||||
}
|
||||
|
||||
function op_empty($field) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_not_regex($field) {
|
||||
$this->query->add_where($this->options['group'], $field, $this->value, 'NOT RLIKE');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function op_empty($field) {
|
||||
if ($this->operator == 'empty') {
|
||||
$operator = "IS NULL";
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views' relationship handlers.
|
||||
* Definition of views_handler_relationship.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -12,12 +12,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple relationship handler that allows a new version of the primary table
|
||||
* to be linked in.
|
||||
* Relationship handler, allows a new version of the primary table to be linked.
|
||||
*
|
||||
* The base relationship handler can only handle a single join. Some relationships
|
||||
* are more complex and might require chains of joins; for those, you must
|
||||
* utilize a custom relationship handler.
|
||||
* The base relationship handler can only handle a single join. Some
|
||||
* relationships are more complex and might require chains of joins; for those,
|
||||
* you must use a custom relationship handler.
|
||||
*
|
||||
* Definition items:
|
||||
* - base: The new base table this relationship will be adding. This does not
|
||||
@@ -36,18 +35,18 @@
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class views_handler_relationship extends views_handler {
|
||||
|
||||
/**
|
||||
* Init handler to let relationships live on tables other than
|
||||
* the table they operate on.
|
||||
* Let relationships live on tables other than the table they operate on.
|
||||
*/
|
||||
function init(&$view, &$options) {
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
if (isset($this->definition['relationship table'])) {
|
||||
$this->table = $this->definition['relationship table'];
|
||||
}
|
||||
if (isset($this->definition['relationship field'])) {
|
||||
// Set both real_field and field so custom handler
|
||||
// can rely on the old field value.
|
||||
// Set both real_field and field so custom handler can rely on the old
|
||||
// field value.
|
||||
$this->real_field = $this->field = $this->definition['relationship field'];
|
||||
}
|
||||
}
|
||||
@@ -55,18 +54,22 @@ class views_handler_relationship extends views_handler {
|
||||
/**
|
||||
* Get this field's label.
|
||||
*/
|
||||
function label() {
|
||||
public function label() {
|
||||
if (!isset($this->options['label'])) {
|
||||
return $this->ui_name();
|
||||
}
|
||||
return $this->options['label'];
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
|
||||
// Relationships definitions should define a default label, but if they aren't get another default value.
|
||||
// Relationships definitions should define a default label, but if they
|
||||
// aren't get another default value.
|
||||
if (!empty($this->definition['label'])) {
|
||||
$label = $this->definition['label'];
|
||||
}
|
||||
@@ -81,10 +84,9 @@ class views_handler_relationship extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Default options form that provides the label widget that all fields
|
||||
* should have.
|
||||
* Provide the label widget that all fields should have.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
@@ -105,7 +107,7 @@ class views_handler_relationship extends views_handler {
|
||||
/**
|
||||
* Called to implement a relationship in a query.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
// Figure out what base table this relationship brings to the party.
|
||||
$table_data = views_fetch_data($this->definition['base']);
|
||||
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
|
||||
@@ -126,7 +128,7 @@ class views_handler_relationship extends views_handler {
|
||||
}
|
||||
|
||||
if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
|
||||
$join = new $def['join_handler'];
|
||||
$join = new $def['join_handler']();
|
||||
}
|
||||
else {
|
||||
$join = new views_join();
|
||||
@@ -137,7 +139,7 @@ class views_handler_relationship extends views_handler {
|
||||
$join->construct();
|
||||
$join->adjusted = TRUE;
|
||||
|
||||
// use a short alias for this:
|
||||
// Use a short alias for this.
|
||||
$alias = $def['table'] . '_' . $this->table;
|
||||
|
||||
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
|
||||
@@ -152,9 +154,10 @@ class views_handler_relationship extends views_handler {
|
||||
/**
|
||||
* You can't groupby a relationship.
|
||||
*/
|
||||
function use_group_by() {
|
||||
public function use_group_by() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,22 +166,44 @@ class views_handler_relationship extends views_handler {
|
||||
* @ingroup views_relationship_handlers
|
||||
*/
|
||||
class views_handler_relationship_broken extends views_handler_relationship {
|
||||
function ui_name($short = FALSE) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return t('Broken/missing handler');
|
||||
}
|
||||
|
||||
function ensure_my_table() { /* No table to ensure! */ }
|
||||
function query() { /* No query to run */ }
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ensure_my_table() {
|
||||
// No table to ensure!
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// No query to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is considered 'broken'
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function broken() { return TRUE; }
|
||||
public function broken() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,11 +2,12 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Relationship for groupwise maximum handler.
|
||||
* Definition of views_handler_relationship_groupwise_max.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Relationship handler that allows a groupwise maximum of the linked in table.
|
||||
*
|
||||
* For a definition, see:
|
||||
* http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html
|
||||
* In lay terms, instead of joining to get all matching records in the linked
|
||||
@@ -58,7 +59,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
/**
|
||||
* Defines default values for options.
|
||||
*/
|
||||
function option_definition() {
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['subquery_sort'] = array('default' => NULL);
|
||||
@@ -72,10 +73,11 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends the relationship's basic options, allowing the user to pick
|
||||
* a sort and an order for it.
|
||||
* Extends the relationship's basic options.
|
||||
*
|
||||
* Allows the user to pick a sort and an order for it.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// Get the sorts that apply to our base.
|
||||
@@ -92,7 +94,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
'#default_value' => !empty($this->options['subquery_sort']) ? $this->options['subquery_sort'] : $this->definition['base'] . '.' . $base_table_data['table']['base']['field'],
|
||||
'#options' => $sort_options,
|
||||
'#description' => theme('advanced_help_topic', array('module' => 'views', 'topic' => 'relationship-representative')) .
|
||||
t("The sort criteria is applied to the data brought in by the relationship to determine how a representative item is obtained for each row. For example, to show the most recent node for each user, pick 'Content: Updated date'."),
|
||||
t("The sort criteria is applied to the data brought in by the relationship to determine how a representative item is obtained for each row. For example, to show the most recent node for each user, pick 'Content: Updated date'."),
|
||||
);
|
||||
|
||||
$form['subquery_order'] = array(
|
||||
@@ -110,8 +112,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
'#default_value' => $this->options['subquery_namespace'],
|
||||
);
|
||||
|
||||
|
||||
// WIP: This stuff doens't work yet: namespacing issues.
|
||||
// WIP: This stuff doesn't work yet: namespacing issues.
|
||||
// A list of suitable views to pick one as the subview.
|
||||
$views = array('' => '<none>');
|
||||
$all_views = views_get_all_views();
|
||||
@@ -120,7 +121,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
// - base must the base that our relationship joins towards
|
||||
// - must have fields.
|
||||
if ($view->base_table == $this->definition['base'] && !empty($view->display['default']->display_options['fields'])) {
|
||||
// TODO: check the field is the correct sort?
|
||||
// @todo check the field is the correct sort?
|
||||
// or let users hang themselves at this stage and check later?
|
||||
if ($view->type == 'Default') {
|
||||
$views[t('Default Views')][$view->name] = $view->name;
|
||||
@@ -152,10 +153,11 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
*
|
||||
* We use this to obtain our subquery SQL.
|
||||
*/
|
||||
function get_temporary_view() {
|
||||
public function get_temporary_view() {
|
||||
views_include('view');
|
||||
$view = new view();
|
||||
$view->vid = 'new'; // @todo: what's this?
|
||||
// @todo What's this?
|
||||
$view->vid = 'new';
|
||||
$view->base_table = $this->definition['base'];
|
||||
$view->add_display('default');
|
||||
return $view;
|
||||
@@ -164,7 +166,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
/**
|
||||
* When the form is submitted, take sure to clear the subquery string cache.
|
||||
*/
|
||||
function options_form_submit(&$form, &$form_state) {
|
||||
public function options_form_submit(&$form, &$form_state) {
|
||||
$cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id'];
|
||||
cache_clear_all($cid, 'cache_views_data');
|
||||
}
|
||||
@@ -175,18 +177,19 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
* generate the subquery when the options are saved, rather than when the view
|
||||
* is run. This saves considerable time.
|
||||
*
|
||||
* @param $options
|
||||
* An array of options:
|
||||
* - subquery_sort: the id of a views sort.
|
||||
* - subquery_order: either ASC or DESC.
|
||||
* @return
|
||||
* @param array $options
|
||||
* An array of options that contains the following items:
|
||||
* - subquery_sort: the id of a views sort.
|
||||
* - subquery_order: either ASC or DESC.
|
||||
*
|
||||
* @return string
|
||||
* The subquery SQL string, ready for use in the main query.
|
||||
*/
|
||||
function left_query($options) {
|
||||
public function left_query($options) {
|
||||
// Either load another view, or create one on the fly.
|
||||
if ($options['subquery_view']) {
|
||||
$temp_view = views_get_view($options['subquery_view']);
|
||||
// Remove all fields from default display
|
||||
// Remove all fields from default display.
|
||||
unset($temp_view->display['default']->display_options['fields']);
|
||||
}
|
||||
else {
|
||||
@@ -195,18 +198,14 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
$temp_view = $this->get_temporary_view();
|
||||
|
||||
// Add the sort from the options to the default display.
|
||||
// This is broken, in that the sort order field also gets added as a
|
||||
// select field. See http://drupal.org/node/844910.
|
||||
// We work around this further down.
|
||||
$sort = $options['subquery_sort'];
|
||||
list($sort_table, $sort_field) = explode('.', $sort);
|
||||
list($sort_table, $sort_field) = explode('.', $options['subquery_sort']);
|
||||
$sort_options = array('order' => $options['subquery_order']);
|
||||
$temp_view->add_item('default', 'sort', $sort_table, $sort_field, $sort_options);
|
||||
}
|
||||
|
||||
// Get the namespace string.
|
||||
$temp_view->namespace = (!empty($options['subquery_namespace'])) ? '_'. $options['subquery_namespace'] : '_INNER';
|
||||
$this->subquery_namespace = (!empty($options['subquery_namespace'])) ? '_'. $options['subquery_namespace'] : 'INNER';
|
||||
$temp_view->namespace = (!empty($options['subquery_namespace'])) ? '_' . $options['subquery_namespace'] : '_INNER';
|
||||
$this->subquery_namespace = (!empty($options['subquery_namespace'])) ? '_' . $options['subquery_namespace'] : 'INNER';
|
||||
|
||||
// The value we add here does nothing, but doing this adds the right tables
|
||||
// and puts in a WHERE clause with a placeholder we can grab later.
|
||||
@@ -217,14 +216,16 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
$base_field = $views_data['table']['base']['field'];
|
||||
$temp_view->add_item('default', 'field', $this->definition['base'], $this->definition['field']);
|
||||
|
||||
// Add the correct argument for our relationship's base
|
||||
// ie the 'how to get back to base' argument.
|
||||
// The relationship definition tells us which one to use.
|
||||
// Add the correct argument for our relationship's base ie the "how to get
|
||||
// back to base" argument; the relationship definition defines which one to
|
||||
// use.
|
||||
$temp_view->add_item(
|
||||
'default',
|
||||
'argument',
|
||||
$this->definition['argument table'], // eg 'term_node',
|
||||
$this->definition['argument field'] // eg 'tid'
|
||||
// For example, 'term_node',
|
||||
$this->definition['argument table'],
|
||||
// For example, 'tid'.
|
||||
$this->definition['argument field']
|
||||
);
|
||||
|
||||
// Build the view. The creates the query object and produces the query
|
||||
@@ -235,7 +236,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
// somewhat so we can get the SQL query from it.
|
||||
$subquery = $temp_view->build_info['query'];
|
||||
|
||||
// Workaround until http://drupal.org/node/844910 is fixed:
|
||||
// Workaround until http://drupal.org/node/844910 is fixed.
|
||||
// Remove all fields from the SELECT except the base id.
|
||||
$fields =& $subquery->getFields();
|
||||
foreach (array_keys($fields) as $field_name) {
|
||||
@@ -245,8 +246,8 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
}
|
||||
}
|
||||
|
||||
// Make every alias in the subquery safe within the outer query by
|
||||
// appending a namespace to it, '_inner' by default.
|
||||
// Make every alias in the subquery safe within the outer query by appending
|
||||
// a namespace to it, '_inner' by default.
|
||||
$tables =& $subquery->getTables();
|
||||
foreach (array_keys($tables) as $table_name) {
|
||||
$tables[$table_name]['alias'] .= $this->subquery_namespace;
|
||||
@@ -264,32 +265,49 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
$where =& $subquery->conditions();
|
||||
$this->alter_subquery_condition($subquery, $where);
|
||||
// Not sure why, but our sort order clause doesn't have a table.
|
||||
// TODO: the call to add_item() above to add the sort handler is probably
|
||||
// @todo The call to add_item() above to add the sort handler is probably
|
||||
// wrong -- needs attention from someone who understands it.
|
||||
// In the meantime, this works, but with a leap of faith...
|
||||
// In the meantime, this works, but with a leap of faith.
|
||||
$orders =& $subquery->getOrderBy();
|
||||
$orders_tmp = array();
|
||||
foreach ($orders as $order_key => $order) {
|
||||
// But if we're using a whole view, we don't know what we have!
|
||||
if ($options['subquery_view']) {
|
||||
list($sort_table, $sort_field) = explode('.', $order_key);
|
||||
}
|
||||
$orders[$sort_table . $this->subquery_namespace . '.' . $sort_field] = $order;
|
||||
unset($orders[$order_key]);
|
||||
// Until http://drupal.org/node/844910 is fixed, $order_key is a field
|
||||
// alias from SELECT. De-alias it using the View object.
|
||||
$sort_table = $temp_view->query->fields[$order_key]['table'];
|
||||
$sort_field = $temp_view->query->fields[$order_key]['field'];
|
||||
$orders_tmp[$sort_table . $this->subquery_namespace . '.' . $sort_field] = $order;
|
||||
}
|
||||
$orders = $orders_tmp;
|
||||
|
||||
// The query we get doesn't include the LIMIT, so add it here.
|
||||
$subquery->range(0, 1);
|
||||
// Clone the query object to force recompilation of the underlying where and
|
||||
// having objects on the next step.
|
||||
$subquery = clone $subquery;
|
||||
|
||||
// Add in Views Query Substitutions such as ***CURRENT_TIME***.
|
||||
views_query_views_alter($subquery);
|
||||
|
||||
// Extract the SQL the temporary view built.
|
||||
$subquery_sql = $subquery->__toString();
|
||||
|
||||
// Replace the placeholder with the outer, correlated field.
|
||||
// Eg, change the placeholder ':users_uid' into the outer field 'users.uid'.
|
||||
// We have to work directly with the SQL, because putting a name of a field
|
||||
// into a SelectQuery that it does not recognize (because it's outer) just
|
||||
// makes it treat it as a string.
|
||||
$outer_placeholder = ':' . str_replace('.', '_', $this->definition['outer field']);
|
||||
$subquery_sql = str_replace($outer_placeholder, $this->definition['outer field'], $subquery_sql);
|
||||
// Replace subquery argument placeholders.
|
||||
$quoted = $subquery->getArguments();
|
||||
$connection = Database::getConnection();
|
||||
foreach ($quoted as $key => $val) {
|
||||
if (is_array($val)) {
|
||||
$quoted[$key] = implode(', ', array_map(array($connection, 'quote'), $val));
|
||||
}
|
||||
// If the correlated placeholder has been located, replace it with the
|
||||
// outer field name.
|
||||
elseif ($val === '**CORRELATED**') {
|
||||
$quoted[$key] = $this->definition['outer field'];
|
||||
}
|
||||
else {
|
||||
$quoted[$key] = $connection->quote($val);
|
||||
}
|
||||
}
|
||||
$subquery_sql = strtr($subquery_sql, $quoted);
|
||||
|
||||
return $subquery_sql;
|
||||
}
|
||||
@@ -301,7 +319,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
*
|
||||
* (Though why is the condition we get in a simple query 3 levels deep???)
|
||||
*/
|
||||
function alter_subquery_condition(QueryAlterableInterface $query, &$conditions) {
|
||||
public function alter_subquery_condition(QueryAlterableInterface $query, &$conditions) {
|
||||
foreach ($conditions as $condition_id => &$condition) {
|
||||
// Skip the #conjunction element.
|
||||
if (is_numeric($condition_id)) {
|
||||
@@ -321,7 +339,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
*
|
||||
* Turns 'foo.bar' into 'foo_NAMESPACE.bar'.
|
||||
*/
|
||||
function condition_namespace($string) {
|
||||
public function condition_namespace($string) {
|
||||
return str_replace('.', $this->subquery_namespace . '.', $string);
|
||||
}
|
||||
|
||||
@@ -330,7 +348,7 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
* This is mostly a copy of our parent's query() except for this bit with
|
||||
* the join class.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
// Figure out what base table this relationship brings to the party.
|
||||
$table_data = views_fetch_data($this->definition['base']);
|
||||
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
|
||||
@@ -374,9 +392,10 @@ class views_handler_relationship_groupwise_max extends views_handler_relationshi
|
||||
$join->construct();
|
||||
$join->adjusted = TRUE;
|
||||
|
||||
// use a short alias for this:
|
||||
// Use a short alias for this.
|
||||
$alias = $def['table'] . '_' . $this->table;
|
||||
|
||||
$this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @todo.
|
||||
* Definition of views_handler_sort.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -21,18 +21,23 @@ class views_handler_sort extends views_handler {
|
||||
/**
|
||||
* Determine if a sort can be exposed.
|
||||
*/
|
||||
function can_expose() { return TRUE; }
|
||||
public function can_expose() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to add the sort to a query.
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
// Add the field.
|
||||
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['order'] = array('default' => 'ASC');
|
||||
@@ -48,7 +53,7 @@ class views_handler_sort extends views_handler {
|
||||
/**
|
||||
* Display whether or not the sort order is ascending or descending
|
||||
*/
|
||||
function admin_summary() {
|
||||
public function admin_summary() {
|
||||
if (!empty($this->options['exposed'])) {
|
||||
return t('Exposed');
|
||||
}
|
||||
@@ -57,18 +62,17 @@ class views_handler_sort extends views_handler {
|
||||
case 'asc':
|
||||
default:
|
||||
return t('asc');
|
||||
break;
|
||||
|
||||
case 'DESC';
|
||||
case 'desc';
|
||||
return t('desc');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic options for all sort criteria
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
if ($this->can_expose()) {
|
||||
$this->show_expose_button($form, $form_state);
|
||||
@@ -84,11 +88,11 @@ class views_handler_sort extends views_handler {
|
||||
/**
|
||||
* Shortcut to display the expose/hide button.
|
||||
*/
|
||||
function show_expose_button(&$form, &$form_state) {
|
||||
public function show_expose_button(&$form, &$form_state) {
|
||||
$form['expose_button'] = array(
|
||||
'#prefix' => '<div class="views-expose clearfix">',
|
||||
'#suffix' => '</div>',
|
||||
// Should always come first
|
||||
// Should always come first.
|
||||
'#weight' => -1000,
|
||||
);
|
||||
|
||||
@@ -131,9 +135,9 @@ class views_handler_sort extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple validate handler
|
||||
* Simple validate handler.
|
||||
*/
|
||||
function options_validate(&$form, &$form_state) {
|
||||
public function options_validate(&$form, &$form_state) {
|
||||
$this->sort_validate($form, $form_state);
|
||||
if (!empty($this->options['exposed'])) {
|
||||
$this->expose_validate($form, $form_state);
|
||||
@@ -142,10 +146,12 @@ class views_handler_sort extends views_handler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple submit handler
|
||||
* Simple submit handler.
|
||||
*/
|
||||
function options_submit(&$form, &$form_state) {
|
||||
unset($form_state['values']['expose_button']); // don't store this.
|
||||
public function options_submit(&$form, &$form_state) {
|
||||
// Don't store this.
|
||||
unset($form_state['values']['expose_button']);
|
||||
|
||||
$this->sort_submit($form, $form_state);
|
||||
if (!empty($this->options['exposed'])) {
|
||||
$this->expose_submit($form, $form_state);
|
||||
@@ -155,7 +161,7 @@ class views_handler_sort extends views_handler {
|
||||
/**
|
||||
* Shortcut to display the value form.
|
||||
*/
|
||||
function show_sort_form(&$form, &$form_state) {
|
||||
public function show_sort_form(&$form, &$form_state) {
|
||||
$options = $this->sort_options();
|
||||
if (!empty($options)) {
|
||||
$form['order'] = array(
|
||||
@@ -166,22 +172,34 @@ class views_handler_sort extends views_handler {
|
||||
}
|
||||
}
|
||||
|
||||
function sort_validate(&$form, &$form_state) { }
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sort_validate(&$form, &$form_state) {
|
||||
}
|
||||
|
||||
function sort_submit(&$form, &$form_state) { }
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sort_submit(&$form, &$form_state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a list of options for the default sort form.
|
||||
* Should be overridden by classes that don't override sort_form
|
||||
*
|
||||
* Should be overridden by classes that don't override sort_form.
|
||||
*/
|
||||
function sort_options() {
|
||||
public function sort_options() {
|
||||
return array(
|
||||
'ASC' => t('Sort ascending'),
|
||||
'DESC' => t('Sort descending'),
|
||||
);
|
||||
}
|
||||
|
||||
function expose_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function expose_form(&$form, &$form_state) {
|
||||
// #flatten will move everything from $form['expose'][$key] to $form[$key]
|
||||
// prior to rendering. That's why the pre_render for it needs to run first,
|
||||
// so that when the next pre_render (the one for fieldsets) runs, it gets
|
||||
@@ -196,18 +214,19 @@ class views_handler_sort extends views_handler {
|
||||
'#required' => TRUE,
|
||||
'#size' => 40,
|
||||
'#weight' => -1,
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide default options for exposed sorts.
|
||||
*/
|
||||
function expose_options() {
|
||||
public function expose_options() {
|
||||
$this->options['expose'] = array(
|
||||
'order' => $this->options['order'],
|
||||
'label' => $this->definition['title'],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,22 +235,44 @@ class views_handler_sort extends views_handler {
|
||||
* @ingroup views_sort_handlers
|
||||
*/
|
||||
class views_handler_sort_broken extends views_handler_sort {
|
||||
function ui_name($short = FALSE) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return t('Broken/missing handler');
|
||||
}
|
||||
|
||||
function ensure_my_table() { /* No table to ensure! */ }
|
||||
function query($group_by = FALSE) { /* No query to run */ }
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ensure_my_table() {
|
||||
// No table to ensure!
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query($group_by = FALSE) {
|
||||
// No query to run.
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item description">' . t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.') . '</div>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the handler is considered 'broken'
|
||||
* Determine if the handler is considered 'broken'.
|
||||
*/
|
||||
function broken() { return TRUE; }
|
||||
public function broken() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -14,7 +14,11 @@
|
||||
* @ingroup views_sort_handlers
|
||||
*/
|
||||
class views_handler_sort_date extends views_handler_sort {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['granularity'] = array('default' => 'second');
|
||||
@@ -22,7 +26,10 @@ class views_handler_sort_date extends views_handler_sort {
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['granularity'] = array(
|
||||
@@ -42,27 +49,32 @@ class views_handler_sort_date extends views_handler_sort {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to add the sort to a query.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
switch ($this->options['granularity']) {
|
||||
case 'second':
|
||||
default:
|
||||
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
|
||||
return;
|
||||
|
||||
case 'minute':
|
||||
$formula = views_date_sql_format('YmdHi', "$this->table_alias.$this->real_field");
|
||||
break;
|
||||
|
||||
case 'hour':
|
||||
$formula = views_date_sql_format('YmdH', "$this->table_alias.$this->real_field");
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
$formula = views_date_sql_format('Ymd', "$this->table_alias.$this->real_field");
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
$formula = views_date_sql_format('Ym', "$this->table_alias.$this->real_field");
|
||||
break;
|
||||
|
||||
case 'year':
|
||||
$formula = views_date_sql_format('Y', "$this->table_alias.$this->real_field");
|
||||
break;
|
||||
@@ -71,4 +83,5 @@ class views_handler_sort_date extends views_handler_sort {
|
||||
// Add the field.
|
||||
$this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,7 +11,11 @@
|
||||
* @ingroup views_sort_handlers
|
||||
*/
|
||||
class views_handler_sort_group_by_numeric extends views_handler_sort {
|
||||
function init(&$view, &$options) {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
|
||||
// Initialize the original handler.
|
||||
@@ -20,9 +24,9 @@ class views_handler_sort_group_by_numeric extends views_handler_sort {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to add the field to a query.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function query() {
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
|
||||
$params = array(
|
||||
@@ -32,7 +36,11 @@ class views_handler_sort_group_by_numeric extends views_handler_sort {
|
||||
$this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order'], NULL, $params);
|
||||
}
|
||||
|
||||
function ui_name($short = FALSE) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function ui_name($short = FALSE) {
|
||||
return $this->get_field(parent::ui_name($short));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,13 +17,20 @@
|
||||
* @ingroup views_sort_handlers
|
||||
*/
|
||||
class views_handler_sort_menu_hierarchy extends views_handler_sort {
|
||||
function option_definition() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['sort_within_level'] = array('default' => FALSE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['sort_within_level'] = array(
|
||||
'#type' => 'checkbox',
|
||||
@@ -33,7 +40,10 @@ class views_handler_sort_menu_hierarchy extends views_handler_sort {
|
||||
);
|
||||
}
|
||||
|
||||
function query() {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->ensure_my_table();
|
||||
$max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH;
|
||||
for ($i = 1; $i <= $max_depth; ++$i) {
|
||||
@@ -51,4 +61,5 @@ class views_handler_sort_menu_hierarchy extends views_handler_sort {
|
||||
$this->query->add_orderby($this->table_alias, $this->field . $i, $this->options['order']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,12 +11,20 @@
|
||||
* @ingroup views_sort_handlers
|
||||
*/
|
||||
class views_handler_sort_random extends views_handler_sort {
|
||||
function query() {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$this->query->add_orderby('rand');
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['order']['#access'] = FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user