Implement hook_project_sort_methods() to allow browsing by the usage data.

Comments

nedjo’s picture

Thanks for taking this on, looks good, I haven't tested.

We could consider shortening the code a bit by avoiding some of the switch statements, e.g.,

return $method == 'usage' ? TRUE : NULL;

For the 'pager' op, I'm thinking we should return TRUE instead of FALSE, to avoid overly long lists.

I imagine as soon as we apply this people are going to want combinations of sort methods, especially category + usage, but that would be for a different patch (and likely would require a fair bit of work, if it were even feasible within the present approach).

drewish’s picture

Status: Needs review » Needs work
StatusFileSize
new7.97 KB

i got the category + usage browsing working. to get the API version specific usage i had to make some changes to the project_page_overview() so that it builds its query first and then merges in those returned by hook_project_sort_methods(). that way i could JOIN against the taxonomy term.

i'm not certain that it's sorting right when is selected as an API version. i suspect for that to work i'd need to be able to see the full query to see if a version had been selected... or, now that i think about it i guess i could just copy and paste the code that project_page_overview() uses:

$version = isset($_SESSION['project_version']) ? $_SESSION['project_version'] : variable_get('project_release_overview', -1);

and setup the query accordingly... though more looking makes it clear that my query is also dependent on variable_get('project_release_browse_versions', 0) being true.

marking this as needs work because of these unknowns but it really does need some reviews.

hunmonk’s picture

i'll ask the same question here that i asked over at http://drupal.org/node/171253 -- isn't this something that views could take care of as we move towards it?

project_page_overview() is a particularly complex and brittle function, and i'm pretty resistant to make changes to it now that might create more weird issues, when we've got a views overhaul on the near horizon.

dww’s picture

Status: Needs work » Postponed

I haven't really thought about how views would interact with these browsing methods. I guess that instead of implementing hook_project_sort_methods(), any module that wants to add its own sorting method will just have to implement its own default view as a subtab. However, it's complicated by taxonomy, since the URL for the view will change depending on if a) taxonomy is enabled and b) the project taxonomy is being used. :( Therefore, again, this is at least weeks, if not a month or more, from being replaced with views.

However, in this case, I'm more inclined to lean towards hunmonk's position. This is absolutely true:

project_page_overview() is a particularly complex and brittle function, and i'm pretty resistant to make changes to it now that might create more weird issues, when we've got a views overhaul on the near horizon.

I'd *hate* to see a browse by usage patch introduce new bugs in this area of the code, and further delay the views conversion and D6 porting. I'm not sure we *need* browse by usage working urgently. Sure, it'd be nice, but so would a 6.0 core release. ;) I'd say http://drupal.org/node/165380 is more important than this in the short term. Just being able to see the statistics at all would be a good start. We can worry about sorting by most popular later.

Therefore, I'm marking this postponed, since I think it really *should* wait for the views-ification, and the complete refactoring (or removal) of this hook.

drewish’s picture

did views support get committed yet? i haven't been following this queue very closely.

aclight’s picture

dww’s picture

Status: Postponed » Closed (duplicate)