Hi @all,
I'd like to build a view that displays the month name an year of the created dates of nodes (similar to the summary output when using the created_year_month argument). So I created a field handler that queries the month and year of the pos date. I realized this by adding a formula field in the query() method like this:
$formula = views_date_sql_format('Y-m', $this->table_alias . '.' . $this->real_field); // real field is 'created'
$params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
$this->field_alias = $this->query->add_field(NULL, $formula, 'my_alias', $params);
Unfortunately I am unable to group by this field to display a count besides the output of all nodes that were posted in that specific month/year. Can anybody give me some advice how to do this?
I'd appreciate any help.
If you need further information, please let me know, as I am really stuck with this problem.
Thanx in advance & cheers
hctom
Comments
Comment #1
dawehnerCan't you groupby the generated alias?
Yeah it's kind of important to know what you want to achieve.
What this aggregation-function of views3 does is to add GROUPBY/aggregate functions to the query.
But you can just aggregate or groupby in sql. But what you seems to want to do is what views does with "groupby" in the style settings. Did you tryed them already?
Comment #2
hctomIt's a little more complicated ;)
What I want to achieve is something like an archive listing. The post dates should be grouped in a listing like this (using the aggregation setting "Group results together" for the field handler):
... and this listing itself should be grouped like this (with the display style grouping setting):
2011
2010
...
So I added a normal "Content: Post date field" with a custom format ("Y") for the style grouping setting and my own field handler that should group the post dates by month/year.
When I add a $this->query->add_groupby('my_alias') manually in the query() method of the field handler, it works... but shouldn't this happen automatically? And I didn't want to add this grouping call by default, because I also may like to use my field handler e.g. in a table to display the month/year for each node separately.
I will provide all the necessary code and the view as soon as possible, so you can have a deeper look on what I'd like to achieve.
Comment #3
hawkeye217 commentedLooking to do the exact same thing. Would love to see your code and the view...
Comment #4
hctomHi,
I finally made it to package my code into a module (attached to this post). This module contains the necessary handlers and a default view which provides a view page with the archive. Just add some content (e.g. with devel generate) to see that the grouping is not really what I expected :-(
If you have any questions or need more information, feel free to post a reply.
Thanx in advance & cheers
hctom
Comment #5
dawehnerCan you be more specific how this is not what you want?
Comment #6
hctom@dereine:
Please see my comment #2. It has everything what I'm trying to achieve... or do you need more info?
Comment #7
dawehnerWell you can do this by using the views groupby feature.
Comment #8
hctomEhm.. did you instal my demo module? I don't think so ;-)
I need two groupings... one for the year and then all posts grouped/aggregated by month for the record count behind e.g. "March 2011"... and as far as I know, thats not possible with views so far, or am I wrong.
So if this is really possible, I'd appreciate a view export describing how to do.
Thanks in advance & cheers
hctom
Comment #9
kars-t commentedHi
I am closing this issue to clean up the issue queue. Feel free to reopen the issue if there is new information and the problem still resides. If not please make sure you close your issues that you don't need any more.
Maybe you can get support from the local user group. Please take a look at this list at groups.drupal.org.