I'm customizing the Vote Up/Down module so that each Organic Group has it's own Vote Up/Down subsection (only members of that particular group can vote on a story), and I'm creating some views to tally the results. I plan on having hundreds of groups, so it's not feasible to create a separate view for each group. Is there a way to create a dynamic view that gets the group id from the group context and supplies that gid to the view?

My problem is with the sorting. I have to supply the gid as part of the tablename for the sort. The gid in this example is 1464, but for other groups the gid would obviously be different. Is there any way to supply the gid dynamically?

$view->sort = array (
array (
'tablename' => 'votingapi_cache_1464_points_count',
'field' => 'value',
'sortorder' => 'DESC',
'options' => '',
),
);

Any ideas?

Here is the complete source of the view:

$view = new stdClass();
$view->name = 'top_stories';
$view->description = 'Lists the top stories for a particular group.';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = '';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = 'There are no stories for this group.';
$view->page_empty_format = '1';
$view->page_type = 'teaser';
$view->url = 'top-stories/$arg';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->sort = array (
array (
'tablename' => 'votingapi_cache_1464_points_count',
'field' => 'value',
'sortorder' => 'DESC',
'options' => '',
),
);
$view->argument = array (
array (
'type' => 'gid',
'argdefault' => '1',
'title' => '',
'options' => '',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'storylink',
),
),
);
$view->exposed_filter = array (
);
$view->requires = array(votingapi_cache_1464_points_count, node);
$views[$view->name] = $view;

Comments

eaton’s picture

It looks like you're using a custom VotingAPI tag for each Group. VotingAPI constructs its Views pseudo-tables by appending the tag and value type.

If you're experienced tweaking Views, it would be possible to put together a custom table entry that leaves the tag as a displayable field rather than filtering it inherently...

It's a bit tricky due to the way the filtering, etc works.

--
Lullabot! | Eaton's blog | VotingAPI discussion

--
Eaton — Partner at Autogram

finkster’s picture

I'll look into that. I'm also looking into creating the view programatically as another option. Not sure if I'm barking up the wrong tree on that, but I guess it's worth investigating.

jasonwhat’s picture

I did something similar once where I wanted to show group content by nodetype on group home page. I can't find the code now, but it is possible to have a snippet that inserts a view and pulls the gid from the nid of the page "arg2" I think. So you would just create one view to sort by voting and pass the argument to it. If you find a solution, please post.

amirboles’s picture

how could i sort content items by there points score ? i can't find it as a field in the view and i don't know wt to do ?

sbordage’s picture

You need to add a relationship.
Choose User then votes.
After that edit your sort criterion.
There is a new item "vote results" near the end of the drop down list.

Regards
Stephane