Group element count

zebrafilm

Member
In my form, every group has its own page and in the last element I have to calc a 'score' of the previous entered radio buttons.
Part of the calculation is to check what the max score per radio button could be, (always the first one)
Since they (most of the time) have a value of 10, I could count the elements within the group and multiply with 10 to get the max score.
Question 1: is there a way to get the amount of elements in group?
Question 2: if so, I assume I will have to deduct the score elements?

I guess the better way would be to check all those first values with a for/next loop if I want to make sure I get the right values but I am afraid it slows down the whole thing. Any other tips?
 
hi A javascript method wouldn't slow things down really, and I think it makes more sense to loop over the actual elements and get the correct data. If you point me at the url then I'd be happy to propose the js you would need to total the scores

-Rob
 
Suggestions more than welcome, first JS books are on the ipad for study but examples are always bigger steps :)

Site http://prescan.santt.nl.10-0-1-85.lnxsvr.eu/ (In my site profile with pw.)

Front end (need to log in)
http://prescan.santt.nl.10-0-1-85.lnxsvr.eu/invoer/prescan-1-invoer

Client goes through every page clicking the answer.
For every page/group I need to make a 'weighting'.

Currently in the 'score' element (showing on the first 1.1.1 page) contains this calc.
================
//Take the maximum score (all first answers combined) should be automatically in an ideal world.
$Max=60;

// Grab trigger points (temp values now but should come from another list )
$C1=50;
$C2=30;
$C3=0;

//"Score' values (will come from other list)
$SC1=7;
$SC2=5;
$SC3=0;


//count the total of all answers, this is what would be nice to create a 'group' total without entering all fields
//=======================
$S=(int)'{prescan1___1_1_1_1_raw}'+(int)'{prescan1___1_1_1_2_raw}'+(int)'{prescan1___1_1_1_3_raw}'+(int)'{prescan1___1_1_1_4_raw}'+(int)'{prescan1___1_1_1_5_raw}'+(int)'{prescan1___1_1_1_6_raw}';

//Make a percentage score
$S= 100/($Max/$S);

//Return the end value;
if ($S >=$C1)
{
return $SC1;
}
elseif ($S >=$C2)
{
return $SC2;
}
else
{
return $SC3;
}

My first intention was to make this calculation within the form but I also need to make many more calculations so it might better to create on 'report' page and add all calc elements there.
 
could you double check the Joomla account you gave as I can't log in with it.
 
If you need to do look ups on the database then an ajax calc element makes more sense than doing it via js. So pretty much what you are already doing in the calc element '1_1_1_score'

Question 1: is there a way to get the amount of elements in group?
This is the best I could come up with:

PHP:
// Build the group ref from the element name
$name = $this->getFullName(true, false);
$name = explode('_', $name);
array_pop($name);
// E.g. group ref is 'prescan1___1_1_1'
$groupRef = implode('_', $name);
 
// Loop over the posted data to add the scores (ignoring any score element)
foreach ($data as $key => $value) {
  $pos = stripos($key, $groupRef);
    if ($pos === 0  && substr($key, -4) === '_raw') {
     if ($key != $groupRef . '_score' && $key != $groupRef . '_score_raw') {
        $S += (int) $value;
      }
  }
}
but it means that for each calc
Question 2: if so, I assume I will have to deduct the score elements?
The code above does that when it checks:

PHP:
 if ($key != $groupRef . '_score' && $key != $groupRef . '_score_raw') {
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top