I took a stab at book.views.inc mostly to try to get my head around how things work, and I had an apparently working file by the end, so here it is.

Comments

merlinofchaos’s picture

Oh this is great! Thank you for the work!

Some comments:

1) Views 2 has a new relationship system. We should use that instead of redefining the 'node' table for the book parent. This means that what we want to do is define the 'book' table, and then a relationship on that table that links from the book table back to the node table. That lets us pull up *any* node information about the book by adding the relationship, and we can chain them.

2) Likewise, the 'top level book' would also be a relationship.

The only existing example of relationship is in nodereference.module, but I'm pretty sure that the default views_handler_relationship would be sufficient to describe this relationship.

This may mean that Views 2 might have to support the D6 menu system's fields, though I don't know that Views 2 will yet be better enough at hierarchy than Views 1. I guess for now we can put the weight in menu_links, but alias the table since menu.views.inc would 'own' the menu_links table directly.

Given all that, I think this file will get very, very short.

john morahan’s picture

StatusFileSize
new2.01 KB

Thanks for the advice, that sounds like a much better approach.

Here's a second attempt. It is indeed much shorter.

merlinofchaos’s picture

Status: Needs review » Active

I re-organized the code to my liking, and committed this. I also added an important change to the relationship handler to allow inner joins on relationships, which books seem to need.

There are things missing at this point, I think:

1) There needs to be an easy way to filter nodes to just top level books. I can get something like this using an argument and a relationship but that's just a summary view and isn't going to be sufficient for all uses, I don't think.

2) This may or may not be possible, but if there were a way to sort by depth + weight then we could easily do a hierarchy. I have to assume there's a way because the menu system knows how to do this, but I'm not all that familiar with that system and I fear it may be beyond Views' capabilities. That said, it's worth looking into; if we can get the query right, then a style handler to handle hierarchy could also translate into taxonomy (though there's *definitely* no way to do taxonomy sorted by depth without an additional module) and that could make a lot of people very happy.

I'm leaving this active until we've at least discussed points 1 and 2, but there is a book.views.inc committed.

john morahan’s picture

Status: Active » Needs review
StatusFileSize
new2.57 KB

Well there's a {menu_links}.depth field that we could make available, that would allow filtering on depth=1 to get top level books, as well as sorting by depth - although I must admit I don't understand how that would help with displaying a hierarchy. There are also the p1, p2, ..., p9 fields, which you can order by (all at once) to get things sorted in DFS order which may be useful.

john morahan’s picture

StatusFileSize
new2.58 KB

Would be better without the magic number 9 obviously.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed! Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

sevi’s picture

Status: Closed (fixed) » Active

I'm sorry for reopening this closed issue. I thought it will be easier to follow the context if I append my issue to this one.

I'm currently trying to enable views to organize books. For that I wrote DraggableViews and the "DraggableViews Book handler" which work great so far.

When I tried books in views the first time I read at the help text of the "Book: Hierarchy" sort criteria:

The order of pages in the book hierarchy. If you want the exactly right order, remember to sort by weight, too.

So I played around until I noticed that ordering by "Book: Weight" as the second sort criteria doesn't affect anything. So I dig deeper and found out that the menu system saves the mlid in the column "p?", where ? is the depth in the hierarchy. That means that the sort criteria "Book: Hierarchy" already defines an unique order.

I don't have any idea so far how to get the weight into the sort criterias... I'm just throwing this out there :)

Greetings,
sevi

dawehner’s picture

Status: Active » Closed (fixed)

I'm sorry for reopening this closed issue. I thought it will be easier to follow the context if I append my issue to this one.

Sry but its not, read http://drupal.org/node/57199 :)

If you have read this, you will be also able to provide more informations :)

Feel free to open a support issue, thx.

sevi’s picture

Well, next try at #576386: Book: It's useless to sort by Book: Weight?.

Sry but its not, read http://drupal.org/node/57199 :)

Why do you want me to read this? I didn't get the point at all O_o.