Commit 0766852e authored by merlinofchaos's avatar merlinofchaos

Fixed the "extra" portion of views_join which was totally borken. Added "has...

Fixed the "extra" portion of views_join which was totally borken. Added "has new content" field shows new/updated.
parent 2d3898d7
......@@ -147,9 +147,9 @@ class views_join {
$output = " $this->type JOIN {" . $this->table . "} $table[alias] ON $left[alias].$this->left_field = $table[alias].$this->field";
// Tack on the extra.
if (isset($extra)) {
foreach ($extra as $field => $value) {
$output .= " AND $table[alias].$this->field";
if (isset($this->extra)) {
foreach ($this->extra as $field => $value) {
$output .= " AND $table[alias].$field";
if (is_array($value) && !empty($value)) {
$output .= " IN ('". implode("','", $value) ."')";
}
......
......@@ -512,14 +512,12 @@ class view extends views_db_object {
$items = array();
if ($query) {
$replacements = module_invoke_all('views_query_substitutions', $this);
foreach ($replacements as $src => $dest) {
$query = str_replace($src, $dest, $query);
$count_query = str_replace($src, $dest, $this->build_info['count_query']);
$query = str_replace(array_keys($replacements), $replacements, $query);
$count_query = str_replace(array_keys($replacements), $replacements, $this->build_info['count_query']);
if (is_array($args)) {
foreach ($args as $id => $arg) {
$args[$id] = str_replace($src, $dest, $arg);
}
if (is_array($args)) {
foreach ($args as $id => $arg) {
$args[$id] = str_replace(array_keys($replacements), $replacements, $arg);
}
}
......
......@@ -308,7 +308,7 @@ function node_views_data() {
$data['node_revisions']['table']['base'] = array(
'field' => 'vid',
'title' => t('Node revisions'),
'help' => t('Node revisions allow you to list revisions to nodes.'),
'help' => t('Node revisions allow you to list revisions of nodes.'),
);
// For other base tables, explain how we join
......@@ -427,6 +427,9 @@ function node_views_data() {
// ----------------------------------------------------------------------
// History table
// We're actually defining a specific instance of the table, so let's
// alias it so that we can later add the real table for other purposes if we
// need it.
$data['history_user']['table']['group'] = t('Node');
// Explain how this table joins to others.
......@@ -443,8 +446,12 @@ function node_views_data() {
);
$data['history_user']['timestamp'] = array(
'title' => t('Has new content'),
'field' => array(
'handler' => 'views_handler_field_history_user_timestamp',
'help' => t('Show a marker if the node has new or updated content.'),
),
'filter' => array(
'title' => t('Has new content'),
'help' => t('Show only nodes that have new content.'),
'handler' => 'views_handler_filter_history_user_timestamp',
),
......@@ -541,6 +548,11 @@ class views_handler_field_node extends views_handler_field {
);
}
/**
* Render whatever the data is as a link to the node.
*
* Data should be made XSS safe prior to calling this function.
*/
function render_link($data, $values) {
if (!empty($this->options['link_to_node'])) {
return l($data, "node/" . $values->{$this->aliases['nid']}, array('html' => TRUE));
......@@ -728,6 +740,72 @@ class views_handler_field_node_revision_link_delete extends views_handler_field_
}
}
class views_handler_field_history_user_timestamp extends views_handler_field_node {
function construct() {
parent::construct();
global $user;
if ($user->uid) {
$this->additional_fields['created'] = array('table' => 'node', 'field' => 'created');
$this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed');
if (module_exists('comment') && !empty($this->options['comments'])) {
$this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp');
}
}
}
function options(&$options) {
parent::options($options);
$options['comments'] = FALSE;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
if (module_exists('comments')) {
$form['comments'] = array(
'#type' => 'checkbox',
'#title' => t('Check for new comments as well'),
'#default_value' => !empty($this->options['comments']),
);
}
}
function query() {
// Only add ourselves to the query if logged in.
global $user;
if (!$user->uid) {
return;
}
parent::query();
}
function render($values) {
// Let's default to 'read' state.
// This code shadows node_mark, but it reads from the db directly and
// we already have that info.
$mark = MARK_READ;
global $user;
if ($user->uid) {
$last_read = $values->{$this->field_alias};
$created = $values->{$this->aliases['created']};
$changed = $values->{$this->aliases['changed']};
$last_comment = module_exists('comments') ? $values->{$this->aliases['last_comment']} : 0;
if (!$last_read && $created > NODE_NEW_LIMIT) {
$mark = MARK_NEW;
}
elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) {
$mark = MARK_UPDATED;
}
elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) {
$mark = MARK_UPDATED;
}
}
return $this->render_link(theme('mark', $mark), $values);
}
}
/**
* Argument handler to accept a node type.
*
......@@ -931,7 +1009,7 @@ class views_handler_filter_node_type extends views_handler_filter_in_operator {
/**
* Filter for new content
*/
class views_handler_filter_history_user_timestamp {
class views_handler_filter_history_user_timestamp extends views_handler_filter {
function options_form(&$form, &$form_state) {
// Remove all the normal options, including exposing.
// @todo: make it so we can expose this filter as a checkbox.
......@@ -949,8 +1027,8 @@ class views_handler_filter_history_user_timestamp {
$limit = time() - NODE_NEW_LIMIT;
$field = "$this->table_alias.$this->real_field";
$this->ensure_my_table();
$field = "$this->table_alias.$this->real_field";
$node = $this->query->ensure_table('node');
if (module_exists('comment')) {
......
......@@ -199,6 +199,13 @@ class views_handler_argument_user_uid extends views_handler_argument {
}
}
/**
* Allow replacement of current userid so we can cache these queries
*/
function user_views_query_substitutions($view) {
global $user;
return array('***CURRENT_USER***' => intval($user->uid));
}
/**
* @}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment