Alright. So my previous question isn't going to get help (only because I'm not sure there's anything that can be done about it)
So I'm going to move forward.
Given 3 node types, A, B, C.
Node A has a nodereference (only allowing one reference) to node type B. Node type B has a nodereference field that can link to unlimited type C nodes.
I want to have a section in Node A which is text. The text will have unlimited values. But the values should be automatically calculated (using computed field module).
the computed field module allows the entering of php code, but I'm not sure how to create it. The script should go to the reference of Node B, and return the title of each Node C which B refers to.
So given this situation.
C Node titles:
cnodetitle1
cnodetitle2
cnodetitle3
cnodetitle4
And an instance of Node B, bnodetitle, which has a reference to cnodetitle2, and cnodetitle4
A user then creates a Node type A, and references bnodetitle. The text field for A will automatically get the values "cnodetitle2" and "cnodetitle4".
I've tried to abstract the problem a bit. I think once I have this, I should be able to work out how to do the rest.
Thanks,
Matt
Comments
Whats your actual goal, what
Whats your actual goal, what do you want to achieve, how are you going to use the information?
My goal is to have the
My goal is to have the information from Node C in Node A. I could have it so it needs to be re-entered, but it would be redudent. But I don't know drupal well enough to do this. I need something like
//some sort of psudo-code, non php
String[]values = this.getB().getAllC(); // returns an array of the titles of all referenced nodes in B
something like that, to an extent.
I should be able to figure things out once I understand how to do that. Return an array of all the values of type
Users of the site will need to create content of type A. But they don't have access to create types B or C. Type B needs to have the links to C, and not A.
But the user creating a type A should have a very fast and easy way to know what information they're using.
Right. So Say C is "LearningObjectives", B is "Course", and A is "TermReview". this is essentially what I am doing.
The Learning objectives can be attached to any number of courses, and any course can teach any learning objective.
But there will be users that will be creating a TermReview, in which they will rate how well students understood each learning objective. They shouldn't have to go to the course, look at the objectives, type them each out, and then append a rating. This should be quicker, and not take much time.
But the abstraction on how to access that data with php code is all I need. I only really need to be able to get the title. The learning objectives only field is the title.
It sounds to me that you want
It sounds to me that you want to be able to display the information of 'B' and 'C' when looking at content type of 'A'.
In that case since A's have node references to B's, you could on pages of type 'A', show full nodes of type 'B' for the reference. For content of type 'B' you can configure its node reference of type 'C' to list the titles.
The point being, I am not sure you really need to store the C's in A, though I may be missing some details.
more info?
Hi Matthew -
I appreciate what you are doing... I might be able to help, but I'm thinking only a 50/50 chance at this point... I've always had a dickens of a time with the calculated fields.
I write db_queries() all the time and use CCK, so I may be able to give some ideas and pointers.
I need more info, though. How are Courses related to TermReviews? E.g, How do we know which courses belong to a TermReview? Or do we always want ALL courses and ALL LearningObjectives displayed in every instance of creating/editing a TermReview?
A TermReview is reviewing a
A TermReview is reviewing a course. And it's reviewing it in the sense that it's giving the user an option to rate each LearningObjective from the course. And the course is found from a nodereference field in the TermReview.
Basic Logic
Ah, very good. So, the code logic and sequence would be:
1) lookup the course record using the node id we have in the node reference field;
2) lookup all learning objectives connected with that one course;
3) loop thru those each learning objective records and get the title;
4) concatenate all these titles into one string;
5) use this string as the default text for a text-area field where the user will be typing their assessments.
Do I understand the goal correctly?
Yes. Although the slight
Yes.
Although the slight difference, is I would want each title to have it's own delta, as opposed to having one huge string, if possible.
But yes, that's what I want to do.
PHP programmer?
This gets into not just db queries, but also CCK array structs *which can change if the CCK fields are changed* and thus break the code. Plus, creating additional instances of fields on-the-fly in a form from a calculated field PHP snippet would be a bit of a trick.
I'm guessing you aren't a PHP programmer, which means that even if we could get a PHP snippet of code right and working for the system config you have now (which would take some work), you wouldn't be able to maintain it through updates and changes.
If I'm right, and you aren't a PHP programmer, then a better approach would be to skip the PHP / calculated fields and find a way to do it using standard CCK.
How would it be, for example, to have a "review" node type that has a user reference to select the student, a node reference to select the course , and then a node reference to select the learning objective? Teachers would create and complete one "review" for each learning objective in the course. Would that do the trick?
The schematics of this
The schematics of this project are pretty laid out, and I can't change the structure.
I am not specifically a php programmer, although I am a programmer. I know java, C/C++, bash, bits of PHP and SQL (standard). I've also looked a bit at Objective-C and C#.
And the only reason I don't know php better is I havn't used it a whole lot. But it's fairly simple. I just need to know the syntax I would need to use. If I were to have that (with a few comments) I'd understand what was going on, and the php side of things wouldn't be an issue.
And anything I don't know for php is just a quick google search away, for the things that aern't the same as every other programming language :P
I'm working on a completely different option right now though.
See, the problem comes from a course having many SLO's. There would be far too many SLO's to search through, and you likely wouldn't know the names of existing ones. I made a view however, which will show you only the learning objectives for a particular course. It works, via arguments, or exposed filter. The problem is, when I use the view for the advanced option for selecting which nodes can be referenced, I don't have access to the exposed filter/arguments. If I could put in say,
www.website.com?q=node/add/feedback-term/%course_code/%course_number
and have the options for learning objectives be limited to the view, then everything would be great. But that's not working. Maybe it's something I'm missing, in terms of settings.
But yea, either that works, or I need to go the php route. And I'm not going to say no just for lack of php experience... See, this is a project for an employer. It's my first time using drupal (or any web development actually), and it's really good. The thing is though, if I can't get this functionality that is required out of drupal, I'll have to start over, with straight html/php/mysql - no drupal. So yea, my options are use php, or use more php haha.
But the multiple fields isn't a must, it could have just a text field, with each objective on it's own line. I could then extract the ratings when needed via php script, and do the nescessary calculations.
And thanks for helping,
Matt
basics & overview; info for query build
Hey Matt -
Good to hear; you're in good shape to dive deep into Drupal. Thanks for the extra fill-in info; It's hard to know the tech level of someone on the the boards.
The passing-multiple-parms to the view is a great approach; I think there may be a method for getting that to work. If there isn't yet, I'll bet it's part of the Views development path to make it so. What we need is a Views guru to tell us (a) can you pass multiple parms to a view like you need to, and (b) the way to configure it to work. I'll do some research there as well; I've needed something similar in the past (I tried it back in Drupal 5.x and gave up) and it'd be handy to know.
On the code side, you'll want to see the structure of the $node arrays to find the element you want. I use something like this:
From there you can find the name of the field used in the content type for the node reference back to the courses.
So that's how your code can access and compare the reference id's. Check your MySQL table structures to find the name of the field holding the node id reference. Let me know the table name and the field names of the node reference fields in the course and learning objectives records, and we can form up a SQL query for you.