After appending my issue to #240850: book.views.inc, where "dereine" told me to open a new issue I finally arrived here :)

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

When I tried to list 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 sorted by weight. It took a while until I noticed that ordering by "Book: Weight" as the second sort criteria doesn't effect 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.

So now, somehow, is it possible to sort the book pages by weight too?

Greetings,
sevi

I'm not sure about the category because I still think that I missed something. So I chose "support request".

Comments

dawehner’s picture

Thx :)
As far as i understand the problem it would work, if you could display the items as hierachical menu. You could do this with theming, and grouping by book parent nid.

dawehner’s picture

Component: Views Data » book data

.

sevi’s picture

Yes,
but can you confirm that 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.

is wrong?

That's actually the question of this issue.

Thanks for the quick response.
Greetings,
sevi

sevi’s picture

Status: Active » Closed (fixed)

Okay, I think I finally understood the message of your last post.

All what the help message tells me is that I should sort by weight too, however I accomplish this. It doesn't tell me explicitly to sort by weight as the second sort criteria but it rather tells me to order it on my own, e.g. with ksort in my theme.

I gonna close this issue now because I don't agree with my starting post any longer.
Thanks for your help and patience,
greetings,
sevi

john morahan’s picture

Category: support » bug
Status: Closed (fixed) » Needs review
StatusFileSize
new3.29 KB
new841 bytes

This whole thing is my fault. I tried it out before submitting the patch that added that help text, and somehow it seemed to work... I guess I must not have tested it very thoroughly.

It is indeed possible to sort by weight+title as well as hierarchy, but the resulting queries are butt-ugly and, in all likelihood, painfully slow (though I haven't actually benchmarked). It's probably better to do this in the theme layer as dereine suggests, if you can. Nonetheless, patch attached for your amusement.

sevi’s picture

First I want to thank you for investing time for this issue.

It is indeed possible to sort by weight+title as well as hierarchy, but the resulting queries are butt-ugly and, ..

Indeed. I've never before seen such an error message:
user warning: Out of sort memory; increase server sort buffer size query: SELECT node.nid AS nid, ..

I haven't tried your patch yet but I guess it won't work. The first time you ORDER BY book_menu_links_weight ASC the whole order might already be unique (or at least it would lead to an unwanted order). So all following sort criterias (p2, p3, p4,..) would be useless (or would not lead to the desired results).

I don't have much time at the moment but I want to explore the deep blue menu system soon :)

Thanks again,
greetings,
sevi

john morahan’s picture

I feel a bit silly defending this hideous patch, but I'm pretty sure it does produce the correct order (assuming it doesn't kill your database server in the process). It does NOT order by book_menu_links_weight - it joins another copy of menu_links for each p? and orders by the weights of those copies. For example:

SELECT node.nid AS nid,
   node.title AS node_title,
   menu_links.weight AS menu_links_weight,
   menu_links.link_title AS menu_links_link_title,
   book_menu_links.p1 AS book_menu_links_p1,
   menu_links2.weight AS menu_links2_weight,
   menu_links2.link_title AS menu_links2_link_title,
   book_menu_links.p2 AS book_menu_links_p2,
   menu_links3.weight AS menu_links3_weight,
   menu_links3.link_title AS menu_links3_link_title,
   book_menu_links.p3 AS book_menu_links_p3,
   menu_links4.weight AS menu_links4_weight,
   menu_links4.link_title AS menu_links4_link_title,
   book_menu_links.p4 AS book_menu_links_p4,
   menu_links5.weight AS menu_links5_weight,
   menu_links5.link_title AS menu_links5_link_title,
   book_menu_links.p5 AS book_menu_links_p5,
   menu_links6.weight AS menu_links6_weight,
   menu_links6.link_title AS menu_links6_link_title,
   book_menu_links.p6 AS book_menu_links_p6,
   menu_links7.weight AS menu_links7_weight,
   menu_links7.link_title AS menu_links7_link_title,
   book_menu_links.p7 AS book_menu_links_p7,
   menu_links8.weight AS menu_links8_weight,
   menu_links8.link_title AS menu_links8_link_title,
   book_menu_links.p8 AS book_menu_links_p8,
   menu_links9.weight AS menu_links9_weight,
   menu_links9.link_title AS menu_links9_link_title,
   book_menu_links.p9 AS book_menu_links_p9
 FROM node node 
 LEFT JOIN book book ON node.nid = book.nid
 LEFT JOIN menu_links book_menu_links ON book.mlid = book_menu_links.mlid
 LEFT JOIN menu_links menu_links ON book_menu_links.p1 = menu_links.mlid
 LEFT JOIN menu_links menu_links2 ON book_menu_links.p2 = menu_links2.mlid
 LEFT JOIN menu_links menu_links3 ON book_menu_links.p3 = menu_links3.mlid
 LEFT JOIN menu_links menu_links4 ON book_menu_links.p4 = menu_links4.mlid
 LEFT JOIN menu_links menu_links5 ON book_menu_links.p5 = menu_links5.mlid
 LEFT JOIN menu_links menu_links6 ON book_menu_links.p6 = menu_links6.mlid
 LEFT JOIN menu_links menu_links7 ON book_menu_links.p7 = menu_links7.mlid
 LEFT JOIN menu_links menu_links8 ON book_menu_links.p8 = menu_links8.mlid
 LEFT JOIN menu_links menu_links9 ON book_menu_links.p9 = menu_links9.mlid
 WHERE node.type in ('book')
   ORDER BY menu_links_weight ASC, menu_links_link_title ASC, book_menu_links_p1 ASC, menu_links2_weight ASC, menu_links2_link_title ASC, book_menu_links_p2 ASC, menu_links3_weight ASC, menu_links3_link_title ASC, book_menu_links_p3 ASC, menu_links4_weight ASC, menu_links4_link_title ASC, book_menu_links_p4 ASC, menu_links5_weight ASC, menu_links5_link_title ASC, book_menu_links_p5 ASC, menu_links6_weight ASC, menu_links6_link_title ASC, book_menu_links_p6 ASC, menu_links7_weight ASC, menu_links7_link_title ASC, book_menu_links_p7 ASC, menu_links8_weight ASC, menu_links8_link_title ASC, book_menu_links_p8 ASC, menu_links9_weight ASC, menu_links9_link_title ASC, book_menu_links_p9 ASC
sevi’s picture

My apologies,
to tell you the truth I've never before built a SQL-query like this. I didn't no that you can sort on a copy of the same table at the same time. Next time I'll be more careful before I tell someone that he's wrong :\

However, as you said before, this query needs too many resources. Thanks for describing your patch to me though, so I've learned more about MySQL/SQL.
Greetings,
sevi

merlinofchaos’s picture

I'm...not sure what to do with this. I'm scared to even look at a patch named 'ungodly'. This isn't seriously here for consideration of actually adding to Views, is it?

john morahan’s picture

Hehe... of course not :) The help text patch is serious. The ungodly one is just a proof of concept that I found amusing and thought I would share.

merlinofchaos’s picture

Status: Needs review » Fixed

Got it. Help patch applied to all branches. Thanks!

Status: Fixed » Closed (fixed)

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