Report card for students, automatic calculation and teacher input
- This topic has 5 replies, 2 voices, and was last updated 2 years, 8 months ago by
Long Nguyen.
-
AuthorPosts
-
July 25, 2022 at 9:07 AM #37174
Jorge
ParticipantI've got an interesting use case, and I'm still wrapping my head around it.
A school wants to have its report/grade cards online, semi-automated and calculated.
The idea is, that the teacher fills the data on a form, and the system outputs the data plus some calculations (averages and such), being able to visualize it on single and multiple views (for siblings).I'm thinking of setting a CPT per subject/course and having a post per student enrolled in it, with a Group/Repeater per month/cycle. And then on a View, display a table with all the subjects the student is enrolled in (multiple CPTs data in the same view, to display the different subjects), and use Twig to calculate the averages where needed.
What I'm not sure about is if it's possible to "filter" the posts to display only the ones that match a specific field to the logged user (WP User ID).
Does that sound feasible? Or am I complicating things too much?
July 25, 2022 at 9:56 PM #37184Long Nguyen
ModeratorHi Jorge,
Yes, it is possible to filter posts by some parameters. You can follow this documentation to know how to use the WP Query (function
get_posts()
) in View https://docs.metabox.io/extensions/mb-views/#running-php-functions
And please note that, it's really hard to query posts by subfield value (in a group). Please use the top field if you want to query posts by custom field value.August 14, 2022 at 2:18 AM #37481Jorge
ParticipantThanks Long, yeah I moved everything to a top field.
I'm trying right now to achieve something but I feel I'm not grasping something (could it be a relationship?).
There are two CTPs: One for records/scores, the other for weighing. The idea is to do some operations between the two as follows: 'Homework score * Homework weigh = Homework final.'
However, if I do a query to create a for loop to display each entry of the Records, I do not know how to access the weighs.On a side note, would it be better to keep this (which I feel it's a bit complex) in a View or would it be better to move it to a PHP file?
August 14, 2022 at 7:48 AM #37487Long Nguyen
ModeratorHi Jorge,
You can create a relationship between CPT Record and Weighting, then set the relation when editing the Record post.
To query Weighting posts in the loop of Record, you can create a nested loop by following this topic https://support.metabox.io/topic/query-in-relationship-post-per-page/#post-29149
Using PHP or Twig (in View) code is fine but you need to have the basic knowledge to understand how it works.
August 17, 2022 at 9:35 AM #37536Jorge
ParticipantThat's great Long, thank you. I got the nested loop working properly.
The tricky part for me was setting the relationship 'from' because I wasn't sure where does that come from, but from the context of the queries made sense.{% set weigh_args = { post_type: 'weight', nopaging: true, relationship: {id: 'weight_grades', from: grade.ID} } %}
Since I will be using fields from both loops across the entire view. I've got a question regarding best practices.
Is it better to get the arguments and "open" the For loop, then get the arguments and open the nested loop, do the content and stuff, then close both loops? Or open the main loop, and where the relationship fields are needed, open the nested loop?
August 18, 2022 at 10:19 AM #37555Long Nguyen
ModeratorHi,
In my experience, you just need to set the argument and open a loop where you need to show list posts. Don't open a loop in the top or middle of the code where you do not need to show the posts.
-
AuthorPosts
- You must be logged in to reply to this topic.