Commit 37e45d17 authored by merlinofchaos's avatar merlinofchaos

55320 by eaton: statistics module goodness. Really good stuff here!"

parent 9a8cbdaa
......@@ -39,8 +39,8 @@ function book_views_tables() {
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
'table' => 'book',
'field' => 'parent'
),
'right' => array(
'field' => 'nid'
......@@ -57,6 +57,12 @@ function book_views_tables() {
'help' => t('Display the title of the parent node'),
),
),
'sorts' => array(
'title' => array(
'name' => t('Book: Parent Title'),
'help' => t('Sort by the title of the parent node'),
),
),
);
return $tables;
......@@ -80,16 +86,18 @@ function views_handler_arg_book_parent($op, & $query, $argtype, $arg = '') {
switch ($op)
{
case 'summary' :
$query->ensure_table("book");
$query->add_field("parent", "book");
$query->add_field("title", "node");
$query->ensure_table("book_parent_node");
$query->add_field("nid");
$fieldinfo['field'] = "book.parent";
$query->add_field("parent", "book");
$query->add_field("title", "book_parent_node");
$query->add_field("nid", "book_parent_node", "pnid");
$query->add_where("book_parent_node.nid IS NOT NULL");
$fieldinfo['field'] = "book_parent_node.title";
return $fieldinfo;
break;
case 'sort':
$query->add_orderby('book', 'weight', $argtype);
$query->add_orderby('node', 'title', $argtype);
$query->add_orderby('book_parent_node', 'title', $argtype);
break;
case 'filter' :
$query->ensure_table("book");
......@@ -97,7 +105,7 @@ function views_handler_arg_book_parent($op, & $query, $argtype, $arg = '') {
$query->add_where("book.vid = node.vid");
break;
case 'link' :
return l($query->title, "$arg/$query->nid");
return l($query->title, "$arg/$query->pnid");
case 'title' :
if ($query)
{
......
......@@ -482,8 +482,8 @@ function views_handler_arg_fulldate($op, &$query, $argtype, $arg = '') {
function views_handler_arg_nid($op, &$query, $argtype, $arg = '') {
switch($op) {
case 'summary':
$query->add_field("title");
$query->add_field('nid');
$query->add_field("title");
$fieldinfo['field'] = 'node.nid';
return $fieldinfo;
case 'sort':
......
......@@ -6,7 +6,57 @@
*/
function statistics_views_tables() {
$tables['node_counter'] = array(
'name' => 'node_counter',
'provider' => 'internal', // won't show up in external list.
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
'fields' => array(
'totalcount' => array(
'name' => t('Node: Total Hits'),
'sortable' => true,
'help' => t('This will display the number of times a node has been read.'),
),
'daycount' => array(
'name' => t('Node: Recent Hits'),
'sortable' => true,
'help' => t('This will display the number of times a node has been read recently.'),
),
'timestamp' => array(
'name' => t('Node: Last Hit Time'),
'sortable' => true,
'handler' => array(
'views_handler_field_date_small' => t('As Short Date'),
'views_handler_field_date' => t('As Medium Date'),
'views_handler_field_date_large' => t('As Long Date'),
'views_handler_field_since' => t('As Time Ago'),
),
'help' => t('Display the time the node was last read.'),
),
),
'sorts' => array(
'totalcount' => array(
'name' => t('Node: Total Hits'),
'help' => t('This allows you to sort by the number of times a node has been read.'),
),
'daycount' => array(
'name' => t('Node: Recent Hits'),
'help' => t('This allows you to sort by the number of times a node has been read recently.'),
),
'timestamp' => array(
'name' => t('Node: Last Hit Time'),
'help' => t('This allows you to sort by the time a node was last read.'),
),
),
);
return $tables;
}
function statistics_views_arguments() {
......@@ -14,5 +64,241 @@ function statistics_views_arguments() {
}
function statistics_views_default_views() {
$view = new stdClass();
$view->name = 'popular_recent';
$view->description = 'Nodes sorted by recent page-views';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'recent popular content';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'popular/latest';
$view->use_pager = TRUE;
$view->nodes_per_page = '20';
$view->menu = TRUE;
$view->menu_title = '';
$view->menu_tab = TRUE;
$view->menu_tab_default = TRUE;
$view->menu_weight = '-1';
$view->block = TRUE;
$view->block_title = 'recent popular content';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '5';
$view->block_more = '1';
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node_counter',
'field' => 'daycount',
'sortorder' => 'DESC',
'options' => '',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'type',
'label' => 'type',
'sortable' => '1',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => 'title',
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
),
array (
'tablename' => 'users',
'field' => 'name',
'label' => 'author',
'sortable' => '1',
),
array (
'tablename' => 'node',
'field' => 'created',
'label' => 'created',
'handler' => 'views_handler_field_date_small',
'sortable' => '1',
),
array (
'tablename' => 'node_counter',
'field' => 'daycount',
'label' => 'recent hits',
'sortable' => '1',
'defaultsort' => 'DESC',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->requires = array(node_counter, node, users);
$views[$view->name] = $view;
$view = new stdClass();
$view->name = 'popular_alltime';
$view->description = 'Nodes sorted by total page-views';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'all-time popular content';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'popular/alltime';
$view->use_pager = TRUE;
$view->nodes_per_page = '20';
$view->menu = TRUE;
$view->menu_title = '';
$view->menu_tab = TRUE;
$view->menu_tab_default = FALSE;
$view->menu_weight = '1';
$view->block = TRUE;
$view->block_title = 'all-time popular content';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '5';
$view->block_more = '1';
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node_counter',
'field' => 'totalcount',
'sortorder' => 'DESC',
'options' => '',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'type',
'label' => 'type',
'sortable' => '1',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => 'title',
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
),
array (
'tablename' => 'users',
'field' => 'name',
'label' => 'author',
'sortable' => '1',
),
array (
'tablename' => 'node',
'field' => 'created',
'label' => 'created',
'handler' => 'views_handler_field_since',
'sortable' => '1',
),
array (
'tablename' => 'node_counter',
'field' => 'totalcount',
'label' => 'reads',
'sortable' => '1',
'defaultsort' => 'DESC',
),
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->requires = array(node_counter, node, users);
$views[$view->name] = $view;
return $views;
}
function theme_views_view_popular_recent($view, $type, $nodes) {
if ($type == 'block') {
$fields = _views_get_fields();
foreach ($nodes as $node) {
foreach ($view->field as $field) {
if ($field['fullname'] == 'node.title') {
$item = _views_handle_field($fields, $field, $node);
}
if ($field['fullname'] == 'node_counter.daycount') {
$item .= ' <span class="popular-content-count">(' . _views_handle_field($fields, $field, $node) . ')</span>';
}
}
$items[] = $item;
}
$output = theme('item_list', $items);
return "<div class='view' id='view-$view->name'>$output</div>\n";
}
else {
return theme('views_view', $view, $type, $nodes);
}
}
function theme_views_view_popular_alltime($view, $type, $nodes) {
if ($type == 'block') {
$fields = _views_get_fields();
foreach ($nodes as $node) {
foreach ($view->field as $field) {
if ($field['fullname'] == 'node.title') {
$item = _views_handle_field($fields, $field, $node);
}
if ($field['fullname'] == 'node_counter.totalcount') {
$item .= ' <span class="popular-content-count">(' . _views_handle_field($fields, $field, $node) . ')</span>';
}
}
$items[] = $item;
}
$output = theme('item_list', $items);
return "<div class='view' id='view-$view->name'>$output</div>\n";
}
else {
return theme('views_view', $view, $type, $nodes);
}
}
\ No newline at end of file
......@@ -537,6 +537,7 @@ function views_view_block($vid) {
* without paging on.
*/
function views_build_view($type, $view, $args = array(), $use_pager = false, $limit = 0, $page = 0) {
$GLOBALS['current_view'] = &$view;
$viewtype = ($type == 'block' ? $view->block_type : $view->page_type);
......
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