it's possible to create a view that list the most flagged nodes in the last x days?

thanks.

Comments

TimelessDomain’s picture

Title: most flagged nodes in the last 30 days » most flagged nodes in the last X # of days
Category: support » feature

there is a flag counter. Though the flag counter does not have a day limitation. You could do most flagged nodes of nodes created in the last 30 days. What you want though is like statistics. Top Flagged Today, Top Flagged All-Time, or Top Flagged over X # of Days. this would be a cool feature, especially if you are using flag to replace voting modules. This would be a feature request then.

brunorios1’s picture

it's exactly what i want!

since it's not possible yet, i created a view that list the top flagged nodes that was flagged in the last 30 days, like a "trending" list...

but the "statistics" feature would be perfect!

thanks.

quicksketch’s picture

This generally is not possible in Flag. You may be able to accomplish it with Views 3, which provides the ability to do COUNT() queries within a View, but it's going to be a very expensive query. Instead of using the Flag Count fields, you'd need to use the Flag Content fields and execute a COUNT() on them. In order to make this performant, you'd want to make a dedicated database table for "week", "month", "year", or whatever, on which you could easily sort such information.

I don't think this will be added as a feature to the Flag module directly, it would be an excellent contrib add-on solution though.

Anonymous’s picture

The core comment module stores three counts: today, week, all-time. Flags could do this.
But a cheaper solution is a View with the flag_count and then restrict by nodes create date > -30 days. Using CCK date. That way only nodes from last month are shown.

brunorios1’s picture

@morningtime

this isn't a "solution"...

most flagged nodes that was CREATED in the last 30 days

is very different of

most flagged nodes in the last 30 days...

jordanmagnuson’s picture

Version: 6.x-2.0-beta5 » 7.x-2.x-dev
Component: Views integration » Miscellaneous

I'm also interested in this, and will probably take a whack at creating a contrib module if no one else has yet.

What I'm thinking is that it would it would be called flag_statistics, and that it would create a db table that would look something like this:

CREATE TABLE flag_statistics (
  fid  SMALLINT UNSIGNED NOT NULL,
  content_id  INT UNSIGNED NOT NULL,
  totalcount  BIGINT UNSIGNED NOT NULL,
  monthcount  MEDIUMINT UNSIGNED NOT NULL,
  weekcount  MEDIUMINT UNSIGNED NOT NULL,
  daycount  MEDIUMINT UNSIGNED NOT NULL,
  last_counted   [timestamp],
  PRIMARY KEY (fid, content_id),
  KEY (totalcount),
  KEY (monthcount),
  KEY (weekcount),
  KEY (daycount),
);

Basically it would just aggregate counts on cron run, similar to core statistics module. Any thoughts?

One issue may be the compound primary key... not sure if views handles compound keys very well?

jordanmagnuson’s picture

Just struck me that it would be much more performant to hook into the flagging process and update the flag_statistics table when a flag is set (then just reset counts during cron, as per core statistics module), rather than counting flags during cron. Counting flags during cron will get very expensive as the number of flags grows towards infinity...

So my question is, is it possible to "hook into" the flagging process, in order to update an arbitrary db table when a user flags some content?

joachim’s picture

Status: Active » Closed (won't fix)

Marking as wontfix.

A flag_statistics module would be best off as a separate contrib project.

fadgadget’s picture

Hi did anythign ever come of this? I was hoping to have a 'most flagged user' view and then display it by week, month, alltime etc

thanks

jordanmagnuson’s picture

I'm still planning to work on this, but it has been bumped down the "to do"...