category_views with default views
| Project: | Category |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Here's a way to use category_views with default views.
I'm putting this as a feature request, but it's more like an use case.
Someone may ask for it while searching for views performance tweaks.
1. In the database:
Modified category_views table.views_id to make it like view_view.name
Data type changed to varchar(32).
2. In function category_views_category()
Appended a new function category_views_get_default_views()
This loads more options to the selection box.
3. In function category_views_cont_update()
Changed both db_query statements to use \'%s\' instead of %d for $node->views_for_cats
4. In function category_views_get_views()
Changed vid with name.
Note that views_get_view() accepts both number and name so this is extra.
5. Made a new function and tentatively called it category_views_get_default_views()
<?php
function category_views_get_default_views() {
$views = array();
$result = db_query("SELECT name FROM {view_view}");
while ($view = db_fetch_object($result)) {
$used[$view->name] = true;
}
$default_views = _views_get_default_views();
foreach ($default_views as $view) {
if (!$used[$view->name]) {
$views[$view->name] = $view->description;
}
}
return $views;
}
?>6. Updated a few containers to begin using the chosen default view by name.

#1
According to feedback on views performance issues, categories shouldnt be called by number but by name.
http://drupal.org/node/259479#comment-974175
I suppose that instead of just making a hack, the list can be made to show all the views available by name from the beginning.
#2
Oh, I just implemented quite the same in 6.x port of category_views, and I never saw this issue before... So after all, the name vs. ID, and default views, was a problem on 5.x too.
I'm not sure about status for this issue, as this is for 5.x, where it wasn't fixed - but it most probably won't by fixed now that 5.x era is slowly expiring. Anyway, the other issue is: #370641: Port category_views to D6
#3
This workaround was limited to appending the default views after the regular views in the category views select box.
Changing the hardcoded usage wasn't trivial so it will be worth giving a look to it during the porting to 6.x.
#4
The 6.x port already waits in the queue (#370641: Port category_views to D6) - I dropped the query, so the proposed 6.x version only gets the list of all views through Views API - there's a bit of a trick about that, but certainly it works for both default and database-stored views, and calls them all by name. I tested that carefully, as I'm moving all my views into a site-specific module now. It waits for Jaza's review now.
#5
Agreed, this issue originally aimed to use views from a module as well.
Generating the list is half of the work, the other changes are for getting category views to grab the results.
This worked for 5.x and views 1 without further problem, may need revision for views 2.
#6
To clarify: On the other issue, I already have it - it works quite well for me (both module-based and database-stored views). All we do now is waiting for Jaza to either commit that one, or voice further concerns (there's no official category_views port for 6.x currently, but I rolled the port together with this fix into a single patch). Take a look if you like, and comment on any doubts you might have. ;-)
I didn't close this issue as duplicate only because it's supposed to be about 5.x.