Whew. I managed to get this to a releasable point today. It's missing functionality. It's a little scattered in some places (though I think I actually did a pretty good job on that). This is the module I was discussing in http://drupal.org/node/35814.

This Module is Alpha Test. This means it's not suitable for general use. It is suitable for running some tests against, but it'll help a lot if you understand Drupal fairly well. I'm looking for commentary about the design and about the as-yet-undesigned (though I think there's clearly a direction) API and about features it should provide that I've missed.

The module is available at http://drupal.logrus.com/files. What follows is the readme.

OVERVIEW

The views module provides a flexible method for Drupal administrators to control 
how lists of content is presented. Traditionally, Drupal has hard-coded most of 
this, particularly in how taxonomy and tracker lists are formatted.

This tool is essentially a sort-of smart query builder that, given enough 
information, can build the proper query, execute it, and display the results. It 
has four modes, plus a special mode, and provides an impressive amount of 
functionality from these modes.

1) Title List.
   The simplest mode is the title list. Given the parameters set in the view, 
the module will pull up a title list and present them to the user. 

2) Table
   It can provide information in a table. The user can pick and choose what 
fields are presented, in what order they are presented, and how they are 
presented. An example of this format is the classic tracker, as in 
http://drupal.org/tracker

3) Teaser List
   The module can provide node teasers. This is actually just as simple as 
providing titles.

4) Full Nodes
   The module can provide lists of full nodes. I'm not sure how this would be 
useful, but I can imagine somebody would want it.

5) Summaries
   The fifth, special mode, exists only when the view expects arguments and does 
not get them. In this special 'summary' mode, it provides a list of what is 
available, with links to the more specific list. For example, many blogging 
sites offer archival content by month. If a view has the form of 
http://www.example.com/archive/YYYYMM, and the argument isn't specified, the 
summary would present all months available.

FEATURES

Views provides almost too many features in order to please the user.

1) Title
   The title of a view can be specified.

2) Header
   Each view can have an arbitrary amount of filtered text preceding it. This 
header can be a summary, instructions, or a description of what the user is 
seeing.

3) Paging
   Views can be set to use the pager, and each view can have its own page size. 
Views can also opt not to use the pager, and limit the number of records 
retrieved.

4) Sorting
   Views can be sorted by multiple fields, in either ascending or descending 
order.

5) Filtering
   Views can be filtered to published status, front page status, node type, 
taxonomy type and vocabulary. In the future, views can be filtered to 
arbitrary module fields.

6) Block or Page presentation
   Views can be presented either as blocks or pages; the same view can actually 
be used as both. Views can have menu entries.

7) Views can accept arbitrary arguments from the URL, and use these as filters.
   Views can accept arguments such as User IDs, Node IDs, dates and taxonomy 
terms.

Because this module is currently in Alpha Testing, the TODO list is fairly 
extensive.

NOTES

The module is implemented using only 4.6 features for now. I'd like to keep it 
this way until it's ready, and then jump it to 4.7, mostly because I don't have 
any 4.7 systems right now, and I don't want to take the time to upgrade or 
create one until there's a stable release.

I probably wrote this thing a little too quickly. Some parts are better than 
others, and it's hard for me to tell which parts are which at this point.

The module is currently named 'nodequery'. I'll rename it to 'views' (or 
something else if a better name comes up) but I've had trouble having the Right 
Name come to me.

TODO

*  Add changed field to prevent multiple admins from saving views simultaneously
*  Check queries for injection attacks, especially on the URL!
*  Check for enabled modules everywhere
*  Expose an API so modules can provide table and sorting and special
   field-handling information.
*  Extend table field info: Let admin change header name. Add 'move up, move 
   down, move to top, move to bottom' buttons to make re-ordering easier. Add 
special handling for non-field data, such as new comments, node changed.
*  Re-factor sorting info so that it goes into the table data and is assembled,
   rather than being hard-coded as it is now.
*  Allow tables to be click-sorted.
*  Actually implement the _block and _menu hooks so that views can expose them.
*  Optional [MORE] link in blocks that are also page views.
*  The edit/add form could be prettier.


Comments

eaton’s picture

...and installing on my test site.

This is really a huge piece of functionality, and should make answering quite a few 'how do I..?' questions LOADS easier. Bravo!

--
Jeff Eaton | Click Here To Find Out Why Drupal "Sucks"

--
Eaton — Partner at Autogram

merlinofchaos’s picture

The module currently keeps an array of tables it knows about, for two primary purposes. This table informs the query generator how tables are linked to the node table, so that when a table is added to the field, it can find a path and ensure all tables in that path are part of the join.

The second purpose is to know what fields are available for the table view. (The 3rd, unimplemented purpose will be to inform it what sorting criteria are available, and beyond that it will probably also gain the filter criteria and the non-field data, such as how many new comments, whether or not a post has been updated; i.e, calculations. Currently the system doesn't handle them).

One of the big purposes of the API will be to expose this data so that modules that have node-linked tables can expose that data and administrators can take advantage of it in their views without having to make code changes.

Another purpose of the API will be to provide pre-generated default views that the system can know about, and modules can actively use. If an administrator then wants to change a view, by editing one of the default views a database record will be created and this edited view will now be used.

Ideally I would like to only collect some of this data when modules are refreshed, though I'm not yet sure how to do that, of it's possible. If anybody knows, it could save me a little research, but it is (I hope) no big deal.

I propose hook_viewapi($op, ...) to handle these.

Possible $ops I can think of:

  • tables -- get table info the module exposes
  • defaultviews -- get the default views the module exposes
  • handlefield -- Many, many fields in the table view require special handling. For example, node titles are turned into links to the node. User names are formatted using format_name. Dates and times have their own special formatting. Many things may be stored in the database as a number which then needs to be translated into something else. This API would let modules tell the view system that a field needs some kind of special translation, and then it could do it.

For using default views, the module should expose a method, such as view_default_view($name, ...) which would display the view. In that method, it would check the database to see if the user has created a custom version of the view; if so load it. If not, load the default view by that name, and run it through the parser and spit out output. Once that is ready, modules such as the forum could then expose default views and provide them to the user. Modules that have existing content can put in a if (module_exists('view')) and if it's there, provide the customizable view, and if not, retain the existing code.

I think I have the theming wrong currently. I'm not sure offhand if this works, but I think it does: if (!theme('view_$view->name')) { ... do default theming ... } -- that way each view could have its own function. If done in two layers, users could then override all views with one function (which would probably be messy but hey, some people don't mind that) or they could pick just a couple of views and override them.

Finally, I have few options on filtering. I am thinking that for the filters, I want to allow users to choose table, field, comparison (one of >, >=, =, <, <=, in, between) and some data for the comparison. It would probably have to be smart enough to validate that the comparison actually works.

Any thoughts on all of this? Is this something suitable for core? It doesn't do exactly what Dries was suggesting in a previous post (it does a great deal more, but in a different way than suggested).

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

merlinofchaos’s picture

Oh! An additional feature I've had at the back of my mind but forgot to put in the list is to provide alternate node views.

For example, there are hacks to the image module to allow a 'next' and 'previous' link on the node view. Except that if that node appears in multiple lists, the buttons may not be appropriate.

Constructing a node URL in the form of node/NID/view/VIEWNAME could provide that kind of functionality, as well as ensuring the breadcrumb trail is appropriate to the view. (Once the view has a proper breadcrumb trail, that is.)

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

jasonwhat’s picture

This is a great module to give users more control over taxonomy overviews, such as mysite.com/taxonomy/term/tid, but will only be fully useful if they are able to work with standard breadcrumbs. For example, a user could creates a custom view for the taxonomy term cats, but whenever someone clicks a node term id link labelling that node, or uses standard menus, or breadcrumbs to go to that taxonomy terms overview page they'll end up at the old standard view, not the newly created view.

merlinofchaos’s picture

That's why I have specialized node views on the desired feature list, and one of the things it would do is rewrite the breadcrumb trail. The breadcrumb trail is one of the things that feature would address, and the more I think about it, the more important I think that is.

I believe it should be possible to completely override the internal taxonomy views with this module as well. I haven't had a chance to actually try that yet.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

scroogie’s picture

This sounds like a very good idea. I will test it as soon as it is converted to HEAD.

alexandreracine’s picture

I wont test this yet, but the idear to be able to sort watever nodes, watever manner I would like sounds good.

This could even be use with other modules?

For example, I use the article module here.
http://www.salsamontreal.com/montrealsalsa/article/am%C3%A9riques/canada...

...but these are not sorted alphabeticaly. You can see the titles...
Academia...
Salsa Ac...
San Tropez...
Salsa on...

So with the "view" module, I could show the same previews of the nodes?

+1 for the idear :)

Alexandre Racine

www.gardienvirtuel.com Sécurité informatique conformité, consultation et plus

www.salsamontreal.com Salsa, évènements, La référence salsa à Montréal

merlinofchaos’s picture

Yes, it could do that.

Looking at your example shows me something I haven't thought about, though. Breadcrumb trails. Going to have to figure out how to deal with that little issue.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

alexandreracine’s picture

This is gonna sound a little weird, but where can I found some info on breadcrumbs? I have seen this word before, but can't figure out -*exactly*- what it is. And the forums gives me some random results...

Is it this that permits to have a structure in the taxonomy system? For example root-trunk-tree-branch-leave-worm? (or Canada-Ontario-Toronto-my street-my house).

Alexandre Racine

www.gardienvirtuel.com Sécurité informatique, conformité, consultation, etc

www.salsamontreal.com La référence salsa à Montréal

merlinofchaos’s picture

The breadcrumb is the path one uses to get to a given page. In most themes it's at the top in the form of

Home >> Page >> Page

With each one being links up the chain. The name comes from the trail of bread crumbs used by Hansel & Gretel to find their way home.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

alexandreracine’s picture

So I would add that this is very important then :)

Also... in your point 5...

5) Filtering
   Views can be filtered to published status, front page status, node type, taxonomy type and vocabulary. In the future, views can be filtered to arbitrary module fields.

Let's say I have two taxonomies... one about club type (techno, R&B, lounge, etc), and another one about locations (New York, London, Montreal, etc).

Would the point 5 be able to create a view in the range of this phrase? : "Show me all !techno! clubs in the world (all locations) but not in !London!"

Alexandre Racine

www.gardienvirtuel.com Sécurité informatique, conformité, consultation, etc

www.salsamontreal.com La référence salsa à Montréal

merlinofchaos’s picture

No, but it'd be a good idea, actually. It should be added to the interesting feature list. Right now it supports a list of taxonomy terms that can be ANDed together, or can be OR'd together, but it doesn't support a NOT. This would be a good idea.

Vaguely related, there's a couple of things that are a little bit difficult to do with taxonomy and generated queries, but are not impossible. One of them is dealing properly with taxonomy hierachy (say I have a recipe vocabulary, and in that hierachy I have Meat and under that I have Beef, Pork, Chicken and Poultry; if a node is Poultry it is sort of also Meat, but not directly. You have to look into the hierarchy to see that.) That's another important feature that'd be nice. Gotta figure out how, though.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

alexandreracine’s picture

You need some kind of recurcive algorithm to do that then...

if not bottom of hierachy search for "this taxonomy"
   in this taxonomy do operations (AND OR NOT)
   go to parent taxonomy
endif

That works if... there is a hierachy.

And cache would greatly improve performance :)

Alexandre Racine

www.gardienvirtuel.com Sécurité informatique, conformité, consultation, etc

www.salsamontreal.com La référence salsa à Montréal

merlinofchaos’s picture

Yes, and putting all of that in one query is a pain. It's doable, but you need to specify a maximum depth, at the very least, which is going to be confusing.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

merlinofchaos’s picture

Has anyone had a chance to actually play with this module? I'm still hopeful for comments on actual usage, if not code comments (which I understand will be somewhat time consuming as the code is already relatively complex).

And I'm still hoping someone working on core will tell me if this is a right path/wrong path type of thing.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

eaton’s picture

I'd love to work with it, but at the moment I'm digging around in a lot of 4.7/HEAD work. As it uses the old FormsAPI, I can't run the module on those sites. I'll try to get it on a 4.6.3 installation when I have the chance, but until then I'm juggling the new stuff...

--
Jeff Eaton | Click Here To Find Out Why Drupal "Sucks"

--
Eaton — Partner at Autogram

Netmonger’s picture

Hey - this module is totally cool! I had to make a slight adjustment however to get it to work: in the schema file, there is a column named 'argumentdefaults', but in the function _nodequery_view_fields funtion it is referred to by 'argumentdefault' - without the 's'.

I modified the schema and it works great!

Nice work! :)

merlinofchaos’s picture

Whoops! That's a silly error on my fault. One that slipped through because I mostly use alter table rather than reimporting the schema.

In the next rev that'll be separated out into its own table anyway.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

merlinofchaos’s picture

I have placed this module in CVS. It's been updated with the right name (yay) and in CVS it:

  • Actually now exposes blocks and menu items
  • Supports all the functionality required to emulate example.com/tracker

I am still working toward having a full API to expose. Required steps to doing that:

1) Genericizing the sorting, so instead of it being hardcoded it acquires data from the tables construct.
2) Adding generic filtering
3) Adding multiple default views. A module should be able to expose a default view of a given name, and utilize that view. If the admin does nothing, that view gets used as set up, but the admin can go and 'edit' that view (which will then create it in the database) and now the modified view will be used in place of the default view. It'll need an option to be able to reset the view to its base, of course.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]