diff -urp -N favorite_nodes_orig/favorite_nodes.module favorite_nodes/favorite_nodes.module --- favorite_nodes_orig/favorite_nodes.module 2008-09-13 23:49:19.000000000 +0200 +++ favorite_nodes/favorite_nodes.module 2008-09-13 23:24:11.000000000 +0200 @@ -574,126 +573,11 @@ function theme_favorite_nodes_view_table return $output; } -function favorite_nodes_views_tables() { - $tables['favorite_nodes'] = array( - 'name' => 'favorite_nodes', - 'provider' => 'internal', - 'join' => array( - 'left' => array( - 'table' => 'node', - 'field' => 'nid', - ), - 'right' => array( - 'field' => 'nid', - ), - ), - 'fields' => array( - 'last' => array( - 'name' => t('Favorite Nodes: Time Added'), - 'sortable' => TRUE, - 'handler' => views_handler_field_dates(), - 'option' => 'string', - 'help' => t('Display the date/time the favorite node was added.'), - ), - 'count' => array( - 'name' => t('Favorite Nodes: Count'), - 'handler' => 'favorite_nodes_handler_user_count', - 'help' => t('Number of times this node was added to favorites by any user.'), - 'sortable' => FALSE, - 'notafield' => TRUE, - ), - ), - 'sorts' => array( - 'last' => array( - 'name' => t('Favorite Nodes: Time Added'), - 'help' => t('Sort by the date/time the favorite node was added.'), - ), - ), - 'filters' => array( - 'uid' => array( - 'field' => 'uid', - 'name' => t('Favorite Nodes: User ID'), - 'operator' => 'views_handler_operator_eqneq', - 'handler' => 'views_handler_filter_favorite_nodes', - 'list-type' => 'select', - 'list' => array( - 'uid_current' => t('Currently Logged In User'), - 'uid_all' => t('All Users'), - ), - 'help' => t('This allows you to filter based on favorites nodes.'), - ), - 'last' => array( - 'name' => t('Favorite Nodes: Time Added'), - 'operator' => 'views_handler_operator_gtlt', - 'value' => views_handler_filter_date_value_form(), - 'handler' => 'views_handler_filter_timestamp', - 'option' => 'string', - 'help' => t('This filter allows favorite nodes to be filtered by the date and time the user added them. Enter dates in the format: CCYY-MM-DD HH:MM:SS. Enter \'now\' to use the current time. You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now.'), - ), - ), - ); - return $tables; -} - -function views_handler_filter_favorite_nodes($op, $filter, $filterinfo, &$query) { - global $user; - - $table_data = _views_get_tables(); - $joininfo = $table_data['favorite_nodes']['join']; - $joininfo['type'] = 'inner'; - $table_num = $query->add_table('favorite_nodes', FALSE, 1, $joininfo); - $table = $query->get_table_name('favorite_nodes', $table_num); - $query->set_distinct(); - - switch ($filter['value']) { - case 'uid_current': - if ($user->uid) { - $query->add_where("$table.uid = $user->uid"); - } - break; - - case 'uid_all': - // No special processing needed, since we do an inner join anyways - break; - } -} - -function favorite_nodes_views_arguments() { - $args['user_id'] = array( - 'name' => t("Favorite Nodes: User ID"), - 'handler' => 'favorite_nodes_handler_argument_uid', - 'help' => t('User ID for Favorite node.'), +/** + * Implementation of hook_views_api(). + */ +function favorite_nodes_views_api() { + return array( + 'api' => 2, ); - return $args; -} - -function favorite_nodes_handler_argument_uid($op, &$query, $argtype, $arg = '') { - switch ($op) { - case 'sort': - // no luck using add_orderby method. - $query->orderby[] = ' num_nodes '. $argtype; - break; - case 'filter': - list($and_or, $uids) = _views_break_phrase($arg); - $and_or = drupal_strtoupper($and_or); - // Similar to taxonomy AND/OR query. - - if ($and_or == 'OR') { - $query->ensure_table('favorite_nodes'); - $cond = array_fill(0, count($uids), "favorite_nodes.uid = %d"); - $query->add_where(implode(" $and_or ", $cond), $uids); - } - else { - foreach ((array)$uids as $uid) { - $num = $query->add_table('favorite_nodes'); - $tablename = $query->get_table_name('favorite_nodes', $num); - $query->add_where("$tablename.uid = %d", $uid); - } - } - break; - } -} - -function favorite_nodes_handler_user_count($fieldinfo, $fielddata, $value, $data) { - return db_result(db_query("SELECT COUNT(*) FROM {favorite_nodes} WHERE nid = %d", $data->nid)); } \ No newline at end of file diff -urp -N favorite_nodes_orig/favorite_nodes.views.inc favorite_nodes/favorite_nodes.views.inc --- favorite_nodes_orig/favorite_nodes.views.inc 1970-01-01 01:00:00.000000000 +0100 +++ favorite_nodes/favorite_nodes.views.inc 2008-09-14 19:32:46.000000000 +0200 @@ -0,0 +1,77 @@ + array( + 'path' => drupal_get_path('module', 'favorite_nodes') .'/includes', + ), + 'handlers' => array( + /*'favorite_nodes_handler_argument_uid' => array( + 'parent' => 'views_handler_argument_numeric', + ),*/ + 'favorite_nodes_handler_user_count' => array( + 'parent' => 'views_handler_field', + ), + ), + ); +} + +/** + * Implementation of hook_views_data(). + */ +function favorite_nodes_views_data() { + $data['favorite_nodes']['table']['group'] = t('Favorite Nodes'); + + $data['favorite_nodes']['table']['join'] = array( + 'node' => array( + 'field' => 'nid', + 'left_field' => 'nid', + ), + 'users' => array( + 'field' => 'uid', + 'left_field' => 'uid', + ), + ); + + $data['favorite_nodes']['last'] = array( + 'title' => t('Time Added'), + 'help' => t('Display the date/time the favorite node was added.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + 'help' => t('This filter allows favorite nodes to be filtered by the date and time the user added them. Enter dates in the format: CCYY-MM-DD HH:MM:SS. Enter \'now\' to use the current time. You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now.'), + ), + ); + + $data['favorite_nodes']['count'] = array( + 'title' => t('Count'), + 'help' => t('Number of times this node was added to favorites by any user.'), + 'real field' => 'nid', + 'field' => array( + 'handler' => 'favorite_nodes_handler_user_count', + 'click sortable' => FALSE, + ), + ); + + $data['favorite_nodes']['uid'] = array( + 'title' => t('User ID'), + 'help' => t('This allows you to filter based on favorites nodes.'), + 'filter' => array( + 'handler' => 'views_handler_filter_user_current', + ), + 'argument' => array( + // use favorite nodes handler? + 'handler' => 'views_handler_argument_numeric', + ), + ); + + return $data; +} \ No newline at end of file diff -urp -N favorite_nodes_orig/includes/favorite_nodes_handler_argument_uid.inc favorite_nodes/includes/favorite_nodes_handler_argument_uid.inc --- favorite_nodes_orig/includes/favorite_nodes_handler_argument_uid.inc 1970-01-01 01:00:00.000000000 +0100 +++ favorite_nodes/includes/favorite_nodes_handler_argument_uid.inc 2008-09-14 19:33:12.000000000 +0200 @@ -0,0 +1,28 @@ +orderby[] = ' num_nodes '. $argtype; + break; + case 'filter': + list($and_or, $uids) = _views_break_phrase($arg); + $and_or = drupal_strtoupper($and_or); + // Similar to taxonomy AND/OR query. + + if ($and_or == 'OR') { + $query->ensure_table('favorite_nodes'); + $cond = array_fill(0, count($uids), "favorite_nodes.uid = %d"); + $query->add_where(implode(" $and_or ", $cond), $uids); + } + else { + foreach ((array)$uids as $uid) { + $num = $query->add_table('favorite_nodes'); + $tablename = $query->get_table_name('favorite_nodes', $num); + $query->add_where("$tablename.uid = %d", $uid); + } + } + break; + } +} \ No newline at end of file diff -urp -N favorite_nodes_orig/includes/favorite_nodes_handler_user_count.inc favorite_nodes/includes/favorite_nodes_handler_user_count.inc --- favorite_nodes_orig/includes/favorite_nodes_handler_user_count.inc 1970-01-01 01:00:00.000000000 +0100 +++ favorite_nodes/includes/favorite_nodes_handler_user_count.inc 2008-09-14 18:04:37.000000000 +0200 @@ -0,0 +1,6 @@ +nid)); + } +} \ No newline at end of file