Mike thanks for the module it's been great to play with.

I wanted to share a couple of simple Quants that I needed for a site and hopefully help with the documentation. I had a requirement to track the number of a particular type of content (entries into a competition in this case) as well as the number of people who had opted into receiving more information in future (via a CCK field). This was surprisingly easy (although I may have missed a quicker way!). I added these to a custom module in the site.

function custommodule_quants() {
  $quants = array();
  
  $quant = new stdClass;
  $quant->id = 'node_photo';       // Unique ID
  $quant->label = t('Photo Uploads');         // The title of the chart
  $quant->labelsum = TRUE;       // Add the sum of items over time to the title
  $quant->query = "SELECT n.created FROM {content_type_photo} c INNER JOIN {node} n
        ON c.nid = n.nid WHERE n.created >= %d
        ORDER BY n.created DESC";
  $quant->table = 'content_type_photo';    // The database table
  $quant->field = 'created';   // The column that stores the timestamp
  $quant->dataType = 'single';   // Only one datapoint used
  $quant->chartType = 'line';    // The type of chart
  $quants[] = $quant;
  
  $quant = new stdClass;
  $quant->id = 'node_photo_optin';       // Unique ID
  $quant->label = t('Photo Opt Ins');         // The title of the chart
  $quant->labelsum = TRUE;       // Add the sum of items over time to the title
  $quant->query = "SELECT n.created FROM {content_type_photo} c INNER JOIN {node} n
        ON c.nid = n.nid WHERE n.created >= %d AND c.field_optin_value = '1' 
        ORDER BY n.created DESC";
  $quant->table = 'content_type_photo';    // The database table
  $quant->field = 'created';   // The column that stores the timestamp
  $quant->dataType = 'single';   // Only one datapoint used
  $quant->chartType = 'line';    // The type of chart
  $quants[] = $quant;
    
  return $quants;
  
}

Anyway hopefully someone will find these useful and perhaps you could roll them into the docs somewhere.

Comments

mstef’s picture

Nice! You're very welcome. This is a really cool module and I'm looking forward to improving it as much as possible. Have you grabbed the latest dev? I suggest you do as there is an important feature addition and small addition to the API. You'll see that aside from just choosing a time-period, like back 1 month, you can select a custom date range. Because of that, if your custom quant declares $quant->query, you also need to provide $quant->queryCustom, which is a slightly altered version to provide the items within a time period.

Please let me know if you have any questions. Thanks for the additional documentation - other users will definitely find it helpful. After you check out the dev, see if you can update your examples.

geerlingguy’s picture

Thanks for providing the examples, ghazlewood! These are pretty much exactly what I'm looking to use on one of my sites. My only question is this - if we return a $quant, does that simply print the chart at that point, or does this send it to a quant page somewhere? (So, what I guess I'm asking is, could I simply set up a page on the site with the PHP input format and throw this code in to get a chart on that page?).

+1 for including example quants in the documentation somewhere.

[Edit: I've tried putting the code into a page with PHP input filter, but that obviously didn't work, because I was just returning an array (duh). Is there a way to embed a quant in a page, then?]

geerlingguy’s picture

Looking at the module, it seems all the quants are only visible on the /analytics page... I'm opening up #980076: Allow Quant Charts to be Embedded? to see if I can get this more extensible :)

mstef’s picture

All charts that show up on the analytics page are provided via hook_quants(). See quants.quant.inc and API.txt for more information and tons of crazy examples...

If you wanted to just throw up some charts on a page or in a block, see what I wrote on #980076: Allow Quant Charts to be Embedded?.

Let me know if you need help..

mstef’s picture

Status: Active » Postponed (maintainer needs more info)
asb’s picture

I can't find API.txt in the module folder anymore; has it been removed? There is only quant.api.php, but it really doesn't have "tons of crazy examples"...

mstef’s picture

Status: Postponed (maintainer needs more info) » Fixed

Sorry - it's since been updated.

See both quant.api.php and includes/quants.inc. (if you're on 7.x, also check out includes/quant_charts.inc)

If you have any specific questions, please open a new issue.

Status: Fixed » Closed (fixed)

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