Question

I would like a link in each of my organic groups where Forena would replicate some of my views and create a pdf document with a page per OG user.

I've looked through the documentation and module but my SQL knowledge is quite primitive and I don't see anything related to using the current NID in queries.

I think the Views Show Query module would allow me to copy the relevant queries into Forena while I learn the SQL.

So my question is, does the above sound possible and would copying the SQL queries that views produces be enough to get me started?

Below is a view using field collections and a screenshot of the views_show_query pasted into Heidi. There are two arguments given to the view. "1422" and "1243".

SELECT field_sts_grades_fc_field_collection_item.nid AS field_sts_grades_fc_field_collection_item_nid, field_collection_item.item_id AS item_id, field_sts_grades_fc_field_collection_item.title AS field_sts_grades_fc_field_collection_item_title, field_sts_grades_fc_field_collection_item__field_data_field_exam_class_reference.field_exam_class_reference_target_id AS field_sts_grades_fc_field_collection_item__field_data_field_, field_sts_grades_fc_field_collection_item__field_data_field_grade_date.field_grade_date_value AS field_sts_grades_fc_field_collection_item__field_data_field__1, field_sts_grades_fc_field_collection_item.created AS field_sts_grades_fc_field_collection_item_created, users_field_data_field_sts_grades_ref__realname.realname AS users_field_data_field_sts_grades_ref__realname_realname, 'node' AS field_data_field_grade_date_node_entity_type, 'field_collection_item' AS field_data_field_sts_grades_ref_field_collection_item_entity, 'field_collection_item' AS field_data_field_grade_decimal_field_collection_item_entity_, 'node' AS field_data_field_exam_class_reference_node_entity_type
FROM 
field_collection_item field_collection_item
LEFT JOIN field_data_field_sts_grades_fc field_data_field_sts_grades_fc ON field_collection_item.item_id = field_data_field_sts_grades_fc.field_sts_grades_fc_value
LEFT JOIN node field_sts_grades_fc_field_collection_item ON field_data_field_sts_grades_fc.entity_id = field_sts_grades_fc_field_collection_item.nid
LEFT JOIN field_data_field_admin_students_class_ref field_sts_grades_fc_field_collection_item__field_data_field_admin_students_class_ref ON field_sts_grades_fc_field_collection_item.nid = field_sts_grades_fc_field_collection_item__field_data_field_admin_students_class_ref.field_admin_students_class_ref_target_id AND (field_sts_grades_fc_field_collection_item__field_data_field_admin_students_class_ref.entity_type = 'entityform' AND field_sts_grades_fc_field_collection_item__field_data_field_admin_students_class_ref.deleted = '0')
LEFT JOIN entityform field_admin_students_class_ref_node ON field_sts_grades_fc_field_collection_item__field_data_field_admin_students_class_ref.entity_id = field_admin_students_class_ref_node.entityform_id
LEFT JOIN field_data_field_sts_grades_ref field_data_field_sts_grades_ref ON field_collection_item.item_id = field_data_field_sts_grades_ref.entity_id AND (field_data_field_sts_grades_ref.entity_type = 'field_collection_item' AND field_data_field_sts_grades_ref.deleted = '0')
LEFT JOIN users users_field_data_field_sts_grades_ref ON field_data_field_sts_grades_ref.field_sts_grades_ref_target_id = users_field_data_field_sts_grades_ref.uid
LEFT JOIN field_data_field_grades_exam_set field_sts_grades_fc_field_collection_item__field_data_field_grades_exam_set ON field_sts_grades_fc_field_collection_item.nid = field_sts_grades_fc_field_collection_item__field_data_field_grades_exam_set.entity_id AND (field_sts_grades_fc_field_collection_item__field_data_field_grades_exam_set.entity_type = 'node' AND field_sts_grades_fc_field_collection_item__field_data_field_grades_exam_set.deleted = '0')
LEFT JOIN field_data_field_exam_class_reference field_sts_grades_fc_field_collection_item__field_data_field_exam_class_reference ON field_sts_grades_fc_field_collection_item.nid = field_sts_grades_fc_field_collection_item__field_data_field_exam_class_reference.entity_id AND (field_sts_grades_fc_field_collection_item__field_data_field_exam_class_reference.entity_type = 'node' AND field_sts_grades_fc_field_collection_item__field_data_field_exam_class_reference.deleted = '0')
LEFT JOIN field_data_field_grade_date field_sts_grades_fc_field_collection_item__field_data_field_grade_date ON field_sts_grades_fc_field_collection_item.nid = field_sts_grades_fc_field_collection_item__field_data_field_grade_date.entity_id AND (field_sts_grades_fc_field_collection_item__field_data_field_grade_date.entity_type = 'node' AND field_sts_grades_fc_field_collection_item__field_data_field_grade_date.deleted = '0')
LEFT JOIN realname users_field_data_field_sts_grades_ref__realname ON users_field_data_field_sts_grades_ref.uid = users_field_data_field_sts_grades_ref__realname.uid
WHERE (( (field_sts_grades_fc_field_collection_item__field_data_field_grades_exam_set.field_grades_exam_set_target_id = '1422') AND (field_sts_grades_fc_field_collection_item__field_data_field_exam_class_reference.field_exam_class_reference_target_id = '1243') ))
ORDER BY field_sts_grades_fc_field_collection_item__field_data_field_ ASC, field_sts_grades_fc_field_collection_item__field_data_field__1 ASC, field_sts_grades_fc_field_collection_item_created ASC, users_field_data_field_sts_grades_ref__realname_realname ASC, field_data_field_sts_grades_ref.field_sts_grades_ref_target_id ASC

enter image description here

Views Screenshot

Was it helpful?

Solution

IMO the approach to use the Views Show Query module as you wrote is definitely a valid approach to get you started. Even though I've not (yet) used this module to produce such queries, this part from the module's project page may need an extra hint about how to further "massage" your query (to further improve it):

... the module adds 'User ID to show final query' field in views preview form. You must enter numeric user ID in this field to view the real SQL query.

More specifically, I would try to transform that "user id" in that query in a "query parameter" to be used by Forena, similar to what you can already see in this SQL query that comes with the Forena samples (note the (:state) in this sample query):

select * from user_distribution WHERE 
  state in (:state)
  order by city, state

In your own site where you have Forena installed, you can find this query at relative path admin/structure/forena/data/sampledb.distribution/edit.

And to see the power of this query with Forena parameters, go have a look at the Users in cities in state Illinois sample, which in your own site you can find via relative path /reports/sample.user_distribution_simple?state=IL.

The interesting/relevant part here is the ?state=IL at the end of it: change it to any other (valid) state like CA, FL, etc, and see what happens (answer: similar report, for the state you asked for).

With that, I think your question (challenge) is reduced to finding a way to find a way to use these kinds of relative paths (with the query strings to indicate report parameter values, and use those parameters in your query parameters also.

Ps: If you refine your question with more specific paths, a samples SQL, the parms you have in mind etc, I might be able to further refiine my answer about also.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top