I am not sure how to ask this question, but I hope I will be making myself clear.

We are building a CMS-like site for the most part, but the customer also wants the capability of adding a prices table for goods that can be consumed by a user on a daily basis.

So far, there is a custom content type 'user daily report' whose purpose is to store info of the likes of:

user1 - 2015/05/01 - 1 breakfast - 1 lunch - 3 drinks

At the end of the month, I have to be able to provide a report which summarizes how much the user has to be charged for his/her accumulated consumption.

I'm not sure how to exactly phrase my question here, since I'm fairly new to Drupal. Therefor I'll try to describe my requirement / question using some language I'm more familiar with:

  • Have Drupal create a products table, a prices table (foreign key-ed to the products table), and add a couple fields to the daily report content type (product_id, amount).

  • In order to create the monthly report, I think I would just use a grouping SQL query (with group by and sum).

The above is not very 'drupalish'. But at the same time, I fail to see how the products and prices tables could be implemented using content types.

To make the question more precise, it is actually a 2 parts question, being:

1) I am not sure that putting the products and prices info inside of Drupal is best achieved by using custom content types. What is the best way to go for you people when faced to this type of functionality?

2) What is the best way of extracting/summarizing the info at the end of the month? I have struggled my way using the views module, but being myself much of an 'old school programmer' I am not necessarily confident that all I need can be achieved by using 'views'.

With all that in mind, my question is: what's the best approach to achieve this goal in a way that integrates well with 'the Drupal way'?

Any hint on the topic is most welcome!

Thanks In Advance!

PS. I've tried the entity-references + views_calc way with a wee prototype. In general, I feel satisfied with the tests I've carried out.

What we need to be able to implement is several tables of products/prices available to different sets of users. All of it based on organic groups (we are using an openatrium distribution).

Using an entity-reference as a field in the users content type, and then adding the necessary relationship when using the views module, I can get what I need. Plus with the Views Calc module I get the summarized stuff.

I still have to try it all in our fully fledged openatrium dev install and see what happens when associating products/prices to groups. But so far, seems promising.

I've learned that my original version of the question didn't fit the questions policy because it was too loose and prone to answers based in personal opinion vs facts (and sorry about that). Maybe the edited version will prevent it from getting closed?

I'll choose Pierre's answer as right, as it has certainly been helpful.

  • 2
    but being myself much of an 'old school programmer' I am not necessarily confident that all I need can be achieved by using 'views'. I used to think the same thing, shunned Views for years. It was a stupid decision, you get so much just done for you. If you're using Drupal entities (nodes, users, taxonomy, etc), you should almost certainly be using Views to gather your data. Might mean you need to read up on how it work internally so you can make whatever small manipulations you need to, but broad-strokes, you're likely re-inventing the wheel if you don't use Views – Clive May 1 '15 at 9:51
  • This question is too broad and subjective: We cannot tell you the best way to do something. – kiamlaluno May 1 '15 at 12:34
  • 1
    Thanks a lot, Clive; that's exactly what I feel: if a go and create a module that takes care of the non-entities new tables, I'll be somehow missing the point of using drupal altogether... I've fought my way with views, but still nowhere near comfortable with them, I'm afraid.... Thanks kiamlaluno; I know. I didn't even know how to start the question. I'll try to create a small functioning prototype following Pierre's directions and tell you all how it goes – Jaime May 1 '15 at 14:18

Your question consists of 2 questions ... I'll use the same numbers to answer them.

1. Alternatives to using Custom Content types

a) Use Drupal Entities (Option 1)

Use the Entity Construction Kit (ECK) module to create 'entities' (= fieldable things ...) like Products and Prices. For each of those entities use "fields" for each of the columns you mentioned. Should you run into fields such as dates, you would have to add modules such as date also.

For the "foreign keys" use the Entity reference module (possibly some related modules of it also, extending its functionality, as mentioned on the ECK project page) and/or the References module (cfr. 'node_reference' and 'user_reference' as contained in CCK for D6).

Maybe modules like Display Suite or Panels could help to enhance the look and feel of it all also?

b) Use custom tables and/or an external database (Option 2)

Custom tables are tables you create yourself, in the same Drupal database. External Databases are databases that are different from the Drupal database, which are typically in formats such as Oracle, PostGress, MS Sql, MySQL, SQLite, some PDO compliant DBMS.

Using this alternative, you can use the Forena module for reporting about the data from within a Drupal site (as further explaining within "reporting" below also). To perform updates (delets, inserts, etc), you'd use your own tools that you'd prefer for the DBMS of your choice. Same for creating the tables, etc.

2. Reporting

Consider using modules such as (either one, or both, depending on your requirements):

Disclosure: I'm a (co-)maintainer of some of the modules mentioned,
I hope this does not violate the site's policy on self-promotion.

  • 1
    I have been using the views module, I don't know the Forena module. I guess that the problem lies less in the view that extracts the info, but rather in how to set the products/prices info inside of the Drupal app. I somehow don't feel that the best approach would be to create 2 news custom content types; and am not sure how to stablish relationships between the 'daily report' and 'products' tables. – Jaime May 1 '15 at 9:02
  • 1
    Merci Pierre for your help so far, I'll be taking a look at all of it. We are already using panels, views, entity reference and panels. I had already been pointed to views_calc. I guess that all boils down to how to store the products and prices 'tables' inside of Drupal. – Jaime May 1 '15 at 9:35
  • Thanks for the edit, but know that there is no reason to include that "edit" itself (just create a revised version of your question) ... Add another comment whenever you're finished looking at these things, eg if you've other comments, etc. – Pierre.Vriens May 1 '15 at 9:36
  • Based on your last comment, I further refined my answer related to "how to store those tables". note: consider also including that comment in your further edited question ... – Pierre.Vriens May 1 '15 at 10:07
  • 1
    Pierre, as explained in my last edit to the question, I'll try in deep the modules you pointed me to. Thanks! – Jaime May 1 '15 at 17:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.