Relating node fields to nodes, and using computer fields to do math with them

Rosamunda - May 11, 2008 - 18:06
Project:Content Construction Kit (CCK)
Version:5.x-1.7
Component:nodereference.module
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hello there!
Is there a way to relate a certain field, of a certain node to a node?
And is there a way to do this with multiple fields, all belonging to certain nodes?

Example

I´ve got a cck nodetype called "users" which has these fields:
name
percentage
taxonomy

And I´ve created four nodes of these nodetype like this:

name: John
percentage: 5%
secelct course (taxonomy): school_course_A

name: Mat
percentage: 10%
secelct course (taxonomy): school_course_A

name: Martha
percentage: 8%
secelct course (taxonomy): school_course_A

name: Jim
percentage: 5%
secelct course (taxonomy): school_course_A

Now, I´ve got another cck nodetype called "tasks", which has these fields:
select month (taxonomy):
select year (taxonomy):
secelct course (taxonomy):
total_tasks:

I´ve created a node from this type called "january tasks" which is filled this way:
select month (taxonomy): january
select year (taxonomy): 2008
secelct course (taxonomy): school_course_A
total_tasks: 1000 points (integer)

Is there a way that I could relate to this certain node "january tasks" the percentages (integers), so I could compute which percentage of the total task has each student?
This way I could have a view that shows in a table something like:

In january of 2008. Course selected: course A
John has made the 5% of the task, so he has: 5 points
Mat has made the 10% of the task, so he has: 10 points
Martha has made the 8% of the task, so he has: 8 points
Jim has made the 5% of the task, so he has: 5 points

Is there a way to relate fields this way?

Thanks for your comments and thoughts!

Rosamunda

#1

jfall - May 11, 2008 - 18:33

Hi again!
ummmm, don't take my word for it, but I do think that this time you are going to need some custom code... I just don't see the abstraction here that would present a general purpose module.
Two SQL queries (one for each node type, filtered by the select course taxonomy term) and a loop over all the user nodes to extract the data & format the output should do the trick... If you haven't got it yet, get the Pro Drupal Development book - I wouldn't start coding in Drupal without it. If you are stuck and don't want to write the code yourself, perhaps write the spec up clearly and post it on the jobs list - it looks like a fairly small job at first blush.
Good luck.

#2

nevets - May 11, 2008 - 18:52

Maybe, but it depends on what you want to achieve, you result table

In january of 2008. Course selected: course A
John has made the 5% of the task, so he has: 5 points
Mat has made the 10% of the task, so he has: 10 points
Martha has made the 8% of the task, so he has: 8 points
Jim has made the 5% of the task, so he has: 5 points

is not readily available from you users and tasks table (at least as I understand it).

You associate a task with a month, year and course. A user though has percentage only associated with a name and course (no month or year)
So what is not clear is what role month and year play.

If we ignore that we can add a calculated field to users to calculate points from percentage. Details would depend on what field types you are using (and probably the role month and year play)

I would also be tempted to use Automatic Nodetitles and name the tasks based on month.year.course and in users instead of using a taxonomy field to reference the course use a node reference field to reference a task (though this depends on what the users table is meant to reflect)

#3

Rosamunda - May 11, 2008 - 19:40

Thanks both of you guys! Now I think I´ve got a fairly clear idea of what should, and shouldn´t expect to achieve with nodereference.

I want to clear a few things about the month/year thing:
Each user have a determined percentage that will not vary. If Martha has 8%, she will have it to the end of times ;)

So, what will vary in fact, is the "total task" points each month.
One month (january 2008), it would be 1000, but another one (feb. 2008) could be 1260.
So Martha will have to get 8% of 1260.

That´s why I thought of the month/year taxonomy, so I would be able to filter martha´s points by month.

I´ve recently got my copy of Pro Drupal Development, but it´s not an easy task, as I´m not php expert (not at all!).

I´ll post it to the jobs announcements if I can´t get it done, but I really wanna try it out first.

So, what would be your suggestion? Should I start with a new module from scratch?, or could I reformulate something that already exists?

Maybe starting with an existing module will consume more time, because ´ll need to get acquainted with it first... but then again, I´ve not any coder experience, nor I´ve ever wrote a module before.

Thanks for your help and suggestions!!!

Rosamunda

#4

jfall - May 14, 2008 - 03:23
Category:task» support request

Personally, I would not recommend trying to write a Drupal module as your first PHP programming experience. I think its just expecting too much.
That said - I have a little extra time to help you out if you like... but we should take this discussion off of the issue queue as this is not really a CCK issue. You can contact me through my contact form and I'll e-mail you back.

#5

KarenS - May 14, 2008 - 09:29

You should check out Computed Field for a way to create a CCK field that contains computed values or Views Calc, which has ways to do calculations in Views.

#6

KarenS - May 14, 2008 - 09:30
Status:active» fixed

#7

Anonymous (not verified) - May 28, 2008 - 09:33
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.