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

CommentFileSizeAuthor
#4 hctarchive.zip4.51 KBhctom

Comments

dawehner’s picture

Can't you groupby the generated alias?

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?

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?

hctom’s picture

It'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):

  • January 2011 (1)
  • February 2011 (5)
  • March 2011 (10)
  • ...

... and this listing itself should be grouped like this (with the display style grouping setting):

2011

  • January 2011 (1)
  • February 2011 (5)
  • March 2011 (10)
  • ...

2010

  • January 2010 (2)
  • February 2010 (3)
  • March 2010 (4)
  • ...

...

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.

hawkeye217’s picture

Looking to do the exact same thing. Would love to see your code and the view...

hctom’s picture

StatusFileSize
new4.51 KB

Hi,

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

dawehner’s picture

. Just add some content (e.g. with devel generate) to see that the grouping is not really what I expected :-(

Can you be more specific how this is not what you want?

hctom’s picture

@dereine:

Please see my comment #2. It has everything what I'm trying to achieve... or do you need more info?

dawehner’s picture

Well you can do this by using the views groupby feature.

hctom’s picture

Ehm.. 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

kars-t’s picture

Status: Active » Fixed

Hi

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.

Status: Fixed » Closed (fixed)

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